📄 xcolor.c
字号:
#include <stdio.h>#include <stdarg.h>#include <string.h>#include <time.h>#include <ctype.h>#include <vibrant.h>#include "clustalw.h"#include "xmenu.h"#define SIMPLE 1#define COMPOUND 2#define LEFTMARGIN 20#define SEPARATION 2#define CHARHEIGHT 10#define CHARWIDTH 6#define A4X 564#define A4Y 800#define A3X 832#define A3Y 1159#define USLETTERX 564#define USLETTERY 750#define SCOREY 3#define HEADER 7#define NOHEADER 0#define MAXRESNO 6#define MAXPARLEN 10#define MAXPAR 100 static void print_ps_info(FILE *fd,int pagesize);static void print_page_header(FILE *fd,int ps_rotation,int maxx,int maxy,int page,int numpages,Boolean header,char *str_time,char *ps_file,int ps_xtrans,int ps_ytrans,float ps_scale);static void print_header_line(FILE *fd,panel_data name_data, panel_data seq_data,int ix,int fr,int lr);static void print_footer_line(FILE *fd,panel_data name_data, panel_data seq_data,int ix,int fr,int lr);static void print_quality_curve(FILE *fd,panel_data seq_data,int fr,int lr,int score_height);static void print_seq_line(FILE *fd,panel_data name_data, panel_data seq_data,int row,int seq,int fr,int lr,int res_number);typedef struct consensus_parameters{char consensus;int cutoff;int length;char cutoff_list[20];} consensus_para; typedef struct color_parameters{int type;char residue;int color;int length;char cons_list[20];} color_para;static void init_color_lut(FILE *fd);static int init_printer_lut(char *filename);static char *init_consensus(panel_data data);static int SaveColPara(char word[MAXPAR][MAXPARLEN],int num_words,int count);static int SaveConPara(char word[MAXPAR][MAXPARLEN],int num_words,int count);static int get_line(char *sinline,char word[MAXPAR][MAXPARLEN]);static int residue_color(char res,char consensus);static Boolean commentline(char *line);#define DEF_NCOLORS 4#define MAX_NCOLORS 8#define DEFAULT_COLOR 0typedef struct rgb_color { char name[20]; float r,g,b;} rgb_color;rgb_color def_color_lut[MAX_NCOLORS]={ "RED" ,0.9, 0.1, 0.1, "BLUE" ,0.1, 0.1, 0.7, "GREEN" ,0.1, 0.9, 0.1, "ORANGE" ,0.9, 0.6, 0.3, "CYAN" ,0.1, 0.9, 0.9, "PINK" ,0.9, 0.5, 0.5, "MAGENTA" ,0.9, 0.1, 0.9, "YELLOW" ,0.9, 0.9, 0.0,};char def_aacolor[MAX_NCOLORS][26]={"krh", "fwy", "ilmv", "gpst"};char def_dnacolor[MAX_NCOLORS][26]={"a", "c", "tu", "g"};extern char revision_level[];extern int max_names; extern int ncolors;extern int ncolor_pars;extern color color_lut[];extern int inverted;extern Boolean residue_exceptions;extern Boolean segment_exceptions;extern Boolean dnaflag;int NumColParas;int NumConParas;color_para Col_Par[100];consensus_para Con_Par[100];void make_colormask(panel_data data){ int i,j; for(i=0;i<data.nseqs;i++) for(j=0;j<data.ncols;j++) data.colormask[i][j] = DEFAULT_COLOR; if (ncolors > 1) { data.consensus=init_consensus(data); for(i=0;i<data.nseqs;i++) for(j=0;j<data.ncols;j++) data.colormask[i][j] = residue_color(data.lines[i][j],data.consensus[j]); }}static void init_color_lut(FILE *fd){ char sinline[1025]; char *args[10]; int i,numargs; Boolean found=FALSE; if (inverted==FALSE) { strcpy(color_lut[0].name,"BLACK"); color_lut[0].r=0.4; color_lut[0].g=0.4; color_lut[0].b=0.4; SelectColor(color_lut[0].r*255, color_lut[0].g*255, color_lut[0].b*255); color_lut[0].val=GetColor(); } else { strcpy(color_lut[0].name,"WHITE"); color_lut[0].r=1.0; color_lut[0].g=1.0; color_lut[0].b=1.0; SelectColor(color_lut[0].r*255, color_lut[0].g*255, color_lut[0].b*255); color_lut[0].val=GetColor(); } ncolors=1; if (fd != NULL) { for (;fgets(sinline,1024,fd)!=NULL;) { sinline[strlen(sinline)-1] = '\0'; if (strcmp(sinline,"@rgbindex")==0) { found = TRUE; break; } } } if (found == TRUE) { for (;fgets(sinline,1024,fd)!=NULL;) { if (commentline(sinline)) continue; if (sinline[0]=='@') break; numargs = getargs(sinline, args, 4); if (numargs != 4) { error("Problem in color rgb index - line %d\n",ncolors+1); break; } else { strcpy(color_lut[ncolors].name, args[0]); color_lut[ncolors].r=atof(args[1]); color_lut[ncolors].g=atof(args[2]); color_lut[ncolors].b=atof(args[3]); SelectColor(color_lut[ncolors].r*255, color_lut[ncolors].g*255, color_lut[ncolors].b*255); color_lut[ncolors].val=GetColor(); ncolors++; if (ncolors>=MAXCOLORS) { warning("Only using first %d colors in rgb index.",MAXCOLORS); break; } } } }/* if we can't find a table, use the hard-coded colors */ if (ncolors==1) { ncolors=MAX_NCOLORS+1; for(i=1;i<ncolors;i++) { strcpy(color_lut[i].name,def_color_lut[i-1].name); color_lut[i].r=def_color_lut[i-1].r; color_lut[i].g=def_color_lut[i-1].g; color_lut[i].b=def_color_lut[i-1].b; SelectColor(color_lut[i].r*255, color_lut[i].g*255, color_lut[i].b*255); color_lut[i].val=GetColor(); } }}void init_color_parameters(char *par_file){ int i,j,err; char sinline[1025]; int maxparas = 50; char inword[MAXPAR][MAXPARLEN]; int num_words; int in_consensus=FALSE,in_color=FALSE; int consensus_found=FALSE,color_found=FALSE; FILE *par_fd=NULL; if(par_file!=NULL) par_fd=fopen(par_file,"r"); if(par_fd==NULL) { info("No color file found - using defaults"); ncolor_pars=0; } init_color_lut(par_fd); if (par_fd != NULL) rewind(par_fd); if (ncolors==0) return; NumColParas=0; NumConParas=0; if (par_fd != NULL) { for(;fgets(sinline,1024,par_fd) != NULL;) { sinline[strlen(sinline)-1] = '\0'; if (commentline(sinline)) continue; switch(sinline[0]) { case '\0': break; case '@': if (strcmp((char*)(sinline+1),"consensus")==0) { in_consensus = TRUE; in_color = FALSE; consensus_found = TRUE; } else if (strcmp((char*)(sinline+1),"color")==0) { in_consensus = FALSE; in_color = TRUE; color_found = TRUE; } break; default: num_words = get_line(sinline,inword); if (in_consensus == TRUE) { err = SaveConPara(inword,num_words,NumConParas); if (err == 0) NumConParas++; } else if (in_color == TRUE) { err = SaveColPara(inword,num_words,NumColParas); if (err == 0) NumColParas++; } if((NumColParas>maxparas) || (NumConParas>maxparas)) error("Too many parameters in color file"); } } if (color_found == FALSE) { error("@color not found in parameter file - using defaults\n"); ncolor_pars=0; } fclose(par_fd); } ncolor_pars=NumColParas;/* if no color parameters found, use the default aa groupings */ if(ncolor_pars==0) { if (dnaflag) { for(i=0;i<DEF_NCOLORS;i++) { for(j=0;j<strlen(def_dnacolor[i]);j++) { Col_Par[ncolor_pars].type=SIMPLE; Col_Par[ncolor_pars].residue=def_dnacolor[i][j]; Col_Par[ncolor_pars].color=i+1; ncolor_pars++; } } } else { for(i=0;i<DEF_NCOLORS;i++) { for(j=0;j<strlen(def_aacolor[i]);j++) { Col_Par[ncolor_pars].type=SIMPLE; Col_Par[ncolor_pars].residue=def_aacolor[i][j]; Col_Par[ncolor_pars].color=i+1; ncolor_pars++; } } } } NumColParas=ncolor_pars;}char *find_file(char *def_file){ char filename[FILENAMELEN]; char *retname; FILE *fd; Boolean found=FALSE;#ifdef UNIX char *path, *path1, *deb, *fin; sint lf, ltot; char *home;#endif strcpy(filename,def_file); fd = fopen(filename,"r"); if (fd != NULL) found=TRUE;#ifdef UNIX if (found == FALSE) { home = getenv("HOME"); if (home != NULL) { sprintf(filename,"%s/%s",home,def_file); fd = fopen(filename,"r"); if (fd != NULL) found=TRUE; } if (found == FALSE) { path=getenv("PATH");/* get the list of path directories, separated by : */ /* added for File System Standards - Francois */ path1=(char *)ckalloc((strlen(path)+64)*sizeof(char)); strcpy(path1,path); strcat(path1,"/usr/share/clustalx:/usr/local/share/clustalx"); lf=(sint)strlen(def_file); deb=path1; do { fin=strchr(deb,':'); if(fin!=NULL) { strncpy(filename,deb,fin-deb); ltot=fin-deb; } else { strcpy(filename,deb); ltot=(sint)strlen(filename); } /* now one directory is in filename */ if( ltot + lf + 1 <= FILENAMELEN) { filename[ltot]='/'; strcpy(filename+ltot+1,def_file); /* now dir is appended with filename */ if( (fd = fopen(filename,"r") ) != NULL) { found=TRUE; break; } } else found = FALSE; deb=fin+1; } while (fin != NULL); } }#endif if (found == TRUE) { fclose(fd); retname=(char *)ckalloc((strlen(filename)+1)*sizeof(char)); strcpy(retname,filename); } else retname=NULL; return(retname);} static char *init_consensus(panel_data data){ char *cons_data; int num_res,seq,res,par,cons_total,i; char residue; cons_data=(char *)ckalloc((data.ncols+1)*sizeof(char)); for (res=0;res<data.ncols;res++) { cons_data[res] = '.'; for (par=0;par<NumConParas;par++) { cons_total = num_res = 0; for (seq=0;seq<data.nseqs;seq++) { residue=tolower(data.lines[seq][res]); if (isalpha(residue)) num_res++; for (i=0;i<Con_Par[par].length;i++) if (residue==tolower(Con_Par[par].cutoff_list[i])) cons_total++; } if (num_res != 0) if (((cons_total*100)/num_res) >= Con_Par[par].cutoff) cons_data[res] = Con_Par[par].consensus; } } return(cons_data);}static int SaveColPara(char word[MAXPAR][MAXPARLEN],int num_words,int count){ int i; if (num_words < 3) { error("Wrong format in color list"); return(1); } if (word[1][0] != '=') { error("Wrong format in color list"); return(2); } if (num_words == 3) { Col_Par[count].type = SIMPLE; Col_Par[count].residue = word[0][0]; Col_Par[count].color = -1; for (i=0;i<ncolors;i++) if (strcmp(word[2],color_lut[i].name)==0) Col_Par[count].color = i; if (Col_Par[count].color == -1) { error("%s not found in rgb index - using %s",word[2],color_lut[0].name); Col_Par[count].color = 0; } } else { if (strcmp(word[3],"if")==0) { Col_Par[count].type = COMPOUND; Col_Par[count].residue = word[0][0]; Col_Par[count].color = -1; for (i=0;i<ncolors;i++) if (strcmp(word[2],color_lut[i].name)==0) Col_Par[count].color = i; if (Col_Par[count].color == -1) { error("%s not found in rgb index - using %s",word[2],color_lut[0].name); Col_Par[count].color = 0; } Col_Par[count].length = num_words - 4; for (i=4;i<num_words;i++) Col_Par[count].cons_list[i-4] = word[i][0]; } else { error("Wrong format in color list"); return(3); } } return(0); }static int SaveConPara(char word[MAXPAR][MAXPARLEN],int num_words,int count){ int i; if (num_words < 3) { error("Wrong format in consensus list"); return(1); } if (word[1][0] != '=') { error("Wrong format in consensus list"); return(2); } Con_Par[count].consensus = word[0][0]; for (i=0;i<MAXPARLEN-1;i++) { if(word[2][i]=='%') word[2][i] = '\0'; } Con_Par[count].cutoff = atoi(word[2]); Con_Par[count].length = num_words - 3; for (i=3;i<num_words;i++) { Con_Par[count].cutoff_list[i-3] = word[i][0]; } return(0); }static int get_line(char *sinline,char word[MAXPAR][MAXPARLEN]){ int i=0, j, word_count=0, char_count=0; int in_word=FALSE; for(i=0;i<MAXPAR-1;i++) for(j=0;j<MAXPARLEN-1;j++) word[i][j]='\0'; for (i=0;i<=strlen(sinline);i++) { switch (sinline[i]) { case ' ': case '\t': case '\0': case ':': if (in_word) { word[word_count][char_count] = '\0'; word_count++; char_count = 0; in_word = FALSE; } break; default: in_word = TRUE; word[word_count][char_count] = sinline[i]; char_count++; break; } } return(word_count);}static int residue_color(char res,char consensus){ int i,j; for (i=0;i<NumColParas;i++) { if (tolower(res) == tolower(Col_Par[i].residue)) { switch (Col_Par[i].type) { case SIMPLE: return(Col_Par[i].color); case COMPOUND: for (j=0;j<Col_Par[i].length;j++) { if (consensus == Col_Par[i].cons_list[j])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -