1 #ifndef VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
10 #include <ViennaRNA/energy_par.h>
13 #include <ViennaRNA/constraints.h>
18 # define INLINE inline
27 #define ON_SAME_STRAND(I,J,C) (((I)>=(C))||((J)<(C)))
122 INLINE PRIVATE
int E_IntLoop_Co(
int type,
159 ubf_eval_int_loop(
int i,
170 unsigned char type_2,
179 if((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))){
180 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
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],
204 if((p==i+1) && (q == j-1))
229 ubf_eval_ext_int_loop(
int i,
240 unsigned char type_2,
247 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
257 if((p==i+1) && (q == j-1))
276 int q, p, j_q, p_i, pq, *c_pq, max_q, max_p, tmp, *rtype, noGUclosure, no_close, energy;
279 unsigned char type, type_2;
282 char *ptype = vc->
ptype;
286 int *indx = vc->
jindx;
291 int ij = indx[j] + i;
292 int hc_decompose = hc[ij];
297 int with_gquad = md->
gquad;
303 type = (
unsigned char)ptype[ij];
304 rtype = &(md->rtype[0]);
306 no_close = (((type==3)||(type==4))&&noGUclosure);
309 for(q = j - 1; q >= max_q; q--){
312 if(hc_up[q+1] < j_q)
break;
314 pq = indx[q] + i + 1;
318 max_p =
MAX2(max_p, tmp);
320 max_p =
MIN2(max_p, tmp);
321 tmp = i + 1 + hc_up[i + 1];
322 max_p =
MIN2(max_p, tmp);
325 ptype_pq = ptype + pq;
329 for(p = i+1; p <= max_p; p++){
335 type_2 = rtype[(
unsigned char)*ptype_pq];
338 if (no_close||(type_2==3)||(type_2==4))
339 if ((p>i+1)||(q<j-1))
continue;
341 energy = ubf_eval_int_loop( i, j, p, q,
343 S_i1, S_j1, *S_p1, *S_q1,
363 if ((!no_close) && ((cp < 0) || ON_SAME_STRAND(i, j, cp))) {
364 energy = E_GQuad_IntLoop(i, j, type, S, ggg, indx, P);
380 int ij, q, p, e, u1, u2, qmin, energy, *rtype, length, *indx, *hc_up, *c, turn;
381 unsigned char type, type_2;
401 rtype = &(md->rtype[0]);
402 type = rtype[(
unsigned char)ptype[ij]];
406 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
408 for (p = j+1; p < length ; p++) {
411 if (hc_up[j+1] < u1)
break;
414 if(qmin < p + turn + 1)
416 for (q = length; q >= qmin; 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;
423 energy = ubf_eval_ext_int_loop( i, j, p, q,
425 S[j+1], S[i-1], S[p-1], S[q+1],
429 energy += c[indx[q]+p];
433 if((ip != NULL) && (iq != NULL)){
453 unsigned char type, type_2;
457 char *ptype = vc->
ptype;
460 int *rtype = &(md->rtype[0]);
461 int *indx = vc->
jindx;
462 char *hard_constraints = vc->
hc->
matrix;
470 type = (
unsigned char)ptype[ij];
471 type_2 = rtype[(
unsigned char)ptype[pq]];
474 if ((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))){
475 e = P->stack[type][type_2];
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],
495 if((p==i+1) && (q == j-1))
521 int nl, ns, u, energy;
524 if (n1>n2) { nl=n1; ns=n2;}
528 return P->stack[type][type_2];
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];
535 if (type>2) energy += P->TerminalAU;
536 if (type_2>2) energy += P->TerminalAU;
543 return P->int11[type][type_2][si1][sj1];
546 energy = P->int21[type][type_2][si1][sq1][sj1];
548 energy = P->int21[type_2][type][sq1][si1][sp1];
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];
560 return P->int22[type][type_2][si1][sp1][sq1][sj1];}
562 energy = P->internal_loop[5]+P->ninio[2];
563 energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
570 energy = (u <=
MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30]+(int)(P->lxc*log((u)/30.)));
572 energy +=
MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
574 energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
581 int ul, us, no_close = 0;
584 if ((
no_closingGU) && ((type2==3)||(type2==4)||(type==3)||(type==4)))
587 if (u1>u2) { ul=u1; us=u2;}
591 z = P->expstack[type][type2];
595 if (ul==1) z *= P->expstack[type][type2];
597 if (type>2) z *= P->expTermAU;
598 if (type2>2) z *= P->expTermAU;
604 return P->expint11[type][type2][si1][sj1];
608 return P->expint21[type][type2][si1][sq1][sj1];
610 return P->expint21[type2][type][sq1][si1][sp1];
613 z = P->expinternal[ul+us] * P->expmismatch1nI[type][si1][sj1] * P->expmismatch1nI[type2][sq1][sp1];
614 return z * P->expninio[2][ul-us];
619 return P->expint22[type][type2][si1][sp1][sq1][sj1];
621 z = P->expinternal[5]*P->expmismatch23I[type][si1][sj1]*P->expmismatch23I[type2][sq1][sp1];
622 return z * P->expninio[2][1];
626 z = P->expinternal[ul+us] * P->expmismatchI[type][si1][sj1] * P->expmismatchI[type2][sq1][sp1];
627 return z * P->expninio[2][ul-us];
634 E_IntLoop_Co(
int type,
648 int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
651 if(type > 2) energy += P->TerminalAU;
652 if(type_2 > 2) energy += P->TerminalAU;
654 if(!dangles)
return energy;
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);
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;
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;
669 if(dangles == 2)
return energy + tmm + tmm_2;
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;
678 if(q+2 < j){ energy += (ci && cp) ?
MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;}
680 energy +=
MIN2(tmm,
MIN2(tmm_2,
MIN2(d5 + d5_2, d3 + d3_2)));
682 else energy +=
MIN2(d3, d5_2);
685 if(q+2 < j){ energy += d5 + d3_2;}
686 else if(q+2 == j){ energy +=
MIN2(d5, d3_2);}
704 int ij, *idx, *my_c, *rtype;
706 unsigned char type, type_2;
721 type = (
unsigned char)ptype[ij];
722 rtype = &(md->rtype[0]);
727 if( (hc->
matrix[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP)
729 type_2 = ptype[idx[*j - 1] + *i + 1];
730 type_2 = rtype[type_2];
731 *en -= P->stack[type][type_2];
743 bp_stack[++(*stack_count)].i = *i + 1;
744 bp_stack[(*stack_count)].j = *j - 1;
766 int cp, ij, p, q, minq, turn, *idx, noGUclosure, no_close, energy,
new, *my_c, *rtype;
767 unsigned char type, type_2;
786 type = (
unsigned char)ptype[ij];
787 rtype = &(md->rtype[0]);
789 S = vc->sequence_encoding2;
791 no_close = (((type==3)||(type==4))&&noGUclosure);
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;
799 if(hc->
up_int[*i+1] < (p - *i - 1))
802 for (q = *j-1; q >= minq; q--) {
803 if(hc->
up_int[q+1] < (*j - q - 1))
806 type_2 = (
unsigned char)ptype[idx[q]+p];
808 if(!(hc->
matrix[idx[q]+p] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC))
811 type_2 = rtype[type_2];
814 if(no_close||(type_2==3)||(type_2==4))
815 if((p>*i+1)||(q<*j-1))
818 energy = ubf_eval_int_loop( *i, *j, p, q,
820 S1[*i+1], S1[*j-1], S1[p-1], S1[q+1],
827 new = energy + my_c[idx[q]+p];
830 bp_stack[++(*stack_count)].i = p;
831 bp_stack[(*stack_count)].j = q;
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;
856 if(ON_SAME_STRAND(*i, *j, cp))
857 if(vrna_BT_gquad_int(vc, *i, *j, en, bp_stack, stack_count)){
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