RNAlib-2.4.8
gquad.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_GQUAD_H
2 #define VIENNA_RNA_PACKAGE_GQUAD_H
3 
6 
7 #ifndef INLINE
8 #ifdef __GNUC__
9 # define INLINE inline
10 #else
11 # define INLINE
12 #endif
13 #endif
14 
29 int E_gquad(int L,
30  int l[3],
31  vrna_param_t *P);
32 
33 
34 FLT_OR_DBL exp_E_gquad(int L,
35  int l[3],
36  vrna_exp_param_t *pf);
37 
38 
39 int E_gquad_ali(int i,
40  int L,
41  int l[3],
42  const short **S,
43  int n_seq,
44  vrna_param_t *P);
45 
46 
47 void E_gquad_ali_en(int i,
48  int L,
49  int l[3],
50  const short **S,
51  int n_seq,
52  int en[2],
53  vrna_param_t *P);
54 
55 
72 int *get_gquad_matrix(short *S,
73  vrna_param_t *P);
74 
75 
76 int *get_gquad_ali_matrix(short *S_cons,
77  short **S,
78  int n_seq,
79  vrna_param_t *P);
80 
81 
82 FLT_OR_DBL *get_gquad_pf_matrix(short *S,
83  FLT_OR_DBL *scale,
84  vrna_exp_param_t *pf);
85 
86 
87 int **get_gquad_L_matrix(short *S,
88  int start,
89  int maxdist,
90  int n,
91  int **g,
92  vrna_param_t *P);
93 
94 
95 void vrna_gquad_mx_local_update(vrna_fold_compound_t *vc,
96  int start);
97 
98 
99 void get_gquad_pattern_mfe(short *S,
100  int i,
101  int j,
102  vrna_param_t *P,
103  int *L,
104  int l[3]);
105 
106 
107 void
108 get_gquad_pattern_exhaustive(short *S,
109  int i,
110  int j,
111  vrna_param_t *P,
112  int *L,
113  int *l,
114  int threshold);
115 
116 
117 void get_gquad_pattern_pf(short *S,
118  int i,
119  int j,
120  vrna_exp_param_t *pf,
121  int *L,
122  int l[3]);
123 
124 
125 plist *get_plist_gquad_from_pr(short *S,
126  int gi,
127  int gj,
128  FLT_OR_DBL *G,
129  FLT_OR_DBL *probs,
130  FLT_OR_DBL *scale,
131  vrna_exp_param_t *pf);
132 
133 
134 plist *get_plist_gquad_from_pr_max(short *S,
135  int gi,
136  int gj,
137  FLT_OR_DBL *G,
138  FLT_OR_DBL *probs,
139  FLT_OR_DBL *scale,
140  int *L,
141  int l[3],
142  vrna_exp_param_t *pf);
143 
144 
145 plist *get_plist_gquad_from_db(const char *structure,
146  float pr);
147 
148 
149 int get_gquad_count(short *S,
150  int i,
151  int j);
152 
153 
154 int get_gquad_layer_count(short *S,
155  int i,
156  int j);
157 
158 
159 void get_gquad_pattern_mfe_ali(short **S,
160  short *S_cons,
161  int n_seq,
162  int i,
163  int j,
164  vrna_param_t *P,
165  int *L,
166  int l[3]);
167 
168 
179 int parse_gquad(const char *struc,
180  int *L,
181  int l[3]);
182 
183 
184 INLINE PRIVATE int backtrack_GQuad_IntLoop(int c,
185  int i,
186  int j,
187  int type,
188  short *S,
189  int *ggg,
190  int *index,
191  int *p,
192  int *q,
193  vrna_param_t *P);
194 
195 
196 INLINE PRIVATE int backtrack_GQuad_IntLoop_comparative(int c,
197  int i,
198  int j,
199  unsigned int *type,
200  short *S_cons,
201  short **S5,
202  short **S3,
203  int *ggg,
204  int *index,
205  int *p,
206  int *q,
207  int n_seq,
208  vrna_param_t *P);
209 
210 
211 INLINE PRIVATE int backtrack_GQuad_IntLoop_L(int c,
212  int i,
213  int j,
214  int type,
215  short *S,
216  int **ggg,
217  int maxdist,
218  int *p,
219  int *q,
220  vrna_param_t *P);
221 
222 
223 PRIVATE INLINE int
224 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
225  int i,
226  int j,
227  int en,
228  vrna_bp_stack_t *bp_stack,
229  int *stack_count);
230 
231 
232 PRIVATE INLINE int
233 vrna_BT_gquad_mfe(vrna_fold_compound_t *vc,
234  int i,
235  int j,
236  vrna_bp_stack_t *bp_stack,
237  int *stack_count)
238 {
239  /*
240  * here we do some fancy stuff to backtrace the stacksize and linker lengths
241  * of the g-quadruplex that should reside within position i,j
242  */
243  short *S;
244  int l[3], L, a, n_seq;
245  vrna_param_t *P;
246 
247  if (vc) {
248  P = vc->params;
249  switch (vc->type) {
250  case VRNA_FC_TYPE_SINGLE:
251  S = vc->sequence_encoding2;
252  L = -1;
253 
254  get_gquad_pattern_mfe(S, i, j, P, &L, l);
255  break;
256 
258  n_seq = vc->n_seq;
259  L = -1;
260  get_gquad_pattern_mfe_ali(vc->S, vc->S_cons, n_seq, i, j, P, &L, l);
261  break;
262  }
263 
264  if (L != -1) {
265  /* fill the G's of the quadruplex into base_pair2 */
266  for (a = 0; a < L; a++) {
267  bp_stack[++(*stack_count)].i = i + a;
268  bp_stack[(*stack_count)].j = i + a;
269  bp_stack[++(*stack_count)].i = i + L + l[0] + a;
270  bp_stack[(*stack_count)].j = i + L + l[0] + a;
271  bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + a;
272  bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + a;
273  bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + L + l[2] + a;
274  bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + L + l[2] + a;
275  }
276  return 1;
277  } else {
278  return 0;
279  }
280  }
281 
282  return 0;
283 }
284 
285 
286 PRIVATE INLINE int
287 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
288  int i,
289  int j,
290  int en,
291  vrna_bp_stack_t *bp_stack,
292  int *stack_count)
293 {
294  int energy, dangles, *idx, ij, p, q, maxl, minl, c0, l1, *ggg;
295  unsigned char type;
296  char *ptype;
297  short si, sj, *S, *S1;
298 
299  vrna_param_t *P;
300  vrna_md_t *md;
301 
302  idx = vc->jindx;
303  ij = idx[j] + i;
304  P = vc->params;
305  md = &(P->model_details);
306  ptype = vc->ptype;
307  type = (unsigned char)ptype[ij];
308  S1 = vc->sequence_encoding;
309  S = vc->sequence_encoding2;
310  dangles = md->dangles;
311  si = S1[i + 1];
312  sj = S1[j - 1];
313  ggg = vc->matrices->ggg;
314  energy = 0;
315 
316  if (dangles == 2)
317  energy += P->mismatchI[type][si][sj];
318 
319  if (type > 2)
320  energy += P->TerminalAU;
321 
322  p = i + 1;
323  if (S1[p] == 3) {
324  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
325  minl = j - i + p - MAXLOOP - 2;
326  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
327  minl = MAX2(c0, minl);
328  c0 = j - 3;
329  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
330  maxl = MIN2(c0, maxl);
331  for (q = minl; q < maxl; q++) {
332  if (S[q] != 3)
333  continue;
334 
335  if (en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1])
336  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
337  }
338  }
339  }
340 
341  for (p = i + 2;
342  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
343  p++) {
344  l1 = p - i - 1;
345  if (l1 > MAXLOOP)
346  break;
347 
348  if (S1[p] != 3)
349  continue;
350 
351  minl = j - i + p - MAXLOOP - 2;
352  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
353  minl = MAX2(c0, minl);
354  c0 = j - 1;
355  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
356  maxl = MIN2(c0, maxl);
357  for (q = minl; q < maxl; q++) {
358  if (S1[q] != 3)
359  continue;
360 
361  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1])
362  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
363  }
364  }
365 
366  q = j - 1;
367  if (S1[q] == 3)
368  for (p = i + 4;
369  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
370  p++) {
371  l1 = p - i - 1;
372  if (l1 > MAXLOOP)
373  break;
374 
375  if (S1[p] != 3)
376  continue;
377 
378  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1])
379  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
380  }
381 
382  return 0;
383 }
384 
385 
403 INLINE PRIVATE int
405  int i,
406  int j,
407  int type,
408  short *S,
409  int *ggg,
410  int *index,
411  int *p,
412  int *q,
413  vrna_param_t *P)
414 {
415  int energy, dangles, k, l, maxl, minl, c0, l1;
416  short si, sj;
417 
419  si = S[i + 1];
420  sj = S[j - 1];
421  energy = 0;
422 
423  if (dangles == 2)
424  energy += P->mismatchI[type][si][sj];
425 
426  if (type > 2)
427  energy += P->TerminalAU;
428 
429  k = i + 1;
430  if (S[k] == 3) {
431  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
432  minl = j - i + k - MAXLOOP - 2;
433  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
434  minl = MAX2(c0, minl);
435  c0 = j - 3;
436  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
437  maxl = MIN2(c0, maxl);
438  for (l = minl; l < maxl; l++) {
439  if (S[l] != 3)
440  continue;
441 
442  if (c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]) {
443  *p = k;
444  *q = l;
445  return 1;
446  }
447  }
448  }
449  }
450 
451  for (k = i + 2;
452  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
453  k++) {
454  l1 = k - i - 1;
455  if (l1 > MAXLOOP)
456  break;
457 
458  if (S[k] != 3)
459  continue;
460 
461  minl = j - i + k - MAXLOOP - 2;
462  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
463  minl = MAX2(c0, minl);
464  c0 = j - 1;
465  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
466  maxl = MIN2(c0, maxl);
467  for (l = minl; l < maxl; l++) {
468  if (S[l] != 3)
469  continue;
470 
471  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]) {
472  *p = k;
473  *q = l;
474  return 1;
475  }
476  }
477  }
478 
479  l = j - 1;
480  if (S[l] == 3)
481  for (k = i + 4;
482  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
483  k++) {
484  l1 = k - i - 1;
485  if (l1 > MAXLOOP)
486  break;
487 
488  if (S[k] != 3)
489  continue;
490 
491  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1]) {
492  *p = k;
493  *q = l;
494  return 1;
495  }
496  }
497 
498  return 0;
499 }
500 
501 
502 INLINE PRIVATE int
503 backtrack_GQuad_IntLoop_comparative(int c,
504  int i,
505  int j,
506  unsigned int *type,
507  short *S_cons,
508  short **S5,
509  short **S3,
510  int *ggg,
511  int *index,
512  int *p,
513  int *q,
514  int n_seq,
515  vrna_param_t *P)
516 {
517  int energy, dangles, k, l, maxl, minl, c0, l1, ss, tt;
518 
520  energy = 0;
521 
522  for (ss = 0; ss < n_seq; ss++) {
523  tt = type[ss];
524  if (tt == 0)
525  tt = 7;
526 
527  if (dangles == 2)
528  energy += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
529 
530  if (tt > 2)
531  energy += P->TerminalAU;
532  }
533 
534  k = i + 1;
535  if (S_cons[k] == 3) {
536  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
537  minl = j - i + k - MAXLOOP - 2;
538  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
539  minl = MAX2(c0, minl);
540  c0 = j - 3;
541  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
542  maxl = MIN2(c0, maxl);
543  for (l = minl; l < maxl; l++) {
544  if (S_cons[l] != 3)
545  continue;
546 
547  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[j - l - 1]) {
548  *p = k;
549  *q = l;
550  return 1;
551  }
552  }
553  }
554  }
555 
556  for (k = i + 2;
557  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
558  k++) {
559  l1 = k - i - 1;
560  if (l1 > MAXLOOP)
561  break;
562 
563  if (S_cons[k] != 3)
564  continue;
565 
566  minl = j - i + k - MAXLOOP - 2;
567  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
568  minl = MAX2(c0, minl);
569  c0 = j - 1;
570  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
571  maxl = MIN2(c0, maxl);
572  for (l = minl; l < maxl; l++) {
573  if (S_cons[l] != 3)
574  continue;
575 
576  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1 + j - l - 1]) {
577  *p = k;
578  *q = l;
579  return 1;
580  }
581  }
582  }
583 
584  l = j - 1;
585  if (S_cons[l] == 3)
586  for (k = i + 4;
587  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
588  k++) {
589  l1 = k - i - 1;
590  if (l1 > MAXLOOP)
591  break;
592 
593  if (S_cons[k] != 3)
594  continue;
595 
596  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1]) {
597  *p = k;
598  *q = l;
599  return 1;
600  }
601  }
602 
603  return 0;
604 }
605 
606 
623 INLINE PRIVATE int
625  int i,
626  int j,
627  int type,
628  short *S,
629  int **ggg,
630  int maxdist,
631  int *p,
632  int *q,
633  vrna_param_t *P)
634 {
635  int energy, dangles, k, l, maxl, minl, c0, l1;
636  short si, sj;
637 
639  si = S[i + 1];
640  sj = S[j - 1];
641  energy = 0;
642 
643  if (dangles == 2)
644  energy += P->mismatchI[type][si][sj];
645 
646  if (type > 2)
647  energy += P->TerminalAU;
648 
649  k = i + 1;
650  if (S[k] == 3) {
651  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
652  minl = j - i + k - MAXLOOP - 2;
653  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
654  minl = MAX2(c0, minl);
655  c0 = j - 3;
656  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
657  maxl = MIN2(c0, maxl);
658  for (l = minl; l < maxl; l++) {
659  if (S[l] != 3)
660  continue;
661 
662  if (c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]) {
663  *p = k;
664  *q = l;
665  return 1;
666  }
667  }
668  }
669  }
670 
671  for (k = i + 2;
672  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
673  k++) {
674  l1 = k - i - 1;
675  if (l1 > MAXLOOP)
676  break;
677 
678  if (S[k] != 3)
679  continue;
680 
681  minl = j - i + k - MAXLOOP - 2;
682  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
683  minl = MAX2(c0, minl);
684  c0 = j - 1;
685  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
686  maxl = MIN2(c0, maxl);
687  for (l = minl; l < maxl; l++) {
688  if (S[l] != 3)
689  continue;
690 
691  if (c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]) {
692  *p = k;
693  *q = l;
694  return 1;
695  }
696  }
697  }
698 
699  l = j - 1;
700  if (S[l] == 3)
701  for (k = i + 4;
702  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
703  k++) {
704  l1 = k - i - 1;
705  if (l1 > MAXLOOP)
706  break;
707 
708  if (S[k] != 3)
709  continue;
710 
711  if (c == energy + ggg[k][l - k] + P->internal_loop[l1]) {
712  *p = k;
713  *q = l;
714  return 1;
715  }
716  }
717 
718  return 0;
719 }
720 
721 
722 INLINE PRIVATE int
723 backtrack_GQuad_IntLoop_L_comparative(int c,
724  int i,
725  int j,
726  unsigned int *type,
727  short *S_cons,
728  short **S5,
729  short **S3,
730  int **ggg,
731  int *p,
732  int *q,
733  int n_seq,
734  vrna_param_t *P)
735 {
736  /*
737  * The case that is handled here actually resembles something like
738  * an interior loop where the enclosing base pair is of regular
739  * kind and the enclosed pair is not a canonical one but a g-quadruplex
740  * that should then be decomposed further...
741  */
742  int mm, dangle_model, k, l, maxl, minl, c0, l1, ss, tt;
743 
744  dangle_model = P->model_details.dangles;
745 
746  mm = 0;
747  for (ss = 0; ss < n_seq; ss++) {
748  tt = type[ss];
749 
750  if (dangle_model == 2)
751  mm += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
752 
753  if (tt > 2)
754  mm += P->TerminalAU;
755  }
756 
757  for (k = i + 2;
758  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
759  k++) {
760  if (S_cons[k] != 3)
761  continue;
762 
763  l1 = k - i - 1;
764  if (l1 > MAXLOOP)
765  break;
766 
767  minl = j - i + k - MAXLOOP - 2;
768  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
769  minl = MAX2(c0, minl);
770  c0 = j - 1;
771  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
772  maxl = MIN2(c0, maxl);
773  for (l = minl; l < maxl; l++) {
774  if (S_cons[l] != 3)
775  continue;
776 
777  c0 = mm + ggg[k][l - k] + n_seq * P->internal_loop[l1 + j - l - 1];
778  if (c == c0) {
779  *p = k;
780  *q = l;
781  return 1;
782  }
783  }
784  }
785  k = i + 1;
786  if (S_cons[k] == 3) {
787  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
788  minl = j - i + k - MAXLOOP - 2;
789  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
790  minl = MAX2(c0, minl);
791  c0 = j - 3;
792  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
793  maxl = MIN2(c0, maxl);
794  for (l = minl; l < maxl; l++) {
795  if (S_cons[l] != 3)
796  continue;
797 
798  if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[j - l - 1]) {
799  *p = k;
800  *q = l;
801  return 1;
802  }
803  }
804  }
805  }
806 
807  l = j - 1;
808  if (S_cons[l] == 3) {
809  for (k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
810  l1 = k - i - 1;
811  if (l1 > MAXLOOP)
812  break;
813 
814  if (S_cons[k] != 3)
815  continue;
816 
817  if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[l1]) {
818  *p = k;
819  *q = l;
820  return 1;
821  }
822  }
823  }
824 
825  return 0;
826 }
827 
828 
829 PRIVATE INLINE
830 int
831 E_GQuad_IntLoop(int i,
832  int j,
833  int type,
834  short *S,
835  int *ggg,
836  int *index,
837  vrna_param_t *P)
838 {
839  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
840  short si, sj;
841 
843  si = S[i + 1];
844  sj = S[j - 1];
845  energy = 0;
846 
847  if (dangles == 2)
848  energy += P->mismatchI[type][si][sj];
849 
850  if (type > 2)
851  energy += P->TerminalAU;
852 
853  ge = INF;
854 
855  p = i + 1;
856  if (S[p] == 3) {
857  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
858  minq = j - i + p - MAXLOOP - 2;
859  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
860  minq = MAX2(c0, minq);
861  c0 = j - 3;
862  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
863  maxq = MIN2(c0, maxq);
864  for (q = minq; q < maxq; q++) {
865  if (S[q] != 3)
866  continue;
867 
868  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
869  ge = MIN2(ge, c0);
870  }
871  }
872  }
873 
874  for (p = i + 2;
875  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
876  p++) {
877  l1 = p - i - 1;
878  if (l1 > MAXLOOP)
879  break;
880 
881  if (S[p] != 3)
882  continue;
883 
884  minq = j - i + p - MAXLOOP - 2;
885  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
886  minq = MAX2(c0, minq);
887  c0 = j - 1;
888  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
889  maxq = MIN2(c0, maxq);
890  for (q = minq; q < maxq; q++) {
891  if (S[q] != 3)
892  continue;
893 
894  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
895  ge = MIN2(ge, c0);
896  }
897  }
898 
899  q = j - 1;
900  if (S[q] == 3)
901  for (p = i + 4;
902  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
903  p++) {
904  l1 = p - i - 1;
905  if (l1 > MAXLOOP)
906  break;
907 
908  if (S[p] != 3)
909  continue;
910 
911  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
912  ge = MIN2(ge, c0);
913  }
914 
915 #if 0
916  /* here comes the additional stuff for the odd dangle models */
917  if (dangles % 1) {
918  en1 = energy + P->dangle5[type][si];
919  en2 = energy + P->dangle5[type][sj];
920  en3 = energy + P->mismatchI[type][si][sj];
921 
922  /* first case with 5' dangle (i.e. j-1) onto enclosing pair */
923  p = i + 1;
924  if (S[p] == 3) {
925  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
926  minq = j - i + p - MAXLOOP - 2;
927  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
928  minq = MAX2(c0, minq);
929  c0 = j - 4;
930  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
931  maxq = MIN2(c0, maxq);
932  for (q = minq; q < maxq; q++) {
933  if (S[q] != 3)
934  continue;
935 
936  c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
937  ge = MIN2(ge, c0);
938  }
939  }
940  }
941 
942  for (p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
943  l1 = p - i - 1;
944  if (l1 > MAXLOOP)
945  break;
946 
947  if (S[p] != 3)
948  continue;
949 
950  minq = j - i + p - MAXLOOP - 2;
951  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
952  minq = MAX2(c0, minq);
953  c0 = j - 2;
954  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
955  maxq = MIN2(c0, maxq);
956  for (q = minq; q < maxq; q++) {
957  if (S[q] != 3)
958  continue;
959 
960  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
961  ge = MIN2(ge, c0);
962  }
963  }
964 
965  q = j - 2;
966  if (S[q] == 3)
967  for (p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
968  l1 = p - i - 1;
969  if (l1 > MAXLOOP)
970  break;
971 
972  if (S[p] != 3)
973  continue;
974 
975  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
976  ge = MIN2(ge, c0);
977  }
978 
979  /* second case with 3' dangle (i.e. i+1) onto enclosing pair */
980  }
981 
982 #endif
983  return ge;
984 }
985 
986 
987 PRIVATE INLINE
988 int *
989 E_GQuad_IntLoop_exhaustive(int i,
990  int j,
991  int **p_p,
992  int **q_p,
993  int type,
994  short *S,
995  int *ggg,
996  int threshold,
997  int *index,
998  vrna_param_t *P)
999 {
1000  int energy, *ge, dangles, p, q, l1, minq, maxq, c0;
1001  short si, sj;
1002  int cnt = 0;
1003 
1005  si = S[i + 1];
1006  sj = S[j - 1];
1007  energy = 0;
1008 
1009  if (dangles == 2)
1010  energy += P->mismatchI[type][si][sj];
1011 
1012  if (type > 2)
1013  energy += P->TerminalAU;
1014 
1015  /* guess how many gquads are possible in interval [i+1,j-1] */
1016  *p_p = (int *)vrna_alloc(sizeof(int) * 256);
1017  *q_p = (int *)vrna_alloc(sizeof(int) * 256);
1018  ge = (int *)vrna_alloc(sizeof(int) * 256);
1019 
1020  p = i + 1;
1021  if (S[p] == 3) {
1022  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1023  minq = j - i + p - MAXLOOP - 2;
1024  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1025  minq = MAX2(c0, minq);
1026  c0 = j - 3;
1027  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1028  maxq = MIN2(c0, maxq);
1029  for (q = minq; q < maxq; q++) {
1030  if (S[q] != 3)
1031  continue;
1032 
1033  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1034  if (c0 <= threshold) {
1035  ge[cnt] = energy + P->internal_loop[j - q - 1];
1036  (*p_p)[cnt] = p;
1037  (*q_p)[cnt++] = q;
1038  }
1039  }
1040  }
1041  }
1042 
1043  for (p = i + 2;
1044  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1045  p++) {
1046  l1 = p - i - 1;
1047  if (l1 > MAXLOOP)
1048  break;
1049 
1050  if (S[p] != 3)
1051  continue;
1052 
1053  minq = j - i + p - MAXLOOP - 2;
1054  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1055  minq = MAX2(c0, minq);
1056  c0 = j - 1;
1057  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1058  maxq = MIN2(c0, maxq);
1059  for (q = minq; q < maxq; q++) {
1060  if (S[q] != 3)
1061  continue;
1062 
1063  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1064  if (c0 <= threshold) {
1065  ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
1066  (*p_p)[cnt] = p;
1067  (*q_p)[cnt++] = q;
1068  }
1069  }
1070  }
1071 
1072  q = j - 1;
1073  if (S[q] == 3)
1074  for (p = i + 4;
1075  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1076  p++) {
1077  l1 = p - i - 1;
1078  if (l1 > MAXLOOP)
1079  break;
1080 
1081  if (S[p] != 3)
1082  continue;
1083 
1084  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
1085  if (c0 <= threshold) {
1086  ge[cnt] = energy + P->internal_loop[l1];
1087  (*p_p)[cnt] = p;
1088  (*q_p)[cnt++] = q;
1089  }
1090  }
1091 
1092  (*p_p)[cnt] = -1;
1093 
1094  return ge;
1095 }
1096 
1097 
1098 PRIVATE INLINE
1099 int
1100 E_GQuad_IntLoop_L(int i,
1101  int j,
1102  int type,
1103  short *S,
1104  int **ggg,
1105  int maxdist,
1106  vrna_param_t *P)
1107 {
1108  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
1109  short si, sj;
1110 
1112  si = S[i + 1];
1113  sj = S[j - 1];
1114  energy = 0;
1115 
1116  if (dangles == 2)
1117  energy += P->mismatchI[type][si][sj];
1118 
1119  if (type > 2)
1120  energy += P->TerminalAU;
1121 
1122  ge = INF;
1123 
1124  p = i + 1;
1125  if (S[p] == 3) {
1126  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1127  minq = j - i + p - MAXLOOP - 2;
1128  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1129  minq = MAX2(c0, minq);
1130  c0 = j - 3;
1131  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1132  maxq = MIN2(c0, maxq);
1133  for (q = minq; q < maxq; q++) {
1134  if (S[q] != 3)
1135  continue;
1136 
1137  c0 = energy + ggg[p][q - p] + P->internal_loop[j - q - 1];
1138  ge = MIN2(ge, c0);
1139  }
1140  }
1141  }
1142 
1143  for (p = i + 2;
1144  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1145  p++) {
1146  l1 = p - i - 1;
1147  if (l1 > MAXLOOP)
1148  break;
1149 
1150  if (S[p] != 3)
1151  continue;
1152 
1153  minq = j - i + p - MAXLOOP - 2;
1154  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1155  minq = MAX2(c0, minq);
1156  c0 = j - 1;
1157  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1158  maxq = MIN2(c0, maxq);
1159  for (q = minq; q < maxq; q++) {
1160  if (S[q] != 3)
1161  continue;
1162 
1163  c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
1164  ge = MIN2(ge, c0);
1165  }
1166  }
1167 
1168  q = j - 1;
1169  if (S[q] == 3)
1170  for (p = i + 4;
1171  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1172  p++) {
1173  l1 = p - i - 1;
1174  if (l1 > MAXLOOP)
1175  break;
1176 
1177  if (S[p] != 3)
1178  continue;
1179 
1180  c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
1181  ge = MIN2(ge, c0);
1182  }
1183 
1184  return ge;
1185 }
1186 
1187 
1188 PRIVATE INLINE
1189 FLT_OR_DBL
1190 exp_E_GQuad_IntLoop(int i,
1191  int j,
1192  int type,
1193  short *S,
1194  FLT_OR_DBL *G,
1195  FLT_OR_DBL *scale,
1196  int *index,
1197  vrna_exp_param_t *pf)
1198 {
1199  int k, l, minl, maxl, u, r;
1200  FLT_OR_DBL q, qe;
1201  double *expintern;
1202  short si, sj;
1203 
1204  q = 0;
1205  si = S[i + 1];
1206  sj = S[j - 1];
1207  qe = (FLT_OR_DBL)pf->expmismatchI[type][si][sj];
1208  expintern = &(pf->expinternal[0]);
1209 
1210  if (type > 2)
1211  qe *= (FLT_OR_DBL)pf->expTermAU;
1212 
1213  k = i + 1;
1214  if (S[k] == 3) {
1215  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1216  minl = j - MAXLOOP - 1;
1217  u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1218  minl = MAX2(u, minl);
1219  u = j - 3;
1220  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1221  maxl = MIN2(u, maxl);
1222  for (l = minl; l < maxl; l++) {
1223  if (S[l] != 3)
1224  continue;
1225 
1226  if (G[index[k] - l] == 0.)
1227  continue;
1228 
1229  q += qe
1230  * G[index[k] - l]
1231  * (FLT_OR_DBL)expintern[j - l - 1]
1232  * scale[j - l + 1];
1233  }
1234  }
1235  }
1236 
1237  for (k = i + 2;
1238  k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1239  k++) {
1240  u = k - i - 1;
1241  if (u > MAXLOOP)
1242  break;
1243 
1244  if (S[k] != 3)
1245  continue;
1246 
1247  minl = j - i + k - MAXLOOP - 2;
1248  r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1249  minl = MAX2(r, minl);
1250  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1251  r = j - 1;
1252  maxl = MIN2(r, maxl);
1253  for (l = minl; l < maxl; l++) {
1254  if (S[l] != 3)
1255  continue;
1256 
1257  if (G[index[k] - l] == 0.)
1258  continue;
1259 
1260  q += qe
1261  * G[index[k] - l]
1262  * (FLT_OR_DBL)expintern[u + j - l - 1]
1263  * scale[u + j - l + 1];
1264  }
1265  }
1266 
1267  l = j - 1;
1268  if (S[l] == 3)
1269  for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1270  u = k - i - 1;
1271  if (u > MAXLOOP)
1272  break;
1273 
1274  if (S[k] != 3)
1275  continue;
1276 
1277  if (G[index[k] - l] == 0.)
1278  continue;
1279 
1280  q += qe
1281  * G[index[k] - l]
1282  * (FLT_OR_DBL)expintern[u]
1283  * scale[u + 2];
1284  }
1285 
1286  return q;
1287 }
1288 
1289 
1295 #endif
void * vrna_alloc(unsigned size)
Allocate space safely.
short ** S
Numerical encoding of the sequences in the alignment.
Definition: fold_compound.h:270
short * S_cons
Numerical encoding of the consensus sequence.
Definition: fold_compound.h:267
char * ptype
Pair type array.
Definition: fold_compound.h:225
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: fold_compound.h:220
vrna_md_t model_details
Model details to be used in the recursions.
Definition: basic.h:94
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: basic.h:43
The most basic data structure required by many functions throughout the RNAlib.
Definition: fold_compound.h:132
The datastructure that contains temperature scaled energy parameters.
Definition: basic.h:56
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: basic.h:111
#define MAXLOOP
Definition: constants.h:29
int parse_gquad(const char *struc, int *L, int l[3])
#define INF
Definition: constants.h:17
int * jindx
DP matrix accessor.
Definition: fold_compound.h:166
Various data structures and pre-processor macros.
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:404
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:177
The data structure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: basic.h:101
Definition: fold_compound.h:116
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: basic.h:116
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: fold_compound.h:162
unsigned int n_seq
The number of sequences in the alignment.
Definition: fold_compound.h:261
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: fold_compound.h:159
Definition: fold_compound.h:115
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:180
Base pair stack element.
Definition: basic.h:142
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
Functions to deal with sets of energy parameters.
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
int * get_gquad_matrix(short *S, vrna_param_t *P)
Get a triangular matrix prefilled with minimum free energy contributions of G-quadruplexes.
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structures.h:358
int * ggg
Energies of g-quadruplexes.
Definition: dp_matrices.h:72
const vrna_fc_type_e type
The type of the vrna_fold_compound_t.
Definition: fold_compound.h:137
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:624