2 * This file is a container for all plotting layout algorithms
5 * The ViennaRNA Package
13 #include "plot_layouts.h"
20 #define PRIVATE static
22 PUBLIC int rna_plot_type = 1; /* 0 = simple, 1 = naview, 2 = circular plot */
25 PRIVATE int *loop_size, *stack_size;
28 PRIVATE void loop(int i, int j, short *pair_table);
31 /* NOTE: all threadprivate variables are uninitialized when entering a thread! */
32 #pragma omp threadprivate(angle, loop_size, stack_size, lp, stk)
35 /*---------------------------------------------------------------------------*/
37 PUBLIC int simple_xy_coordinates(short *pair_table, float *x, float *y)
39 float INIT_ANGLE=0.; /* initial bending angle */
40 float INIT_X = 100.; /* coordinate of first digit */
41 float INIT_Y = 100.; /* see above */
47 length = pair_table[0];
48 angle = (float*) space( (length+5)*sizeof(float) );
49 loop_size = (int*) space( 16+(length/5)*sizeof(int) );
50 stack_size = (int*) space( 16+(length/5)*sizeof(int) );
52 loop(0, length+1, pair_table);
53 loop_size[lp] -= 2; /* correct for cheating with function loop */
59 for (i = 1; i <= length; i++) {
60 x[i] = x[i-1]+RADIUS*cos(alpha);
61 y[i] = y[i-1]+RADIUS*sin(alpha);
62 alpha += PI-angle[i+1];
72 /*---------------------------------------------------------------------------*/
74 PRIVATE void loop(int i, int j, short *pair_table)
75 /* i, j are the positions AFTER the last pair of a stack; i.e
76 i-1 and j+1 are paired. */
78 int count = 2; /* counts the VERTICES of a loop polygon; that's
79 NOT necessarily the number of unpaired bases!
80 Upon entry the loop has already 2 vertices, namely
83 int r = 0, bubble = 0; /* bubble counts the unpaired digits in loops */
85 int i_old, partner, k, l, start_k, start_l, fill, ladder;
91 remember = (short *) space((1+(j-i)/5)*2*sizeof(short));
93 i_old = i-1, j++; /* j has now been set to the partner of the
94 previous pair for correct while-loop
97 partner = pair_table[i];
98 if ((!partner) || (i==0))
99 i++, count++, bubble++;
102 k = i, l = partner; /* beginning of stack */
105 i = partner+1; /* next i for the current loop */
107 start_k = k, start_l = l;
110 k++, l--, ladder++; /* go along the stack region */
112 while (pair_table[k] == l);
116 angle[start_k+1+fill] += PIHALF; /* Loop entries and */
117 angle[start_l-1-fill] += PIHALF; /* exits get an */
118 angle[start_k] += PIHALF; /* additional PI/2. */
119 angle[start_l] += PIHALF; /* Why ? (exercise) */
121 for (; fill >= 1; fill--) {
122 angle[start_k+fill] = PI; /* fill in the angles */
123 angle[start_l-fill] = PI; /* for the backbone */
127 stack_size[++stk] = ladder;
128 loop(k, l, pair_table);
131 polygon = PI*(count-2)/(float)count; /* bending angle in loop polygon */
133 begin = i_old < 0 ? 0 : i_old;
134 for (v = 1; v <= r; v++) {
135 diff = remember[v]-begin;
136 for (fill = 0; fill <= diff; fill++)
137 angle[begin+fill] += polygon;
140 begin = remember[++v];
142 loop_size[++lp] = bubble;
146 /*---------------------------------------------------------------------------*/
148 PUBLIC int simple_circplot_coordinates(short *pair_table, float *x, float *y){
149 unsigned int length = (unsigned int) pair_table[0];
151 float d = 2*PI/length;
152 for(i=0; i < length; i++){
153 x[i] = cos(i * d - PI/2);
154 y[i] = sin(i * d - PI/2);