2 PostScript and GML output for RNA secondary structures
3 and pair probability matrices
5 c Ivo Hofacker and Peter F Stadler
15 #include "fold_vars.h"
20 #include "plot_layouts.h"
22 static char UNUSED rcsid[] = "$Id: PS_dot.c,v 1.38 2007/02/02 15:18:13 ivo Exp $";
25 #define PI 3.141592654
32 PRIVATE FILE *PS_dot_common(char *seq, char *wastlfile, char *comment,
34 PRIVATE char **annote(const char *structure, const char *AS[]);
37 /*---------------------------------------------------------------------------*/
39 /* options for gml output:
40 uppercase letters: print sequence labels
41 lowercase letters: no sequence lables
44 (nothing else implemented at present)
45 default: no graphics data at all
48 PUBLIC int gmlRNA(char *string, char *structure, char *ssfile, char option)
57 if (isupper(option)) labels = 1;
59 gmlfile = fopen(ssfile, "w");
60 if (gmlfile == NULL) {
61 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
65 length = strlen(string);
67 pair_table = make_pair_table(structure);
73 X = (float *) space((length+1)*sizeof(float));
74 Y = (float *) space((length+1)*sizeof(float));
75 if (rna_plot_type == 0)
76 i = simple_xy_coordinates(pair_table, X, Y);
78 i = naview_xy_coordinates(pair_table, X, Y);
80 if(i!=length) fprintf(stderr,"strange things happening in gmlRNA ...\n");
83 /* No Graphics Information */
89 "# Vienna RNA Package %s\n"
91 "# CreationDate: %s\n"
93 "# Options: %s\n", VERSION, time_stamp(), ssfile, option_string());
97 for (i=1; i<=length; i++){
100 if (option) fprintf(gmlfile,
101 "label \"%c\"",string[i-1]);
102 if ((option == 'X')||(option=='x'))
104 "\n graphics [ x %9.4f y %9.4f ]\n", X[i-1], Y[i-1]);
105 fprintf(gmlfile," ]\n");
107 for (i=1; i<length; i++)
109 "edge [ source %d target %d ]\n", i, i+1);
110 for (i=1; i<=length; i++) {
113 "edge [ source %d target %d ]\n", i, pair_table[i]);
115 fprintf(gmlfile, "]\n");
120 return 1; /* success */
123 /*---------------------------------------------------------------------------*/
124 int PS_rna_plot(char *string, char *structure, char *ssfile) {
125 return PS_rna_plot_a(string, structure, ssfile, NULL, NULL);
128 static const char *RNAss_head =
130 "/RNAplot 100 dict def\n"
133 "/outlinecolor {0.2 setgray} bind def\n"
134 "/paircolor {0.2 setgray} bind def\n"
135 "/seqcolor {0 setgray} bind def\n"
136 "/cshow { dup stringwidth pop -2 div fsize -3 div rmoveto show} bind def\n"
137 "/min { 2 copy gt { exch } if pop } bind def\n"
138 "/max { 2 copy lt { exch } if pop } bind def\n"
139 "/arccoords { % i j arccoords\n"
140 " % puts optimal x1 y1 x2 y2 coordinates used in bezier curves from i to j\n"
141 " % onto the stack\n"
142 " dup 3 -1 roll dup 4 -1 roll lt dup dup 5 2 roll {exch} if\n"
143 " dup 3 -1 roll dup 3 -1 roll exch sub 1 sub dup\n"
144 " 4 -2 roll 5 -1 roll {exch} if 4 2 roll\n"
145 " sequence length dup 2 div exch 3 1 roll lt \n"
146 " {exch 5 -1 roll pop 4 -2 roll exch 4 2 roll}\n"
147 " { 4 2 roll 5 -1 roll dup 6 1 roll {exch} if\n"
148 " 4 -2 roll exch pop dup 3 -1 roll dup 4 1 roll\n"
149 " exch add 4 -1 roll dup 5 1 roll sub 1 sub\n"
150 " 5 -1 roll not {4 -2 roll exch 4 2 roll} if\n"
152 " % compute the scalingfactor and prepare (1-sf) and sf*r\n"
153 " 2 mul exch cpr 3 1 roll div dup\n"
154 " 3 -1 roll mul exch 1 exch sub exch\n"
155 " % compute the coordinates\n"
156 " 3 -1 roll 1 sub coor exch get aload pop % get coord for i\n"
157 " 4 -1 roll dup 5 1 roll mul 3 -1 roll dup 4 1 roll add exch % calculate y1\n"
158 " 4 -1 roll dup 5 1 roll mul 3 -1 roll dup 4 1 roll add exch % calculate x1\n"
159 " 5 -1 roll 1 sub coor exch get aload pop % get coord for j\n"
160 " % duplicate j coord\n"
161 " dup 3 -1 roll dup 4 1 roll exch 8 2 roll\n"
162 " 6 -1 roll dup 7 1 roll mul 5 -1 roll dup 6 1 roll add exch % calculate y2\n"
163 " 6 -1 roll mul 5 -1 roll add exch % calculate x2\n"
164 " 6 -2 roll % reorder\n"
167 " gsave outlinecolor newpath\n"
168 " coor 0 get aload pop 0.8 0 360 arc % draw 5' circle of 1st sequence\n"
169 " currentdict /cutpoint known % check if cutpoint is defined\n"
170 " {coor 0 cutpoint getinterval\n"
171 " {aload pop lineto} forall % draw outline of 1st sequence\n"
172 " coor cutpoint 1 add get aload pop\n"
173 " 2 copy moveto 0.8 0 360 arc % draw 5' circle of 2nd sequence\n"
174 " coor cutpoint 1 add coor length cutpoint 1 add sub getinterval\n"
175 " {aload pop lineto} forall} % draw outline of 2nd sequence\n"
176 " {coor {aload pop lineto} forall} % draw outline as a whole\n"
182 " 0.7 setlinewidth\n"
183 " [9 3.01] 9 setdash\n"
185 " pairs {aload pop\n"
186 " currentdict (cpr) known\n"
188 " coor exch 1 sub get aload pop moveto\n"
189 " exch arccoords curveto\n"
191 " { coor exch 1 sub get aload pop moveto\n"
192 " coor exch 1 sub get aload pop lineto\n"
203 " aload pop moveto\n"
204 " dup sequence exch 1 getinterval cshow\n"
210 " /Helvetica findfont fsize scalefont setfont\n"
213 " 0.8 setlinewidth\n"
214 " 72 216 translate\n"
215 " % find the coordinate range\n"
216 " /xmax -1000 def /xmin 10000 def\n"
217 " /ymax -1000 def /ymin 10000 def\n"
220 " dup ymin lt {dup /ymin exch def} if\n"
221 " dup ymax gt {/ymax exch def} {pop} ifelse\n"
222 " dup xmin lt {dup /xmin exch def} if\n"
223 " dup xmax gt {/xmax exch def} {pop} ifelse\n"
225 " /size {xmax xmin sub ymax ymin sub max} bind def\n"
226 " 72 6 mul size div dup scale\n"
227 " size xmin sub xmax sub 2 div size ymin sub ymax sub 2 div\n"
232 static const char *anote_macros =
234 "% extra definitions for standard anotations\n"
235 "/min { 2 copy gt { exch } if pop } bind def\n"
236 "/BLACK { 0 0 0 } def\n"
237 "/RED { 1 0 0 } def\n"
238 "/GREEN { 0 1 0 } def\n"
239 "/BLUE { 0 0 1 } def\n"
240 "/WHITE { 1 1 1 } def\n"
241 "/LabelFont { % font size LabelFont\n"
242 " exch findfont exch fsize mul scalefont setfont\n"
244 "/Label { % i dx dy (text) Label\n"
245 " % write text at base i plus offset dx, dy\n"
246 " 4 3 roll 1 sub coor exch get aload pop moveto\n"
247 " 3 1 roll fsize mul exch fsize mul exch rmoveto\n"
250 "/cmark { % i cmark draw circle around base i\n"
251 " newpath 1 sub coor exch get aload pop\n"
252 " fsize 2 div 0 360 arc stroke\n"
254 "/gmark { % i j c gmark\n"
255 " % draw basepair i,j with c counter examples in gray\n"
257 " 3 min [0 0.33 0.66 0.9] exch get setgray\n"
258 " 1 sub dup coor exch get aload pop moveto\n"
259 " sequence exch 1 getinterval cshow\n"
260 " 1 sub dup coor exch get aload pop moveto\n"
261 " sequence exch 1 getinterval cshow\n"
264 "/segmark { % f i j lw r g b segmark\n"
265 " % mark segment [i,j] with outline width lw and color rgb\n"
266 " % use omark and Fomark instead\n"
268 " setrgbcolor setlinewidth\n"
270 " 1 sub exch 1 sub dup\n"
271 " coor exch get aload pop moveto\n"
272 " currentdict (cpr) known\n"
274 " 3 -1 roll dup 4 1 roll dup\n"
276 " 3 1 roll dup 3 -1 roll dup\n"
277 " 4 1 roll exch 5 2 roll exch\n"
282 " 1 exch { coor exch get aload pop lineto } for\n"
284 " dup 3 1 roll 1 add exch 1 add arccoords pop pop\n"
285 " 4 2 roll 5 -1 roll coor exch get aload pop curveto\n"
290 " coor exch get aload pop lineto\n"
293 " { closepath fill } if stroke\n"
296 "/omark { % i j lw r g b omark\n"
297 " % stroke segment [i..j] with linewidth lw, color rgb\n"
298 " false 7 1 roll segmark\n"
300 "/Fomark { % i j r g b Fomark\n"
301 " % fill segment [i..j] with color rgb\n"
302 " % should precede drawbases\n"
303 " 1 4 1 roll true 7 1 roll segmark\n"
305 "/BFmark{ % i j k l r g b BFmark\n"
306 " % fill block between pairs (i,j) and (k,l) with color rgb\n"
307 " % should precede drawbases\n"
311 " currentdict (cpr) known\n"
313 " dup 1 sub coor exch get aload pop moveto % move to l\n"
314 " dup 1 sub 4 -1 roll dup 5 1 roll 1 sub 1 exch\n"
315 " { coor exch get aload pop lineto } for % lines from l to j\n"
316 " 3 -1 roll 4 -1 roll dup 5 1 roll arccoords curveto % curve from j to i\n"
317 " exch dup 4 -1 roll 1 sub exch 1 sub 1 exch\n"
318 " { coor exch get aload pop lineto } for % lines from i to k\n"
319 " exch arccoords curveto% curve from k to l\n"
321 " { exch 4 3 roll exch 1 sub exch 1 sub dup\n"
322 " coor exch get aload pop moveto\n"
323 " exch 1 exch { coor exch get aload pop lineto } for\n"
324 " exch 1 sub exch 1 sub dup\n"
325 " coor exch get aload pop lineto\n"
326 " exch 1 exch { coor exch get aload pop lineto } for\n"
328 " closepath fill stroke\n"
332 " dup 0.3 mul 1 exch sub sethsbcolor\n"
334 "/colorpair { % i j hue sat colorpair\n"
335 " % draw basepair i,j in color\n"
336 " % 1 index 0.00 ne {\n"
340 " fsize setlinewidth\n"
341 " currentdict (cpr) known\n"
344 " coor exch 1 sub get aload pop moveto\n"
345 " exch arccoords curveto\n"
347 " { 1 sub coor exch get aload pop moveto\n"
348 " 1 sub coor exch get aload pop lineto\n"
356 int PS_rna_plot_a(char *string, char *structure, char *ssfile, char *pre, char *post)
358 float xmin, xmax, ymin, ymax, size;
365 length = strlen(string);
367 xyplot = fopen(ssfile, "w");
368 if (xyplot == NULL) {
369 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
373 pair_table = make_pair_table(structure);
375 X = (float *) space((length+1)*sizeof(float));
376 Y = (float *) space((length+1)*sizeof(float));
377 switch(rna_plot_type){
378 case VRNA_PLOT_TYPE_SIMPLE: i = simple_xy_coordinates(pair_table, X, Y);
380 case VRNA_PLOT_TYPE_CIRCULAR: {
381 int radius = 3*length;
382 i = simple_circplot_coordinates(pair_table, X, Y);
383 for (i = 0; i < length; i++) {
391 default: i = naview_xy_coordinates(pair_table, X, Y);
394 if(i!=length) fprintf(stderr,"strange things happening in PS_rna_plot...\n");
398 for (i = 1; i < length; i++) {
399 xmin = X[i] < xmin ? X[i] : xmin;
400 xmax = X[i] > xmax ? X[i] : xmax;
401 ymin = Y[i] < ymin ? Y[i] : ymin;
402 ymax = Y[i] > ymax ? Y[i] : ymax;
404 size = MAX2((xmax-xmin),(ymax-ymin));
407 "%%!PS-Adobe-3.0 EPSF-3.0\n"
408 "%%%%Creator: %s, ViennaRNA-%s\n"
409 "%%%%CreationDate: %s"
410 "%%%%Title: RNA Secondary Structure Plot\n"
411 "%%%%BoundingBox: 66 210 518 662\n"
412 "%%%%DocumentFonts: Helvetica\n"
414 "%%%%EndComments\n\n"
415 "%%Options: %s\n", rcsid+5, VERSION, time_stamp(), option_string());
416 fprintf(xyplot, "%% to switch off outline pairs of sequence comment or\n"
417 "%% delete the appropriate line near the end of the file\n\n");
418 fprintf(xyplot, "%s", RNAss_head);
421 fprintf(xyplot, "%s", anote_macros);
423 fprintf(xyplot, "%%%%EndProlog\n");
425 fprintf(xyplot, "RNAplot begin\n"
426 "%% data start here\n");
429 if ((c = strchr(structure, '&'))) {
431 cutpoint = c - structure;
432 string[cutpoint] = ' '; /* replace & with space */
433 fprintf(xyplot, "/cutpoint %d def\n", cutpoint);
437 fprintf(xyplot,"/sequence (\\\n");
440 fprintf(xyplot, "%.255s\\\n", string+i); /* no lines longer than 255 */
443 fprintf(xyplot,") def\n");
445 fprintf(xyplot, "/coor [\n");
446 for (i = 0; i < length; i++)
447 fprintf(xyplot, "[%3.8f %3.8f]\n", X[i], Y[i]);
448 fprintf(xyplot, "] def\n");
449 /* correction coordinates for quadratic beziers in case we produce a circplot */
450 if(rna_plot_type == VRNA_PLOT_TYPE_CIRCULAR)
451 fprintf(xyplot, "/cpr %6.2f def\n", (float)3*length);
453 fprintf(xyplot, "/pairs [\n");
454 for (i = 1; i <= length; i++)
456 fprintf(xyplot, "[%d %d]\n", i, pair_table[i]);
457 fprintf(xyplot, "] def\n\n");
459 fprintf(xyplot, "init\n\n");
462 fprintf(xyplot, "%% Start Annotations\n");
463 fprintf(xyplot, "%s\n", pre);
464 fprintf(xyplot, "%% End Annotations\n");
467 "%% switch off outline pairs or bases by removing these lines\n"
473 fprintf(xyplot, "%% Start Annotations\n");
474 fprintf(xyplot, "%s\n", post);
475 fprintf(xyplot, "%% End Annotations\n");
477 fprintf(xyplot, "%% show it\nshowpage\n");
478 fprintf(xyplot, "end\n");
479 fprintf(xyplot, "%%%%EOF\n");
485 return 1; /* success */
488 int PS_rna_plot_a_gquad(char *string,
493 float xmin, xmax, ymin, ymax, size;
495 int ee, gb, ge, Lg, l[3];
498 short *pair_table, *pair_table_g;;
501 length = strlen(string);
503 xyplot = fopen(ssfile, "w");
504 if (xyplot == NULL) {
505 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
509 pair_table = make_pair_table(structure);
510 pair_table_g = make_pair_table(structure);
513 while ( (ee=parse_gquad(structure+ge, &Lg, l)) >0 ) {
515 gb=ge-Lg*4-l[0]-l[1]-l[2]+1;
516 /* add pseudo-base pair encloding gquad */
517 for (i=0; i<Lg; i++) {
518 pair_table_g[ge-i]=gb+i;
519 pair_table_g[gb+i]=ge-i;
523 X = (float *) space((length+1)*sizeof(float));
524 Y = (float *) space((length+1)*sizeof(float));
525 switch(rna_plot_type){
526 case VRNA_PLOT_TYPE_SIMPLE: i = simple_xy_coordinates(pair_table_g, X, Y);
528 case VRNA_PLOT_TYPE_CIRCULAR: {
529 int radius = 3*length;
530 i = simple_circplot_coordinates(pair_table_g, X, Y);
531 for (i = 0; i < length; i++) {
539 default: i = naview_xy_coordinates(pair_table_g, X, Y);
542 if(i!=length) fprintf(stderr,"strange things happening in PS_rna_plot...\n");
546 for (i = 1; i < length; i++) {
547 xmin = X[i] < xmin ? X[i] : xmin;
548 xmax = X[i] > xmax ? X[i] : xmax;
549 ymin = Y[i] < ymin ? Y[i] : ymin;
550 ymax = Y[i] > ymax ? Y[i] : ymax;
552 size = MAX2((xmax-xmin),(ymax-ymin));
555 "%%!PS-Adobe-3.0 EPSF-3.0\n"
556 "%%%%Creator: %s, ViennaRNA-%s\n"
557 "%%%%CreationDate: %s"
558 "%%%%Title: RNA Secondary Structure Plot\n"
559 "%%%%BoundingBox: 66 210 518 662\n"
560 "%%%%DocumentFonts: Helvetica\n"
562 "%%%%EndComments\n\n"
563 "%%Options: %s\n", rcsid+5, VERSION, time_stamp(), option_string());
564 fprintf(xyplot, "%% to switch off outline pairs of sequence comment or\n"
565 "%% delete the appropriate line near the end of the file\n\n");
566 fprintf(xyplot, "%s", RNAss_head);
569 fprintf(xyplot, "%s", anote_macros);
571 fprintf(xyplot, "%%%%EndProlog\n");
573 fprintf(xyplot, "RNAplot begin\n"
574 "%% data start here\n");
577 if ((c = strchr(structure, '&'))) {
579 cutpoint = c - structure;
580 string[cutpoint] = ' '; /* replace & with space */
581 fprintf(xyplot, "/cutpoint %d def\n", cutpoint);
585 fprintf(xyplot,"/sequence (\\\n");
588 fprintf(xyplot, "%.255s\\\n", string+i); /* no lines longer than 255 */
591 fprintf(xyplot,") def\n");
593 fprintf(xyplot, "/coor [\n");
594 for (i = 0; i < length; i++)
595 fprintf(xyplot, "[%3.8f %3.8f]\n", X[i], Y[i]);
596 fprintf(xyplot, "] def\n");
597 /* correction coordinates for quadratic beziers in case we produce a circplot */
598 if(rna_plot_type == VRNA_PLOT_TYPE_CIRCULAR)
599 fprintf(xyplot, "/cpr %6.2f def\n", (float)3*length);
601 fprintf(xyplot, "/pairs [\n");
602 for (i = 1; i <= length; i++)
604 fprintf(xyplot, "[%d %d]\n", i, pair_table[i]);
605 /* add gquad pairs */
607 while ( (ee=parse_gquad(structure+ge, &Lg, l)) >0 ) {
609 fprintf(xyplot, "%% gquad\n");
611 gb=ge-Lg*4-l[0]-l[1]-l[2]+1; /* add pseudo-base pair encloding gquad */
612 for (k=0; k<Lg; k++) {
614 for (il=0, ii=gb+k; il<3; il++) {
616 fprintf(xyplot, "[%d %d]\n", ii, jj);
620 fprintf(xyplot, "[%d %d]\n", jj, ii);
624 fprintf(xyplot, "] def\n\n");
626 fprintf(xyplot, "init\n\n");
629 fprintf(xyplot, "%% Start Annotations\n");
630 fprintf(xyplot, "%s\n", pre);
631 fprintf(xyplot, "%% End Annotations\n");
634 "%% switch off outline pairs or bases by removing these lines\n"
640 fprintf(xyplot, "%% Start Annotations\n");
641 fprintf(xyplot, "%s\n", post);
642 fprintf(xyplot, "%% End Annotations\n");
644 fprintf(xyplot, "%% show it\nshowpage\n");
645 fprintf(xyplot, "end\n");
646 fprintf(xyplot, "%%%%EOF\n");
653 return 1; /* success */
657 int PS_rna_plot_snoop_a(char *string, char *structure, char *ssfile, int *relative_access, const char *seqs[])
659 float xmin, xmax, ymin, ymax, size;
664 short *pair_table_snoop;
666 length = strlen(string);
668 xyplot = fopen(ssfile, "w");
669 if (xyplot == NULL) {
670 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
674 pair_table = make_pair_table(structure);
675 pair_table_snoop = make_pair_table_snoop(structure);
677 X = (float *) space((length+1)*sizeof(float));
678 Y = (float *) space((length+1)*sizeof(float));
679 if (rna_plot_type == 0)
680 i = simple_xy_coordinates(pair_table, X, Y);
682 i = naview_xy_coordinates(pair_table, X, Y);
683 if(i!=length) fprintf(stderr,"strange things happening in PS_rna_plot...\n");
684 /* printf("cut_point %d\n", cut_point); */
687 /* for (i = 1; i < length; i++) { */
688 /* printf("%d X %f Y %f \n", i, X[i], Y[i]); */
689 /* xmin = X[i] < xmin ? X[i] : xmin; */
690 /* xmax = X[i] > xmax ? X[i] : xmax; */
691 /* ymin = Y[i] < ymin ? Y[i] : ymin; */
692 /* ymax = Y[i] > ymax ? Y[i] : ymax; */
694 /* localize centre of the interaction bucket. Geometry */
696 for (i = 1; i < cut_point; i++) { /* interior loop of size 0 */
697 if(pair_table_snoop[i] != 0){
698 X[i-1]=X[pair_table_snoop[i]-1];
699 Y[i-1]=Y[pair_table_snoop[i]-1];
701 else if(pair_table_snoop[i-1] && pair_table_snoop[i+1]){ /* interior loop of size 1 */
702 X[i-1]=X[pair_table_snoop[i-1] -1-1];
703 Y[i-1]=Y[pair_table_snoop[i-1] -1-1];
705 else if(pair_table_snoop[i-1] && pair_table_snoop[i+2]){ /* interior loop of size 2 */
706 if(pair_table_snoop[i-1] - pair_table_snoop[i+2] ==2){
707 X[i-1]=X[pair_table_snoop[i-1]-2];
708 Y[i-1]=Y[pair_table_snoop[i-1]-2];
709 X[i]=X[pair_table_snoop[i+2]];
710 Y[i]=Y[pair_table_snoop[i+2]];
713 else if(pair_table[pair_table_snoop[i-1]-1]){
714 X[i-1]=X[pair_table_snoop[i-1]-2];
715 Y[i-1]=Y[pair_table_snoop[i-1]-2];
716 X[i]=X[pair_table[pair_table_snoop[i-1]-1]-1];
717 Y[i]=Y[pair_table[pair_table_snoop[i-1]-1]-1];
720 else if(pair_table[pair_table_snoop[i-1]-2]){
721 X[i-1]=X[pair_table_snoop[i-1]-3];
722 Y[i-1]=Y[pair_table_snoop[i-1]-3];
723 X[i]=X[pair_table[pair_table_snoop[i-1]-2]-1];
724 Y[i]=Y[pair_table[pair_table_snoop[i-1]-2]-1];
727 else if(pair_table[pair_table_snoop[i-1]-3]){
728 X[i-1]=X[pair_table_snoop[i-1]-4];
729 Y[i-1]=Y[pair_table_snoop[i-1]-4];
730 X[i]=X[pair_table[pair_table_snoop[i-1]-3]-1];
731 Y[i]=Y[pair_table[pair_table_snoop[i-1]-3]-1];
735 X[i-1]=X[pair_table_snoop[i-1]-2];
736 Y[i-1]=Y[pair_table_snoop[i-1]-2];
737 X[i]=X[pair_table_snoop[i+2]];
738 Y[i]=Y[pair_table_snoop[i+2]];
742 else if(pair_table_snoop[i-1] && pair_table_snoop[i+3]){ /* interior loop of size 2 */
743 if(pair_table[pair_table_snoop[i-1]-1]){
744 X[i-1]=0.5*(X[pair_table_snoop[i-1]-1]+X[pair_table_snoop[i-1]-2]);
745 Y[i-1]=0.5*(Y[pair_table_snoop[i-1]-1]+Y[pair_table_snoop[i-1]-2]);
746 X[i]= 0.5*(X[pair_table[pair_table_snoop[i-1]-1]-1]+X[pair_table_snoop[i-1]-2]);
747 Y[i]= 0.5*(Y[pair_table[pair_table_snoop[i-1]-1]-1]+Y[pair_table_snoop[i-1]-2]);
748 X[i+1]=0.5*(X[pair_table[pair_table_snoop[i-1]-1]-2]+X[pair_table[pair_table_snoop[i-1]-1]-1]);
749 Y[i+1]=0.5*(Y[pair_table[pair_table_snoop[i-1]-1]-2]+Y[pair_table[pair_table_snoop[i-1]-1]-1]);
753 else if(pair_table[pair_table_snoop[i-1]-2]){
754 X[i-1]=0.5*(X[pair_table_snoop[i-1]-2]+X[pair_table_snoop[i-1]-3]);
755 Y[i-1]=0.5*(Y[pair_table_snoop[i-1]-2]+Y[pair_table_snoop[i-1]-3]);
756 X[i]= 0.5*(X[pair_table[pair_table_snoop[i-1]-2]-1]+X[pair_table_snoop[i-1]-3]);
757 Y[i]= 0.5*(Y[pair_table[pair_table_snoop[i-1]-2]-1]+Y[pair_table_snoop[i-1]-3]);
758 X[i+1]=0.5*(X[pair_table[pair_table_snoop[i-1]-2]-2]+X[pair_table[pair_table_snoop[i-1]-2]-1]);
759 Y[i+1]=0.5*(Y[pair_table[pair_table_snoop[i-1]-2]-2]+Y[pair_table[pair_table_snoop[i-1]-2]-1]);
762 else if(pair_table[pair_table_snoop[i-1]-3]){
763 X[i-1]=0.5*(X[pair_table_snoop[i-1]-3]+X[pair_table_snoop[i-1]-4]);
764 Y[i-1]=0.5*(Y[pair_table_snoop[i-1]-3]+Y[pair_table_snoop[i-1]-4]);
765 X[i]= 0.5*(X[pair_table[pair_table_snoop[i-1]-3]-1]+X[pair_table_snoop[i-1]-4]);
766 Y[i]= 0.5*(Y[pair_table[pair_table_snoop[i-1]-3]-1]+Y[pair_table_snoop[i-1]-4]);
767 X[i+1]=0.5*(X[pair_table[pair_table_snoop[i-1]-3]-2]+X[pair_table[pair_table_snoop[i-1]-3]-1]);
768 Y[i+1]=0.5*(Y[pair_table[pair_table_snoop[i-1]-3]-2]+Y[pair_table[pair_table_snoop[i-1]-3]-1]);
772 X[i-1]=X[pair_table_snoop[i-1]-2];
773 Y[i-1]=Y[pair_table_snoop[i-1]-2];
774 X[i]=X[pair_table_snoop[i-1]-2];
775 Y[i]=Y[pair_table_snoop[i-1]-2];
776 X[i+1]=X[pair_table_snoop[i-1]-2];
777 Y[i+1]=Y[pair_table_snoop[i-1]-2];
786 float X0=-1,Y0=-1,X1=-1,Y1=-1,X2=-1,Y2=-1;
788 for(i=1;i<cut_point; i++){
789 if(pair_table_snoop[i]){
790 X0=X[pair_table_snoop[i]-1];Y0=Y[pair_table_snoop[i]-1];
791 /* c1=pair_table_snoop[i]; */
796 for(;i<cut_point; i++){
797 if(pair_table_snoop[i]){
798 X1=X[pair_table_snoop[i]-1];Y1=Y[pair_table_snoop[i]-1];
799 /* c2=pair_table_snoop[i]; */
804 for(;i<cut_point; i++){
805 if(pair_table_snoop[i]){
806 X2=X[pair_table_snoop[i]-1];Y2=Y[pair_table_snoop[i]-1];
807 /* c3=pair_table_snoop[i]; */
812 /* for(i=cut_point-2;i>pair_table_snoop[c1]; i--){ */
813 /* if(pair_table_snoop[i]){ */
814 /* X1=X[pair_table_snoop[i]-1];Y1=Y[pair_table_snoop[i]-1]; */
815 /* c2=pair_table_snoop[i]; */
820 /* for(i=pair_table_snoop[c1]+1;i<pair_table_snoop[c2]; i++){ */
821 /* if(pair_table_snoop[i]){ */
822 /* X2=X[pair_table_snoop[i]-1];Y2=Y[pair_table_snoop[i]-1]; */
823 /* c3=pair_table_snoop[i]; */
828 if(X0 < 0 || X1 < 0 || X2 < 0){
829 printf("Could not get the center of the binding bucket. No ps file will be produced!\n");
832 free(pair_table_snoop);
834 pair_table=NULL;pair_table_snoop=NULL;X=NULL;Y=NULL;
837 double alpha = (X0 -X1)/(Y1-Y0);
838 double alpha_p = (X1 -X2)/(Y2-Y1);
839 double b = (Y0+Y1 -alpha*(X0+X1))*0.5;
840 double b_p = (Y1+Y2 -alpha_p*(X1+X2))*0.5;
841 /* if(abs(alpha -alpha_p) > 0.0000001){ */
842 xC = (b_p - b) / (alpha - alpha_p);
844 R = sqrt((xC-X0)*(xC-X0) + (yC-Y0)*(yC-Y0));
845 d = sqrt((X0-X1)*(X0-X1) + (Y0-Y1)*(Y0-Y1));
846 for (i = 1; i < cut_point; i++) {
847 X[i-1] = X[i-1] + 0.25*(xC-X[i-1]);
848 Y[i-1] = Y[i-1] + 0.25*(yC-Y[i-1]);
850 size = MAX2((xmax-xmin),(ymax-ymin));
852 "%%!PS-Adobe-3.0 EPSF-3.0\n"
853 "%%%%Creator: %s, ViennaRNA-%s\n"
854 "%%%%CreationDate: %s"
855 "%%%%Title: RNA Secondary Structure Plot\n"
856 "%%%%BoundingBox: 66 210 518 662\n"
857 "%%%%DocumentFonts: Helvetica\n"
859 "%%%%EndComments\n\n"
860 "%%Options: %s\n", rcsid+5, VERSION, time_stamp(), option_string());
861 fprintf(xyplot, "%% to switch off outline pairs of sequence comment or\n"
862 "%% delete the appropriate line near the end of the file\n\n");
863 fprintf(xyplot, "%s", RNAss_head);
865 fprintf(xyplot, "%s", anote_macros);
867 fprintf(xyplot, "%s", anote_macros);
868 A = annote(structure, (const char**) seqs);
870 fprintf(xyplot, "%%%%EndProlog\n");
872 fprintf(xyplot, "RNAplot begin\n"
873 "%% data start here\n");
875 if (cut_point > 0 && cut_point <= strlen(string))
876 fprintf(xyplot, "/cutpoint %d def\n", cut_point-1);
878 fprintf(xyplot,"/sequence (\\\n");
881 fprintf(xyplot, "%.255s\\\n", string+i); /* no lines longer than 255 */
884 fprintf(xyplot,") def\n");
886 fprintf(xyplot, "/coor [\n");
887 for (i = 0; i < length; i++)
888 fprintf(xyplot, "[%3.3f %3.3f]\n", X[i], Y[i]);
889 fprintf(xyplot, "] def\n");
891 fprintf(xyplot, "/pairs [\n");
892 for (i = 1; i <= length; i++)
894 fprintf(xyplot, "[%d %d]\n", i, pair_table[i]);
895 for (i = 1; i <= length; i++)
896 if (pair_table_snoop[i]>i)
897 fprintf(xyplot, "[%d %d]\n", i, pair_table_snoop[i]);
898 fprintf(xyplot, "] def\n\n");
900 fprintf(xyplot,"/S [\n");
901 for(i=0;i<cut_point-1; i++){
902 fprintf(xyplot, " %f\n", (float)relative_access[i]/100);
904 fprintf(xyplot,"]\n bind def\n");
905 fprintf(xyplot,"/invert false def\n");
906 fprintf(xyplot,"/range 0.8 def\n");
907 fprintf(xyplot,"/drawreliability {\n"
910 " coor 0 cutpoint getinterval {\n"
913 " Smax div range mul\n"
914 " invert {range exch sub} if\n"
917 " fsize 2.5 div 0 360 arc\n"
924 fprintf(xyplot, "init\n\n");
927 fprintf(xyplot, "%% Start Annotations\n");
928 fprintf(xyplot, "%s\n", A[0]);
929 fprintf(xyplot, "%% End Annotations\n");
933 fprintf(xyplot,"%%switch off outline pairs or bases by removing these lines\n");
935 fprintf(xyplot,"drawreliability\n");
941 /* fprintf(xyplot, "%d cmark\n",c1); */
942 /* fprintf(xyplot, "%d cmark\n",c2); */
943 /* fprintf(xyplot, "%d cmark\n",c3); */
945 fprintf(xyplot, "%% Start Annotations\n");
946 fprintf(xyplot, "%s\n", A[1]);
947 fprintf(xyplot, "%% End Annotations\n");
949 fprintf(xyplot, "%% show it\nshowpage\n");
950 fprintf(xyplot, "end\n");
951 fprintf(xyplot, "%%%%EOF\n");
954 if(seqs){free(A[0]);free(A[1]);free(A);}
955 free(pair_table);free(pair_table_snoop);
957 return 1; /* success */
961 PRIVATE char **annote(const char *structure, const char *AS[]) {
962 char *ps, *colorps, **A;
963 int i, n, s, pairings, maxl;
965 char * colorMatrix[6][3] = {
966 {"0.0 1", "0.0 0.6", "0.0 0.2"}, /* red */
967 {"0.16 1","0.16 0.6", "0.16 0.2"}, /* ochre */
968 {"0.32 1","0.32 0.6", "0.32 0.2"}, /* turquoise */
969 {"0.48 1","0.48 0.6", "0.48 0.2"}, /* green */
970 {"0.65 1","0.65 0.6", "0.65 0.2"}, /* blue */
971 {"0.81 1","0.81 0.6", "0.81 0.2"} /* violet */
978 A = (char **) space(sizeof(char *)*2);
979 ps = (char *) space(maxl);
980 colorps = (char *) space(maxl);
981 ptable = alimake_pair_table(structure);
982 for (i=1; i<=n; i++) {
983 char pps[64], ci='\0', cj='\0';
984 int j, type, pfreq[8] = {0,0,0,0,0,0,0,0}, vi=0, vj=0;
985 if ((j=ptable[i])<i) continue;
986 for (s=0; AS[s]!=NULL; s++) {
987 type = pair[encode_char(AS[s][i-1])][encode_char(AS[s][j-1])];
990 if (AS[s][i-1] != ci) { ci = AS[s][i-1]; vi++;}
991 if (AS[s][j-1] != cj) { cj = AS[s][j-1]; vj++;}
994 for (pairings=0,s=1; s<=7; s++) {
995 if (pfreq[s]) pairings++;
998 if ((maxl - strlen(ps) < 192) || ((maxl - strlen(colorps)) < 64)) {
1000 ps = realloc(ps, maxl);
1001 colorps = realloc(colorps, maxl);
1002 if ((ps==NULL) || (colorps == NULL))
1003 nrerror("out of memory in realloc");
1007 snprintf(pps, 64, "%d %d %s colorpair\n",
1008 i,j, colorMatrix[pairings-1][pfreq[0]]);
1009 strcat(colorps, pps);
1013 snprintf(pps, 64, "%d %d %d gmark\n", i, j, pfreq[0]);
1017 snprintf(pps, 64, "%d cmark\n", i);
1021 snprintf(pps, 64, "%d cmark\n", j);
1031 /*--------------------------------------------------------------------------*/
1034 int svg_rna_plot(char *string, char *structure, char *ssfile)
1036 float xmin, xmax, ymin, ymax, size;
1038 float *X, *Y, *R = NULL, *CX = NULL, *CY = NULL;
1042 length = strlen(string);
1044 xyplot = fopen(ssfile, "w");
1045 if (xyplot == NULL) {
1046 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
1050 pair_table = make_pair_table(structure);
1052 X = (float *) space((length+1)*sizeof(float));
1053 Y = (float *) space((length+1)*sizeof(float));
1055 switch(rna_plot_type){
1056 case VRNA_PLOT_TYPE_SIMPLE: i = simple_xy_coordinates(pair_table, X, Y);
1058 case VRNA_PLOT_TYPE_CIRCULAR: {
1059 int radius = 3*length;
1061 R = (float *) space((length+1)*sizeof(float));
1062 CX = (float *) space((length+1)*sizeof(float));
1063 CY = (float *) space((length+1)*sizeof(float));
1064 i = simple_circplot_coordinates(pair_table, X, Y);
1065 for (i = 0; i < length; i++) {
1066 if(i+1 < pair_table[i+1]){
1067 dr = (pair_table[i+1]-i+1 <= (length/2 + 1)) ? pair_table[i+1]-i : i + length - pair_table[i+1];
1068 R[i] = 1. - (2.*dr/(float)length);
1070 else if(pair_table[i+1]){
1071 R[i] = R[pair_table[i+1]-1];
1076 CX[i] = X[i] * radius * R[i] + radius;
1077 CY[i] = Y[i] * radius * R[i] + radius;
1085 default: i = naview_xy_coordinates(pair_table, X, Y);
1089 if(i!=length) fprintf(stderr,"strange things happening in PS_rna_plot...\n");
1094 for (i = 1; i < length; i++) {
1095 xmin = X[i] < xmin ? X[i] : xmin;
1096 xmax = X[i] > xmax ? X[i] : xmax;
1097 ymin = Y[i] < ymin ? Y[i] : ymin;
1098 ymax = Y[i] > ymax ? Y[i] : ymax;
1100 for (i = 0; i < length; i++)
1101 Y[i] = ymin+ymax - Y[i]; /* mirror coordinates so they look as in PS */
1103 if(rna_plot_type == VRNA_PLOT_TYPE_CIRCULAR)
1104 for (i = 0; i < length; i++){
1105 CY[i] = ymin+ymax - CY[i]; /* mirror coordinates so they look as in PS */
1108 size = MAX2((xmax-xmin),(ymax-ymin));
1109 size += 15; /* add some so the bounding box isn't too tight */
1112 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
1113 "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"452\" width=\"452\">\n");
1115 "<script type=\"text/ecmascript\">\n"
1118 " function click() {\n"
1119 " var seq = document.getElementById(\"seq\");\n"
1120 " if (shown==1) {\n"
1121 " seq.setAttribute(\"style\", \"visibility: hidden\");\n"
1124 " seq.setAttribute(\"style\", \"visibility: visible\");\n"
1131 " <rect style=\"stroke: white; fill: white\" height=\"452\" x=\"0\" y=\"0\" width=\"452\" onclick=\"click(evt)\" />\n"
1132 " <g transform=\"scale(%7f,%7f) translate(%7f,%7f)\">\n",
1133 SIZE/size, SIZE/size, (size-xmin-xmax)/2, (size-ymin-ymax)/2);
1136 " <polyline style=\"stroke: black; fill: none; stroke-width: 1.5\" id=\"outline\" points=\"\n");
1137 for (i = 0; i < length; i++)
1138 fprintf(xyplot, " %3.3f,%3.3f\n", X[i], Y[i]);
1139 fprintf(xyplot," \" />\n");
1141 fprintf(xyplot," <g style=\"stroke: black; stroke-width: 1; fill: none;\" id=\"pairs\">\n");
1142 for (i = 1; i <= length; i++) {
1144 if ((j=pair_table[i])>i){
1145 if(rna_plot_type == VRNA_PLOT_TYPE_CIRCULAR)
1147 " <path id=\"%d,%d\" d=\"M %6.15f %6.15f C %6.15f,%6.15f %6.15f,%6.15f %6.15f %6.15f\" />\n",
1148 i,j, X[i-1], Y[i-1], CX[i-1], CY[i-1], CX[j-1], CY[j-1], X[j-1], Y[j-1]);
1151 " <line id=\"%d,%d\" x1=\"%6.5f\" y1=\"%6.5f\" x2=\"%6.5f\" y2=\"%6.5f\" />\n",
1152 i,j, X[i-1], Y[i-1], X[j-1], Y[j-1]);
1155 fprintf(xyplot, " </g>\n");
1156 fprintf(xyplot, " <g style=\"font-family: SansSerif\" transform=\"translate(-4.6, 4)\" id=\"seq\">\n");
1157 for (i = 0; i < length; i++)
1158 fprintf(xyplot, " <text x=\"%.3f\" y=\"%.3f\">%c</text>\n", X[i], Y[i], string[i]);
1159 fprintf(xyplot, " </g>\n");
1160 fprintf(xyplot, " </g>\n");
1161 fprintf(xyplot, "</svg>\n");
1170 return 1; /* success */
1173 /*--------------------------------------------------------------------------*/
1175 PUBLIC int ssv_rna_plot(char *string, char *structure, char *ssfile)
1176 { /* produce input for the SStructView java applet */
1182 float xmin, xmax, ymin, ymax;
1184 ssvfile = fopen(ssfile, "w");
1185 if (ssvfile == NULL) {
1186 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
1189 length = strlen(string);
1190 pair_table = make_pair_table(structure);
1192 /* make coordinates */
1193 X = (float *) space((length+1)*sizeof(float));
1194 Y = (float *) space((length+1)*sizeof(float));
1196 if (rna_plot_type == 0)
1197 i = simple_xy_coordinates(pair_table, X, Y);
1199 i = naview_xy_coordinates(pair_table, X, Y);
1201 fprintf(stderr,"strange things happening in ssv_rna_plot...\n");
1203 /* make coords nonegative */
1206 for (i = 1; i < length; i++) {
1207 xmin = X[i] < xmin ? X[i] : xmin;
1208 xmax = X[i] > xmax ? X[i] : xmax;
1209 ymin = Y[i] < ymin ? Y[i] : ymin;
1210 ymax = Y[i] > ymax ? Y[i] : ymax;
1213 for (i = 0; i <= length; i++)
1218 for (i = 0; i <= length; i++)
1224 float size, xoff, yoff;
1225 float JSIZE = 500; /* size of the java applet window */
1226 /* rescale coordinates, center on square of size HSIZE */
1227 size = MAX2((xmax-xmin),(ymax-ymin));
1228 xoff = (size - xmax + xmin)/2;
1229 yoff = (size - ymax + ymin)/2;
1230 for (i = 0; i <= length; i++) {
1231 X[i] = (X[i]-xmin+xoff)*(JSIZE-10)/size + 5;
1232 Y[i] = (Y[i]-ymin+yoff)*(JSIZE-10)/size + 5;
1239 "# Vienna RNA Package %s\n"
1240 "# SStructView Output\n"
1241 "# CreationDate: %s\n"
1243 "# Options: %s\n", VERSION, time_stamp(), ssfile, option_string());
1244 for (i=1; i<=length; i++)
1245 fprintf(ssvfile, "BASE\t%d\t%c\t%d\t%d\n",
1246 i, string[i-1], (int) (X[i-1]+0.5), (int) (Y[i-1]+0.5));
1247 for (bp=1, i=1; i<=length; i++)
1248 if (pair_table[i]>i)
1249 fprintf(ssvfile, "BASE-PAIR\tbp%d\t%d\t%d\n", bp++, i, pair_table[i]);
1254 return 1; /* success */
1257 /*---------------------------------------------------------------------------*/
1258 PUBLIC int xrna_plot(char *string, char *structure, char *ssfile)
1259 { /* produce input for XRNA RNA drawing program */
1266 ss_file = fopen(ssfile, "w");
1267 if (ss_file == NULL) {
1268 fprintf(stderr, "can't open file %s - not doing xy_plot\n", ssfile);
1272 length = strlen(string);
1273 pair_table = make_pair_table(structure);
1275 /* make coordinates */
1276 X = (float *) space((length+1)*sizeof(float));
1277 Y = (float *) space((length+1)*sizeof(float));
1279 if (rna_plot_type == 0)
1280 i = simple_xy_coordinates(pair_table, X, Y);
1282 i = naview_xy_coordinates(pair_table, X, Y);
1284 fprintf(stderr,"strange things happening in xrna_plot...\n");
1287 "# Vienna RNA Package %s, XRNA output\n"
1288 "# CreationDate: %s\n"
1289 "# Options: %s\n", VERSION, time_stamp(), option_string());
1290 for (i=1; i<=length; i++)
1291 /* XRNA likes to have coordinate mirrored, so we use (-X, Y) */
1292 fprintf(ss_file, "%d %c %6.2f %6.2f %d %d\n", i, string[i-1],
1293 -X[i-1], Y[i-1], (pair_table[i]?1:0), pair_table[i]);
1298 return 1; /* success */
1302 /*---------------------------------------------------------------------------*/
1303 const char *RNAdp_prolog =
1304 "%This file contains the square roots of the base pair probabilities in the form\n"
1305 "% i j sqrt(p(i,j)) ubox\n\n"
1307 "/DPdict 100 dict def\n"
1309 "/logscale false def\n"
1310 "/lpmin 1e-05 log def\n\n"
1311 "/box { %size x y box - draws box centered on x,y\n"
1312 " 2 index 0.5 mul sub % x -= 0.5\n"
1313 " exch 2 index 0.5 mul sub exch % y -= 0.5\n"
1314 " 3 -1 roll dup rectfill\n"
1318 " log dup add lpmin div 1 exch sub dup 0 lt { pop 0 } if\n"
1321 " exch len exch sub 1 add box\n"
1325 " len exch sub 1 add box\n"
1328 "% print sequence along all 4 sides\n"
1330 " [0.7 0.7 len add 0]\n"
1331 " [-0.3 len sub -0.4 -90]\n"
1332 " [-0.3 len sub 0.7 len add -90]\n"
1335 " aload pop rotate translate\n"
1336 " 0 1 len 1 sub {\n"
1338 " sequence exch 1 getinterval\n"
1345 " 0.01 setlinewidth\n"
1346 " len log 0.9 sub cvi 10 exch exp % grid spacing\n"
1348 " dup dup 20 div dup 2 array astore exch 40 div setdash\n"
1349 " } { [0.3 0.7] 0.1 setdash } ifelse\n"
1355 " len exch sub 0 exch moveto\n"
1356 " len exch len exch sub lineto\n"
1360 " 0.04 setlinewidth \n"
1361 " currentdict /cutpoint known {\n"
1363 " dup dup -1 moveto len 1 add lineto\n"
1364 " len exch sub dup\n"
1365 " -1 exch moveto len 1 add exch lineto\n"
1368 " 0.5 neg dup translate\n"
1374 /*---------------------------------------------------------------------------*/
1375 int PS_color_dot_plot(char *seq, cpair *pi, char *wastlfile) {
1376 /* produce color PostScript dot plot from cpair */
1381 length= strlen(seq);
1382 wastl = PS_dot_common(seq, wastlfile, NULL, 0);
1383 if (wastl==NULL) return 0; /* return 0 for failure */
1385 fprintf(wastl, "/hsb {\n"
1386 "dup 0.3 mul 1 exch sub sethsbcolor\n"
1389 fprintf(wastl, "\n%%draw the grid\ndrawgrid\n\n");
1390 fprintf(wastl,"%%start of base pair probability data\n");
1395 fprintf(wastl,"%1.2f %1.2f hsb %d %d %1.6f ubox\n",
1396 pi[i].hue, pi[i].sat, pi[i].i, pi[i].j, sqrt(pi[i].p));
1399 fprintf(wastl,"%1.2f %1.2f hsb %d %d %1.4f lbox\n",
1400 pi[i].hue, pi[i].sat, pi[i].i, pi[i].j, pi[i].p);
1404 fprintf(wastl,"showpage\n"
1408 return 1; /* success */
1411 /*---------------------------------------------------------------------------*/
1413 const char *RNAdp_gquad_triangle =
1414 "/min { 2 copy gt { exch } if pop } bind def\n\n"
1415 "/utri{ % i j prob utri\n"
1418 " 0.85 mul 0.15 add 0.95 0.33\n"
1419 " 3 1 roll % prepare hsb color\n"
1421 " % now produce the coordinates for lines\n"
1422 " exch 1 sub dup len exch sub dup 4 -1 roll dup 3 1 roll dup len exch sub\n"
1423 " moveto lineto lineto closepath fill\n"
1428 static int sort_plist_by_type_desc(const void *p1, const void *p2){
1429 if(((plist*)p1)->type > ((plist*)p2)->type) return -1;
1430 if(((plist*)p1)->type < ((plist*)p2)->type) return 1;
1434 static int sort_plist_by_prob_asc(const void *p1, const void *p2){
1435 if(((plist*)p1)->p > ((plist*)p2)->p) return 1;
1436 if(((plist*)p1)->p < ((plist*)p2)->p) return -1;
1442 PUBLIC int PS_dot_plot_list(char *seq,
1449 int length, pl_size, gq_num;
1451 plist *pl1, *pl_tmp;
1453 length= strlen(seq);
1454 wastl = PS_dot_common(seq, wastlfile, comment, 0);
1455 if (wastl==NULL) return 0; /* return 0 for failure */
1457 fprintf(wastl, "%s\n", RNAdp_gquad_triangle);
1459 fprintf(wastl,"%%data starts here\n");
1461 /* sort the plist to bring all gquad triangles to the front */
1462 for(gq_num = pl_size = 0, pl1 = pl; pl1->i > 0; pl1++, pl_size++)
1463 if(pl1->type == 1) gq_num++;
1464 qsort(pl, pl_size, sizeof(plist), sort_plist_by_type_desc);
1465 /* sort all gquad triangles by probability to bring lower probs to the front */
1466 qsort(pl, gq_num, sizeof(plist), sort_plist_by_prob_asc);
1468 /* print triangles for g-quadruplexes in upper half */
1469 fprintf(wastl,"\n%%start of quadruplex data\n");
1470 for (pl1=pl; pl1->type == 1; pl1++) {
1472 fprintf(wastl, "%d %d %1.9f utri\n", pl1->i, pl1->j, tmp);
1475 fprintf(wastl, "\n%%draw the grid\ndrawgrid\n\n");
1476 fprintf(wastl,"%%start of base pair probability data\n");
1478 /* print boxes in upper right half*/
1479 for (; pl1->i>0; pl1++) {
1482 fprintf(wastl,"%d %d %1.9f ubox\n", pl1->i, pl1->j, tmp);
1486 /* print boxes in lower left half (mfe) */
1487 for (pl1=mf; pl1->i>0; pl1++) {
1489 fprintf(wastl,"%d %d %1.7f lbox\n", pl1->i, pl1->j, tmp);
1492 fprintf(wastl,"showpage\n"
1496 return 1; /* success */
1499 const char *RNAdp_prolog_turn =
1501 "% print sequence at bottom\n"
1503 " len 2 sqrt div dup neg 0.28 add exch 0.78 sub translate\n"
1504 " 0 1 len 1 sub {\n"
1505 " dup dup 2 sqrt mul 0 moveto\n"
1506 " sequence exch 1 getinterval\n"
1512 " 0.01 setlinewidth\n"
1513 " len log 0.9 sub cvi 10 exch exp % grid spacing\n"
1515 " dup dup 20 div dup 2 array astore exch 40 div setdash\n"
1516 " } { [0.3 0.7] 0.1 setdash } ifelse\n"
1517 " 0 exch len { %for (0, gridspacing, len) \n"
1518 " dup dup %duplicate what - gridspacing??\n"
1519 " dup len exch sub moveto %moveto diagonal?\n"
1521 " {dup dup len exch sub winSize add lineto}\n"
1522 " {dup len lineto}ifelse\n"
1523 " dup len exch sub moveto %moveto diagonal?\n"
1524 " dup len winSize sub le\n"
1525 " {dup dup len exch sub dup winSize exch sub len add exch lineto}\n"
1526 " {dup dup len exch sub len exch lineto}ifelse"
1529 " len log 0.9 sub cvi 10 exch exp % grid spacing\n"
1531 " dup dup 20 div dup 2 array astore exch 40 div setdash\n"
1532 " } { [0.3 0.7] 0.1 setdash } ifelse\n"
1533 " 0 exch len { %for (0, gridspacing, len) \n"
1534 " dup dup %duplicate what - gridspacing??\n"
1535 " dup len exch sub moveto %moveto diagonal?\n"
1536 " len exch sub 0.7 sub exch 0.7 sub exch lineto\n"
1539 " winSize len moveto len winSize lineto stroke\n"
1541 " 0.04 setlinewidth \n"
1542 " currentdict /cutpoint known {\n"
1544 " dup dup -1 moveto len 1 add lineto\n"
1545 " len exch sub dup\n"
1546 " -1 exch moveto len 1 add exch lineto\n"
1549 " 0.5 neg dup translate\n"
1552 int PS_color_dot_plot_turn(char *seq, cpair *pi, char *wastlfile, int winSize) {
1553 /* produce color PostScript dot plot from cpair */
1558 length= strlen(seq);
1559 wastl = PS_dot_common(seq, wastlfile, NULL, winSize);
1561 return 0; /* return 0 for failure */
1563 fprintf(wastl, "/hsb {\n"
1564 "dup 0.3 mul 1 exch sub sethsbcolor\n"
1569 fprintf(wastl, "\n%%draw the grid\ndrawgrid_turn\n\n");
1571 fprintf(wastl, "\n%%draw the grid\ndrawgrid\n\n");
1572 fprintf(wastl,"%%start of base pair probability data\n");
1577 fprintf(wastl,"%1.2f %1.2f hsb %d %d %1.6f ubox\n",
1578 pi[i].hue, pi[i].sat, pi[i].i, pi[i].j, sqrt(pi[i].p));/*sqrt??*/
1581 fprintf(wastl,"%1.2f %1.2f hsb %d %d %1.4f lbox\n",
1582 pi[i].hue, pi[i].sat, pi[i].i, pi[i].j, pi[i].p);
1586 fprintf(wastl,"showpage\n"
1590 return 1; /* success */
1593 int PS_dot_plot_turn(char *seq, struct plist *pl, char *wastlfile, int winSize) {
1594 /* produce color PostScript dot plot from cpair */
1599 length= strlen(seq);
1600 wastl = PS_dot_common(seq, wastlfile, NULL, winSize);
1602 return 0; /* return 0 for failure */
1605 fprintf(wastl, "\n%%draw the grid\ndrawgrid_turn\n\n");
1607 fprintf(wastl, "\n%%draw the grid\ndrawgrid\n\n");
1608 fprintf(wastl,"%%start of base pair probability data\n");
1612 fprintf(wastl,"%d %d %1.4f ubox\n",
1613 pl[i].i, pl[i].j, sqrt(pl[i].p));
1617 fprintf(wastl,"showpage\n"
1621 return 1; /* success */
1624 static FILE * PS_dot_common(char *seq, char *wastlfile,
1625 char *comment, int winsize) {
1626 /* write PS header etc for all dot plot variants */
1631 length= strlen(seq);
1632 wastl = fopen(wastlfile,"w");
1634 fprintf(stderr, "can't open %s for dot plot\n", wastlfile);
1635 return NULL; /* return 0 for failure */
1637 strncpy(name, wastlfile, 30);
1638 if ((c=strrchr(name, '_'))!=0) *c='\0';
1641 "%%!PS-Adobe-3.0 EPSF-3.0\n"
1642 "%%%%Title: RNA Dot Plot\n"
1643 "%%%%Creator: %s, ViennaRNA-%s\n"
1644 "%%%%CreationDate: %s", rcsid+5, VERSION, time_stamp());
1646 fprintf(wastl, "%%%%BoundingBox: 66 530 520 650\n");
1648 fprintf(wastl, "%%%%BoundingBox: 66 211 518 662\n");
1650 "%%%%DocumentFonts: Helvetica\n"
1652 "%%%%EndComments\n\n"
1653 "%%Options: %s\n", option_string());
1655 if (comment) fprintf(wastl,"%% %s\n",comment);
1657 fprintf(wastl,"%s", RNAdp_prolog);
1659 fprintf(wastl,"DPdict begin\n"
1660 "%%delete next line to get rid of title\n"
1661 "270 665 moveto /Helvetica findfont 14 scalefont setfont "
1662 "(%s) show\n\n", name);
1664 fprintf(wastl,"/sequence { (\\\n");
1665 for (i=0; i<strlen(seq); i+=255)
1666 fprintf(wastl, "%.255s\\\n", seq+i);
1667 fprintf(wastl,") } def\n");
1669 fprintf(wastl,"/winSize %d def\n",winsize);
1670 fprintf(wastl,"/len { sequence length } bind def\n\n");
1671 if (cut_point>0) fprintf(wastl,"/cutpoint %d def\n\n", cut_point);
1675 fprintf(wastl,"292 416 translate\n"
1676 "72 6 mul len 1 add winSize add 2 sqrt mul div dup scale\n");
1678 fprintf(wastl,"72 216 translate\n"
1679 "72 6 mul len 1 add div dup scale\n");
1680 fprintf(wastl, "/Helvetica findfont 0.95 scalefont setfont\n\n");
1683 fprintf(wastl, "%s", RNAdp_prolog_turn);
1684 fprintf(wastl,"0.5 dup translate\n"
1689 fprintf(wastl,"drawseq\n"
1690 "0.5 dup translate\n"
1691 "%% draw diagonal\n"
1692 "0.04 setlinewidth\n"
1693 "0 len moveto len 0 lineto stroke \n\n");
1697 int PS_color_aln(const char *structure, const char *filename,
1698 const char *seqs[], const char *names[]) {
1699 /* produce PS sequence alignment color-annotated by consensus structure */
1701 int N,i,j,k,x,y,tmp,columnWidth;
1702 char *tmpBuffer,*ssEscaped,*ruler, *cons;
1704 float fontWidth, fontHeight, imageHeight, imageWidth,tmpColumns;
1705 int length, maxName, maxNum, currPos;
1706 float lineStep,blockStep,consStep,ssStep,rulerStep,nameStep,numberStep;
1707 float maxConsBar,startY,namesX,seqsX, currY;
1708 float score,barHeight,xx,yy;
1712 char * colorMatrix[6][3] = {
1713 {"0.0 1", "0.0 0.6", "0.0 0.2"}, /* red */
1714 {"0.16 1","0.16 0.6", "0.16 0.2"}, /* ochre */
1715 {"0.32 1","0.32 0.6", "0.32 0.2"}, /* turquoise */
1716 {"0.48 1","0.48 0.6", "0.48 0.2"}, /* green */
1717 {"0.65 1","0.65 0.6", "0.65 0.2"}, /* blue */
1718 {"0.81 1","0.81 0.6", "0.81 0.2"} /* violet */
1721 const char *alnPlotHeader =
1722 "%%!PS-Adobe-3.0 EPSF-3.0\n"
1723 "%%%%BoundingBox: %i %i %i %i\n"
1725 "%% draws Vienna RNA like colored boxes\n"
1726 "/box { %% x1 y1 x2 y2 hue saturation\n"
1728 " dup 0.3 mul 1 exch sub sethsbcolor\n"
1729 " exch 3 index sub exch 2 index sub rectfill\n"
1732 "%% draws a box in current color\n"
1733 "/box2 { %% x1 y1 x2 y2\n"
1734 " exch 3 index sub exch 2 index sub rectfill\n"
1736 "/string { %% (Text) x y\n"
1743 "/Courier findfont\n"
1744 "[10 0 0 -10 0 0] makefont setfont\n";
1747 outfile = fopen(filename, "w");
1749 if (outfile == NULL) {
1750 fprintf(stderr, "can't open file %s - not doing alignment plot\n",
1755 columnWidth=60; /* Display long alignments in blocks of this size */
1756 fontWidth=6; /* Font metrics */
1758 lineStep=fontHeight+2; /* distance between lines */
1759 blockStep=3.5*fontHeight; /* distance between blocks */
1760 consStep=fontHeight*0.5; /* distance between alignment and conservation curve */
1761 ssStep=2; /* distance between secondary structure line and sequences */
1762 rulerStep=2; /* distance between sequences and ruler */
1763 nameStep=3*fontWidth; /* distance between names and sequences */
1764 numberStep=fontWidth; /* distance between sequeces and numbers */
1765 maxConsBar=2.5*fontHeight; /* Height of conservation curve */
1766 startY=2; /* "y origin" */
1767 namesX=fontWidth; /* "x origin" */
1769 /* Number of columns of the alignment */
1770 length=strlen(seqs[0]);
1772 /* Allocate memory for various strings, length*2 is (more than)
1773 enough for all of them */
1774 tmpBuffer = (char *) space((unsigned) MAX2(length*2,columnWidth)+1);
1775 ssEscaped=(char *) space((unsigned) length*2);
1776 ruler=(char *) space((unsigned) length*2);
1778 pair_table=make_pair_table(structure);
1779 /* Get length of longest name and count sequences in alignment*/
1781 for (i=maxName=N=0; names[i] != NULL; i++) {
1783 tmp=strlen(names[i]);
1784 if (tmp>maxName) maxName=tmp;
1788 /* x-coord. where sequences start */
1789 seqsX=namesX+maxName*fontWidth+nameStep;
1791 /* calculate number of digits of the alignment length */
1792 snprintf(tmpBuffer,length, "%i",length);
1793 maxNum=strlen(tmpBuffer);
1796 /* Calculate bounding box */
1797 tmpColumns=columnWidth;
1798 if (length<columnWidth){
1801 imageWidth=ceil(namesX+(maxName+tmpColumns+maxNum)*fontWidth+2*nameStep+fontWidth+numberStep);
1802 imageHeight=startY+ceil((float)length/columnWidth)*((N+2)*lineStep+blockStep+consStep+ssStep+rulerStep);
1804 /* Write postscript header including correct bounding box */
1805 fprintf(outfile,alnPlotHeader,0,0,(int)imageWidth,(int)imageHeight,(int)imageHeight);
1807 /* Create ruler and secondary structure lines */
1809 /* Init all with dots */
1810 for (i=0;i<(length);i++){
1814 for (i=0;i<length;i++){
1815 /* Write number every 10th position, leave out block breaks */
1816 if ((i+1)%10==0 && (i+1)%columnWidth!=0){
1817 snprintf(tmpBuffer,length,"%i",i+1);
1818 strncpy(ruler+i,tmpBuffer,strlen(tmpBuffer));
1823 /* Draw color annotation first */
1824 /* Repeat for all pairs */
1825 for (i=1; i<=length; i++) {
1826 if ((j=pair_table[i])>i) {
1827 /* Repeat for open and closing position */
1829 int pairings, nonpair, s, col;
1830 int ptype[8] = {0,0,0,0,0,0,0,0};
1832 col = (k==0)?i-1:j-1;
1833 block=ceil((float)(col+1)/columnWidth);
1834 xx=seqsX+(col-(block-1)*columnWidth)*fontWidth;
1835 /* Repeat for each sequence */
1836 for (s=pairings=nonpair=0; s<N; s++) {
1837 ptype[BP_pair[ENCODE(seqs[s][i-1])][ENCODE(seqs[s][j-1])]]++;
1839 for (pairings=0,s=1; s<=7; s++) {
1840 if (ptype[s]) pairings++;
1844 color = colorMatrix[pairings-1][nonpair];
1845 for (s=0; s<N; s++) {
1846 yy=startY+(block-1)*(lineStep*(N+2)+blockStep+consStep+rulerStep)+ssStep*(block)+(s+1)*lineStep;
1848 /* Color according due color information in pi-array, only if base pair is possible */
1849 if (BP_pair[ENCODE(seqs[s][i-1])][ENCODE(seqs[s][j-1])]) {
1851 fprintf(outfile, "%.1f %.1f %.1f %.1f %s box\n",
1852 xx,yy-1,xx+fontWidth,yy+fontHeight+1,color);
1861 /* Process rest of the output in blocks of columnWidth */
1866 cons = consensus(seqs);
1868 while (currPos<length) {
1870 /* Display secondary structure line */
1871 fprintf(outfile,"0 setgray\n");
1872 strncpy(tmpBuffer,structure+currPos,columnWidth);
1873 tmpBuffer[columnWidth]='\0';
1876 while ((c=tmpBuffer[x])){
1880 ssEscaped[y++]='\\';
1887 fprintf(outfile, "(%s) %.1f %.1f string\n", ssEscaped,seqsX,currY);
1888 currY+=ssStep+lineStep;
1890 /* Display names, sequences and numbers */
1892 for (i=0; i<N; i++) {
1894 strncpy(tmpBuffer,seqs[i]+currPos,columnWidth);
1895 tmpBuffer[columnWidth]='\0';
1898 for (j=0;j<(currPos+strlen(tmpBuffer));j++){
1899 if (seqs[i][j] != '-') match++;
1902 fprintf(outfile, "(%s) %.1f %.1f string\n", names[i],namesX,currY);
1903 fprintf(outfile, "(%s) %.1f %.1f string\n", tmpBuffer,seqsX,currY);
1904 fprintf(outfile, "(%i) %.1f %.1f string\n", match,seqsX+fontWidth*(strlen(tmpBuffer))+numberStep,currY);
1908 strncpy(tmpBuffer,ruler+currPos,columnWidth);
1909 tmpBuffer[columnWidth]='\0';
1910 fprintf(outfile, "(%s) %.1f %.1f string\n", tmpBuffer,seqsX,currY);
1915 /*Display conservation bar*/
1917 fprintf(outfile,"0.6 setgray\n");
1918 for (i=currPos;(i<currPos+columnWidth && i<length);i++){
1921 if (cons[i] == seqs[j][i]) match++;
1922 if (cons[i]=='U' && seqs[j][i]=='T') match++;
1923 if (cons[i]=='T' && seqs[j][i]=='U') match++;
1925 score=(float)(match-1)/(N-1);
1927 if (cons[i] == '-' ||
1933 barHeight=maxConsBar*score;
1938 xx=seqsX+(i-(columnWidth*currPos/columnWidth))*fontWidth;
1940 fprintf(outfile,"%.1f %.1f %.1f %.1f box2\n",
1942 currY+maxConsBar-barHeight,
1948 currPos+=columnWidth;
1952 fprintf(outfile,"showpage\n");
1956 free(ssEscaped);free(ruler);
1962 int aliPS_color_aln(const char *structure, const char *filename,
1963 const char *seqs[], const char *names[]) {
1964 /* produce PS sequence alignment color-annotated by consensus structure */
1966 int N,i,j,k,x,y,tmp,columnWidth;
1967 char *tmpBuffer,*ssEscaped,*ruler, *cons;
1969 float fontWidth, fontHeight, imageHeight, imageWidth,tmpColumns;
1970 int length, maxName, maxNum, currPos;
1971 float lineStep,blockStep,consStep,ssStep,rulerStep,nameStep,numberStep;
1972 float maxConsBar,startY,namesX,seqsX, currY;
1973 float score,barHeight,xx,yy;
1977 char * colorMatrix[6][3] = {
1978 {"0.0 1", "0.0 0.6", "0.0 0.2"}, /* red */
1979 {"0.16 1","0.16 0.6", "0.16 0.2"}, /* ochre */
1980 {"0.32 1","0.32 0.6", "0.32 0.2"}, /* turquoise */
1981 {"0.48 1","0.48 0.6", "0.48 0.2"}, /* green */
1982 {"0.65 1","0.65 0.6", "0.65 0.2"}, /* blue */
1983 {"0.81 1","0.81 0.6", "0.81 0.2"} /* violet */
1986 const char *alnPlotHeader =
1987 "%%!PS-Adobe-3.0 EPSF-3.0\n"
1988 "%%%%BoundingBox: %i %i %i %i\n"
1990 "%% draws Vienna RNA like colored boxes\n"
1991 "/box { %% x1 y1 x2 y2 hue saturation\n"
1993 " dup 0.3 mul 1 exch sub sethsbcolor\n"
1994 " exch 3 index sub exch 2 index sub rectfill\n"
1997 "%% draws a box in current color\n"
1998 "/box2 { %% x1 y1 x2 y2\n"
1999 " exch 3 index sub exch 2 index sub rectfill\n"
2001 "/string { %% (Text) x y\n"
2008 "/Courier findfont\n"
2009 "[10 0 0 -10 0 0] makefont setfont\n";
2012 outfile = fopen(filename, "w");
2013 if (outfile == NULL) {
2014 fprintf(stderr, "can't open file %s - not doing alignment plot\n",
2019 columnWidth=100; /* Display long alignments in blocks of this size */
2020 fontWidth=6; /* Font metrics */
2022 lineStep=fontHeight+2; /* distance between lines */
2023 blockStep=3.5*fontHeight; /* distance between blocks */
2024 consStep=fontHeight*0.5; /* distance between alignment and conservation curve */
2025 ssStep=2; /* distance between secondary structure line and sequences */
2026 rulerStep=2; /* distance between sequences and ruler */
2027 nameStep=3*fontWidth; /* distance between names and sequences */
2028 numberStep=fontWidth; /* distance between sequeces and numbers */
2029 maxConsBar=2.5*fontHeight; /* Height of conservation curve */
2030 startY=2; /* "y origin" */
2031 namesX=fontWidth; /* "x origin" */
2033 /* Number of columns of the alignment */
2034 length=strlen(seqs[0]);
2036 /* Allocate memory for various strings, length*2 is (more than)
2037 enough for all of them */
2038 tmpBuffer = (char *) space((unsigned) columnWidth + length*2 );
2039 ssEscaped=(char *) space((unsigned) length*2 );
2040 ruler=(char *) space((unsigned) length*2 );
2041 /* char * structur; */
2042 /* structur = (char*) space((length+1)*sizeof(char)); */
2043 /* structur = strdup(structure); */
2044 /* for(i=0; i<length;i++){ */
2045 /* if(structur[i] == '<') structur[i]='('; */
2046 /* if(structur[i] == '>') structur[i]=')'; */
2048 /* structur[length]='\0'; */
2049 /* printf("%s \n", structur); */
2050 pair_table=alimake_pair_table(structure);
2051 /* Get length of longest name and count sequences in alignment*/
2053 for (i=maxName=N=0; names[i] != NULL; i++) {
2055 tmp=strlen(names[i]);
2056 if (tmp>maxName) maxName=tmp;
2060 /* x-coord. where sequences start */
2061 seqsX=namesX+maxName*fontWidth+nameStep;
2063 /* calculate number of digits of the alignment length */
2064 snprintf(tmpBuffer,length, "%i",length);
2065 maxNum=strlen(tmpBuffer);
2068 /* Calculate bounding box */
2069 tmpColumns=columnWidth;
2070 if (length<columnWidth){
2073 imageWidth=ceil(namesX+(maxName+tmpColumns+maxNum)*fontWidth+2*nameStep+fontWidth+numberStep);
2074 imageHeight=startY+ceil((float)length/columnWidth)*((N+2)*lineStep+blockStep+consStep+ssStep+rulerStep);
2076 /* Write postscript header including correct bounding box */
2077 fprintf(outfile,alnPlotHeader,0,0,(int)imageWidth,(int)imageHeight,(int)imageHeight);
2079 /* Create ruler and secondary structure lines */
2081 /* Init all with dots */
2082 for (i=0;i<(length);i++){
2086 for (i=0;i<length;i++){
2087 /* Write number every 10th position, leave out block breaks */
2088 if ((i+1)%10==0 && (i+1)%columnWidth!=0){
2089 snprintf(tmpBuffer,length,"%i",i+1);
2090 strncpy(ruler+i,tmpBuffer,strlen(tmpBuffer));
2095 /* Draw color annotation first */
2096 /* Repeat for all pairs */
2097 for (i=1; i<=length; i++) {
2098 if ((j=pair_table[i])>i) {
2099 /* Repeat for open and closing position */
2101 int pairings, nonpair, s, col;
2102 int ptype[8] = {0,0,0,0,0,0,0,0};
2104 col = (k==0)?i-1:j-1;
2105 block=ceil((float)(col+1)/columnWidth);
2106 xx=seqsX+(col-(block-1)*columnWidth)*fontWidth;
2107 /* Repeat for each sequence */
2108 for (s=pairings=nonpair=0; s<N; s++) {
2109 ptype[BP_pair[ENCODE(seqs[s][i-1])][ENCODE(seqs[s][j-1])]]++;
2111 for (pairings=0,s=1; s<=7; s++) {
2112 if (ptype[s]) pairings++;
2116 color = colorMatrix[pairings-1][nonpair];
2117 for (s=0; s<N; s++) {
2118 yy=startY+(block-1)*(lineStep*(N+2)+blockStep+consStep+rulerStep)+ssStep*(block)+(s+1)*lineStep;
2120 /* Color according due color information in pi-array, only if base pair is possible */
2121 if (BP_pair[ENCODE(seqs[s][i-1])][ENCODE(seqs[s][j-1])]) {
2123 fprintf(outfile, "%.1f %.1f %.1f %.1f %s box\n",
2124 xx,yy-1,xx+fontWidth,yy+fontHeight+1,color);
2133 /* Process rest of the output in blocks of columnWidth */
2138 cons = consensus(seqs);
2140 while (currPos<length) {
2142 /* Display secondary structure line */
2143 fprintf(outfile,"0 setgray\n");
2144 strncpy(tmpBuffer,structure+currPos,columnWidth);
2145 tmpBuffer[columnWidth]='\0';
2148 while ((c=tmpBuffer[x])){
2152 ssEscaped[y++]='\\';
2159 fprintf(outfile, "(%s) %.1f %.1f string\n", ssEscaped,seqsX,currY);
2160 currY+=ssStep+lineStep;
2162 /* Display names, sequences and numbers */
2164 for (i=0; i<N; i++) {
2166 strncpy(tmpBuffer,seqs[i]+currPos,columnWidth);
2167 tmpBuffer[columnWidth]='\0';
2170 for (j=0;j<(currPos+strlen(tmpBuffer));j++){
2171 if (seqs[i][j] != '-') match++;
2174 fprintf(outfile, "(%s) %.1f %.1f string\n", names[i],namesX,currY);
2175 fprintf(outfile, "(%s) %.1f %.1f string\n", tmpBuffer,seqsX,currY);
2176 fprintf(outfile, "(%i) %.1f %.1f string\n", match,seqsX+fontWidth*(strlen(tmpBuffer))+numberStep,currY);
2180 strncpy(tmpBuffer,ruler+currPos,columnWidth);
2181 tmpBuffer[columnWidth]='\0';
2182 fprintf(outfile, "(%s) %.1f %.1f string\n", tmpBuffer,seqsX,currY);
2187 /*Display conservation bar*/
2189 fprintf(outfile,"0.6 setgray\n");
2190 for (i=currPos;(i<currPos+columnWidth && i<length);i++){
2193 if (cons[i] == seqs[j][i]) match++;
2194 if (cons[i]=='U' && seqs[j][i]=='T') match++;
2195 if (cons[i]=='T' && seqs[j][i]=='U') match++;
2197 score=(float)(match-1)/(N-1);
2199 if (cons[i] == '-' ||
2205 barHeight=maxConsBar*score;
2210 xx=seqsX+(i-(columnWidth*currPos/columnWidth))*fontWidth;
2212 fprintf(outfile,"%.1f %.1f %.1f %.1f box2\n",
2214 currY+maxConsBar-barHeight,
2220 currPos+=columnWidth;
2223 fprintf(outfile,"showpage\n");
2226 free(ssEscaped);free(ruler);
2232 /*###########################################*/
2233 /*# deprecated functions below #*/
2234 /*###########################################*/
2236 int PS_dot_plot(char *string, char *wastlfile) {
2237 /* this is just a wrapper to call PS_dot_plot_list */
2238 int i, j, k, length, maxl, mf_num;
2242 length = strlen(string);
2244 pl = (struct plist *)space(maxl*sizeof(struct plist));
2246 /*make plist out of pr array*/
2247 for (i=1; i<length; i++)
2248 for (j=i+1; j<=length; j++) {
2249 if (pr[iindx[i]-j]<PMIN) continue;
2252 pl = (struct plist *)xrealloc(pl,maxl*sizeof(struct plist));
2256 pl[k++].p = pr[iindx[i]-j];
2261 /*make plist out of base_pair array*/
2262 mf_num = base_pair ? base_pair[0].i : 0;
2263 mf = (struct plist *)space((mf_num+1)*sizeof(struct plist));
2264 for (k=0; k<mf_num; k++) {
2265 mf[k].i = base_pair[k+1].i;
2266 mf[k].j = base_pair[k+1].j;
2267 mf[k].p = 0.95*0.95;
2272 i = PS_dot_plot_list(string, wastlfile, pl, mf, "");