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