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

📄 highlight.cc

📁 unix或linux下的DNA分析软件源码 其功能如下 1. Edit up to 256 peptide or DNA sequences simultaneously. 2. Transla
💻 CC
📖 第 1 页 / 共 2 页
字号:
//-------------------------------------------------------------------------//// highlight.cc                                                            //// latest revision: 07-11-2000                                             //// Copyright (C) 2000 by Thomas J. Nelson                                  ////-------------------------------------------------------------------------//#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#define min(a,b) (((a)<(b)) ? (a) : (b))#define max(a,b) (((a)>(b)) ? (a) : (b))enum{ TITLE, BOX, COMMENT, LABEL, TEXT };char *getstring(char* heading, char* string, char *defstring);int getint(char *heading, int &answer, int defint);double getdouble(char *heading, double &answer, double defdouble);void remove_terminal_cr(char *s);void remove_terminal_spaces(char *s);void calculate_matches(char **s1, char **match, int count, int pos,      int matchmode, int identitymode);int ismatch(char a, char b, int identitymode);void fill_sequence_strings(char *norm, char *hilight, char **s1, char **match,     int seqno, int offset, int width);void read_data(FILE *fp1, char **s1, char **match, int &count, char **label,    int &labelcount, int &longest_length);void print_title(FILE *fp, char **label, int labelcount, int xstart,     int &ystart, int size, char *lcolor, char *ps_color_string, char *titlefont);void print_box(FILE *fp, char **label, int count, int labelcount, int startpos,     int width, int size, int chunkspacesize, int chunk, int xseqstart, int ystart);void print_label(FILE *fp, char **label, int count, int labelcount, int startpos,     int width, int size, int chunkspacesize, int chunk, int xseqstart, int ystart,     char *font);void print_text(FILE *fp, char **label, int count, int labelcount, int startpos,     int separatorpos, int width, int size, int chunkspacesize, int chunk,      int xseqstart, int ystart, char *font);void get_sequence_text(char *result, char *label, int offset, int width,      int &text_xpos);int labeltype(char *s, char *&ptr);int nextarg(char *&ptr);int between(int a,int b,int c);int between(double a, double b, double c);int main(int argc, char **argv){   int k,count,labelcount,page,offset;   FILE *fp1, *fp2;   char file1[128], file2[128];   char **s1;   char **label;   char **match;   char titlefont[64];   char namefont[64];   char font[64];   char ps_color_string[64];   char fcolor[64],bcolor[64],gcolor[64],hcolor[64],lcolor[64];   char tempstring[1024];   char normalstring[1024];   char matchstring[1024];   char titlestring[1024];   char formatstring[1024];   int matchmode      = 1;   int size           = 10;   int wantcolor      = 1;   int width          = 40;   int longest_length = 0;   int chunkspacesize = size;   int chunksperpage;   int identitymode   = 1;   double leftmargin  = 0.5;   double topmargin   = 1.0;   int xtranslate;   int ytranslate;   int chunk, separatorpos, startpos, xstart, x, y, seqno, xseqstart, ystart;   s1    = new char*[1000];   match = new char*[1000];   label = new char*[1000];   printf("Highlight - converts alignment file to PostScript, highlighting\n");   printf("positions that match the controlling sequence(s).              \n");   printf("See manual for format of alignment files.\n");   getstring("Alignment file ", file1, "1.txt");   sprintf(tempstring, "%s.ps", file1);   getstring("PostScript file", file2, tempstring);   getint("Controlling sequence(1=1st, 2=1st+2nd, 3=any 4=best)", matchmode, matchmode);   getint("Enter 1=identity 2=homology", identitymode, identitymode);   getstring("Font for title        ", titlefont, "Times-Roman");   getstring("Font for sequence name", namefont, "Times-Roman");   getstring("Font for sequence     ", font, "Helvetica");   getint("Char size", size, size);   getint("Sequence characters per line", width, width);   getint("Enter 0=B/W 1=color", wantcolor, wantcolor);   if(wantcolor)   {      strcpy(ps_color_string, "setrgbcolor");      getstring("Normal character RGBcolor     ", fcolor, "0.000 0.000 0.000");      getstring("Normal background RGBcolor    ", bcolor, "0.950 0.950 0.950");      getstring("Highlighted character RGBcolor", gcolor, "0.000 0.000 0.000");      getstring("Highlight background RGBcolor ", hcolor, "1.000 1.000 0.000");      getstring("Label character RGBcolor      ", lcolor, "0.000 0.000 0.000");   }else   {  strcpy(ps_color_string, "setgray");      getstring("Normal character gray value     ", fcolor, "0.000");      getstring("Normal background gray value    ", bcolor, "0.950");      getstring("Highlighted character gray value", gcolor, "1.000");      getstring("Highlight background gray value ", hcolor, "0.050");      getstring("Label character gray value      ", lcolor, "0.000");   }   if((fp1=fopen(file1,"rb")) == NULL)    {  printf("\nUnable to open file xxx%sxxx\n",file1);      exit(1);   }   if((fp2=fopen(file2,"wb")) == NULL)    {  printf("\nUnable to open file xxx%sxxx\n",file2);      exit(1);   }   //// Read the sequences   count = 0;   labelcount = 0;   page = 1;   read_data(fp1, s1, match, count, label, labelcount, longest_length);   printf("%d sequences counted\n", count);   getint("Spacing between chunks", chunkspacesize, chunkspacesize);   ////  684 = 9.5 inches * 72 points/inch   chunksperpage = 684 / ((size*count) + chunkspacesize);   getint("Chunks per page       ", chunksperpage, chunksperpage);   getdouble("Top margin (inches)   ", topmargin, topmargin);   getdouble("Left margin (inches)  ", leftmargin, leftmargin);   xtranslate = int(leftmargin * 72);   ytranslate = int(-topmargin * 72);    //// Create postscript   fprintf(fp2, "%s\n", "%!PS-Adobe-2.0 EPSF-2.0");   fprintf(fp2, "%s\n", "%%Title: None");   fprintf(fp2, "%s %s\n", "%%Creator:", argv[0]);   fprintf(fp2, "%s\n", "%%BoundingBox: 0 0 596 842");   fprintf(fp2, "%s\n", "%%Pages: 1");   fprintf(fp2, "%s\n", "%%DocumentFonts:");   fprintf(fp2, "%s\n", "%%EndComments");   fprintf(fp2, "%s\n", "%%EndProlog");   fprintf(fp2, "%s %d %d\n", "%%Page:", page, page);   fprintf(fp2, "%s\n", "/origstate save def");   fprintf(fp2, "%d %d translate\n", xtranslate, ytranslate);   formatstring[0] = 0;   sprintf(tempstring, "%d ", size);   for(k=0;k<width;k++) strcat(formatstring, tempstring);   if(!strchr(s1[0], '|'))   {  printf("Error: Sequence name must be separated by sequence by a vertical bar (|)\n");      exit(EXIT_FAILURE);   }   separatorpos = (int)(strchr(s1[0], '|') - s1[0]);          calculate_matches(s1, match, count, separatorpos, matchmode, identitymode);   xstart = 20;   xseqstart = 0;   startpos = 0;   chunk = 0;   ystart = 800;   seqno = 0;   print_title(fp2, label, labelcount, xstart, ystart, size, lcolor,       ps_color_string, titlefont);   for(y = ystart; y>0; y-=size)   {       ////  Print sequence name       fprintf(fp2, "%s %s\n", lcolor, ps_color_string);       fprintf(fp2, "/%s %s\n", namefont, "findfont");       fprintf(fp2, "%d %s\n",  size,"scalefont setfont");       strncpy(titlestring, s1[seqno], separatorpos);       titlestring[separatorpos] = 0;       fprintf(fp2, "%d %d moveto\n", xstart, y);       fprintf(fp2, "(%s) show\n", titlestring);       if(xseqstart==0) xseqstart = xstart + int(0.6 * size * strlen(titlestring));       //// Print match boxes       fprintf(fp2, "%s %s\n", hcolor, ps_color_string);       for(k=startpos+1; k<=startpos+width; k++)       {  x = xseqstart + (k-startpos-1) * size;          if(match[seqno][k+separatorpos])              fprintf(fp2, "%d %d %d %d rectfill\n",x-1,y-1,size,size);       }       fprintf(fp2, "%s %s\n", bcolor, ps_color_string);       for(k=startpos+1; k<=startpos+width; k++)       {  x = xseqstart + (k-startpos-1) * size;          if(!match[seqno][k+separatorpos])              fprintf(fp2, "%d %d %d %d rectfill\n",x-1,y-1,size,size);       }       //// Print sequence       fprintf(fp2, "/%s %s\n", font, "findfont");       fprintf(fp2, "%d %s\n",  size,"scalefont setfont");       offset = 1 + separatorpos + startpos;       fill_sequence_strings(normalstring, matchstring, s1, match, seqno,            offset, width);        fprintf(fp2, "%d %d moveto\n", xseqstart, y);       fprintf(fp2, "%s %s\n", fcolor, ps_color_string);       fprintf(fp2, "(%s) [%s] xshow\n", normalstring, formatstring);       fprintf(fp2, "%d %d moveto\n", xseqstart, y);       fprintf(fp2, "%s %s\n", gcolor, ps_color_string);       fprintf(fp2, "(%s) [%s] xshow\n", matchstring, formatstring);       seqno++;       if(seqno>=count)        {   seqno=0;           fprintf(fp2, "%s %s\n", lcolor, ps_color_string);           ////  Print boxes after each chunk           print_box(fp2, label, count, labelcount, startpos, width, size,                 chunkspacesize, chunk, xseqstart, ystart);           ////  Print labels           print_label(fp2, label, count, labelcount, startpos, width, size,                 chunkspacesize, chunk, xseqstart, ystart, namefont);           ////  Print text           print_text(fp2, label, count, labelcount, startpos, separatorpos,                 width, size, chunkspacesize, chunk, xseqstart, ystart, namefont);           chunk++;           startpos += width;            if(startpos >= (int)strlen(s1[seqno])) break;              y -=chunkspacesize;           if(chunk >= chunksperpage)           {    chunk=0;                page++;                y = ystart + size;                fprintf(fp2, "%s\n", "showpage");                fprintf(fp2, "%s\n", "origstate restore");                fprintf(fp2, "%s %d %d\n", "%%Page:",page,page);                fprintf(fp2, "%s\n\n", "/origstate save def");                fprintf(fp2, "%d %d translate\n", xtranslate, ytranslate);           }       }   }   fprintf(fp2, "%s\n", "showpage");   fprintf(fp2, "%s\n", "origstate restore");   fprintf(fp2, "%s\n", "%%Trailer");    fclose(fp1);   fclose(fp2);   for(k=0;k<labelcount;k++) delete[] label[k];   for(k=0;k<count;k++){ delete[] s1[k]; delete[] match[k]; }   delete[] label;   delete[] s1;   delete[] match;   exit(EXIT_SUCCESS);}//-------------------------------------------------------------------------//// getstring                                                               ////-------------------------------------------------------------------------//char *getstring(char *heading, char *string, char *defstring){   printf("%s [%s]:", heading, defstring); fflush(stdout);   fgets(string, 64, stdin);   if(string == NULL || string[0]=='\n') strcpy(string, defstring);   remove_terminal_cr(string);   return(string);}//-------------------------------------------------------------------------//// getint                                                                  ////-------------------------------------------------------------------------//int getint(char *heading, int &answer, int defint){   char string[1024];   printf("%s [%d]:", heading, defint); fflush(stdout);   fgets(string, 64, stdin);   if(string == NULL || string[0]=='\n') sprintf(string, "%d", defint);   remove_terminal_cr(string);   answer = atoi(string);   return atoi(string);}//-------------------------------------------------------------------------//// getdouble                                                               ////-------------------------------------------------------------------------//double getdouble(char *heading, double &answer, double defdouble){   char string[1024];   printf("%s [%g]:", heading, defdouble); fflush(stdout);   fgets(string, 64, stdin);   if(string == NULL || string[0]=='\n') sprintf(string, "%g", defdouble);   remove_terminal_cr(string);   answer = atof(string);   return atof(string);}//-------------------------------------------------------------------------//// remove_terminal_cr                                                      ////-------------------------------------------------------------------------//void remove_terminal_cr(char *s){    int pos = max(0, (int)(strlen(s))-1);    if(s[pos]=='\n') s[pos]=0;}//-------------------------------------------------------------------------//// remove_terminal_spaces                                                  ////-------------------------------------------------------------------------//void remove_terminal_spaces(char *s){    int k;    int pos = max(0, (int)(strlen(s))-1);    for(k=pos; k>=0; k--) if(s[k]==' ') s[k]=0; else break;}//-------------------------------------------------------------------------//// calculate_matches                                                       ////-------------------------------------------------------------------------//void calculate_matches(char **s1, char **match, int count, int pos,      int matchmode, int im){   int i,j,j2, hit[count], most, highest;   int len=0;   for(j=0; j<count; j++) len = max(len, (int)strlen(s1[j]));   for(j=0; j<count; j++)     for(i=0; i<(int)strlen(s1[j]); i++)         match[j][i]=0;   for(i=pos; i<len; i++)          {  switch(matchmode)      {  case 1:  // match 1st sequence only            for(j=1; j<count; j++)                 if(ismatch(s1[j][i], s1[0][i], im)){ match[0][i]=1; match[j][i]=1; }            break;

⌨️ 快捷键说明

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