RNAlib-2.4.10
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 void E_gquad_ali_en(int i,
40  int L,
41  int l[3],
42  const short **S,
43  unsigned int **a2s,
44  unsigned int n_seq,
45  vrna_param_t *P,
46  int en[2]);
47 
48 
65 int *get_gquad_matrix(short *S,
66  vrna_param_t *P);
67 
68 
69 int *get_gquad_ali_matrix(short *S_cons,
70  short **S,
71  unsigned int **a2s,
72  int n_seq,
73  vrna_param_t *P);
74 
75 
76 FLT_OR_DBL *get_gquad_pf_matrix(short *S,
77  FLT_OR_DBL *scale,
78  vrna_exp_param_t *pf);
79 
80 
81 FLT_OR_DBL *get_gquad_pf_matrix_comparative(short *S_cons,
82  short **S,
83  unsigned int **a2s,
84  FLT_OR_DBL *scale,
85  unsigned int n_seq,
86  vrna_exp_param_t *pf);
87 
88 
89 int **get_gquad_L_matrix(short *S,
90  int start,
91  int maxdist,
92  int n,
93  int **g,
94  vrna_param_t *P);
95 
96 
97 void vrna_gquad_mx_local_update(vrna_fold_compound_t *vc,
98  int start);
99 
100 
101 void get_gquad_pattern_mfe(short *S,
102  int i,
103  int j,
104  vrna_param_t *P,
105  int *L,
106  int l[3]);
107 
108 
109 void
110 get_gquad_pattern_exhaustive(short *S,
111  int i,
112  int j,
113  vrna_param_t *P,
114  int *L,
115  int *l,
116  int threshold);
117 
118 
119 void get_gquad_pattern_pf(short *S,
120  int i,
121  int j,
122  vrna_exp_param_t *pf,
123  int *L,
124  int l[3]);
125 
126 
127 plist *get_plist_gquad_from_pr(short *S,
128  int gi,
129  int gj,
130  FLT_OR_DBL *G,
131  FLT_OR_DBL *probs,
132  FLT_OR_DBL *scale,
133  vrna_exp_param_t *pf);
134 
135 
136 plist *get_plist_gquad_from_pr_max(short *S,
137  int gi,
138  int gj,
139  FLT_OR_DBL *G,
140  FLT_OR_DBL *probs,
141  FLT_OR_DBL *scale,
142  int *L,
143  int l[3],
144  vrna_exp_param_t *pf);
145 
146 
147 plist *get_plist_gquad_from_db(const char *structure,
148  float pr);
149 
150 
151 plist *
152 vrna_get_plist_gquad_from_pr(vrna_fold_compound_t *fc,
153  int gi,
154  int gj);
155 
156 
157 plist *
158 vrna_get_plist_gquad_from_pr_max(vrna_fold_compound_t *fc,
159  int gi,
160  int gj,
161  int *Lmax,
162  int lmax[3]);
163 
164 
165 int get_gquad_count(short *S,
166  int i,
167  int j);
168 
169 
170 int get_gquad_layer_count(short *S,
171  int i,
172  int j);
173 
174 
175 void get_gquad_pattern_mfe_ali(short **S,
176  unsigned int **a2s,
177  short *S_cons,
178  int n_seq,
179  int i,
180  int j,
181  vrna_param_t *P,
182  int *L,
183  int l[3]);
184 
185 
196 int parse_gquad(const char *struc,
197  int *L,
198  int l[3]);
199 
200 
201 INLINE PRIVATE int backtrack_GQuad_IntLoop(int c,
202  int i,
203  int j,
204  int type,
205  short *S,
206  int *ggg,
207  int *index,
208  int *p,
209  int *q,
210  vrna_param_t *P);
211 
212 
213 INLINE PRIVATE int backtrack_GQuad_IntLoop_comparative(int c,
214  int i,
215  int j,
216  unsigned int *type,
217  short *S_cons,
218  short **S5,
219  short **S3,
220  unsigned int **a2s,
221  int *ggg,
222  int *index,
223  int *p,
224  int *q,
225  int n_seq,
226  vrna_param_t *P);
227 
228 
229 INLINE PRIVATE int backtrack_GQuad_IntLoop_L(int c,
230  int i,
231  int j,
232  int type,
233  short *S,
234  int **ggg,
235  int maxdist,
236  int *p,
237  int *q,
238  vrna_param_t *P);
239 
240 
241 PRIVATE INLINE int
242 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
243  int i,
244  int j,
245  int en,
246  vrna_bp_stack_t *bp_stack,
247  int *stack_count);
248 
249 
250 PRIVATE INLINE int
251 vrna_BT_gquad_mfe(vrna_fold_compound_t *vc,
252  int i,
253  int j,
254  vrna_bp_stack_t *bp_stack,
255  int *stack_count)
256 {
257  /*
258  * here we do some fancy stuff to backtrace the stacksize and linker lengths
259  * of the g-quadruplex that should reside within position i,j
260  */
261  short *S;
262  int l[3], L, a, n_seq;
263  vrna_param_t *P;
264 
265  if (vc) {
266  P = vc->params;
267  switch (vc->type) {
268  case VRNA_FC_TYPE_SINGLE:
269  S = vc->sequence_encoding2;
270  L = -1;
271 
272  get_gquad_pattern_mfe(S, i, j, P, &L, l);
273  break;
274 
276  n_seq = vc->n_seq;
277  L = -1;
278  get_gquad_pattern_mfe_ali(vc->S, vc->a2s, vc->S_cons, n_seq, i, j, P, &L, l);
279  break;
280  }
281 
282  if (L != -1) {
283  /* fill the G's of the quadruplex into base_pair2 */
284  for (a = 0; a < L; a++) {
285  bp_stack[++(*stack_count)].i = i + a;
286  bp_stack[(*stack_count)].j = i + a;
287  bp_stack[++(*stack_count)].i = i + L + l[0] + a;
288  bp_stack[(*stack_count)].j = i + L + l[0] + a;
289  bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + a;
290  bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + a;
291  bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + L + l[2] + a;
292  bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + L + l[2] + a;
293  }
294  return 1;
295  } else {
296  return 0;
297  }
298  }
299 
300  return 0;
301 }
302 
303 
304 PRIVATE INLINE int
305 vrna_BT_gquad_int(vrna_fold_compound_t *vc,
306  int i,
307  int j,
308  int en,
309  vrna_bp_stack_t *bp_stack,
310  int *stack_count)
311 {
312  int energy, dangles, *idx, ij, p, q, maxl, minl, c0, l1, *ggg;
313  unsigned char type;
314  char *ptype;
315  short si, sj, *S, *S1;
316 
317  vrna_param_t *P;
318  vrna_md_t *md;
319 
320  idx = vc->jindx;
321  ij = idx[j] + i;
322  P = vc->params;
323  md = &(P->model_details);
324  ptype = vc->ptype;
325  type = (unsigned char)ptype[ij];
326  S1 = vc->sequence_encoding;
327  S = vc->sequence_encoding2;
328  dangles = md->dangles;
329  si = S1[i + 1];
330  sj = S1[j - 1];
331  ggg = vc->matrices->ggg;
332  energy = 0;
333 
334  if (dangles == 2)
335  energy += P->mismatchI[type][si][sj];
336 
337  if (type > 2)
338  energy += P->TerminalAU;
339 
340  p = i + 1;
341  if (S1[p] == 3) {
342  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
343  minl = j - i + p - MAXLOOP - 2;
344  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
345  minl = MAX2(c0, minl);
346  c0 = j - 3;
347  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
348  maxl = MIN2(c0, maxl);
349  for (q = minl; q < maxl; q++) {
350  if (S[q] != 3)
351  continue;
352 
353  if (en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1])
354  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
355  }
356  }
357  }
358 
359  for (p = i + 2;
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  minl = j - i + p - MAXLOOP - 2;
370  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
371  minl = MAX2(c0, minl);
372  c0 = j - 1;
373  maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
374  maxl = MIN2(c0, maxl);
375  for (q = minl; q < maxl; q++) {
376  if (S1[q] != 3)
377  continue;
378 
379  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1])
380  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
381  }
382  }
383 
384  q = j - 1;
385  if (S1[q] == 3)
386  for (p = i + 4;
387  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
388  p++) {
389  l1 = p - i - 1;
390  if (l1 > MAXLOOP)
391  break;
392 
393  if (S1[p] != 3)
394  continue;
395 
396  if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1])
397  return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
398  }
399 
400  return 0;
401 }
402 
403 
421 INLINE PRIVATE int
423  int i,
424  int j,
425  int type,
426  short *S,
427  int *ggg,
428  int *index,
429  int *p,
430  int *q,
431  vrna_param_t *P)
432 {
433  int energy, dangles, k, l, maxl, minl, c0, l1;
434  short si, sj;
435 
436  dangles = P->model_details.dangles;
437  si = S[i + 1];
438  sj = S[j - 1];
439  energy = 0;
440 
441  if (dangles == 2)
442  energy += P->mismatchI[type][si][sj];
443 
444  if (type > 2)
445  energy += P->TerminalAU;
446 
447  k = i + 1;
448  if (S[k] == 3) {
449  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
450  minl = j - i + k - MAXLOOP - 2;
451  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
452  minl = MAX2(c0, minl);
453  c0 = j - 3;
454  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
455  maxl = MIN2(c0, maxl);
456  for (l = minl; l < maxl; l++) {
457  if (S[l] != 3)
458  continue;
459 
460  if (c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]) {
461  *p = k;
462  *q = l;
463  return 1;
464  }
465  }
466  }
467  }
468 
469  for (k = i + 2;
470  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
471  k++) {
472  l1 = k - i - 1;
473  if (l1 > MAXLOOP)
474  break;
475 
476  if (S[k] != 3)
477  continue;
478 
479  minl = j - i + k - MAXLOOP - 2;
480  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
481  minl = MAX2(c0, minl);
482  c0 = j - 1;
483  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
484  maxl = MIN2(c0, maxl);
485  for (l = minl; l < maxl; l++) {
486  if (S[l] != 3)
487  continue;
488 
489  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]) {
490  *p = k;
491  *q = l;
492  return 1;
493  }
494  }
495  }
496 
497  l = j - 1;
498  if (S[l] == 3)
499  for (k = i + 4;
500  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
501  k++) {
502  l1 = k - i - 1;
503  if (l1 > MAXLOOP)
504  break;
505 
506  if (S[k] != 3)
507  continue;
508 
509  if (c == energy + ggg[index[l] + k] + P->internal_loop[l1]) {
510  *p = k;
511  *q = l;
512  return 1;
513  }
514  }
515 
516  return 0;
517 }
518 
519 
520 INLINE PRIVATE int
521 backtrack_GQuad_IntLoop_comparative(int c,
522  int i,
523  int j,
524  unsigned int *type,
525  short *S_cons,
526  short **S5,
527  short **S3,
528  unsigned int **a2s,
529  int *ggg,
530  int *index,
531  int *p,
532  int *q,
533  int n_seq,
534  vrna_param_t *P)
535 {
536  int energy, dangles, k, l, maxl, minl, c0, l1, ss, tt, u1, u2, eee;
537 
538  dangles = P->model_details.dangles;
539  energy = 0;
540 
541  for (ss = 0; ss < n_seq; ss++) {
542  tt = type[ss];
543  if (tt == 0)
544  tt = 7;
545 
546  if (dangles == 2)
547  energy += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
548 
549  if (tt > 2)
550  energy += P->TerminalAU;
551  }
552 
553  k = i + 1;
554  if (S_cons[k] == 3) {
555  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
556  minl = j - i + k - MAXLOOP - 2;
557  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
558  minl = MAX2(c0, minl);
559  c0 = j - 3;
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  eee = 0;
567 
568  for (ss = 0; ss < n_seq; ss++) {
569  u1 = a2s[ss][j - 1] - a2s[ss][l];
570  eee += P->internal_loop[u1];
571  }
572 
573  if (c == energy + ggg[index[l] + k] + eee) {
574  *p = k;
575  *q = l;
576  return 1;
577  }
578  }
579  }
580  }
581 
582  for (k = i + 2;
583  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
584  k++) {
585  l1 = k - i - 1;
586  if (l1 > MAXLOOP)
587  break;
588 
589  if (S_cons[k] != 3)
590  continue;
591 
592  minl = j - i + k - MAXLOOP - 2;
593  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
594  minl = MAX2(c0, minl);
595  c0 = j - 1;
596  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
597  maxl = MIN2(c0, maxl);
598  for (l = minl; l < maxl; l++) {
599  if (S_cons[l] != 3)
600  continue;
601 
602  eee = 0;
603 
604  for (ss = 0; ss < n_seq; ss++) {
605  u1 = a2s[ss][k - 1] - a2s[ss][i];
606  u2 = a2s[ss][j - 1] - a2s[ss][l];
607  eee += P->internal_loop[u1 + u2];
608  }
609 
610  if (c == energy + ggg[index[l] + k] + eee) {
611  *p = k;
612  *q = l;
613  return 1;
614  }
615  }
616  }
617 
618  l = j - 1;
619  if (S_cons[l] == 3)
620  for (k = i + 4;
621  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
622  k++) {
623  l1 = k - i - 1;
624  if (l1 > MAXLOOP)
625  break;
626 
627  if (S_cons[k] != 3)
628  continue;
629 
630  eee = 0;
631 
632  for (ss = 0; ss < n_seq; ss++) {
633  u1 = a2s[ss][k - 1] - a2s[ss][i];
634  eee += P->internal_loop[u1];
635  }
636 
637  if (c == energy + ggg[index[l] + k] + eee) {
638  *p = k;
639  *q = l;
640  return 1;
641  }
642  }
643 
644  return 0;
645 }
646 
647 
664 INLINE PRIVATE int
666  int i,
667  int j,
668  int type,
669  short *S,
670  int **ggg,
671  int maxdist,
672  int *p,
673  int *q,
674  vrna_param_t *P)
675 {
676  int energy, dangles, k, l, maxl, minl, c0, l1;
677  short si, sj;
678 
679  dangles = P->model_details.dangles;
680  si = S[i + 1];
681  sj = S[j - 1];
682  energy = 0;
683 
684  if (dangles == 2)
685  energy += P->mismatchI[type][si][sj];
686 
687  if (type > 2)
688  energy += P->TerminalAU;
689 
690  k = i + 1;
691  if (S[k] == 3) {
692  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
693  minl = j - i + k - MAXLOOP - 2;
694  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
695  minl = MAX2(c0, minl);
696  c0 = j - 3;
697  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
698  maxl = MIN2(c0, maxl);
699  for (l = minl; l < maxl; l++) {
700  if (S[l] != 3)
701  continue;
702 
703  if (c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]) {
704  *p = k;
705  *q = l;
706  return 1;
707  }
708  }
709  }
710  }
711 
712  for (k = i + 2;
713  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
714  k++) {
715  l1 = k - i - 1;
716  if (l1 > MAXLOOP)
717  break;
718 
719  if (S[k] != 3)
720  continue;
721 
722  minl = j - i + k - MAXLOOP - 2;
723  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
724  minl = MAX2(c0, minl);
725  c0 = j - 1;
726  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
727  maxl = MIN2(c0, maxl);
728  for (l = minl; l < maxl; l++) {
729  if (S[l] != 3)
730  continue;
731 
732  if (c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]) {
733  *p = k;
734  *q = l;
735  return 1;
736  }
737  }
738  }
739 
740  l = j - 1;
741  if (S[l] == 3)
742  for (k = i + 4;
743  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
744  k++) {
745  l1 = k - i - 1;
746  if (l1 > MAXLOOP)
747  break;
748 
749  if (S[k] != 3)
750  continue;
751 
752  if (c == energy + ggg[k][l - k] + P->internal_loop[l1]) {
753  *p = k;
754  *q = l;
755  return 1;
756  }
757  }
758 
759  return 0;
760 }
761 
762 
763 INLINE PRIVATE int
764 backtrack_GQuad_IntLoop_L_comparative(int c,
765  int i,
766  int j,
767  unsigned int *type,
768  short *S_cons,
769  short **S5,
770  short **S3,
771  unsigned int **a2s,
772  int **ggg,
773  int *p,
774  int *q,
775  int n_seq,
776  vrna_param_t *P)
777 {
778  /*
779  * The case that is handled here actually resembles something like
780  * an interior loop where the enclosing base pair is of regular
781  * kind and the enclosed pair is not a canonical one but a g-quadruplex
782  * that should then be decomposed further...
783  */
784  int mm, dangle_model, k, l, maxl, minl, c0, l1, ss, tt, eee, u1, u2;
785 
786  dangle_model = P->model_details.dangles;
787 
788  mm = 0;
789  for (ss = 0; ss < n_seq; ss++) {
790  tt = type[ss];
791 
792  if (dangle_model == 2)
793  mm += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
794 
795  if (tt > 2)
796  mm += P->TerminalAU;
797  }
798 
799  for (k = i + 2;
800  k < j - VRNA_GQUAD_MIN_BOX_SIZE;
801  k++) {
802  if (S_cons[k] != 3)
803  continue;
804 
805  l1 = k - i - 1;
806  if (l1 > MAXLOOP)
807  break;
808 
809  minl = j - i + k - MAXLOOP - 2;
810  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
811  minl = MAX2(c0, minl);
812  c0 = j - 1;
813  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
814  maxl = MIN2(c0, maxl);
815  for (l = minl; l < maxl; l++) {
816  if (S_cons[l] != 3)
817  continue;
818 
819  eee = 0;
820 
821  for (ss = 0; ss < n_seq; ss++) {
822  u1 = a2s[ss][k - 1] - a2s[ss][i];
823  u2 = a2s[ss][j - 1] - a2s[ss][l];
824  eee += P->internal_loop[u1 + u2];
825  }
826 
827  c0 = mm +
828  ggg[k][l - k] +
829  eee;
830 
831  if (c == c0) {
832  *p = k;
833  *q = l;
834  return 1;
835  }
836  }
837  }
838  k = i + 1;
839  if (S_cons[k] == 3) {
840  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
841  minl = j - i + k - MAXLOOP - 2;
842  c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
843  minl = MAX2(c0, minl);
844  c0 = j - 3;
845  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
846  maxl = MIN2(c0, maxl);
847  for (l = minl; l < maxl; l++) {
848  if (S_cons[l] != 3)
849  continue;
850 
851  eee = 0;
852 
853  for (ss = 0; ss < n_seq; ss++) {
854  u1 = a2s[ss][j - 1] - a2s[ss][l];
855  eee += P->internal_loop[u1];
856  }
857 
858  if (c == mm + ggg[k][l - k] + eee) {
859  *p = k;
860  *q = l;
861  return 1;
862  }
863  }
864  }
865  }
866 
867  l = j - 1;
868  if (S_cons[l] == 3) {
869  for (k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
870  l1 = k - i - 1;
871  if (l1 > MAXLOOP)
872  break;
873 
874  if (S_cons[k] != 3)
875  continue;
876 
877  eee = 0;
878 
879  for (ss = 0; ss < n_seq; ss++) {
880  u1 = a2s[ss][k - 1] - a2s[ss][i];
881  eee += P->internal_loop[u1];
882  }
883 
884  if (c == mm + ggg[k][l - k] + eee) {
885  *p = k;
886  *q = l;
887  return 1;
888  }
889  }
890  }
891 
892  return 0;
893 }
894 
895 
896 PRIVATE INLINE
897 int
898 E_GQuad_IntLoop(int i,
899  int j,
900  int type,
901  short *S,
902  int *ggg,
903  int *index,
904  vrna_param_t *P)
905 {
906  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
907  short si, sj;
908 
909  dangles = P->model_details.dangles;
910  si = S[i + 1];
911  sj = S[j - 1];
912  energy = 0;
913 
914  if (dangles == 2)
915  energy += P->mismatchI[type][si][sj];
916 
917  if (type > 2)
918  energy += P->TerminalAU;
919 
920  ge = INF;
921 
922  p = i + 1;
923  if (S[p] == 3) {
924  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
925  minq = j - i + p - MAXLOOP - 2;
926  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
927  minq = MAX2(c0, minq);
928  c0 = j - 3;
929  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
930  maxq = MIN2(c0, maxq);
931  for (q = minq; q < maxq; q++) {
932  if (S[q] != 3)
933  continue;
934 
935  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
936  ge = MIN2(ge, c0);
937  }
938  }
939  }
940 
941  for (p = i + 2;
942  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
943  p++) {
944  l1 = p - i - 1;
945  if (l1 > MAXLOOP)
946  break;
947 
948  if (S[p] != 3)
949  continue;
950 
951  minq = j - i + p - MAXLOOP - 2;
952  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
953  minq = MAX2(c0, minq);
954  c0 = j - 1;
955  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
956  maxq = MIN2(c0, maxq);
957  for (q = minq; q < maxq; q++) {
958  if (S[q] != 3)
959  continue;
960 
961  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
962  ge = MIN2(ge, c0);
963  }
964  }
965 
966  q = j - 1;
967  if (S[q] == 3)
968  for (p = i + 4;
969  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
970  p++) {
971  l1 = p - i - 1;
972  if (l1 > MAXLOOP)
973  break;
974 
975  if (S[p] != 3)
976  continue;
977 
978  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
979  ge = MIN2(ge, c0);
980  }
981 
982 #if 0
983  /* here comes the additional stuff for the odd dangle models */
984  if (dangles % 1) {
985  en1 = energy + P->dangle5[type][si];
986  en2 = energy + P->dangle5[type][sj];
987  en3 = energy + P->mismatchI[type][si][sj];
988 
989  /* first case with 5' dangle (i.e. j-1) onto enclosing pair */
990  p = i + 1;
991  if (S[p] == 3) {
992  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
993  minq = j - i + p - MAXLOOP - 2;
994  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
995  minq = MAX2(c0, minq);
996  c0 = j - 4;
997  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
998  maxq = MIN2(c0, maxq);
999  for (q = minq; q < maxq; q++) {
1000  if (S[q] != 3)
1001  continue;
1002 
1003  c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1004  ge = MIN2(ge, c0);
1005  }
1006  }
1007  }
1008 
1009  for (p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
1010  l1 = p - i - 1;
1011  if (l1 > MAXLOOP)
1012  break;
1013 
1014  if (S[p] != 3)
1015  continue;
1016 
1017  minq = j - i + p - MAXLOOP - 2;
1018  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1019  minq = MAX2(c0, minq);
1020  c0 = j - 2;
1021  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1022  maxq = MIN2(c0, maxq);
1023  for (q = minq; q < maxq; q++) {
1024  if (S[q] != 3)
1025  continue;
1026 
1027  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1028  ge = MIN2(ge, c0);
1029  }
1030  }
1031 
1032  q = j - 2;
1033  if (S[q] == 3)
1034  for (p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
1035  l1 = p - i - 1;
1036  if (l1 > MAXLOOP)
1037  break;
1038 
1039  if (S[p] != 3)
1040  continue;
1041 
1042  c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
1043  ge = MIN2(ge, c0);
1044  }
1045 
1046  /* second case with 3' dangle (i.e. i+1) onto enclosing pair */
1047  }
1048 
1049 #endif
1050  return ge;
1051 }
1052 
1053 
1054 PRIVATE INLINE
1055 int
1056 E_GQuad_IntLoop_comparative(int i,
1057  int j,
1058  int *tt,
1059  short *S_cons,
1060  short **S5,
1061  short **S3,
1062  unsigned int **a2s,
1063  int *ggg,
1064  int *index,
1065  int n_seq,
1066  vrna_param_t *P)
1067 {
1068  int eee, energy, ge, dangles, p, q, l1, u1, u2, minq, maxq, c0, type, s;
1069  short si, sj;
1070  vrna_md_t *md;
1071 
1072  md = &(P->model_details);
1073  energy = 0;
1074 
1075  for (s = 0; s < n_seq; s++) {
1076  type = tt[s];
1077  if (md->dangles == 2)
1078  energy += P->mismatchI[type][S3[s][i]][S5[s][j]];
1079 
1080  if (type > 2)
1081  energy += P->TerminalAU;
1082  }
1083 
1084  ge = INF;
1085 
1086  p = i + 1;
1087  if (S_cons[p] == 3) {
1088  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1089  minq = j - i + p - MAXLOOP - 2;
1090  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1091  minq = MAX2(c0, minq);
1092  c0 = j - 3;
1093  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1094  maxq = MIN2(c0, maxq);
1095  for (q = minq; q < maxq; q++) {
1096  if (S_cons[q] != 3)
1097  continue;
1098 
1099  eee = 0;
1100 
1101  for (s = 0; s < n_seq; s++) {
1102  u1 = a2s[s][j - 1] - a2s[s][q];
1103  eee += P->internal_loop[u1];
1104  }
1105 
1106  c0 = energy +
1107  ggg[index[q] + p] +
1108  eee;
1109  ge = MIN2(ge, c0);
1110  }
1111  }
1112  }
1113 
1114  for (p = i + 2;
1115  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1116  p++) {
1117  l1 = p - i - 1;
1118  if (l1 > MAXLOOP)
1119  break;
1120 
1121  if (S_cons[p] != 3)
1122  continue;
1123 
1124  minq = j - i + p - MAXLOOP - 2;
1125  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1126  minq = MAX2(c0, minq);
1127  c0 = j - 1;
1128  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1129  maxq = MIN2(c0, maxq);
1130  for (q = minq; q < maxq; q++) {
1131  if (S_cons[q] != 3)
1132  continue;
1133 
1134  eee = 0;
1135 
1136  for (s = 0; s < n_seq; s++) {
1137  u1 = a2s[s][p - 1] - a2s[s][i];
1138  u2 = a2s[s][j - 1] - a2s[s][q];
1139  eee += P->internal_loop[u1 + u2];
1140  }
1141 
1142  c0 = energy +
1143  ggg[index[q] + p] +
1144  eee;
1145  ge = MIN2(ge, c0);
1146  }
1147  }
1148 
1149  q = j - 1;
1150  if (S_cons[q] == 3)
1151  for (p = i + 4;
1152  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1153  p++) {
1154  l1 = p - i - 1;
1155  if (l1 > MAXLOOP)
1156  break;
1157 
1158  if (S_cons[p] != 3)
1159  continue;
1160 
1161  eee = 0;
1162 
1163  for (s = 0; s < n_seq; s++) {
1164  u1 = a2s[s][p - 1] - a2s[s][i];
1165  eee += P->internal_loop[u1];
1166  }
1167 
1168  c0 = energy +
1169  ggg[index[q] + p] +
1170  eee;
1171  ge = MIN2(ge, c0);
1172  }
1173 
1174  return ge;
1175 }
1176 
1177 
1178 PRIVATE INLINE
1179 int
1180 E_GQuad_IntLoop_L_comparative(int i,
1181  int j,
1182  int *tt,
1183  short *S_cons,
1184  short **S5,
1185  short **S3,
1186  unsigned int **a2s,
1187  int **ggg,
1188  int n_seq,
1189  vrna_param_t *P)
1190 {
1191  int eee, energy, ge, dangles, p, q, l1, u1, u2, minq, maxq, c0, type, s;
1192  short si, sj;
1193  vrna_md_t *md;
1194 
1195  md = &(P->model_details);
1196  energy = 0;
1197 
1198  for (s = 0; s < n_seq; s++) {
1199  type = tt[s];
1200  if (md->dangles == 2)
1201  energy += P->mismatchI[type][S3[s][i]][S5[s][j]];
1202 
1203  if (type > 2)
1204  energy += P->TerminalAU;
1205  }
1206 
1207  ge = INF;
1208 
1209  p = i + 1;
1210  if (S_cons[p] == 3) {
1211  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1212  minq = j - i + p - MAXLOOP - 2;
1213  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1214  minq = MAX2(c0, minq);
1215  c0 = j - 3;
1216  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1217  maxq = MIN2(c0, maxq);
1218  for (q = minq; q < maxq; q++) {
1219  if (S_cons[q] != 3)
1220  continue;
1221 
1222  eee = 0;
1223 
1224  for (s = 0; s < n_seq; s++) {
1225  u1 = a2s[s][j - 1] - a2s[s][q];
1226  eee += P->internal_loop[u1];
1227  }
1228 
1229  c0 = energy +
1230  ggg[p][q - p] +
1231  eee;
1232  ge = MIN2(ge, c0);
1233  }
1234  }
1235  }
1236 
1237  for (p = i + 2;
1238  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1239  p++) {
1240  l1 = p - i - 1;
1241  if (l1 > MAXLOOP)
1242  break;
1243 
1244  if (S_cons[p] != 3)
1245  continue;
1246 
1247  minq = j - i + p - MAXLOOP - 2;
1248  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1249  minq = MAX2(c0, minq);
1250  c0 = j - 1;
1251  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1252  maxq = MIN2(c0, maxq);
1253  for (q = minq; q < maxq; q++) {
1254  if (S_cons[q] != 3)
1255  continue;
1256 
1257  eee = 0;
1258 
1259  for (s = 0; s < n_seq; s++) {
1260  u1 = a2s[s][p - 1] - a2s[s][i];
1261  u2 = a2s[s][j - 1] - a2s[s][q];
1262  eee += P->internal_loop[u1 + u2];
1263  }
1264 
1265  c0 = energy +
1266  ggg[p][q - p] +
1267  eee;
1268  ge = MIN2(ge, c0);
1269  }
1270  }
1271 
1272  q = j - 1;
1273  if (S_cons[q] == 3)
1274  for (p = i + 4;
1275  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1276  p++) {
1277  l1 = p - i - 1;
1278  if (l1 > MAXLOOP)
1279  break;
1280 
1281  if (S_cons[p] != 3)
1282  continue;
1283 
1284  eee = 0;
1285 
1286  for (s = 0; s < n_seq; s++) {
1287  u1 = a2s[s][p - 1] - a2s[s][i];
1288  eee += P->internal_loop[u1];
1289  }
1290 
1291  c0 = energy +
1292  ggg[p][q - p] +
1293  eee;
1294  ge = MIN2(ge, c0);
1295  }
1296 
1297  return ge;
1298 }
1299 
1300 
1301 PRIVATE INLINE
1302 int *
1303 E_GQuad_IntLoop_exhaustive(int i,
1304  int j,
1305  int **p_p,
1306  int **q_p,
1307  int type,
1308  short *S,
1309  int *ggg,
1310  int threshold,
1311  int *index,
1312  vrna_param_t *P)
1313 {
1314  int energy, *ge, dangles, p, q, l1, minq, maxq, c0;
1315  short si, sj;
1316  int cnt = 0;
1317 
1318  dangles = P->model_details.dangles;
1319  si = S[i + 1];
1320  sj = S[j - 1];
1321  energy = 0;
1322 
1323  if (dangles == 2)
1324  energy += P->mismatchI[type][si][sj];
1325 
1326  if (type > 2)
1327  energy += P->TerminalAU;
1328 
1329  /* guess how many gquads are possible in interval [i+1,j-1] */
1330  *p_p = (int *)vrna_alloc(sizeof(int) * 256);
1331  *q_p = (int *)vrna_alloc(sizeof(int) * 256);
1332  ge = (int *)vrna_alloc(sizeof(int) * 256);
1333 
1334  p = i + 1;
1335  if (S[p] == 3) {
1336  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1337  minq = j - i + p - MAXLOOP - 2;
1338  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1339  minq = MAX2(c0, minq);
1340  c0 = j - 3;
1341  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1342  maxq = MIN2(c0, maxq);
1343  for (q = minq; q < maxq; q++) {
1344  if (S[q] != 3)
1345  continue;
1346 
1347  c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1348  if (c0 <= threshold) {
1349  ge[cnt] = energy + P->internal_loop[j - q - 1];
1350  (*p_p)[cnt] = p;
1351  (*q_p)[cnt++] = q;
1352  }
1353  }
1354  }
1355  }
1356 
1357  for (p = i + 2;
1358  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1359  p++) {
1360  l1 = p - i - 1;
1361  if (l1 > MAXLOOP)
1362  break;
1363 
1364  if (S[p] != 3)
1365  continue;
1366 
1367  minq = j - i + p - MAXLOOP - 2;
1368  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1369  minq = MAX2(c0, minq);
1370  c0 = j - 1;
1371  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1372  maxq = MIN2(c0, maxq);
1373  for (q = minq; q < maxq; q++) {
1374  if (S[q] != 3)
1375  continue;
1376 
1377  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1378  if (c0 <= threshold) {
1379  ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
1380  (*p_p)[cnt] = p;
1381  (*q_p)[cnt++] = q;
1382  }
1383  }
1384  }
1385 
1386  q = j - 1;
1387  if (S[q] == 3)
1388  for (p = i + 4;
1389  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1390  p++) {
1391  l1 = p - i - 1;
1392  if (l1 > MAXLOOP)
1393  break;
1394 
1395  if (S[p] != 3)
1396  continue;
1397 
1398  c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
1399  if (c0 <= threshold) {
1400  ge[cnt] = energy + P->internal_loop[l1];
1401  (*p_p)[cnt] = p;
1402  (*q_p)[cnt++] = q;
1403  }
1404  }
1405 
1406  (*p_p)[cnt] = -1;
1407 
1408  return ge;
1409 }
1410 
1411 
1412 PRIVATE INLINE
1413 int
1414 E_GQuad_IntLoop_L(int i,
1415  int j,
1416  int type,
1417  short *S,
1418  int **ggg,
1419  int maxdist,
1420  vrna_param_t *P)
1421 {
1422  int energy, ge, dangles, p, q, l1, minq, maxq, c0;
1423  short si, sj;
1424 
1425  dangles = P->model_details.dangles;
1426  si = S[i + 1];
1427  sj = S[j - 1];
1428  energy = 0;
1429 
1430  if (dangles == 2)
1431  energy += P->mismatchI[type][si][sj];
1432 
1433  if (type > 2)
1434  energy += P->TerminalAU;
1435 
1436  ge = INF;
1437 
1438  p = i + 1;
1439  if (S[p] == 3) {
1440  if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1441  minq = j - i + p - MAXLOOP - 2;
1442  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1443  minq = MAX2(c0, minq);
1444  c0 = j - 3;
1445  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1446  maxq = MIN2(c0, maxq);
1447  for (q = minq; q < maxq; q++) {
1448  if (S[q] != 3)
1449  continue;
1450 
1451  c0 = energy + ggg[p][q - p] + P->internal_loop[j - q - 1];
1452  ge = MIN2(ge, c0);
1453  }
1454  }
1455  }
1456 
1457  for (p = i + 2;
1458  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1459  p++) {
1460  l1 = p - i - 1;
1461  if (l1 > MAXLOOP)
1462  break;
1463 
1464  if (S[p] != 3)
1465  continue;
1466 
1467  minq = j - i + p - MAXLOOP - 2;
1468  c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1469  minq = MAX2(c0, minq);
1470  c0 = j - 1;
1471  maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1472  maxq = MIN2(c0, maxq);
1473  for (q = minq; q < maxq; q++) {
1474  if (S[q] != 3)
1475  continue;
1476 
1477  c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
1478  ge = MIN2(ge, c0);
1479  }
1480  }
1481 
1482  q = j - 1;
1483  if (S[q] == 3)
1484  for (p = i + 4;
1485  p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1486  p++) {
1487  l1 = p - i - 1;
1488  if (l1 > MAXLOOP)
1489  break;
1490 
1491  if (S[p] != 3)
1492  continue;
1493 
1494  c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
1495  ge = MIN2(ge, c0);
1496  }
1497 
1498  return ge;
1499 }
1500 
1501 
1502 PRIVATE INLINE
1503 FLT_OR_DBL
1504 exp_E_GQuad_IntLoop(int i,
1505  int j,
1506  int type,
1507  short *S,
1508  FLT_OR_DBL *G,
1509  FLT_OR_DBL *scale,
1510  int *index,
1511  vrna_exp_param_t *pf)
1512 {
1513  int k, l, minl, maxl, u, r;
1514  FLT_OR_DBL q, qe;
1515  double *expintern;
1516  short si, sj;
1517 
1518  q = 0;
1519  si = S[i + 1];
1520  sj = S[j - 1];
1521  qe = (FLT_OR_DBL)pf->expmismatchI[type][si][sj];
1522  expintern = &(pf->expinternal[0]);
1523 
1524  if (type > 2)
1525  qe *= (FLT_OR_DBL)pf->expTermAU;
1526 
1527  k = i + 1;
1528  if (S[k] == 3) {
1529  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1530  minl = j - MAXLOOP - 1;
1531  u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1532  minl = MAX2(u, minl);
1533  u = j - 3;
1534  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1535  maxl = MIN2(u, maxl);
1536  for (l = minl; l < maxl; l++) {
1537  if (S[l] != 3)
1538  continue;
1539 
1540  if (G[index[k] - l] == 0.)
1541  continue;
1542 
1543  q += qe
1544  * G[index[k] - l]
1545  * (FLT_OR_DBL)expintern[j - l - 1]
1546  * scale[j - l + 1];
1547  }
1548  }
1549  }
1550 
1551  for (k = i + 2;
1552  k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1553  k++) {
1554  u = k - i - 1;
1555  if (u > MAXLOOP)
1556  break;
1557 
1558  if (S[k] != 3)
1559  continue;
1560 
1561  minl = j - i + k - MAXLOOP - 2;
1562  r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1563  minl = MAX2(r, minl);
1564  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1565  r = j - 1;
1566  maxl = MIN2(r, maxl);
1567  for (l = minl; l < maxl; l++) {
1568  if (S[l] != 3)
1569  continue;
1570 
1571  if (G[index[k] - l] == 0.)
1572  continue;
1573 
1574  q += qe
1575  * G[index[k] - l]
1576  * (FLT_OR_DBL)expintern[u + j - l - 1]
1577  * scale[u + j - l + 1];
1578  }
1579  }
1580 
1581  l = j - 1;
1582  if (S[l] == 3)
1583  for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1584  u = k - i - 1;
1585  if (u > MAXLOOP)
1586  break;
1587 
1588  if (S[k] != 3)
1589  continue;
1590 
1591  if (G[index[k] - l] == 0.)
1592  continue;
1593 
1594  q += qe
1595  * G[index[k] - l]
1596  * (FLT_OR_DBL)expintern[u]
1597  * scale[u + 2];
1598  }
1599 
1600  return q;
1601 }
1602 
1603 
1604 PRIVATE INLINE
1605 FLT_OR_DBL
1606 exp_E_GQuad_IntLoop_comparative(int i,
1607  int j,
1608  int *tt,
1609  short *S_cons,
1610  short **S5,
1611  short **S3,
1612  unsigned int **a2s,
1613  FLT_OR_DBL *G,
1614  FLT_OR_DBL *scale,
1615  int *index,
1616  int n_seq,
1617  vrna_exp_param_t *pf)
1618 {
1619  int k, l, minl, maxl, u, u1, u2, r, s, type;
1620  FLT_OR_DBL q, qe, qqq;
1621  double *expintern;
1622  short si, sj;
1623  vrna_md_t *md;
1624 
1625  q = 0;
1626  qe = 1.;
1627  md = &(pf->model_details);
1628  expintern = &(pf->expinternal[0]);
1629 
1630  for (s = 0; s < n_seq; s++) {
1631  type = tt[s];
1632  if (md->dangles == 2)
1633  qe *= (FLT_OR_DBL)pf->expmismatchI[type][S3[s][i]][S5[s][j]];
1634 
1635  if (type > 2)
1636  qe *= (FLT_OR_DBL)pf->expTermAU;
1637  }
1638 
1639  k = i + 1;
1640  if (S_cons[k] == 3) {
1641  if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1642  minl = j - MAXLOOP - 1;
1643  u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1644  minl = MAX2(u, minl);
1645  u = j - 3;
1646  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1647  maxl = MIN2(u, maxl);
1648  for (l = minl; l < maxl; l++) {
1649  if (S_cons[l] != 3)
1650  continue;
1651 
1652  if (G[index[k] - l] == 0.)
1653  continue;
1654 
1655  qqq = 1.;
1656 
1657  for (s = 0; s < n_seq; s++) {
1658  u1 = a2s[s][j - 1] - a2s[s][l];
1659  qqq *= expintern[u1];
1660  }
1661 
1662  q += qe *
1663  G[index[k] - l] *
1664  qqq *
1665  scale[j - l + 1];
1666  }
1667  }
1668  }
1669 
1670  for (k = i + 2;
1671  k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1672  k++) {
1673  u = k - i - 1;
1674  if (u > MAXLOOP)
1675  break;
1676 
1677  if (S_cons[k] != 3)
1678  continue;
1679 
1680  minl = j - i + k - MAXLOOP - 2;
1681  r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1682  minl = MAX2(r, minl);
1683  maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1684  r = j - 1;
1685  maxl = MIN2(r, maxl);
1686  for (l = minl; l < maxl; l++) {
1687  if (S_cons[l] != 3)
1688  continue;
1689 
1690  if (G[index[k] - l] == 0.)
1691  continue;
1692 
1693  qqq = 1.;
1694 
1695  for (s = 0; s < n_seq; s++) {
1696  u1 = a2s[s][k - 1] - a2s[s][i];
1697  u2 = a2s[s][j - 1] - a2s[s][l];
1698  qqq *= expintern[u1 + u2];
1699  }
1700 
1701  q += qe *
1702  G[index[k] - l] *
1703  qqq *
1704  scale[u + j - l + 1];
1705  }
1706  }
1707 
1708  l = j - 1;
1709  if (S_cons[l] == 3)
1710  for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1711  u = k - i - 1;
1712  if (u > MAXLOOP)
1713  break;
1714 
1715  if (S_cons[k] != 3)
1716  continue;
1717 
1718  if (G[index[k] - l] == 0.)
1719  continue;
1720 
1721  qqq = 1.;
1722 
1723  for (s = 0; s < n_seq; s++) {
1724  u1 = a2s[s][k - 1] - a2s[s][i];
1725  qqq *= expintern[u1];
1726  }
1727 
1728  q += qe *
1729  G[index[k] - l] *
1730  qqq *
1731  scale[u + 2];
1732  }
1733 
1734  return q;
1735 }
1736 
1737 
1743 #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:95
vrna_md_t model_details
Model details to be used in the recursions.
Definition: basic.h:153
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:422
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:102
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:143
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:665