RNAlib-2.2.5
gquad.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_GQUAD_H
2 #define VIENNA_RNA_PACKAGE_GQUAD_H
3 
5 #include <ViennaRNA/params.h>
6 
7 #ifndef INLINE
8 #ifdef __GNUC__
9 # define INLINE inline
10 #else
11 # define INLINE
12 #endif
13 #endif
14 
25 int E_gquad(int L,
26  int l[3],
27  vrna_param_t *P);
28 
29 FLT_OR_DBL exp_E_gquad( int L,
30  int l[3],
31  vrna_exp_param_t *pf);
32 
33 int E_gquad_ali(int i,
34  int L,
35  int l[3],
36  const short **S,
37  int n_seq,
38  vrna_param_t *P);
39 
40 
41 void E_gquad_ali_en( int i,
42  int L,
43  int l[3],
44  const short **S,
45  int n_seq,
46  int en[2],
47  vrna_param_t *P);
48 
65 int *get_gquad_matrix(short *S, vrna_param_t *P);
66 
67 int *get_gquad_ali_matrix(short *S_cons,
68  short **S,
69  int n_seq,
70  vrna_param_t *P);
71 
72 FLT_OR_DBL *get_gquad_pf_matrix( short *S,
73  FLT_OR_DBL *scale,
74  vrna_exp_param_t *pf);
75 
76 int **get_gquad_L_matrix( short *S,
77  int start,
78  int maxdist,
79  int **g,
80  vrna_param_t *P);
81 
82 void vrna_gquad_mx_local_update( vrna_fold_compound_t *vc,
83  int start);
84 
85 void get_gquad_pattern_mfe(short *S,
86  int i,
87  int j,
88  vrna_param_t *P,
89  int *L,
90  int l[3]);
91 
92 void
93 get_gquad_pattern_exhaustive( short *S,
94  int i,
95  int j,
96  vrna_param_t *P,
97  int *L,
98  int *l,
99  int threshold);
100 
101 void get_gquad_pattern_pf( short *S,
102  int i,
103  int j,
104  vrna_exp_param_t *pf,
105  int *L,
106  int l[3]);
107 
108 plist *get_plist_gquad_from_pr( short *S,
109  int gi,
110  int gj,
111  FLT_OR_DBL *G,
112  FLT_OR_DBL *probs,
113  FLT_OR_DBL *scale,
114  vrna_exp_param_t *pf);
115 plist *get_plist_gquad_from_pr_max(short *S,
116  int gi,
117  int gj,
118  FLT_OR_DBL *G,
119  FLT_OR_DBL *probs,
120  FLT_OR_DBL *scale,
121  int *L,
122  int l[3],
123  vrna_exp_param_t *pf);
124 
125 plist *get_plist_gquad_from_db( const char *structure,
126  float pr);
127 
128 int get_gquad_count(short *S,
129  int i,
130  int j);
131 
132 int get_gquad_layer_count(short *S,
133  int i,
134  int j);
135 
136 
147 int parse_gquad(const char *struc, int *L, int l[3]);
148 
149 INLINE PRIVATE int backtrack_GQuad_IntLoop(int c,
150  int i,
151  int j,
152  int type,
153  short *S,
154  int *ggg,
155  int *index,
156  int *p,
157  int *q,
158  vrna_param_t *P);
159 
160 INLINE PRIVATE int backtrack_GQuad_IntLoop_L(int c,
161  int i,
162  int j,
163  int type,
164  short *S,
165  int **ggg,
166  int maxdist,
167  int *p,
168  int *q,
169  vrna_param_t *P);
170 
171 PRIVATE INLINE int
172 vrna_BT_gquad_mfe(vrna_fold_compound_t *vc,
173  int i,
174  int j,
175  vrna_bp_stack_t *bp_stack,
176  int *stack_count);
177 
178 PRIVATE INLINE int
179 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
180  int i,
181  int j,
182  int en,
183  vrna_bp_stack_t *bp_stack,
184  int *stack_count);
185 
186 PRIVATE INLINE int
187 vrna_BT_gquad_mfe(vrna_fold_compound_t *vc,
188  int i,
189  int j,
190  vrna_bp_stack_t *bp_stack,
191  int *stack_count){
192 
193  /*
194  here we do some fancy stuff to backtrace the stacksize and linker lengths
195  of the g-quadruplex that should reside within position i,j
196  */
197  short *S;
198  int l[3], L, a;
199  vrna_param_t *P;
200 
201  P = vc->params;
202  S = vc->sequence_encoding2;
203  L = -1;
204 
205  get_gquad_pattern_mfe(S, i, j, P, &L, l);
206 
207  if(L != -1){
208  /* fill the G's of the quadruplex into base_pair2 */
209  for(a=0;a<L;a++){
210  bp_stack[++(*stack_count)].i = i+a;
211  bp_stack[(*stack_count)].j = i+a;
212  bp_stack[++(*stack_count)].i = i+L+l[0]+a;
213  bp_stack[(*stack_count)].j = i+L+l[0]+a;
214  bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+a;
215  bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+a;
216  bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+L+l[2]+a;
217  bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+L+l[2]+a;
218  }
219  return 1;
220  } else {
221  return 0;
222  }
223 }
224 
225 PRIVATE INLINE int
226 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
227  int i,
228  int j,
229  int en,
230  vrna_bp_stack_t *bp_stack,
231  int *stack_count){
232 
233  int energy, dangles, *idx, ij, p, q, maxl, minl, c0, l1, *rtype, *ggg;
234  unsigned char type;
235  char *ptype;
236  short si, sj, *S, *S1;
237 
238  vrna_param_t *P;
239  vrna_md_t *md;
240 
241  idx = vc->jindx;
242  ij = idx[j] + i;
243  P = vc->params;
244  md = &(P->model_details);
245  ptype = vc->ptype;
246  rtype = &(md->rtype[0]);
247  type = rtype[(unsigned char)ptype[ij]];
248  S1 = vc->sequence_encoding;
249  S = vc->sequence_encoding2;
250  dangles = md->dangles;
251  si = S1[i + 1];
252  sj = S1[j - 1];
253  ggg = vc->matrices->ggg;
254  energy = 0;
255 
256  if(dangles == 2)
257  energy += P->mismatchI[type][si][sj];
258 
259  if(type > 2)
260  energy += P->TerminalAU;
261 
262  p = i + 1;
263  if(S1[p] == 3){
264  if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
265  minl = j - i + p - MAXLOOP - 2;
266  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
267  minl = MAX2(c0, minl);
268  c0 = j - 3;
269  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
270  maxl = MIN2(c0, maxl);
271  for(q = minl; q < maxl; q++){
272  if(S[q] != 3) continue;
273  if(en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1]){
274  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
275  }
276  }
277  }
278  }
279 
280  for(p = i + 2;
281  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
282  p++){
283  l1 = p - i - 1;
284  if(l1>MAXLOOP) break;
285  if(S1[p] != 3) continue;
286  minl = j - i + p - MAXLOOP - 2;
287  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
288  minl = MAX2(c0, minl);
289  c0 = j - 1;
290  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
291  maxl = MIN2(c0, maxl);
292  for(q = minl; q < maxl; q++){
293  if(S1[q] != 3) continue;
294  if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1]){
295  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
296  }
297  }
298  }
299 
300  q = j - 1;
301  if(S1[q] == 3)
302  for(p = i + 4;
303  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
304  p++){
305  l1 = p - i - 1;
306  if(l1>MAXLOOP) break;
307  if(S1[p] != 3) continue;
308  if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1]){
309  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
310  }
311  }
312 
313  return 0;
314 }
315 
333 INLINE PRIVATE int backtrack_GQuad_IntLoop(int c,
334  int i,
335  int j,
336  int type,
337  short *S,
338  int *ggg,
339  int *index,
340  int *p,
341  int *q,
342  vrna_param_t *P){
343 
344  int energy, dangles, k, l, maxl, minl, c0, l1;
345  short si, sj;
346 
347  dangles = P->model_details.dangles;
348  si = S[i + 1];
349  sj = S[j - 1];
350  energy = 0;
351 
352  if(dangles == 2)
353  energy += P->mismatchI[type][si][sj];
354 
355  if(type > 2)
356  energy += P->TerminalAU;
357 
358  k = i + 1;
359  if(S[k] == 3){
360  if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
361  minl = j - i + k - MAXLOOP - 2;
362  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
363  minl = MAX2(c0, minl);
364  c0 = j - 3;
365  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
366  maxl = MIN2(c0, maxl);
367  for(l = minl; l < maxl; l++){
368  if(S[l] != 3) continue;
369  if(c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]){
370  *p = k; *q = l;
371  return 1;
372  }
373  }
374  }
375  }
376 
377  for(k = i + 2;
378  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
379  k++){
380  l1 = k - i - 1;
381  if(l1>MAXLOOP) break;
382  if(S[k] != 3) continue;
383  minl = j - i + k - MAXLOOP - 2;
384  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
385  minl = MAX2(c0, minl);
386  c0 = j - 1;
387  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
388  maxl = MIN2(c0, maxl);
389  for(l = minl; l < maxl; l++){
390  if(S[l] != 3) continue;
391  if(c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]){
392  *p = k; *q = l;
393  return 1;
394  }
395  }
396  }
397 
398  l = j - 1;
399  if(S[l] == 3)
400  for(k = i + 4;
401  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
402  k++){
403  l1 = k - i - 1;
404  if(l1>MAXLOOP) break;
405  if(S[k] != 3) continue;
406  if(c == energy + ggg[index[l] + k] + P->internal_loop[l1]){
407  *p = k; *q = l;
408  return 1;
409  }
410  }
411 
412  return 0;
413 }
414 
431 INLINE PRIVATE int backtrack_GQuad_IntLoop_L(int c,
432  int i,
433  int j,
434  int type,
435  short *S,
436  int **ggg,
437  int maxdist,
438  int *p,
439  int *q,
440  vrna_param_t *P){
441 
442  int energy, dangles, k, l, maxl, minl, c0, l1;
443  short si, sj;
444 
445  dangles = P->model_details.dangles;
446  si = S[i + 1];
447  sj = S[j - 1];
448  energy = 0;
449 
450  if(dangles == 2)
451  energy += P->mismatchI[type][si][sj];
452 
453  if(type > 2)
454  energy += P->TerminalAU;
455 
456  k = i + 1;
457  if(S[k] == 3){
458  if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
459  minl = j - i + k - MAXLOOP - 2;
460  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
461  minl = MAX2(c0, minl);
462  c0 = j - 3;
463  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
464  maxl = MIN2(c0, maxl);
465  for(l = minl; l < maxl; l++){
466  if(S[l] != 3) continue;
467  if(c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]){
468  *p = k; *q = l;
469  return 1;
470  }
471  }
472  }
473  }
474 
475  for(k = i + 2;
476  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
477  k++){
478  l1 = k - i - 1;
479  if(l1>MAXLOOP) break;
480  if(S[k] != 3) continue;
481  minl = j - i + k - MAXLOOP - 2;
482  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
483  minl = MAX2(c0, minl);
484  c0 = j - 1;
485  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
486  maxl = MIN2(c0, maxl);
487  for(l = minl; l < maxl; l++){
488  if(S[l] != 3) continue;
489  if(c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]){
490  *p = k; *q = l;
491  return 1;
492  }
493  }
494  }
495 
496  l = j - 1;
497  if(S[l] == 3)
498  for(k = i + 4;
499  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
500  k++){
501  l1 = k - i - 1;
502  if(l1>MAXLOOP) break;
503  if(S[k] != 3) continue;
504  if(c == energy + ggg[k][l - k] + P->internal_loop[l1]){
505  *p = k; *q = l;
506  return 1;
507  }
508  }
509 
510  return 0;
511 }
512 
513 PRIVATE INLINE
514 int
515 E_GQuad_IntLoop(int i,
516  int j,
517  int type,
518  short *S,
519  int *ggg,
520  int *index,
521  vrna_param_t *P){
522 
523  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
524  short si, sj;
525 
526  dangles = P->model_details.dangles;
527  si = S[i + 1];
528  sj = S[j - 1];
529  energy = 0;
530 
531  if(dangles == 2)
532  energy += P->mismatchI[type][si][sj];
533 
534  if(type > 2)
535  energy += P->TerminalAU;
536 
537  ge = INF;
538 
539  p = i + 1;
540  if(S[p] == 3){
541  if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
542  minq = j - i + p - MAXLOOP - 2;
543  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
544  minq = MAX2(c0, minq);
545  c0 = j - 3;
546  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
547  maxq = MIN2(c0, maxq);
548  for(q = minq; q < maxq; q++){
549  if(S[q] != 3) continue;
550  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
551  ge = MIN2(ge, c0);
552  }
553  }
554  }
555 
556  for(p = i + 2;
557  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
558  p++){
559  l1 = p - i - 1;
560  if(l1>MAXLOOP) break;
561  if(S[p] != 3) continue;
562  minq = j - i + p - MAXLOOP - 2;
563  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
564  minq = MAX2(c0, minq);
565  c0 = j - 1;
566  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
567  maxq = MIN2(c0, maxq);
568  for(q = minq; q < maxq; q++){
569  if(S[q] != 3) continue;
570  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
571  ge = MIN2(ge, c0);
572  }
573  }
574 
575  q = j - 1;
576  if(S[q] == 3)
577  for(p = i + 4;
578  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
579  p++){
580  l1 = p - i - 1;
581  if(l1>MAXLOOP) break;
582  if(S[p] != 3) continue;
583  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
584  ge = MIN2(ge, c0);
585  }
586 
587 #if 0
588  /* here comes the additional stuff for the odd dangle models */
589  if(dangles % 1){
590  en1 = energy + P->dangle5[type][si];
591  en2 = energy + P->dangle5[type][sj];
592  en3 = energy + P->mismatchI[type][si][sj];
593 
594  /* first case with 5' dangle (i.e. j-1) onto enclosing pair */
595  p = i + 1;
596  if(S[p] == 3){
597  if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
598  minq = j - i + p - MAXLOOP - 2;
599  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
600  minq = MAX2(c0, minq);
601  c0 = j - 4;
602  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
603  maxq = MIN2(c0, maxq);
604  for(q = minq; q < maxq; q++){
605  if(S[q] != 3) continue;
606  c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
607  ge = MIN2(ge, c0);
608  }
609  }
610  }
611 
612  for(p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
613  l1 = p - i - 1;
614  if(l1>MAXLOOP) break;
615  if(S[p] != 3) continue;
616  minq = j - i + p - MAXLOOP - 2;
617  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
618  minq = MAX2(c0, minq);
619  c0 = j - 2;
620  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
621  maxq = MIN2(c0, maxq);
622  for(q = minq; q < maxq; q++){
623  if(S[q] != 3) continue;
624  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
625  ge = MIN2(ge, c0);
626  }
627  }
628 
629  q = j - 2;
630  if(S[q] == 3)
631  for(p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
632  l1 = p - i - 1;
633  if(l1>MAXLOOP) break;
634  if(S[p] != 3) continue;
635  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
636  ge = MIN2(ge, c0);
637  }
638 
639  /* second case with 3' dangle (i.e. i+1) onto enclosing pair */
640 
641  }
642 #endif
643  return ge;
644 }
645 
646 PRIVATE INLINE
647 int *
648 E_GQuad_IntLoop_exhaustive( int i,
649  int j,
650  int **p_p,
651  int **q_p,
652  int type,
653  short *S,
654  int *ggg,
655  int threshold,
656  int *index,
657  vrna_param_t *P){
658 
659  int energy, *ge, dangles, p, q, l1, minq, maxq, c0;
660  short si, sj;
661  int cnt = 0;
662 
663  dangles = P->model_details.dangles;
664  si = S[i + 1];
665  sj = S[j - 1];
666  energy = 0;
667 
668  if(dangles == 2)
669  energy += P->mismatchI[type][si][sj];
670 
671  if(type > 2)
672  energy += P->TerminalAU;
673 
674  /* guess how many gquads are possible in interval [i+1,j-1] */
675  *p_p = (int *)vrna_alloc(sizeof(int) * 256);
676  *q_p = (int *)vrna_alloc(sizeof(int) * 256);
677  ge = (int *)vrna_alloc(sizeof(int) * 256);
678 
679  p = i + 1;
680  if(S[p] == 3){
681  if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
682  minq = j - i + p - MAXLOOP - 2;
683  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
684  minq = MAX2(c0, minq);
685  c0 = j - 3;
686  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
687  maxq = MIN2(c0, maxq);
688  for(q = minq; q < maxq; q++){
689  if(S[q] != 3) continue;
690  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
691  if(c0 <= threshold){
692  ge[cnt] = energy + P->internal_loop[j - q - 1];
693  (*p_p)[cnt] = p;
694  (*q_p)[cnt++] = q;
695  }
696  }
697  }
698  }
699 
700  for(p = i + 2;
701  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
702  p++){
703  l1 = p - i - 1;
704  if(l1>MAXLOOP) break;
705  if(S[p] != 3) continue;
706  minq = j - i + p - MAXLOOP - 2;
707  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
708  minq = MAX2(c0, minq);
709  c0 = j - 1;
710  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
711  maxq = MIN2(c0, maxq);
712  for(q = minq; q < maxq; q++){
713  if(S[q] != 3) continue;
714  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
715  if(c0 <= threshold){
716  ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
717  (*p_p)[cnt] = p;
718  (*q_p)[cnt++] = q;
719  }
720  }
721  }
722 
723  q = j - 1;
724  if(S[q] == 3)
725  for(p = i + 4;
726  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
727  p++){
728  l1 = p - i - 1;
729  if(l1>MAXLOOP) break;
730  if(S[p] != 3) continue;
731  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
732  if(c0 <= threshold){
733  ge[cnt] = energy + P->internal_loop[l1];
734  (*p_p)[cnt] = p;
735  (*q_p)[cnt++] = q;
736  }
737  }
738 
739 
740  (*p_p)[cnt] = -1;
741 
742  return ge;
743 }
744 
745 PRIVATE INLINE
746 int
747 E_GQuad_IntLoop_L(int i,
748  int j,
749  int type,
750  short *S,
751  int **ggg,
752  int maxdist,
753  vrna_param_t *P){
754 
755  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
756  short si, sj;
757 
758  dangles = P->model_details.dangles;
759  si = S[i + 1];
760  sj = S[j - 1];
761  energy = 0;
762 
763  if(dangles == 2)
764  energy += P->mismatchI[type][si][sj];
765 
766  if(type > 2)
767  energy += P->TerminalAU;
768 
769  ge = INF;
770 
771  p = i + 1;
772  if(S[p] == 3){
773  if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
774  minq = j - i + p - MAXLOOP - 2;
775  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
776  minq = MAX2(c0, minq);
777  c0 = j - 3;
778  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
779  maxq = MIN2(c0, maxq);
780  for(q = minq; q < maxq; q++){
781  if(S[q] != 3) continue;
782  c0 = energy + ggg[p][q-p] + P->internal_loop[j - q - 1];
783  ge = MIN2(ge, c0);
784  }
785  }
786  }
787 
788  for(p = i + 2;
789  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
790  p++){
791  l1 = p - i - 1;
792  if(l1>MAXLOOP) break;
793  if(S[p] != 3) continue;
794  minq = j - i + p - MAXLOOP - 2;
795  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
796  minq = MAX2(c0, minq);
797  c0 = j - 1;
798  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
799  maxq = MIN2(c0, maxq);
800  for(q = minq; q < maxq; q++){
801  if(S[q] != 3) continue;
802  c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
803  ge = MIN2(ge, c0);
804  }
805  }
806 
807  q = j - 1;
808  if(S[q] == 3)
809  for(p = i + 4;
810  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
811  p++){
812  l1 = p - i - 1;
813  if(l1>MAXLOOP) break;
814  if(S[p] != 3) continue;
815  c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
816  ge = MIN2(ge, c0);
817  }
818 
819  return ge;
820 }
821 
822 PRIVATE INLINE
824 exp_E_GQuad_IntLoop(int i,
825  int j,
826  int type,
827  short *S,
828  FLT_OR_DBL *G,
829  int *index,
830  vrna_exp_param_t *pf){
831 
832  int k, l, minl, maxl, u, r;
833  FLT_OR_DBL q, qe;
834  double *expintern;
835  short si, sj;
836 
837  q = 0;
838  si = S[i + 1];
839  sj = S[j - 1];
840  qe = (FLT_OR_DBL)pf->expmismatchI[type][si][sj];
841  expintern = pf->expinternal;
842 
843  if(type > 2)
844  qe *= (FLT_OR_DBL)pf->expTermAU;
845 
846  k = i + 1;
847  if(S[k] == 3){
848  if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
849  minl = j - i + k - MAXLOOP - 2;
850  u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
851  minl = MAX2(u, minl);
852  u = j - 3;
853  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
854  maxl = MIN2(u, maxl);
855  for(l = minl; l < maxl; l++){
856  if(S[l] != 3) continue;
857  if(G[index[k]-l] == 0.) continue;
858  q += qe * G[index[k]-l] * (FLT_OR_DBL)expintern[j - l - 1];
859  }
860  }
861  }
862 
863 
864  for(k = i + 2;
865  k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
866  k++){
867  u = k - i - 1;
868  if(u > MAXLOOP) break;
869  if(S[k] != 3) continue;
870  minl = j - i + k - MAXLOOP - 2;
871  r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
872  minl = MAX2(r, minl);
873  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
874  r = j - 1;
875  maxl = MIN2(r, maxl);
876  for(l = minl; l < maxl; l++){
877  if(S[l] != 3) continue;
878  if(G[index[k]-l] == 0.) continue;
879  q += qe * G[index[k]-l] * (FLT_OR_DBL)expintern[u + j - l - 1];
880  }
881  }
882 
883  l = j - 1;
884  if(S[l] == 3)
885  for(k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++){
886  u = k - i - 1;
887  if(u>MAXLOOP) break;
888  if(S[k] != 3) continue;
889  if(G[index[k]-l] == 0.) continue;
890  q += qe * G[index[k]-l] * (FLT_OR_DBL)expintern[u];
891  }
892 
893  return q;
894 }
895 
901 #endif
void * vrna_alloc(unsigned size)
Allocate space safely.
char * ptype
Pair type array.
Definition: data_structures.h:460
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:455
#define MAXLOOP
Definition: energy_const.h:28
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:88
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:39
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:390
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:50
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:112
int * jindx
DP matrix accessor.
Definition: data_structures.h:417
PRIVATE int backtrack_GQuad_IntLoop_L(int c, int i, int j, int type, short *S, int **ggg, int maxdist, int *p, int *q, vrna_param_t *P)
Definition: gquad.h:431
int rtype[8]
Reverse base pair type array.
Definition: model.h:240
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:187
#define INF
Definition: energy_const.h:16
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:94
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:117
this datastructure is used as input parameter in functions of PS_dot.h and others ...
Definition: data_structures.h:164
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:413
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:410
int * get_gquad_matrix(short *S, vrna_param_t *P)
Get a triangular matrix prefilled with minimum free energy contributions of G-quadruplexes.
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:190
Base pair stack element.
Definition: data_structures.h:192
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
int parse_gquad(const char *struc, int *L, int l[3])
PRIVATE int backtrack_GQuad_IntLoop(int c, int i, int j, int type, short *S, int *ggg, int *index, int *p, int *q, vrna_param_t *P)
Definition: gquad.h:333
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
int * ggg
Energies of g-quadruplexes.
Definition: dp_matrices.h:66