⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcolor.c

📁 经典生物信息学多序列比对工具clustalw
💻 C
📖 第 1 页 / 共 2 页
字号:
                                                return(Col_Par[i].color);                                }                                break;                        default:                                return(DEFAULT_COLOR);                        }                }        }        return(DEFAULT_COLOR);}static Boolean commentline(char *line){        int i; 	if (line[0] == '#') return TRUE;        for(i=0;line[i]!='\n' && line[i]!=EOS;i++) {                if( !isspace(line[i]) )                        return FALSE;        }        return TRUE;}int block_height,block_left,block_top;int header_top,seq_top,footer_top,curve_top;void write_ps_file(spanel p,char *ps_file,char *par_file,int pagesize,int orientation,Boolean header, Boolean ruler, Boolean resno, Boolean resize,int first_printres,int last_printres,int blength,Boolean show_curve){	int i,j,bn,seq,numseqs;	int err;	int blocklen,numpages;	int fr,lr;	int page,row;	int ps_rotation=0,ps_xtrans=0,ps_ytrans=0;	float ps_scale,hscale,wscale;	int maxseq;	int maxx=0,maxy=0;	int score_height=0;	int main_header=0;	int numelines,numecols;	int nhead,nfoot;	int ppix_width;    /* width of the page in pixels */	int pchar_height;    /* height of the page in chars for sequences */	int ppix_height;    /* height of the page in pixels for sequences */        int blocksperpage,numblocks;	int *res_number;	panel_data name_data,seq_data;	FILE *fd;	time_t *tptr=NULL,ttime;	char *str_time;/* open the output file */	if ((fd=fopen(ps_file,"w"))==NULL)	{		error("Cannot open file %s",ps_file);		return;	}/* check for printer-specific rgb values */	err=init_printer_lut(par_file);	if(err>0) warning("No PS Colors file: using default colors\n");/* get the page size parameters */	if (pagesize==A4)	{		if (orientation==PORTRAIT)		{			maxx=A4X;			maxy=A4Y;			ps_rotation=0;		}		else		{			maxx=A4Y;			maxy=A4X;			ps_rotation=-90;		}	}	else if (pagesize==A3)	{		if (orientation==PORTRAIT)		{			maxx=A3X;			maxy=A3Y;			ps_rotation=0;		}		else		{			maxx=A3Y;			maxy=A3X;			ps_rotation=-90;		}	}	else if (pagesize==USLETTER)	{		if (orientation==PORTRAIT)		{			maxx=USLETTERX;			maxy=USLETTERY;			ps_rotation=0;		}		else		{			maxx=USLETTERY;			maxy=USLETTERX;			ps_rotation=-90;		}	}	if(show_curve) score_height=SCOREY;	if(header) main_header=HEADER;	else main_header=NOHEADER;        ppix_width=maxx-LEFTMARGIN*2;        ppix_height=maxy-main_header*CHARHEIGHT;/* get the name data */	GetPanelExtra(p.names,&name_data);/* get the sequence data */	GetPanelExtra(p.seqs,&seq_data);	numseqs=seq_data.nseqs;	nhead=seq_data.nhead;	if(ruler)		nfoot=seq_data.nfoot;	else		nfoot=seq_data.nfoot-1;	numelines=nhead+nfoot+score_height+SEPARATION;/* check the block length, residue range parameters */	if(first_printres<=0)		first_printres=1;	if((last_printres<=0) || (last_printres>seq_data.ncols))		last_printres=seq_data.ncols;	if(first_printres>last_printres)	{		error("Bad residue range - cannot write postscript");		return;	}	if (blength==0 || last_printres-first_printres+1<blength) 		blocklen=last_printres-first_printres+1;	else		blocklen=blength;	res_number=(int *)ckalloc((name_data.nseqs+1)*sizeof(int));	for(i=0;i<name_data.nseqs;i++)	{		res_number[i]=0;		for(j=0;j<first_printres-1;j++)			if(isalpha(seq_data.lines[i][j])) res_number[i]++;	}	if(resno)		numecols=MAXRESNO+1+max_names;	else		numecols=1+max_names;/* print out the PS revision level etc. */	ttime = time(tptr);	str_time = ctime(&ttime);	print_ps_info(fd,pagesize);/* calculate scaling factors, block sizes to fit the page etc. */        if (resize==FALSE || blocklen==last_printres-first_printres+1)        {/* split the alignment into blocks of sequences. If the blocks are too longfor the page - tough! */		if(resize==FALSE)                	ps_scale=1.0;		else			ps_scale=(float)ppix_width/(float)((blocklen+numecols)*CHARWIDTH);		ps_xtrans= LEFTMARGIN * (1-ps_scale);		ps_ytrans= ppix_height * (1-ps_scale);		if (pagesize!=A3 && orientation==LANDSCAPE)			ps_xtrans-=LEFTMARGIN;        	pchar_height=((maxy/CHARHEIGHT)-main_header)/ps_scale;        	maxseq=pchar_height-numelines;		block_height = (maxseq+numelines) * CHARHEIGHT;		numpages = (numseqs/maxseq) + 1;		seq=0;		for (page=0;page<numpages;page++)		{/* print the top of page header */			print_page_header(fd,ps_rotation,maxx,maxy,			   page,numpages,header,str_time,			   ps_file,ps_xtrans,ps_ytrans,ps_scale);			block_top = maxy - main_header*CHARHEIGHT;			block_left = LEFTMARGIN + (1+max_names)*CHARWIDTH; 			header_top = block_top;			fr=first_printres-1;			lr=last_printres-1;/*  show the header lines */			for (i=0;i<nhead;i++)				print_header_line(fd,name_data,seq_data,i,fr,lr);			seq_top = block_top-nhead*CHARHEIGHT;/*  show the sequence lines */			for (row=0;row<maxseq ;row++)			{				if(resno)				{					for(i=fr;i<=lr;i++)						if(isalpha(seq_data.lines[seq][i]))							res_number[seq]++;				}				print_seq_line(fd,name_data,seq_data,row,seq,fr,lr,res_number[seq]);				seq++;				if(seq>=numseqs)				{					row++;					break;				}			}			footer_top = seq_top-row*CHARHEIGHT;/*  show the footer lines */			for (i=0;i<nfoot;i++)				print_footer_line(fd,name_data,seq_data,i,fr,lr);			curve_top = footer_top-nfoot*CHARHEIGHT;/* show the quality curve */			if(show_curve)				print_quality_curve(fd,seq_data,fr,lr,score_height);			fprintf(fd,"\nshowpage\n");			fprintf(fd,"restore\n");		}        }        else        {/* split the alignment into blocks of residues, and scale the blocks to fit the page */        	maxseq=ppix_height/CHARHEIGHT-numelines-main_header;		hscale=(float)maxseq/(float)numseqs;		wscale=(float)ppix_width/(float)((blocklen+numecols)*CHARWIDTH);                ps_scale=MIN(hscale,wscale);		ps_xtrans= LEFTMARGIN * (1-ps_scale);		ps_ytrans= ppix_height * (1-ps_scale);		if (pagesize!=A3 && orientation==LANDSCAPE)			ps_xtrans-=LEFTMARGIN;        	pchar_height=((maxy/CHARHEIGHT)-main_header)/ps_scale;        	maxseq=pchar_height-numelines;		block_height = (numseqs+numelines) * CHARHEIGHT;		blocksperpage = pchar_height/(numseqs+numelines);		if (blocksperpage==0)		{			error("illegal combination of print parameters");			return;		}		numblocks = (last_printres-first_printres) / blocklen + 1;        	if (numblocks % blocksperpage == 0)			numpages = numblocks / blocksperpage;        	else			numpages = numblocks / blocksperpage + 1;		for (bn=0;bn<numblocks;bn++)		{			page = bn / blocksperpage;/* print the top of page header */			if (bn % blocksperpage == 0)				print_page_header(fd,ps_rotation,maxx,maxy,			   	page,numpages,header,str_time,			   	ps_file,ps_xtrans,ps_ytrans,ps_scale);			block_top = maxy - main_header*CHARHEIGHT-block_height*(bn%blocksperpage);			block_left = LEFTMARGIN + (1+max_names)*CHARWIDTH; 			header_top = block_top;			seq_top = block_top-nhead*CHARHEIGHT;			footer_top = block_top-(nhead+numseqs)*CHARHEIGHT;			curve_top = block_top-(nhead+numseqs+nfoot)*CHARHEIGHT;			fr=first_printres-1 + blocklen*bn;			lr=fr+blocklen-1;			if(lr>=last_printres) lr=last_printres-1;/*  show the header lines */			for (i=0;i<nhead;i++)				print_header_line(fd,name_data,seq_data,i,fr,lr);/*  show the sequence lines */			for (i=0;i<numseqs;i++)			{				row = i % maxseq;				if(resno)				{					for(j=fr;j<=lr;j++)						if(isalpha(seq_data.lines[i][j]))							res_number[i]++;				}				print_seq_line(fd,name_data,seq_data,row,i,fr,lr,res_number[i]);			}/*  show the footer lines */			for (i=0;i<nfoot;i++)				print_footer_line(fd,name_data,seq_data,i,fr,lr);/* show the quality curve */			if(show_curve)				print_quality_curve(fd,seq_data,fr,lr,score_height);			if ((bn == (numblocks-1)) || ((bn % blocksperpage == blocksperpage-1)))			{				fprintf(fd,"\nshowpage\n");				fprintf(fd,"restore\n");			}		}	}	fclose(fd);	return;}static int init_printer_lut(char *filename){ 	FILE *fd;	char sinline[1025];	char *args[10];	char name[20];	int i,numargs;	Boolean found=FALSE;	char *par_file=NULL;/* reset the printer rgb colors to the color file rgb values */	for(i=0;i<ncolors;i++)	{		color_lut[i].pr=color_lut[i].r;		color_lut[i].pg=color_lut[i].g;		color_lut[i].pb=color_lut[i].b;	}/* search for the printer color file */	if(filename[0]==EOS) return 1;	par_file=find_file(filename);	if(par_file==NULL)	{		error("Cannot find printer file %s",filename);		return 1;	}	if ((fd=fopen(par_file,"r"))==NULL)	{		error("Cannot open printer file %s",par_file);		return 1;	}	for (;fgets(sinline,1024,fd)!=NULL;)	{		if (commentline(sinline)) continue;		numargs = getargs(sinline, args, 4);		if (numargs != 4)		{			error("Problem in parameter file - line %d\n",ncolors+1);			break;		}		else		{/* we've found a color - find the index the color lut */			strcpy(name, args[0]);			for(i=0;i<ncolors;i++)			{				if(strcmp(name,color_lut[i].name)==0)				{					color_lut[i].pr=atof(args[1]);					color_lut[i].pg=atof(args[2]);					color_lut[i].pb=atof(args[3]);				}			}		}	}	ckfree(par_file);	return 0;}static void print_ps_info(FILE *fd,int pagesize){	fprintf(fd,"%%!PS-Adobe-1.0\n");	fprintf(fd,"%%%%Creator: Julie Thompson\n");	fprintf(fd,"%%%%Title:ClustalX Alignment\n");	fprintf(fd,"%%%%EndComments\n");	fprintf(fd,"/box { newpath\n");	fprintf(fd,"\t-0 -3 moveto\n");	fprintf(fd,"\t-0 %d lineto\n",CHARHEIGHT-3);	fprintf(fd,"\t%d %d lineto\n",CHARWIDTH,CHARHEIGHT-3);	fprintf(fd,"\t%d -3 lineto\n",CHARWIDTH);	fprintf(fd,"\tclosepath\n");	fprintf(fd,"      } def\n\n");		fprintf(fd,"/color_char { gsave\n");	fprintf(fd,"\tsetrgbcolor\n");	fprintf(fd,"\tmoveto\n");	fprintf(fd,"\tshow\n");	fprintf(fd,"\tgrestore\n");	fprintf(fd,"      } def\n\n");		fprintf(fd,"/cbox { gsave\n");	fprintf(fd,"\ttranslate\n");	fprintf(fd,"\tnewpath\n");	fprintf(fd,"\t0 0 moveto\n");	fprintf(fd,"\tlineto\n");	fprintf(fd,"\tlineto\n");	fprintf(fd,"\tlineto\n");	fprintf(fd,"\tclosepath\n");	fprintf(fd,"\tfill\n");	fprintf(fd,"\tgrestore\n");	fprintf(fd,"      } def\n\n");	fprintf(fd,"/color_inv { gsave\n");	fprintf(fd,"\tsetrgbcolor\n");	fprintf(fd,"\ttranslate\n");	fprintf(fd,"\tbox fill\n");	fprintf(fd,"\tgrestore\n");	fprintf(fd,"\tmoveto\n");	fprintf(fd,"\tshow\n");	fprintf(fd,"      } def\n\n");        fprintf(fd,"/white_inv { gsave\n");        fprintf(fd,"\tsetrgbcolor\n");        fprintf(fd,"\ttranslate\n");        fprintf(fd,"\tbox fill\n");        fprintf(fd,"\tgrestore\n");        fprintf(fd,"\tgsave\n");        fprintf(fd,"\tsetrgbcolor\n");        fprintf(fd,"\tmoveto\n");        fprintf(fd,"\tshow\n");        fprintf(fd,"\tgrestore\n");        fprintf(fd,"      } def\n\n");	if (pagesize==A3)		fprintf(fd,"statusdict begin a3 end\n\n");/* For canon color printer, use a3tray instead of a3!! */}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){	int ps_x,ps_y;	char tstr[50];	fprintf(fd,"%%%%Page: P%d\n",page);	fprintf(fd,"save\n\n");	if (ps_rotation==-90)	{		fprintf(fd,"0 %d translate\n",maxx);		fprintf(fd,"%d rotate\n",ps_rotation);	}	if (header)	{		sprintf(tstr,"CLUSTAL %s MULTIPLE SEQUENCE ALIGNMENT",revision_level);		ps_x = (maxx-strlen(tstr)*10)/2;		ps_y = maxy - 2*CHARHEIGHT;		fprintf(fd,"%d %d moveto\n",ps_x,ps_y);		fprintf(fd,"/Times-Bold findfont 14 scalefont setfont\n");		fprintf(fd,"(%s) show\n\n",tstr);		ps_x = 20;		ps_y = maxy - 4*CHARHEIGHT;		fprintf(fd,"%d %d moveto\n",ps_x,ps_y);		fprintf(fd,"(File: %s) show\n\n",ps_file);		sprintf(tstr,"Date: %s",str_time);		ps_x = maxx-strlen(tstr)*8-20;		ps_y = maxy - 4*CHARHEIGHT;		fprintf(fd,"%d %d moveto\n",ps_x,ps_y);		fprintf(fd,"(%s) show\n\n",tstr);		sprintf(tstr,"Page %d of %d",page+1,numpages);		ps_x = 20;		ps_y = maxy - 5*CHARHEIGHT-4;		fprintf(fd,"%d %d moveto\n",ps_x,ps_y);		fprintf(fd,"(%s) show\n\n",tstr);	}		fprintf(fd,"%d %d translate\n",ps_xtrans,ps_ytrans);	fprintf(fd,"%#3.2f %#3.2f scale\n",ps_scale,ps_scale);	fprintf(fd,"/Courier-Bold findfont 10 scalefont setfont\n");}static void print_header_line(FILE *fd,panel_data name_data, panel_data seq_data,int ix,int fr,int lr){	int i;	int ps_x,ps_y;	ps_x = LEFTMARGIN;	ps_y = header_top - (ix * CHARHEIGHT);	fprintf(fd,"%d %d moveto\n",ps_x,ps_y);	fprintf(fd,"(%*s ) show\n",max_names,name_data.header[ix]);	for(i=fr;i<=lr;i++)	{		ps_x = block_left + (i-fr) * CHARWIDTH; 		fprintf(fd,"(");		fprintf(fd,"%c",seq_data.header[ix][i]);		fprintf(fd,") ");		fprintf(fd,"%d %d %d %d 1.0 1.0 1.0 color_inv\n",ps_x,ps_y,ps_x,ps_y);	}	fprintf(fd,"\n");}static void print_footer_line(FILE *fd,panel_data name_data, panel_data seq_data,int ix,int fr,int lr){	int i;	int ps_x,ps_y;	ps_x = LEFTMARGIN;	ps_y = footer_top - (ix * CHARHEIGHT);	fprintf(fd,"%d %d moveto\n",ps_x,ps_y);	fprintf(fd,"(%*s ) show\n",max_names,name_data.footer[ix]);	for(i=fr;i<=lr;i++)	{		ps_x = block_left + (i-fr) * CHARWIDTH; 		fprintf(fd,"(");		fprintf(fd,"%c",seq_data.footer[ix][i]);		fprintf(fd,") ");		fprintf(fd,"%d %d %d %d 1.0 1.0 1.0 color_inv\n",ps_x,ps_y,ps_x,ps_y);	}	fprintf(fd,"\n");}static void print_quality_curve(FILE *fd,panel_data seq_data,int fr,int lr,int score_height){	int i,w,h;	int ps_x,ps_y,curve_bottom;	w=CHARWIDTH;	ps_x = block_left+CHARWIDTH;       	curve_bottom=curve_top-score_height*CHARHEIGHT;	fprintf(fd,"0.3 0.3 0.3 setrgbcolor\n");	for(i=fr+1;i<=lr;i++)	{		fprintf(fd,"%d %d moveto\n",ps_x,curve_bottom);       		h=score_height*CHARHEIGHT*((float)seq_data.colscore[i]/100.0);		if(h<1) h=1;		fprintf(fd,"%d 0 %d %d 0 %d %d %d cbox\n",w,w,h,h,ps_x,curve_bottom);		ps_x+=CHARWIDTH;	}	fprintf(fd,"0.0 0.0 0.0 setrgbcolor\n");}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){	int i,color;	int ps_x,ps_y;	float red, green, blue;	ps_x = LEFTMARGIN;	ps_y = seq_top - (row * CHARHEIGHT);	fprintf(fd,"%d %d moveto\n",ps_x,ps_y);	fprintf(fd,"(%*s ) show\n",max_names,name_data.lines[seq]);	for(i=fr;i<=lr;i++)	{		color = seq_data.colormask[seq][i];		red = color_lut[color].pr;		green = color_lut[color].pg;		blue = color_lut[color].pb;		ps_x = block_left + (i-fr) * CHARWIDTH; 		fprintf(fd,"(");		fprintf(fd,"%c",seq_data.lines[seq][i]);		fprintf(fd,") ");                if(segment_exceptions && seq_data.segment_exception[seq][i] > 0)                {                       fprintf(fd,"%d %d %1.1f %1.1f %1.1f %d %d %1.1f %1.1f %1.1f white_inv\n",				ps_x,ps_y,1.0,1.0,1.0,ps_x,ps_y,0.1,0.1,0.1);                }                else if(residue_exceptions && seq_data.residue_exception[seq][i] == TRUE)                {                       fprintf(fd,"%d %d %1.1f %1.1f %1.1f %d %d %1.1f %1.1f %1.1f white_inv\n",				ps_x,ps_y,1.0,1.0,1.0,ps_x,ps_y,0.4,0.4,0.4);                }                else                {                       if(inverted)                              fprintf(fd,"%d %d %d %d %1.1f %1.1f %1.1f color_inv\n",				ps_x,ps_y,ps_x,ps_y,red,green,blue);                       else                              fprintf(fd,"%d %d %1.1f %1.1f %1.1f color_char\n",				ps_x,ps_y,red,green,blue);                }	}	if(res_number>0)	{		ps_x = block_left + (lr-fr+1) * CHARWIDTH; 		ps_y = seq_top - (row * CHARHEIGHT);		fprintf(fd,"%d %d moveto\n",ps_x,ps_y);		fprintf(fd,"(%*d) show\n",MAXRESNO,res_number);	}	fprintf(fd,"\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -