RNAlib-2.4.10
internal.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_LOOPS_INTERNAL_H
2 #define VIENNA_RNA_PACKAGE_LOOPS_INTERNAL_H
3 
5 #include <ViennaRNA/params/default.h>
10 
11 #ifdef VRNA_WARN_DEPRECATED
12 # if defined(DEPRECATED)
13 # undef DEPRECATED
14 # endif
15 # if defined(__clang__)
16 # define DEPRECATED(func, msg) func __attribute__ ((deprecated("", msg)))
17 # elif defined(__GNUC__)
18 # define DEPRECATED(func, msg) func __attribute__ ((deprecated(msg)))
19 # else
20 # define DEPRECATED(func, msg) func
21 # endif
22 #else
23 # define DEPRECATED(func, msg) func
24 #endif
25 
26 #ifdef __GNUC__
27 # define INLINE inline
28 #else
29 # define INLINE
30 #endif
31 
49 int
50 vrna_E_int_loop(vrna_fold_compound_t *fc,
51  int i,
52  int j);
53 
54 
62 int
64  int i,
65  int j,
66  int k,
67  int l);
68 
69 
70 int
71 vrna_E_ext_int_loop(vrna_fold_compound_t *fc,
72  int i,
73  int j,
74  int *ip,
75  int *iq);
76 
77 
78 int
79 vrna_E_stack(vrna_fold_compound_t *fc,
80  int i,
81  int j);
82 
83 
84 /* End basic interface */
94 /* j < i indicates circular folding, i.e. collect contributions for exterior int loops */
96 vrna_exp_E_int_loop(vrna_fold_compound_t *fc,
97  int i,
98  int j);
99 
100 
102 vrna_exp_E_interior_loop(vrna_fold_compound_t *fc,
103  int i,
104  int j,
105  int k,
106  int l);
107 
108 
109 /* End partition function interface */
127 int
129  int *i,
130  int *j,
131  int *en,
132  vrna_bp_stack_t *bp_stack,
133  int *stack_count);
134 
135 
140 int
142  int *i,
143  int *j,
144  int en,
145  vrna_bp_stack_t *bp_stack,
146  int *stack_count);
147 
148 
154 #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY
155 
161 #ifdef ON_SAME_STRAND
162 #undef ON_SAME_STRAND
163 #endif
164 
165 #define ON_SAME_STRAND(I, J, C) (((I) >= (C)) || ((J) < (C)))
166 
211 PRIVATE INLINE int E_IntLoop(int n1,
212  int n2,
213  int type,
214  int type_2,
215  int si1,
216  int sj1,
217  int sp1,
218  int sq1,
219  vrna_param_t *P);
220 
221 
241 PRIVATE INLINE FLT_OR_DBL exp_E_IntLoop(int u1,
242  int u2,
243  int type,
244  int type2,
245  short si1,
246  short sj1,
247  short sp1,
248  short sq1,
249  vrna_exp_param_t *P);
250 
251 
252 PRIVATE INLINE int E_IntLoop_Co(int type,
253  int type_2,
254  int i,
255  int j,
256  int p,
257  int q,
258  int cutpoint,
259  short si1,
260  short sj1,
261  short sp1,
262  short sq1,
263  int dangles,
264  vrna_param_t *P);
265 
266 
267 /*
268  * ugly but fast interior loop evaluation
269  *
270  * Avoid including this function in your own code. It only serves
271  * as a fast inline block internally re-used throughout the RNAlib. It
272  * evalutes the free energy of interior loops in single sequences or sequence
273  * hybrids. Soft constraints are also applied if available.
274  *
275  * NOTE: do not include into doxygen reference manual!
276  */
277 PRIVATE INLINE int
278 ubf_eval_int_loop(int i,
279  int j,
280  int p,
281  int q,
282  int i1,
283  int j1,
284  int p1,
285  int q1,
286  short si,
287  short sj,
288  short sp,
289  short sq,
290  unsigned char type,
291  unsigned char type_2,
292  int *rtype,
293  int ij,
294  int cp,
295  vrna_param_t *P,
296  vrna_sc_t *sc)
297 {
298  int energy, u1, u2;
299 
300  u1 = p1 - i;
301  u2 = j1 - q;
302 
303  if ((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))) {
304  /* regular interior loop */
305  energy = E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
306  } else {
307  /* interior loop like cofold structure */
308  short Si, Sj;
309  Si = ON_SAME_STRAND(i, i1, cp) ? si : -1;
310  Sj = ON_SAME_STRAND(j1, j, cp) ? sj : -1;
311  energy = E_IntLoop_Co(rtype[type], rtype[type_2],
312  i, j, p, q,
313  cp,
314  Si, Sj,
315  sp, sq,
317  P);
318  }
319 
320  /* add soft constraints */
321  if (sc) {
322  if (sc->energy_up)
323  energy += sc->energy_up[i1][u1]
324  + sc->energy_up[q1][u2];
325 
326  if (sc->energy_bp)
327  energy += sc->energy_bp[ij];
328 
329  if (sc->energy_stack)
330  if (u1 + u2 == 0) {
331  int a = sc->energy_stack[i]
332  + sc->energy_stack[p]
333  + sc->energy_stack[q]
334  + sc->energy_stack[j];
335  energy += a;
336  }
337 
338  if (sc->f)
339  energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
340  }
341 
342  return energy;
343 }
344 
345 
346 PRIVATE INLINE int
347 ubf_eval_int_loop2(int i,
348  int j,
349  int p,
350  int q,
351  int i1,
352  int j1,
353  int p1,
354  int q1,
355  short si,
356  short sj,
357  short sp,
358  short sq,
359  unsigned char type,
360  unsigned char type_2,
361  int *rtype,
362  int ij,
363  unsigned int *sn,
364  unsigned int *ss,
365  vrna_param_t *P,
366  vrna_sc_t *sc)
367 {
368  int energy, u1, u2;
369 
370  u1 = p1 - i;
371  u2 = j1 - q;
372 
373  if ((sn[i] == sn[p]) && (sn[q] == sn[j])) {
374  /* regular interior loop */
375  energy = E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
376  } else {
377  /* interior loop like cofold structure */
378  short Si, Sj;
379  Si = (sn[i1] == sn[i]) ? si : -1;
380  Sj = (sn[j] == sn[j1]) ? sj : -1;
381  energy = E_IntLoop_Co(rtype[type], rtype[type_2],
382  i, j, p, q,
383  ss[1],
384  Si, Sj,
385  sp, sq,
387  P);
388  }
389 
390  /* add soft constraints */
391  if (sc) {
392  if (sc->energy_up)
393  energy += sc->energy_up[i1][u1]
394  + sc->energy_up[q1][u2];
395 
396  if (sc->energy_bp)
397  energy += sc->energy_bp[ij];
398 
399  if (sc->energy_stack)
400  if (u1 + u2 == 0) {
401  int a = sc->energy_stack[i]
402  + sc->energy_stack[p]
403  + sc->energy_stack[q]
404  + sc->energy_stack[j];
405  energy += a;
406  }
407 
408  if (sc->f)
409  energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
410  }
411 
412  return energy;
413 }
414 
415 
416 /*
417  * ugly but fast exterior interior loop evaluation
418  *
419  * Avoid including this function in your own code. It only serves
420  * as a fast inline block internally re-used throughout the RNAlib. It
421  * evalutes the free energy of interior loops in single sequences or sequence
422  * hybrids. Soft constraints are also applied if available.
423  *
424  * NOTE: do not include into doxygen reference manual!
425  */
426 PRIVATE INLINE int
427 ubf_eval_ext_int_loop(int i,
428  int j,
429  int p,
430  int q,
431  int i1,
432  int j1,
433  int p1,
434  int q1,
435  short si,
436  short sj,
437  short sp,
438  short sq,
439  unsigned char type,
440  unsigned char type_2,
441  int length,
442  vrna_param_t *P,
443  vrna_sc_t *sc)
444 {
445  int energy, u1, u2, u3;
446 
447  u1 = i1;
448  u2 = p1 - j;
449  u3 = length - q;
450 
451  energy = E_IntLoop(u2, u1 + u3, type, type_2, si, sj, sp, sq, P);
452 
453  /* add soft constraints */
454  if (sc) {
455  if (sc->energy_up) {
456  energy += sc->energy_up[j1][u2]
457  + ((u3 > 0) ? sc->energy_up[q1][u3] : 0)
458  + ((u1 > 0) ? sc->energy_up[1][u1] : 0);
459  }
460 
461  if (sc->energy_stack)
462  if (u1 + u2 + u3 == 0)
463  energy += sc->energy_stack[i]
464  + sc->energy_stack[p]
465  + sc->energy_stack[q]
466  + sc->energy_stack[j];
467 
468  if (sc->f)
469  energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
470  }
471 
472  return energy;
473 }
474 
475 
476 PRIVATE INLINE int
477 E_IntLoop(int n1,
478  int n2,
479  int type,
480  int type_2,
481  int si1,
482  int sj1,
483  int sp1,
484  int sq1,
485  vrna_param_t *P)
486 {
487  /* compute energy of degree 2 loop (stack bulge or interior) */
488  int nl, ns, u, energy;
489 
490  energy = INF;
491 
492  if (n1 > n2) {
493  nl = n1;
494  ns = n2;
495  } else {
496  nl = n2;
497  ns = n1;
498  }
499 
500  if (nl == 0)
501  return P->stack[type][type_2]; /* stack */
502 
503  if (ns == 0) {
504  /* bulge */
505  energy = (nl <= MAXLOOP) ? P->bulge[nl] :
506  (P->bulge[30] + (int)(P->lxc * log(nl / 30.)));
507  if (nl == 1) {
508  energy += P->stack[type][type_2];
509  } else {
510  if (type > 2)
511  energy += P->TerminalAU;
512 
513  if (type_2 > 2)
514  energy += P->TerminalAU;
515  }
516 
517  return energy;
518  } else {
519  /* interior loop */
520  if (ns == 1) {
521  if (nl == 1) /* 1x1 loop */
522  return P->int11[type][type_2][si1][sj1];
523 
524  if (nl == 2) {
525  /* 2x1 loop */
526  if (n1 == 1)
527  energy = P->int21[type][type_2][si1][sq1][sj1];
528  else
529  energy = P->int21[type_2][type][sq1][si1][sp1];
530 
531  return energy;
532  } else {
533  /* 1xn loop */
534  energy =
535  (nl + 1 <=
536  MAXLOOP) ? (P->internal_loop[nl + 1]) : (P->internal_loop[30] +
537  (int)(P->lxc * log((nl + 1) / 30.)));
538  energy += MIN2(MAX_NINIO, (nl - ns) * P->ninio[2]);
539  energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
540  return energy;
541  }
542  } else if (ns == 2) {
543  if (nl == 2) {
544  /* 2x2 loop */
545  return P->int22[type][type_2][si1][sp1][sq1][sj1];
546  } else if (nl == 3) {
547  /* 2x3 loop */
548  energy = P->internal_loop[5] + P->ninio[2];
549  energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
550  return energy;
551  }
552  }
553 
554  {
555  /* generic interior loop (no else here!)*/
556  u = nl + ns;
557  energy =
558  (u <=
559  MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30] + (int)(P->lxc * log((u) / 30.)));
560 
561  energy += MIN2(MAX_NINIO, (nl - ns) * P->ninio[2]);
562 
563  energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
564  }
565  }
566 
567  return energy;
568 }
569 
570 
571 PRIVATE INLINE FLT_OR_DBL
573  int u2,
574  int type,
575  int type2,
576  short si1,
577  short sj1,
578  short sp1,
579  short sq1,
580  vrna_exp_param_t *P)
581 {
582  int ul, us, no_close = 0;
583  double z = 0.;
584  int noGUclosure = P->model_details.noGUclosure;
585 
586  if ((noGUclosure) && ((type2 == 3) || (type2 == 4) || (type == 3) || (type == 4)))
587  no_close = 1;
588 
589  if (u1 > u2) {
590  ul = u1;
591  us = u2;
592  } else {
593  ul = u2;
594  us = u1;
595  }
596 
597  if (ul == 0) {
598  /* stack */
599  z = P->expstack[type][type2];
600  } else if (!no_close) {
601  if (us == 0) {
602  /* bulge */
603  z = P->expbulge[ul];
604  if (ul == 1) {
605  z *= P->expstack[type][type2];
606  } else {
607  if (type > 2)
608  z *= P->expTermAU;
609 
610  if (type2 > 2)
611  z *= P->expTermAU;
612  }
613 
614  return (FLT_OR_DBL)z;
615  } else if (us == 1) {
616  if (ul == 1) /* 1x1 loop */
617  return (FLT_OR_DBL)(P->expint11[type][type2][si1][sj1]);
618 
619  if (ul == 2) {
620  /* 2x1 loop */
621  if (u1 == 1)
622  return (FLT_OR_DBL)(P->expint21[type][type2][si1][sq1][sj1]);
623  else
624  return (FLT_OR_DBL)(P->expint21[type2][type][sq1][si1][sp1]);
625  } else {
626  /* 1xn loop */
627  z = P->expinternal[ul + us] * P->expmismatch1nI[type][si1][sj1] *
628  P->expmismatch1nI[type2][sq1][sp1];
629  return (FLT_OR_DBL)(z * P->expninio[2][ul - us]);
630  }
631  } else if (us == 2) {
632  if (ul == 2) {
633  /* 2x2 loop */
634  return (FLT_OR_DBL)(P->expint22[type][type2][si1][sp1][sq1][sj1]);
635  } else if (ul == 3) {
636  /* 2x3 loop */
637  z = P->expinternal[5] * P->expmismatch23I[type][si1][sj1] *
638  P->expmismatch23I[type2][sq1][sp1];
639  return (FLT_OR_DBL)(z * P->expninio[2][1]);
640  }
641  }
642 
643  /* generic interior loop (no else here!)*/
644  z = P->expinternal[ul + us] * P->expmismatchI[type][si1][sj1] *
645  P->expmismatchI[type2][sq1][sp1];
646  return (FLT_OR_DBL)(z * P->expninio[2][ul - us]);
647  }
648 
649  return (FLT_OR_DBL)z;
650 }
651 
652 
653 PRIVATE INLINE int
654 E_IntLoop_Co(int type,
655  int type_2,
656  int i,
657  int j,
658  int p,
659  int q,
660  int cutpoint,
661  short si1,
662  short sj1,
663  short sp1,
664  short sq1,
665  int dangles,
666  vrna_param_t *P)
667 {
668  int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
669 
670  energy = 0;
671  if (type > 2)
672  energy += P->TerminalAU;
673 
674  if (type_2 > 2)
675  energy += P->TerminalAU;
676 
677  if (!dangles)
678  return energy;
679 
680  ci = ON_SAME_STRAND(i, i + 1, cutpoint);
681  cj = ON_SAME_STRAND(j - 1, j, cutpoint);
682  cp = ON_SAME_STRAND(p - 1, p, cutpoint);
683  cq = ON_SAME_STRAND(q, q + 1, cutpoint);
684 
685  d3 = ci ? P->dangle3[type][si1] : 0;
686  d5 = cj ? P->dangle5[type][sj1] : 0;
687  d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
688  d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
689 
690  tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
691  tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
692 
693  if (dangles == 2)
694  return energy + tmm + tmm_2;
695 
696  /* now we may have non-double dangles only */
697  if (p - i > 2) {
698  if (j - q > 2)
699  energy += tmm + tmm_2;
700  else if (j - q == 2)
701  energy += (cj && cq) ? MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;
702  else
703  energy += d3 + d5_2;
704  } else if (p - i == 2) {
705  if (j - q > 2)
706  energy += (ci && cp) ? MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;
707  else if (j - q == 2)
708  energy += MIN2(tmm, MIN2(tmm_2, MIN2(d5 + d5_2, d3 + d3_2)));
709  else
710  energy += MIN2(d3, d5_2);
711  } else {
712  if (j - q > 2)
713  energy += d5 + d3_2;
714  else if (j - q == 2)
715  energy += MIN2(d5, d3_2);
716  }
717 
718  return energy;
719 }
720 
721 
726 #endif
727 
728 #endif
Functions and data structures for secondary structure soft constraints.
int vrna_eval_int_loop(vrna_fold_compound_t *fc, int i, int j, int k, int l)
Evaluate the free energy contribution of an interior loop with delimiting base pairs and ...
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
int * energy_stack
Pseudo Energy contribution per base pair involved in a stack.
Definition: soft.h:202
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: basic.h:111
#define MAXLOOP
Definition: constants.h:29
vrna_callback_sc_energy * f
A function pointer used for pseudo energy contribution in MFE calculations.
Definition: soft.h:206
#define INF
Definition: constants.h:17
Various data structures and pre-processor macros.
The soft constraints data structure.
Definition: soft.h:170
The data structure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: basic.h:102
Functions and data structures for handling of secondary structure hard constraints.
int ** energy_up
Energy contribution for stretches of unpaired nucleotides.
Definition: soft.h:176
#define VRNA_DECOMP_PAIR_IL
Indicator for interior loop decomposition step.
Definition: basic.h:144
int vrna_BT_int_loop(vrna_fold_compound_t *fc, int *i, int *j, int en, vrna_bp_stack_t *bp_stack, int *stack_count)
Backtrack an interior loop closed by .
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
Functions to deal with sets of energy parameters.
int * energy_bp
Energy contribution for base pairs.
Definition: soft.h:187
int vrna_BT_stack(vrna_fold_compound_t *fc, int *i, int *j, int *en, vrna_bp_stack_t *bp_stack, int *stack_count)
Backtrack a stacked pair closed by .
General utility- and helper-functions used throughout the ViennaRNA Package.
int noGUclosure
Do not allow loops to be closed by GU pair.
Definition: model.h:207
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
PRIVATE FLT_OR_DBL 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: internal.h:572
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: internal.h:477
void * data
A pointer to the data object provided for for pseudo energy contribution functions of the generic sof...
Definition: soft.h:223