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