RNAlib-2.4.0
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, *S_cons;
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, *rtype, *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  rtype = &(md->rtype[0]);
298  type = rtype[(unsigned char)ptype[ij]];
299  S1 = vc->sequence_encoding;
300  S = vc->sequence_encoding2;
301  dangles = md->dangles;
302  si = S1[i + 1];
303  sj = S1[j - 1];
304  ggg = vc->matrices->ggg;
305  energy = 0;
306 
307  if (dangles == 2)
308  energy += P->mismatchI[type][si][sj];
309 
310  if (type > 2)
311  energy += P->TerminalAU;
312 
313  p = i + 1;
314  if (S1[p] == 3) {
315  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
316  minl = j - i + p - MAXLOOP - 2;
317  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
318  minl = MAX2(c0, minl);
319  c0 = j - 3;
320  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
321  maxl = MIN2(c0, maxl);
322  for (q = minl; q < maxl; q++) {
323  if (S[q] != 3)
324  continue;
325 
326  if (en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1])
327  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
328  }
329  }
330  }
331 
332  for (p = i + 2;
333  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
334  p++) {
335  l1 = p - i - 1;
336  if (l1 > MAXLOOP)
337  break;
338 
339  if (S1[p] != 3)
340  continue;
341 
342  minl = j - i + p - MAXLOOP - 2;
343  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
344  minl = MAX2(c0, minl);
345  c0 = j - 1;
346  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
347  maxl = MIN2(c0, maxl);
348  for (q = minl; q < maxl; q++) {
349  if (S1[q] != 3)
350  continue;
351 
352  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1])
353  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
354  }
355  }
356 
357  q = j - 1;
358  if (S1[q] == 3)
359  for (p = i + 4;
360  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
361  p++) {
362  l1 = p - i - 1;
363  if (l1 > MAXLOOP)
364  break;
365 
366  if (S1[p] != 3)
367  continue;
368 
369  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1])
370  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
371  }
372 
373  return 0;
374 }
375 
376 
394 INLINE PRIVATE int
396  int i,
397  int j,
398  int type,
399  short *S,
400  int *ggg,
401  int *index,
402  int *p,
403  int *q,
404  vrna_param_t *P)
405 {
406  int energy, dangles, k, l, maxl, minl, c0, l1;
407  short si, sj;
408 
409  dangles = P->model_details.dangles;
410  si = S[i + 1];
411  sj = S[j - 1];
412  energy = 0;
413 
414  if (dangles == 2)
415  energy += P->mismatchI[type][si][sj];
416 
417  if (type > 2)
418  energy += P->TerminalAU;
419 
420  k = i + 1;
421  if (S[k] == 3) {
422  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
423  minl = j - i + k - MAXLOOP - 2;
424  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
425  minl = MAX2(c0, minl);
426  c0 = j - 3;
427  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
428  maxl = MIN2(c0, maxl);
429  for (l = minl; l < maxl; l++) {
430  if (S[l] != 3)
431  continue;
432 
433  if (c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]) {
434  *p = k;
435  *q = l;
436  return 1;
437  }
438  }
439  }
440  }
441 
442  for (k = i + 2;
443  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
444  k++) {
445  l1 = k - i - 1;
446  if (l1 > MAXLOOP)
447  break;
448 
449  if (S[k] != 3)
450  continue;
451 
452  minl = j - i + k - MAXLOOP - 2;
453  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
454  minl = MAX2(c0, minl);
455  c0 = j - 1;
456  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
457  maxl = MIN2(c0, maxl);
458  for (l = minl; l < maxl; l++) {
459  if (S[l] != 3)
460  continue;
461 
462  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]) {
463  *p = k;
464  *q = l;
465  return 1;
466  }
467  }
468  }
469 
470  l = j - 1;
471  if (S[l] == 3)
472  for (k = i + 4;
473  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
474  k++) {
475  l1 = k - i - 1;
476  if (l1 > MAXLOOP)
477  break;
478 
479  if (S[k] != 3)
480  continue;
481 
482  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1]) {
483  *p = k;
484  *q = l;
485  return 1;
486  }
487  }
488 
489  return 0;
490 }
491 
492 
493 INLINE PRIVATE int
494 backtrack_GQuad_IntLoop_comparative(int c,
495  int i,
496  int j,
497  int *type,
498  short *S_cons,
499  short **S5,
500  short **S3,
501  int *ggg,
502  int *index,
503  int *p,
504  int *q,
505  int n_seq,
506  vrna_param_t *P)
507 {
508  int energy, dangles, k, l, maxl, minl, c0, l1, ss, tt;
509 
510  dangles = P->model_details.dangles;
511  energy = 0;
512 
513  for (ss = 0; ss < n_seq; ss++) {
514  tt = type[ss];
515  if (tt == 0)
516  tt = 7;
517 
518  if (dangles == 2)
519  energy += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
520 
521  if (tt > 2)
522  energy += P->TerminalAU;
523  }
524 
525  k = i + 1;
526  if (S_cons[k] == 3) {
527  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
528  minl = j - i + k - MAXLOOP - 2;
529  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
530  minl = MAX2(c0, minl);
531  c0 = j - 3;
532  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
533  maxl = MIN2(c0, maxl);
534  for (l = minl; l < maxl; l++) {
535  if (S_cons[l] != 3)
536  continue;
537 
538  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[j - l - 1]) {
539  *p = k;
540  *q = l;
541  return 1;
542  }
543  }
544  }
545  }
546 
547  for (k = i + 2;
548  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
549  k++) {
550  l1 = k - i - 1;
551  if (l1 > MAXLOOP)
552  break;
553 
554  if (S_cons[k] != 3)
555  continue;
556 
557  minl = j - i + k - MAXLOOP - 2;
558  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
559  minl = MAX2(c0, minl);
560  c0 = j - 1;
561  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
562  maxl = MIN2(c0, maxl);
563  for (l = minl; l < maxl; l++) {
564  if (S_cons[l] != 3)
565  continue;
566 
567  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1 + j - l - 1]) {
568  *p = k;
569  *q = l;
570  return 1;
571  }
572  }
573  }
574 
575  l = j - 1;
576  if (S_cons[l] == 3)
577  for (k = i + 4;
578  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
579  k++) {
580  l1 = k - i - 1;
581  if (l1 > MAXLOOP)
582  break;
583 
584  if (S_cons[k] != 3)
585  continue;
586 
587  if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1]) {
588  *p = k;
589  *q = l;
590  return 1;
591  }
592  }
593 
594  return 0;
595 }
596 
597 
614 INLINE PRIVATE int
616  int i,
617  int j,
618  int type,
619  short *S,
620  int **ggg,
621  int maxdist,
622  int *p,
623  int *q,
624  vrna_param_t *P)
625 {
626  int energy, dangles, k, l, maxl, minl, c0, l1;
627  short si, sj;
628 
629  dangles = P->model_details.dangles;
630  si = S[i + 1];
631  sj = S[j - 1];
632  energy = 0;
633 
634  if (dangles == 2)
635  energy += P->mismatchI[type][si][sj];
636 
637  if (type > 2)
638  energy += P->TerminalAU;
639 
640  k = i + 1;
641  if (S[k] == 3) {
642  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
643  minl = j - i + k - MAXLOOP - 2;
644  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
645  minl = MAX2(c0, minl);
646  c0 = j - 3;
647  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
648  maxl = MIN2(c0, maxl);
649  for (l = minl; l < maxl; l++) {
650  if (S[l] != 3)
651  continue;
652 
653  if (c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]) {
654  *p = k;
655  *q = l;
656  return 1;
657  }
658  }
659  }
660  }
661 
662  for (k = i + 2;
663  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
664  k++) {
665  l1 = k - i - 1;
666  if (l1 > MAXLOOP)
667  break;
668 
669  if (S[k] != 3)
670  continue;
671 
672  minl = j - i + k - MAXLOOP - 2;
673  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
674  minl = MAX2(c0, minl);
675  c0 = j - 1;
676  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
677  maxl = MIN2(c0, maxl);
678  for (l = minl; l < maxl; l++) {
679  if (S[l] != 3)
680  continue;
681 
682  if (c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]) {
683  *p = k;
684  *q = l;
685  return 1;
686  }
687  }
688  }
689 
690  l = j - 1;
691  if (S[l] == 3)
692  for (k = i + 4;
693  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
694  k++) {
695  l1 = k - i - 1;
696  if (l1 > MAXLOOP)
697  break;
698 
699  if (S[k] != 3)
700  continue;
701 
702  if (c == energy + ggg[k][l - k] + P->internal_loop[l1]) {
703  *p = k;
704  *q = l;
705  return 1;
706  }
707  }
708 
709  return 0;
710 }
711 
712 
713 INLINE PRIVATE int
714 backtrack_GQuad_IntLoop_L_comparative(int c,
715  int i,
716  int j,
717  int *type,
718  short *S_cons,
719  short **S5,
720  short **S3,
721  int **ggg,
722  int *p,
723  int *q,
724  int n_seq,
725  vrna_param_t *P)
726 {
727  /*
728  * The case that is handled here actually resembles something like
729  * an interior loop where the enclosing base pair is of regular
730  * kind and the enclosed pair is not a canonical one but a g-quadruplex
731  * that should then be decomposed further...
732  */
733  int mm, dangle_model, k, l, maxl, minl, c0, l1, ss, tt;
734 
735  dangle_model = P->model_details.dangles;
736 
737  mm = 0;
738  for (ss = 0; ss < n_seq; ss++) {
739  tt = type[ss];
740 
741  if (dangle_model == 2)
742  mm += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
743 
744  if (tt > 2)
745  mm += P->TerminalAU;
746  }
747 
748  for (k = i + 2;
749  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
750  k++) {
751  if (S_cons[k] != 3)
752  continue;
753 
754  l1 = k - i - 1;
755  if (l1 > MAXLOOP)
756  break;
757 
758  minl = j - i + k - MAXLOOP - 2;
759  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
760  minl = MAX2(c0, minl);
761  c0 = j - 1;
762  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
763  maxl = MIN2(c0, maxl);
764  for (l = minl; l < maxl; l++) {
765  if (S_cons[l] != 3)
766  continue;
767 
768  c0 = mm + ggg[k][l - k] + n_seq * P->internal_loop[l1 + j - l - 1];
769  if (c == c0) {
770  *p = k;
771  *q = l;
772  return 1;
773  }
774  }
775  }
776  k = i + 1;
777  if (S_cons[k] == 3) {
778  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
779  minl = j - i + k - MAXLOOP - 2;
780  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
781  minl = MAX2(c0, minl);
782  c0 = j - 3;
783  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
784  maxl = MIN2(c0, maxl);
785  for (l = minl; l < maxl; l++) {
786  if (S_cons[l] != 3)
787  continue;
788 
789  if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[j - l - 1]) {
790  *p = k;
791  *q = l;
792  return 1;
793  }
794  }
795  }
796  }
797 
798  l = j - 1;
799  if (S_cons[l] == 3) {
800  for (k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
801  l1 = k - i - 1;
802  if (l1 > MAXLOOP)
803  break;
804 
805  if (S_cons[k] != 3)
806  continue;
807 
808  if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[l1]) {
809  *p = k;
810  *q = l;
811  return 1;
812  }
813  }
814  }
815 
816  return 0;
817 }
818 
819 
820 PRIVATE INLINE
821 int
822 E_GQuad_IntLoop(int i,
823  int j,
824  int type,
825  short *S,
826  int *ggg,
827  int *index,
828  vrna_param_t *P)
829 {
830  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
831  short si, sj;
832 
833  dangles = P->model_details.dangles;
834  si = S[i + 1];
835  sj = S[j - 1];
836  energy = 0;
837 
838  if (dangles == 2)
839  energy += P->mismatchI[type][si][sj];
840 
841  if (type > 2)
842  energy += P->TerminalAU;
843 
844  ge = INF;
845 
846  p = i + 1;
847  if (S[p] == 3) {
848  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
849  minq = j - i + p - MAXLOOP - 2;
850  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
851  minq = MAX2(c0, minq);
852  c0 = j - 3;
853  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
854  maxq = MIN2(c0, maxq);
855  for (q = minq; q < maxq; q++) {
856  if (S[q] != 3)
857  continue;
858 
859  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
860  ge = MIN2(ge, c0);
861  }
862  }
863  }
864 
865  for (p = i + 2;
866  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
867  p++) {
868  l1 = p - i - 1;
869  if (l1 > MAXLOOP)
870  break;
871 
872  if (S[p] != 3)
873  continue;
874 
875  minq = j - i + p - MAXLOOP - 2;
876  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
877  minq = MAX2(c0, minq);
878  c0 = j - 1;
879  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
880  maxq = MIN2(c0, maxq);
881  for (q = minq; q < maxq; q++) {
882  if (S[q] != 3)
883  continue;
884 
885  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
886  ge = MIN2(ge, c0);
887  }
888  }
889 
890  q = j - 1;
891  if (S[q] == 3)
892  for (p = i + 4;
893  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
894  p++) {
895  l1 = p - i - 1;
896  if (l1 > MAXLOOP)
897  break;
898 
899  if (S[p] != 3)
900  continue;
901 
902  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
903  ge = MIN2(ge, c0);
904  }
905 
906 #if 0
907  /* here comes the additional stuff for the odd dangle models */
908  if (dangles % 1) {
909  en1 = energy + P->dangle5[type][si];
910  en2 = energy + P->dangle5[type][sj];
911  en3 = energy + P->mismatchI[type][si][sj];
912 
913  /* first case with 5' dangle (i.e. j-1) onto enclosing pair */
914  p = i + 1;
915  if (S[p] == 3) {
916  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
917  minq = j - i + p - MAXLOOP - 2;
918  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
919  minq = MAX2(c0, minq);
920  c0 = j - 4;
921  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
922  maxq = MIN2(c0, maxq);
923  for (q = minq; q < maxq; q++) {
924  if (S[q] != 3)
925  continue;
926 
927  c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
928  ge = MIN2(ge, c0);
929  }
930  }
931  }
932 
933  for (p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
934  l1 = p - i - 1;
935  if (l1 > MAXLOOP)
936  break;
937 
938  if (S[p] != 3)
939  continue;
940 
941  minq = j - i + p - MAXLOOP - 2;
942  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
943  minq = MAX2(c0, minq);
944  c0 = j - 2;
945  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
946  maxq = MIN2(c0, maxq);
947  for (q = minq; q < maxq; q++) {
948  if (S[q] != 3)
949  continue;
950 
951  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
952  ge = MIN2(ge, c0);
953  }
954  }
955 
956  q = j - 2;
957  if (S[q] == 3)
958  for (p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
959  l1 = p - i - 1;
960  if (l1 > MAXLOOP)
961  break;
962 
963  if (S[p] != 3)
964  continue;
965 
966  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
967  ge = MIN2(ge, c0);
968  }
969 
970  /* second case with 3' dangle (i.e. i+1) onto enclosing pair */
971  }
972 
973 #endif
974  return ge;
975 }
976 
977 
978 PRIVATE INLINE
979 int *
980 E_GQuad_IntLoop_exhaustive(int i,
981  int j,
982  int **p_p,
983  int **q_p,
984  int type,
985  short *S,
986  int *ggg,
987  int threshold,
988  int *index,
989  vrna_param_t *P)
990 {
991  int energy, *ge, dangles, p, q, l1, minq, maxq, c0;
992  short si, sj;
993  int cnt = 0;
994 
995  dangles = P->model_details.dangles;
996  si = S[i + 1];
997  sj = S[j - 1];
998  energy = 0;
999 
1000  if (dangles == 2)
1001  energy += P->mismatchI[type][si][sj];
1002 
1003  if (type > 2)
1004  energy += P->TerminalAU;
1005 
1006  /* guess how many gquads are possible in interval [i+1,j-1] */
1007  *p_p = (int *)vrna_alloc(sizeof(int) * 256);
1008  *q_p = (int *)vrna_alloc(sizeof(int) * 256);
1009  ge = (int *)vrna_alloc(sizeof(int) * 256);
1010 
1011  p = i + 1;
1012  if (S[p] == 3) {
1013  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1014  minq = j - i + p - MAXLOOP - 2;
1015  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1016  minq = MAX2(c0, minq);
1017  c0 = j - 3;
1018  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1019  maxq = MIN2(c0, maxq);
1020  for (q = minq; q < maxq; q++) {
1021  if (S[q] != 3)
1022  continue;
1023 
1024  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1025  if (c0 <= threshold) {
1026  ge[cnt] = energy + P->internal_loop[j - q - 1];
1027  (*p_p)[cnt] = p;
1028  (*q_p)[cnt++] = q;
1029  }
1030  }
1031  }
1032  }
1033 
1034  for (p = i + 2;
1035  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1036  p++) {
1037  l1 = p - i - 1;
1038  if (l1 > MAXLOOP)
1039  break;
1040 
1041  if (S[p] != 3)
1042  continue;
1043 
1044  minq = j - i + p - MAXLOOP - 2;
1045  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1046  minq = MAX2(c0, minq);
1047  c0 = j - 1;
1048  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1049  maxq = MIN2(c0, maxq);
1050  for (q = minq; q < maxq; q++) {
1051  if (S[q] != 3)
1052  continue;
1053 
1054  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1055  if (c0 <= threshold) {
1056  ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
1057  (*p_p)[cnt] = p;
1058  (*q_p)[cnt++] = q;
1059  }
1060  }
1061  }
1062 
1063  q = j - 1;
1064  if (S[q] == 3)
1065  for (p = i + 4;
1066  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1067  p++) {
1068  l1 = p - i - 1;
1069  if (l1 > MAXLOOP)
1070  break;
1071 
1072  if (S[p] != 3)
1073  continue;
1074 
1075  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
1076  if (c0 <= threshold) {
1077  ge[cnt] = energy + P->internal_loop[l1];
1078  (*p_p)[cnt] = p;
1079  (*q_p)[cnt++] = q;
1080  }
1081  }
1082 
1083  (*p_p)[cnt] = -1;
1084 
1085  return ge;
1086 }
1087 
1088 
1089 PRIVATE INLINE
1090 int
1091 E_GQuad_IntLoop_L(int i,
1092  int j,
1093  int type,
1094  short *S,
1095  int **ggg,
1096  int maxdist,
1097  vrna_param_t *P)
1098 {
1099  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
1100  short si, sj;
1101 
1102  dangles = P->model_details.dangles;
1103  si = S[i + 1];
1104  sj = S[j - 1];
1105  energy = 0;
1106 
1107  if (dangles == 2)
1108  energy += P->mismatchI[type][si][sj];
1109 
1110  if (type > 2)
1111  energy += P->TerminalAU;
1112 
1113  ge = INF;
1114 
1115  p = i + 1;
1116  if (S[p] == 3) {
1117  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1118  minq = j - i + p - MAXLOOP - 2;
1119  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1120  minq = MAX2(c0, minq);
1121  c0 = j - 3;
1122  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1123  maxq = MIN2(c0, maxq);
1124  for (q = minq; q < maxq; q++) {
1125  if (S[q] != 3)
1126  continue;
1127 
1128  c0 = energy + ggg[p][q - p] + P->internal_loop[j - q - 1];
1129  ge = MIN2(ge, c0);
1130  }
1131  }
1132  }
1133 
1134  for (p = i + 2;
1135  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1136  p++) {
1137  l1 = p - i - 1;
1138  if (l1 > MAXLOOP)
1139  break;
1140 
1141  if (S[p] != 3)
1142  continue;
1143 
1144  minq = j - i + p - MAXLOOP - 2;
1145  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1146  minq = MAX2(c0, minq);
1147  c0 = j - 1;
1148  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1149  maxq = MIN2(c0, maxq);
1150  for (q = minq; q < maxq; q++) {
1151  if (S[q] != 3)
1152  continue;
1153 
1154  c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
1155  ge = MIN2(ge, c0);
1156  }
1157  }
1158 
1159  q = j - 1;
1160  if (S[q] == 3)
1161  for (p = i + 4;
1162  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1163  p++) {
1164  l1 = p - i - 1;
1165  if (l1 > MAXLOOP)
1166  break;
1167 
1168  if (S[p] != 3)
1169  continue;
1170 
1171  c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
1172  ge = MIN2(ge, c0);
1173  }
1174 
1175  return ge;
1176 }
1177 
1178 
1179 PRIVATE INLINE
1180 FLT_OR_DBL
1181 exp_E_GQuad_IntLoop(int i,
1182  int j,
1183  int type,
1184  short *S,
1185  FLT_OR_DBL *G,
1186  FLT_OR_DBL *scale,
1187  int *index,
1188  vrna_exp_param_t *pf)
1189 {
1190  int k, l, minl, maxl, u, r;
1191  FLT_OR_DBL q, qe;
1192  double *expintern;
1193  short si, sj;
1194 
1195  q = 0;
1196  si = S[i + 1];
1197  sj = S[j - 1];
1198  qe = (FLT_OR_DBL)pf->expmismatchI[type][si][sj];
1199  expintern = &(pf->expinternal[0]);
1200 
1201  if (type > 2)
1202  qe *= (FLT_OR_DBL)pf->expTermAU;
1203 
1204  k = i + 1;
1205  if (S[k] == 3) {
1206  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1207  minl = j - MAXLOOP - 1;
1208  u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1209  minl = MAX2(u, minl);
1210  u = j - 3;
1211  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1212  maxl = MIN2(u, maxl);
1213  for (l = minl; l < maxl; l++) {
1214  if (S[l] != 3)
1215  continue;
1216 
1217  if (G[index[k] - l] == 0.)
1218  continue;
1219 
1220  q += qe
1221  * G[index[k] - l]
1222  * (FLT_OR_DBL)expintern[j - l - 1]
1223  * scale[j - l + 1];
1224  }
1225  }
1226  }
1227 
1228  for (k = i + 2;
1229  k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1230  k++) {
1231  u = k - i - 1;
1232  if (u > MAXLOOP)
1233  break;
1234 
1235  if (S[k] != 3)
1236  continue;
1237 
1238  minl = j - i + k - MAXLOOP - 2;
1239  r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1240  minl = MAX2(r, minl);
1241  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1242  r = j - 1;
1243  maxl = MIN2(r, maxl);
1244  for (l = minl; l < maxl; l++) {
1245  if (S[l] != 3)
1246  continue;
1247 
1248  if (G[index[k] - l] == 0.)
1249  continue;
1250 
1251  q += qe
1252  * G[index[k] - l]
1253  * (FLT_OR_DBL)expintern[u + j - l - 1]
1254  * scale[u + j - l + 1];
1255  }
1256  }
1257 
1258  l = j - 1;
1259  if (S[l] == 3)
1260  for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1261  u = k - i - 1;
1262  if (u > MAXLOOP)
1263  break;
1264 
1265  if (S[k] != 3)
1266  continue;
1267 
1268  if (G[index[k] - l] == 0.)
1269  continue;
1270 
1271  q += qe
1272  * G[index[k] - l]
1273  * (FLT_OR_DBL)expintern[u]
1274  * scale[u + 2];
1275  }
1276 
1277  return q;
1278 }
1279 
1280 
1286 #endif
void * vrna_alloc(unsigned size)
Allocate space safely.
short ** S
Numerical encoding of the sequences in the alignment.
Definition: data_structures.h:595
short * S_cons
Numerical encoding of the consensus sequence.
Definition: data_structures.h:592
char * ptype
Pair type array.
Definition: data_structures.h:550
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:545
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:192
#define MAXLOOP
Definition: energy_const.h:29
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:95
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structure_utils.h:69
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:48
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:463
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:57
int parse_gquad(const char *struc, int *L, int l[3])
int * jindx
DP matrix accessor.
Definition: data_structures.h:491
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:395
Various data structures and pre-processor macros.
#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
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:189
Definition: data_structures.h:447
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:121
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:487
unsigned int n_seq
The number of sequences in the alignment.
Definition: data_structures.h:586
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:484
Definition: data_structures.h:446
Base pair stack element.
Definition: data_structures.h:229
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:116
int rtype[8]
Reverse base pair type array.
Definition: model.h:241
vrna_fc_type_e type
The type of the vrna_fold_compound_t.
Definition: data_structures.h:468
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:615