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