RNAlib-2.2.0-RC3
interior_loops.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <math.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <ViennaRNA/fold_vars.h>
10 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/params.h>
13 #include <ViennaRNA/constraints.h>
15 #include <ViennaRNA/gquad.h>
16 
17 #ifdef __GNUC__
18 # define INLINE inline
19 #else
20 # define INLINE
21 #endif
22 
23 #ifdef ON_SAME_STRAND
24 #undef ON_SAME_STRAND
25 #endif
26 
27 #define ON_SAME_STRAND(I,J,C) (((I)>=(C))||((J)<(C)))
28 
82 INLINE PRIVATE int E_IntLoop(int n1,
83  int n2,
84  int type,
85  int type_2,
86  int si1,
87  int sj1,
88  int sp1,
89  int sq1,
90  vrna_param_t *P);
91 
111 INLINE PRIVATE double exp_E_IntLoop(int u1,
112  int u2,
113  int type,
114  int type2,
115  short si1,
116  short sj1,
117  short sp1,
118  short sq1,
119  vrna_exp_param_t *P);
120 
121 
122 INLINE PRIVATE int E_IntLoop_Co(int type,
123  int type_2,
124  int i,
125  int j,
126  int p,
127  int q,
128  int cutpoint,
129  short si1,
130  short sj1,
131  short sp1,
132  short sq1,
133  int dangles,
134  vrna_param_t *P);
135 
136 
140 INLINE PRIVATE int E_stack(int i, int j, vrna_fold_compound *vc);
141 
142 /*
143 #################################
144 # BEGIN OF FUNCTION DEFINITIONS #
145 #################################
146 */
147 
148 /*
149  * ugly but fast interior loop evaluation
150  *
151  * This function may be included in your own code, but actually only serves
152  * as a fast inline block internally re-used throughout the RNAlib. It
153  * evalutes the free energy of interior loops in single sequences or sequence
154  * hybrids. Soft constraints are also applied if available.
155  *
156  * NOTE: do not include into doxygen reference manual!
157  */
158 INLINE PRIVATE int
159 ubf_eval_int_loop( int i,
160  int j,
161  int p,
162  int q,
163  int u1,
164  int u2,
165  short si,
166  short sj,
167  short sp,
168  short sq,
169  unsigned char type,
170  unsigned char type_2,
171  int *rtype,
172  int ij,
173  int cp,
174  vrna_param_t *P,
175  vrna_sc_t *sc){
176 
177  int energy;
178 
179  if((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))){ /* regular interior loop */
180  energy = E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
181  } else { /* interior loop like cofold structure */
182  short Si, Sj;
183  Si = ON_SAME_STRAND(i, i + 1, cp) ? si : -1;
184  Sj = ON_SAME_STRAND(j - 1, j, cp) ? sj : -1;
185  energy = E_IntLoop_Co(rtype[type], rtype[type_2],
186  i, j, p, q,
187  cp,
188  Si, Sj,
189  sp, sq,
191  P);
192  }
193 
194  /* add soft constraints */
195  if(sc){
196  if(sc->free_energies)
197  energy += sc->free_energies[i+1][u1]
198  + sc->free_energies[q+1][u2];
199 
200  if(sc->en_basepair)
201  energy += sc->en_basepair[ij];
202 
203  if(sc->en_stack)
204  if((p==i+1) && (q == j-1))
205  energy += sc->en_stack[i]
206  + sc->en_stack[p]
207  + sc->en_stack[q]
208  + sc->en_stack[j];
209 
210  if(sc->f)
211  energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
212  }
213 
214  return energy;
215 
216 }
217 
218 /*
219  * ugly but fast exterior interior loop evaluation
220  *
221  * This function may be included in your own code, but actually only serves
222  * as a fast inline block internally re-used throughout the RNAlib. It
223  * evalutes the free energy of interior loops in single sequences or sequence
224  * hybrids. Soft constraints are also applied if available.
225  *
226  * NOTE: do not include into doxygen reference manual!
227  */
228 INLINE PRIVATE int
229 ubf_eval_ext_int_loop(int i,
230  int j,
231  int p,
232  int q,
233  int u1,
234  int u2,
235  short si,
236  short sj,
237  short sp,
238  short sq,
239  unsigned char type,
240  unsigned char type_2,
241  int length,
242  vrna_param_t *P,
243  vrna_sc_t *sc){
244 
245  int energy;
246 
247  energy = E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
248 
249  /* add soft constraints */
250  if(sc){
251  if(sc->free_energies)
252  energy += sc->free_energies[j+1][p-j-1]
253  + sc->free_energies[q+1][length-q]
254  + sc->free_energies[1][i-1];
255 
256  if(sc->en_stack)
257  if((p==i+1) && (q == j-1))
258  energy += sc->en_stack[i]
259  + sc->en_stack[p]
260  + sc->en_stack[q]
261  + sc->en_stack[j];
262 
263  if(sc->f)
264  energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
265  }
266 
267  return energy;
268 
269 }
270 
271 INLINE PRIVATE int
272 vrna_E_int_loop(vrna_fold_compound *vc,
273  int i,
274  int j){
275 
276  int q, p, j_q, p_i, pq, *c_pq, max_q, max_p, tmp, *rtype, noGUclosure, no_close, energy;
277  short *S_p1, *S_q1;
278  char *ptype_pq;
279  unsigned char type, type_2;
280  char *hc_pq;
281  int cp = vc->cutpoint;
282  char *ptype = vc->ptype;
283  short *S = vc->sequence_encoding;
284  short S_i1 = S[i+1];
285  short S_j1 = S[j-1];
286  int *indx = vc->jindx;
287  char *hc = vc->hc->matrix;
288  int *hc_up = vc->hc->up_int;
289  vrna_sc_t *sc = vc->sc;
290  vrna_param_t *P = vc->params;
291  int ij = indx[j] + i;
292  int hc_decompose = hc[ij];
293  int e = INF;
294  int *c = vc->matrices->c;
295  int *ggg = vc->matrices->ggg;
296  vrna_md_t *md = &(P->model_details);
297  int with_gquad = md->gquad;
298  int turn = md->min_loop_size;
299 
300  /* CONSTRAINED INTERIOR LOOP start */
301  if(hc_decompose & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
302 
303  type = (unsigned char)ptype[ij];
304  rtype = &(md->rtype[0]);
305  noGUclosure = md->noGUclosure;
306  no_close = (((type==3)||(type==4))&&noGUclosure);
307  max_q = i+turn+2;
308  max_q = MAX2(max_q, j - MAXLOOP - 1);
309  for(q = j - 1; q >= max_q; q--){
310  j_q = j - q - 1;
311 
312  if(hc_up[q+1] < j_q) break;
313 
314  pq = indx[q] + i + 1;
315  p_i = 0;
316  max_p = i + 1;
317  tmp = i + 1 + MAXLOOP - j_q;
318  max_p = MAX2(max_p, tmp);
319  tmp = q - turn;
320  max_p = MIN2(max_p, tmp);
321  tmp = i + 1 + hc_up[i + 1];
322  max_p = MIN2(max_p, tmp);
323  hc_pq = hc + pq;
324  c_pq = c + pq;
325  ptype_pq = ptype + pq;
326 
327  S_p1 = S + i;
328  S_q1 = S + q + 1;
329  for(p = i+1; p <= max_p; p++){
330 
331  /* discard this configuration if (p,q) is not allowed to be enclosed pair of an interior loop */
333 
334  if(*c_pq != INF){
335  type_2 = rtype[(unsigned char)*ptype_pq];
336 
337  if (noGUclosure)
338  if (no_close||(type_2==3)||(type_2==4))
339  if ((p>i+1)||(q<j-1)) continue; /* continue unless stack */
340 
341  energy = ubf_eval_int_loop( i, j, p, q,
342  p_i, j_q,
343  S_i1, S_j1, *S_p1, *S_q1,
344  type, type_2, rtype,
345  ij, cp,
346  P, sc);
347  energy += *c_pq;
348  e = MIN2(e, energy);
349  }
350 
351  }
352  hc_pq++; /* get hc[pq + 1] */
353  c_pq++; /* get c[pq + 1] */
354  p_i++; /* increase unpaired region [i+1...p-1] */
355  ptype_pq++; /* get ptype[pq + 1] */
356  S_p1++;
357  pq++;
358  } /* end q-loop */
359  } /* end p-loop */
360 
361  if(with_gquad){
362  /* include all cases where a g-quadruplex may be enclosed by base pair (i,j) */
363  if ((!no_close) && ((cp < 0) || ON_SAME_STRAND(i, j, cp))) {
364  energy = E_GQuad_IntLoop(i, j, type, S, ggg, indx, P);
365  e = MIN2(e, energy);
366  }
367  }
368 
369  }
370  return e;
371 }
372 
373 INLINE PRIVATE int
374 vrna_E_ext_int_loop(vrna_fold_compound *vc,
375  int i,
376  int j,
377  int *ip,
378  int *iq){
379 
380  int ij, q, p, e, u1, u2, qmin, energy, *rtype, length, *indx, *hc_up, *c, turn;
381  unsigned char type, type_2;
382  vrna_md_t *md;
383  char *ptype, *hc;
384  vrna_param_t *P;
385  short *S;
386  vrna_sc_t *sc;
387 
388  length = vc->length;
389  indx = vc->jindx;
390  ptype = vc->ptype;
391  c = vc->matrices->c;
392  hc = vc->hc->matrix;
393  hc_up = vc->hc->up_int;
394  P = vc->params;
395  md = &(P->model_details);
396  turn = md->min_loop_size;
397  S = vc->sequence_encoding;
398  sc = vc->sc;
399 
400  ij = indx[j] + i;
401  rtype = &(md->rtype[0]);
402  type = rtype[(unsigned char)ptype[ij]];
403  e = INF;
404 
405  /* CONSTRAINED INTERIOR LOOP start */
406  if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
407 
408  for (p = j+1; p < length ; p++) {
409  u1 = p-j-1;
410  if (u1+i-1>MAXLOOP) break;
411  if (hc_up[j+1] < u1) break;
412 
413  qmin = u1+i-1+length-MAXLOOP;
414  if(qmin < p + turn + 1)
415  qmin = p+turn+1;
416  for (q = length; q >= qmin; q--) {
417  u2 = i-1 + length-q;
418  if(hc_up[q+1] < u2) break;
419  if(hc[indx[q]+p] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
420  type_2 = rtype[(unsigned char)ptype[indx[q]+p]];
421  if (u1+u2>MAXLOOP) continue;
422 
423  energy = ubf_eval_ext_int_loop( i, j, p, q,
424  u1, u2,
425  S[j+1], S[i-1], S[p-1], S[q+1],
426  type, type_2,
427  length,
428  P, sc);
429  energy += c[indx[q]+p];
430 
431  if (energy < e){
432  e = energy;
433  if((ip != NULL) && (iq != NULL)){
434  *ip = p;
435  *iq = q;
436  }
437  }
438  }
439  }
440  }
441  }
442 
443  return e;
444 }
445 
446 
447 INLINE PRIVATE int
448 vrna_E_stack( vrna_fold_compound *vc,
449  int i,
450  int j){
451 
452  int e, ij, pq, p, q;
453  unsigned char type, type_2;
454 
455  int cp = vc->cutpoint;
456  short *S = vc->sequence_encoding;
457  char *ptype = vc->ptype;
458  vrna_param_t *P = vc->params;
459  vrna_md_t *md = &(P->model_details);
460  int *rtype = &(md->rtype[0]);
461  int *indx = vc->jindx;
462  char *hard_constraints = vc->hc->matrix;
463  vrna_sc_t *sc = vc->sc;
464 
465  e = INF;
466  p = i + 1;
467  q = j - 1;
468  ij = indx[j] + i;
469  pq = indx[q] + p;
470  type = (unsigned char)ptype[ij];
471  type_2 = rtype[(unsigned char)ptype[pq]];
472 
473  if((hard_constraints[pq] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC) && (hard_constraints[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP)){
474  if ((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))){ /* regular stack */
475  e = P->stack[type][type_2];
476  } else { /* stack like cofold structure */
477  short si, sj;
478  si = ON_SAME_STRAND(i, i + 1, cp) ? S[i+1] : -1;
479  sj = ON_SAME_STRAND(j - 1, j, cp) ? S[j-1] : -1;
480  e = E_IntLoop_Co(rtype[type], rtype[type_2],
481  i, j, p, q,
482  cp,
483  si, sj,
484  S[p-1], S[q+1],
485  md->dangles,
486  P);
487  }
488 
489  /* add soft constraints */
490  if(sc){
491  if(sc->en_basepair)
492  e += sc->en_basepair[ij];
493 
494  if(sc->en_stack)
495  if((p==i+1) && (q == j-1))
496  e += sc->en_stack[i]
497  + sc->en_stack[p]
498  + sc->en_stack[q]
499  + sc->en_stack[j];
500 
501  if(sc->f)
502  e += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
503  }
504  }
505 
506  return e;
507 }
508 
509 INLINE PRIVATE int
510 E_IntLoop(int n1,
511  int n2,
512  int type,
513  int type_2,
514  int si1,
515  int sj1,
516  int sp1,
517  int sq1,
518  vrna_param_t *P){
519 
520  /* compute energy of degree 2 loop (stack bulge or interior) */
521  int nl, ns, u, energy;
522  energy = INF;
523 
524  if (n1>n2) { nl=n1; ns=n2;}
525  else {nl=n2; ns=n1;}
526 
527  if (nl == 0)
528  return P->stack[type][type_2]; /* stack */
529 
530  if (ns==0) { /* bulge */
531  energy = (nl<=MAXLOOP)?P->bulge[nl]:
532  (P->bulge[30]+(int)(P->lxc*log(nl/30.)));
533  if (nl==1) energy += P->stack[type][type_2];
534  else {
535  if (type>2) energy += P->TerminalAU;
536  if (type_2>2) energy += P->TerminalAU;
537  }
538  return energy;
539  }
540  else { /* interior loop */
541  if (ns==1) {
542  if (nl==1) /* 1x1 loop */
543  return P->int11[type][type_2][si1][sj1];
544  if (nl==2) { /* 2x1 loop */
545  if (n1==1)
546  energy = P->int21[type][type_2][si1][sq1][sj1];
547  else
548  energy = P->int21[type_2][type][sq1][si1][sp1];
549  return energy;
550  }
551  else { /* 1xn loop */
552  energy = (nl+1<=MAXLOOP)?(P->internal_loop[nl+1]) : (P->internal_loop[30]+(int)(P->lxc*log((nl+1)/30.)));
553  energy += MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
554  energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
555  return energy;
556  }
557  }
558  else if (ns==2) {
559  if(nl==2) { /* 2x2 loop */
560  return P->int22[type][type_2][si1][sp1][sq1][sj1];}
561  else if (nl==3){ /* 2x3 loop */
562  energy = P->internal_loop[5]+P->ninio[2];
563  energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
564  return energy;
565  }
566 
567  }
568  { /* generic interior loop (no else here!)*/
569  u = nl + ns;
570  energy = (u <= MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30]+(int)(P->lxc*log((u)/30.)));
571 
572  energy += MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
573 
574  energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
575  }
576  }
577  return energy;
578 }
579 
580 INLINE PRIVATE double exp_E_IntLoop(int u1, int u2, int type, int type2, short si1, short sj1, short sp1, short sq1, vrna_exp_param_t *P){
581  int ul, us, no_close = 0;
582  double z = 0.;
583 
584  if ((no_closingGU) && ((type2==3)||(type2==4)||(type==3)||(type==4)))
585  no_close = 1;
586 
587  if (u1>u2) { ul=u1; us=u2;}
588  else {ul=u2; us=u1;}
589 
590  if (ul==0) /* stack */
591  z = P->expstack[type][type2];
592  else if(!no_close){
593  if (us==0) { /* bulge */
594  z = P->expbulge[ul];
595  if (ul==1) z *= P->expstack[type][type2];
596  else {
597  if (type>2) z *= P->expTermAU;
598  if (type2>2) z *= P->expTermAU;
599  }
600  return z;
601  }
602  else if (us==1) {
603  if (ul==1){ /* 1x1 loop */
604  return P->expint11[type][type2][si1][sj1];
605  }
606  if (ul==2) { /* 2x1 loop */
607  if (u1==1)
608  return P->expint21[type][type2][si1][sq1][sj1];
609  else
610  return P->expint21[type2][type][sq1][si1][sp1];
611  }
612  else { /* 1xn loop */
613  z = P->expinternal[ul+us] * P->expmismatch1nI[type][si1][sj1] * P->expmismatch1nI[type2][sq1][sp1];
614  return z * P->expninio[2][ul-us];
615  }
616  }
617  else if (us==2) {
618  if(ul==2) /* 2x2 loop */
619  return P->expint22[type][type2][si1][sp1][sq1][sj1];
620  else if(ul==3){ /* 2x3 loop */
621  z = P->expinternal[5]*P->expmismatch23I[type][si1][sj1]*P->expmismatch23I[type2][sq1][sp1];
622  return z * P->expninio[2][1];
623  }
624  }
625  /* generic interior loop (no else here!)*/
626  z = P->expinternal[ul+us] * P->expmismatchI[type][si1][sj1] * P->expmismatchI[type2][sq1][sp1];
627  return z * P->expninio[2][ul-us];
628 
629  }
630  return z;
631 }
632 
633 INLINE PRIVATE int
634 E_IntLoop_Co( int type,
635  int type_2,
636  int i,
637  int j,
638  int p,
639  int q,
640  int cutpoint,
641  short si1,
642  short sj1,
643  short sp1,
644  short sq1,
645  int dangles,
646  vrna_param_t *P){
647 
648  int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
649 
650  energy = 0;
651  if(type > 2) energy += P->TerminalAU;
652  if(type_2 > 2) energy += P->TerminalAU;
653 
654  if(!dangles) return energy;
655 
656  ci = ON_SAME_STRAND(i, i + 1, cutpoint);
657  cj = ON_SAME_STRAND(j - 1, j, cutpoint);
658  cp = ON_SAME_STRAND(p - 1, p, cutpoint);
659  cq = ON_SAME_STRAND(q, q + 1, cutpoint);
660 
661  d3 = ci ? P->dangle3[type][si1] : 0;
662  d5 = cj ? P->dangle5[type][sj1] : 0;
663  d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
664  d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
665 
666  tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
667  tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
668 
669  if(dangles == 2) return energy + tmm + tmm_2;
670 
671  /* now we may have non-double dangles only */
672  if(i+2 < p){
673  if(q+2 < j){ energy += tmm + tmm_2;}
674  else if(q+2 == j){ energy += (cj && cq) ? MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;}
675  else energy += d3 + d5_2;
676  }
677  else if(i+2 == p){
678  if(q+2 < j){ energy += (ci && cp) ? MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;}
679  else if(q+2 == j){
680  energy += MIN2(tmm, MIN2(tmm_2, MIN2(d5 + d5_2, d3 + d3_2)));
681  }
682  else energy += MIN2(d3, d5_2);
683  }
684  else{
685  if(q+2 < j){ energy += d5 + d3_2;}
686  else if(q+2 == j){ energy += MIN2(d5, d3_2);}
687  }
688  return energy;
689 }
690 
691 
696 INLINE PRIVATE int
698  int *i,
699  int *j,
700  int *en,
701  bondT *bp_stack,
702  int *stack_count){
703 
704  int ij, *idx, *my_c, *rtype;
705  char *ptype;
706  unsigned char type, type_2;
707 
708  vrna_param_t *P;
709  vrna_md_t *md;
710  vrna_hc_t *hc;
711  vrna_sc_t *sc;
712 
713  idx = vc->jindx;
714  P = vc->params;
715  md = &(P->model_details);
716  hc = vc->hc;
717  sc = vc->sc;
718  my_c = vc->matrices->c;
719  ij = idx[*j] + *i;
720  ptype = vc->ptype;
721  type = (unsigned char)ptype[ij];
722  rtype = &(md->rtype[0]);
723 
724  if(my_c[ij] == *en){ /* always true, if (i.j) closes canonical structure,
725  thus (i+1.j-1) must be a pair
726  */
727  if( (hc->matrix[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP)
728  && (hc->matrix[idx[*j - 1] + *i + 1] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC)){
729  type_2 = ptype[idx[*j - 1] + *i + 1];
730  type_2 = rtype[type_2];
731  *en -= P->stack[type][type_2];
732  if(sc){
733  if(sc->en_basepair)
734  *en -= sc->en_basepair[ij];
735  if(sc->en_stack)
736  *en -= sc->en_stack[*i]
737  + sc->en_stack[*i + 1]
738  + sc->en_stack[*j - 1]
739  + sc->en_stack[*j];
740  if(sc->f)
741  *en -= sc->f(*i, *j, *i + 1, *j - 1, VRNA_DECOMP_PAIR_IL, sc->data);
742  }
743  bp_stack[++(*stack_count)].i = *i + 1;
744  bp_stack[(*stack_count)].j = *j - 1;
745  (*i)++;
746  (*j)--;
747  return 1;
748  }
749  }
750 
751  return 0;
752 }
753 
758 INLINE PRIVATE int
760  int *i,
761  int *j,
762  int en,
763  bondT *bp_stack,
764  int *stack_count){
765 
766  int cp, ij, p, q, minq, turn, *idx, noGUclosure, no_close, energy, new, *my_c, *rtype;
767  unsigned char type, type_2;
768  char *ptype;
769  short *S1, *S;
770 
771  vrna_param_t *P;
772  vrna_md_t *md;
773  vrna_hc_t *hc;
774  vrna_sc_t *sc;
775 
776  cp = vc->cutpoint;
777  idx = vc->jindx;
778  P = vc->params;
779  md = &(P->model_details);
780  hc = vc->hc;
781  sc = vc->sc;
782  my_c = vc->matrices->c;
783  turn = md->min_loop_size;
784  ij = idx[*j] + *i;
785  ptype = vc->ptype;
786  type = (unsigned char)ptype[ij];
787  rtype = &(md->rtype[0]);
788  S1 = vc->sequence_encoding;
789  S = vc->sequence_encoding2;
790  noGUclosure = md->noGUclosure;
791  no_close = (((type==3)||(type==4))&&noGUclosure);
792 
793  if(hc->matrix[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP)
794  for (p = *i+1; p <= MIN2(*j-2-turn,*i+MAXLOOP+1); p++) {
795  minq = *j-*i+p-MAXLOOP-2;
796  if (minq<p+1+turn)
797  minq = p+1+turn;
798 
799  if(hc->up_int[*i+1] < (p - *i - 1))
800  break;
801 
802  for (q = *j-1; q >= minq; q--) {
803  if(hc->up_int[q+1] < (*j - q - 1))
804  break;
805 
806  type_2 = (unsigned char)ptype[idx[q]+p];
807 
808  if(!(hc->matrix[idx[q]+p] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC))
809  continue;
810 
811  type_2 = rtype[type_2];
812 
813  if(noGUclosure)
814  if(no_close||(type_2==3)||(type_2==4))
815  if((p>*i+1)||(q<*j-1))
816  continue; /* continue unless stack */
817 
818  energy = ubf_eval_int_loop( *i, *j, p, q,
819  p-*i-1, *j-q-1,
820  S1[*i+1], S1[*j-1], S1[p-1], S1[q+1],
821  type, type_2,
822  rtype,
823  ij,
824  -1,
825  P,
826  sc);
827  new = energy + my_c[idx[q]+p];
828 
829  if(new == en){
830  bp_stack[++(*stack_count)].i = p;
831  bp_stack[(*stack_count)].j = q;
832  if(sc)
833  if(sc->bt){
834  PAIR *ptr, *aux_bps;
835  aux_bps = sc->bt(*i, *j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
836  for(ptr = aux_bps; ptr && ptr->i != -1; ptr++){
837  bp_stack[++(*stack_count)].i = ptr->i;
838  bp_stack[(*stack_count)].j = ptr->j;
839  }
840  free(aux_bps);
841  }
842  *i = p, *j = q;
843  return 1; /* success */
844  }
845  }
846  }
847 
848  /* is it a g-quadruplex? */
849  if(md->gquad){
850  /*
851  The case that is handled here actually resembles something like
852  an interior loop where the enclosing base pair is of regular
853  kind and the enclosed pair is not a canonical one but a g-quadruplex
854  that should then be decomposed further...
855  */
856  if(ON_SAME_STRAND(*i, *j, cp))
857  if(vrna_BT_gquad_int(vc, *i, *j, en, bp_stack, stack_count)){
858  *i = *j = -1; /* tell the calling block to continue backtracking with next block */
859  return 1;
860  }
861  }
862 
863  return 0; /* unsuccessful */
864 }
865 
871 #endif
int * ggg
Energies of g-quadruplexes.
Definition: data_structures.h:432
int * c
Energy array, given that i-j pair.
Definition: data_structures.h:425
struct vrna_hc_t * hc
The hard constraints data structure used for structure prediction.
Definition: data_structures.h:716
int noGUclosure
Do not allow loops to be closed by GU pair.
Definition: model.h:181
int cutpoint
The position of the (cofold) cutpoint within the provided sequence. If there is no cutpoint...
Definition: data_structures.h:712
#define VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC
Hard constraints flag, base pair encloses a multi branch loop.
Definition: constraints.h:225
The hard constraints data structure.
Definition: constraints.h:390
char * matrix
Upper triangular matrix encoding where a base pair or unpaired nucleotide is allowed.
Definition: constraints.h:391
int * up_int
A linear array that holds the number of allowed unpaired nucleotides in an interior loop...
Definition: constraints.h:400
#define MAXLOOP
Definition: energy_const.h:28
int no_closingGU
GU allowed only inside stacks if set to 1.
struct vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:721
PAIR *(* bt)(int, int, int, int, char, void *)
A function pointer used to obtain backtraced base pairs in loop regions that were altered by soft con...
Definition: constraints.h:433
int * jindx
DP matrix accessor.
Definition: data_structures.h:725
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
PRIVATE int E_stack(int i, int j, vrna_fold_compound *vc)
Evaluate energy of a base pair stack closed by (i,j)
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:184
int ** free_energies
Energy contribution for unpaired sequence stretches.
Definition: constraints.h:414
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:118
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:79
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:698
#define INF
Definition: energy_const.h:16
Energy evaluation of exterior loops for MFE and partition function calculations.
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:123
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:718
PRIVATE int vrna_BT_stack(vrna_fold_compound *vc, int *i, int *j, int *en, bondT *bp_stack, int *stack_count)
Backtrack a stacked pair closed by .
Definition: interior_loops.h:697
int min_loop_size
Minimum size of hairpin loops.
Definition: model.h:194
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:172
unsigned int length
The length of the sequence (or sequence alignment)
Definition: data_structures.h:711
#define VRNA_CONSTRAINT_CONTEXT_INT_LOOP
Hard constraints flag, base pair encloses an interior loop.
Definition: constraints.h:217
Various functions related to G-quadruplex computations.
char * ptype
Pair type array.
Definition: data_structures.h:749
Base pair.
Definition: data_structures.h:73
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:41
The soft constraints data structure.
Definition: constraints.h:413
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:169
void * data
A pointer to the data object provided for for pseudo energy contribution functions of the generalized...
Definition: constraints.h:470
Here all all declarations of the global variables used throughout RNAlib.
PRIVATE double exp_E_IntLoop(int u1, int u2, int type, int type2, short si1, short sj1, short sp1, short sq1, vrna_exp_param_t *P)
Definition: interior_loops.h:580
Base pair data structure used in subopt.c.
Definition: data_structures.h:97
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:744
struct vrna_sc_t * sc
The soft constraints for usage in structure prediction and evaluation.
Definition: data_structures.h:763
PRIVATE int E_IntLoop(int n1, int n2, int type, int type_2, int si1, int sj1, int sp1, int sq1, vrna_param_t *P)
Definition: interior_loops.h:510
int * en_basepair
Energy contribution for base pairs.
Definition: constraints.h:415
#define VRNA_DECOMP_PAIR_IL
Generalized constraint folding flag indicating interior loop decomposition step.
Definition: constraints.h:274
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:86
int * en_stack
Pseudo Energy contribution per base pair involved in a stack.
Definition: constraints.h:419
int(* f)(int, int, int, int, char, void *)
A function pointer used for pseudo energy contribution in MFE calculations.
Definition: constraints.h:423
PRIVATE int vrna_BT_int_loop(vrna_fold_compound *vc, int *i, int *j, int en, bondT *bp_stack, int *stack_count)
Backtrack an interior loop closed by .
Definition: interior_loops.h:759