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