/* PostScript output for Sequence / Structure Alignments c Ivo Hofacker, Peter F Stadler, Ronny Lorenz Vienna RNA package */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include "ViennaRNA/model.h" #include "ViennaRNA/utils.h" #include "ViennaRNA/fold_vars.h" #include "ViennaRNA/aln_util.h" #include "ViennaRNA/plot_aln.h" /* ################################# # PRIVATE MACROS # ################################# */ /* ################################# # GLOBAL VARIABLES # ################################# */ /* ################################# # PRIVATE VARIABLES # ################################# */ /* ################################# # PRIVATE FUNCTION DECLARATIONS # ################################# */ /* ################################# # BEGIN OF FUNCTION DEFINITIONS # ################################# */ int PS_color_aln(const char *structure, const char *filename, const char *seqs[], const char *names[]) { /* produce PS sequence alignment color-annotated by consensus structure */ int N,i,j,k,x,y,tmp,columnWidth; char *tmpBuffer,*ssEscaped,*ruler, *cons; char c; float fontWidth, fontHeight, imageHeight, imageWidth,tmpColumns; int length, maxName, maxNum, currPos; float lineStep,blockStep,consStep,ssStep,rulerStep,nameStep,numberStep; float maxConsBar,startY,namesX,seqsX, currY; float score,barHeight,xx,yy; int match,block; FILE *outfile; short *pair_table; char * colorMatrix[6][3] = { {"0.0 1", "0.0 0.6", "0.0 0.2"}, /* red */ {"0.16 1","0.16 0.6", "0.16 0.2"}, /* ochre */ {"0.32 1","0.32 0.6", "0.32 0.2"}, /* turquoise */ {"0.48 1","0.48 0.6", "0.48 0.2"}, /* green */ {"0.65 1","0.65 0.6", "0.65 0.2"}, /* blue */ {"0.81 1","0.81 0.6", "0.81 0.2"} /* violet */ }; const char *alnPlotHeader = "%%!PS-Adobe-3.0 EPSF-3.0\n" "%%%%BoundingBox: %i %i %i %i\n" "%%%%EndComments\n" "%% draws Vienna RNA like colored boxes\n" "/box { %% x1 y1 x2 y2 hue saturation\n" " gsave\n" " dup 0.3 mul 1 exch sub sethsbcolor\n" " exch 3 index sub exch 2 index sub rectfill\n" " grestore\n" "} def\n" "%% draws a box in current color\n" "/box2 { %% x1 y1 x2 y2\n" " exch 3 index sub exch 2 index sub rectfill\n" "} def\n" "/string { %% (Text) x y\n" " 6 add\n" " moveto\n" " show\n" "} def\n" "0 %i translate\n" "1 -1 scale\n" "/Courier findfont\n" "[10 0 0 -10 0 0] makefont setfont\n"; vrna_md_t md; set_model_details(&md); outfile = fopen(filename, "w"); if (outfile == NULL) { vrna_message_warning("can't open file %s - not doing alignment plot\n", filename); return 0; } columnWidth=60; /* Display long alignments in blocks of this size */ fontWidth=6; /* Font metrics */ fontHeight=6.5; lineStep=fontHeight+2; /* distance between lines */ blockStep=3.5*fontHeight; /* distance between blocks */ consStep=fontHeight*0.5; /* distance between alignment and conservation curve */ ssStep=2; /* distance between secondary structure line and sequences */ rulerStep=2; /* distance between sequences and ruler */ nameStep=3*fontWidth; /* distance between names and sequences */ numberStep=fontWidth; /* distance between sequeces and numbers */ maxConsBar=2.5*fontHeight; /* Height of conservation curve */ startY=2; /* "y origin" */ namesX=fontWidth; /* "x origin" */ /* Number of columns of the alignment */ length=strlen(seqs[0]); /* Allocate memory for various strings, length*2 is (more than) enough for all of them */ tmpBuffer = (char *) vrna_alloc((unsigned) MAX2(length*2,columnWidth)+1); ssEscaped=(char *) vrna_alloc((unsigned) length*2); ruler=(char *) vrna_alloc((unsigned) length*2); pair_table=vrna_ptable(structure); /* Get length of longest name and count sequences in alignment*/ for (i=maxName=N=0; names[i] != NULL; i++) { N++; tmp=strlen(names[i]); if (tmp>maxName) maxName=tmp; } /* x-coord. where sequences start */ seqsX=namesX+maxName*fontWidth+nameStep; /* calculate number of digits of the alignment length */ snprintf(tmpBuffer,length, "%i",length); maxNum=strlen(tmpBuffer); /* Calculate bounding box */ tmpColumns=columnWidth; if (lengthi) { /* Repeat for open and closing position */ for (k=0;k<2;k++){ int pairings, nonpair, s, col; int ptype[8] = {0,0,0,0,0,0,0,0}; char *color; col = (k==0)?i-1:j-1; block=ceil((float)(col+1)/columnWidth); xx=seqsX+(col-(block-1)*columnWidth)*fontWidth; /* Repeat for each sequence */ for (s=pairings=nonpair=0; s') structur[i]=')'; */ /* } */ /* structur[length]='\0'; */ /* printf("%s \n", structur); */ pair_table=vrna_pt_ali_get(structure); /* Get length of longest name and count sequences in alignment*/ for (i=maxName=N=0; names[i] != NULL; i++) { N++; tmp=strlen(names[i]); if (tmp>maxName) maxName=tmp; } /* x-coord. where sequences start */ seqsX=namesX+maxName*fontWidth+nameStep; /* calculate number of digits of the alignment length */ snprintf(tmpBuffer,length, "%i",length); maxNum=strlen(tmpBuffer); /* Calculate bounding box */ tmpColumns=columnWidth; if (lengthi) { /* Repeat for open and closing position */ for (k=0;k<2;k++){ int pairings, nonpair, s, col; int ptype[8] = {0,0,0,0,0,0,0,0}; char *color; col = (k==0)?i-1:j-1; block=ceil((float)(col+1)/columnWidth); xx=seqsX+(col-(block-1)*columnWidth)*fontWidth; /* Repeat for each sequence */ for (s=pairings=nonpair=0; s