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