1 #ifndef VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
10 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/constraints.h>
16 # define INLINE inline
114 INLINE PRIVATE
int E_IntLoop_Co(
int type,
151 ubf_eval_int_loop(
int i,
162 unsigned char type_2,
171 if((cp < 0) || ( ((i >= cp) || (p < cp)) && ((q >= cp) || (j < cp)))){
172 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
175 Si = ((i >= cp) || ((i + 1) < cp)) ? si : -1;
176 Sj = (((j - 1) >= cp) || (j < cp)) ? sj : -1;
177 energy = E_IntLoop_Co(rtype[type], rtype[type_2],
196 if((p==i+1) && (q == j-1))
221 ubf_eval_ext_int_loop(
int i,
232 unsigned char type_2,
239 energy =
E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
249 if((p==i+1) && (q == j-1))
268 int q, p, j_q, p_i, pq, *c_pq, max_q, max_p, tmp, *rtype, noGUclosure, no_close, energy;
271 unsigned char type, type_2;
274 char *ptype = vc->
ptype;
278 int *indx = vc->
jindx;
283 int ij = indx[j] + i;
284 int hc_decompose = hc[ij];
289 int with_gquad = md->
gquad;
295 type = (
unsigned char)ptype[ij];
296 rtype = &(md->rtype[0]);
298 no_close = (((type==3)||(type==4))&&noGUclosure);
301 for(q = j - 1; q >= max_q; q--){
304 if(hc_up[q+1] < j_q)
break;
306 pq = indx[q] + i + 1;
310 max_p =
MAX2(max_p, tmp);
312 max_p =
MIN2(max_p, tmp);
313 tmp = i + 1 + hc_up[i + 1];
314 max_p =
MIN2(max_p, tmp);
317 ptype_pq = ptype + pq;
321 for(p = i+1; p <= max_p; p++){
327 type_2 = rtype[(
unsigned char)*ptype_pq];
330 if (no_close||(type_2==3)||(type_2==4))
331 if ((p>i+1)||(q<j-1))
continue;
333 energy = ubf_eval_int_loop( i, j, p, q,
335 S_i1, S_j1, *S_p1, *S_q1,
355 if ((!no_close) && ((cp < 0) || ((i >= cp) || (j < cp)))) {
356 energy = E_GQuad_IntLoop(i, j, type, S, ggg, indx, P);
372 int ij, q, p, e, u1, u2, qmin, energy, *rtype, length, *indx, *hc_up, *c, turn;
373 unsigned char type, type_2;
393 rtype = &(md->rtype[0]);
394 type = rtype[(
unsigned char)ptype[ij]];
398 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
400 for (p = j+1; p < length ; p++) {
403 if (hc_up[j+1] < u1)
break;
406 if(qmin < p + turn + 1)
408 for (q = length; q >= qmin; q--) {
410 if(hc_up[q+1] < u2)
break;
411 if(hc[indx[q]+p] & VRNA_CONSTRAINT_CONTEXT_INT_LOOP){
412 type_2 = rtype[(
unsigned char)ptype[indx[q]+p]];
413 if (u1+u2>MAXLOOP)
continue;
415 energy = ubf_eval_ext_int_loop( i, j, p, q,
417 S[j+1], S[i-1], S[p-1], S[q+1],
421 energy += c[indx[q]+p];
425 if((ip != NULL) && (iq != NULL)){
445 unsigned char type, type_2;
449 char *ptype = vc->
ptype;
452 int *rtype = &(md->rtype[0]);
453 int *indx = vc->
jindx;
454 char *hard_constraints = vc->
hc->
matrix;
462 type = (
unsigned char)ptype[ij];
463 type_2 = rtype[(
unsigned char)ptype[pq]];
466 if ((cp < 0) || (((i >= cp) || (p < cp)) && ((q >= cp) || (j < cp)))){
467 e = P->stack[type][type_2];
470 si = ((i >= cp) || ((i + 1) < cp)) ? S[i+1] : -1;
471 sj = (((j - 1) >= cp) || (j < cp)) ? S[j-1] : -1;
472 e = E_IntLoop_Co(rtype[type], rtype[type_2],
487 if((p==i+1) && (q == j-1))
513 int nl, ns, u, energy;
516 if (n1>n2) { nl=n1; ns=n2;}
520 return P->stack[type][type_2];
523 energy = (nl<=
MAXLOOP)?P->bulge[nl]:
524 (P->bulge[30]+(
int)(P->lxc*log(nl/30.)));
525 if (nl==1) energy += P->stack[type][type_2];
527 if (type>2) energy += P->TerminalAU;
528 if (type_2>2) energy += P->TerminalAU;
535 return P->int11[type][type_2][si1][sj1];
538 energy = P->int21[type][type_2][si1][sq1][sj1];
540 energy = P->int21[type_2][type][sq1][si1][sp1];
544 energy = (nl+1<=
MAXLOOP)?(P->internal_loop[nl+1]) : (P->internal_loop[30]+(int)(P->lxc*log((nl+1)/30.)));
545 energy +=
MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
546 energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
552 return P->int22[type][type_2][si1][sp1][sq1][sj1];}
554 energy = P->internal_loop[5]+P->ninio[2];
555 energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
562 energy = (u <=
MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30]+(int)(P->lxc*log((u)/30.)));
564 energy +=
MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
566 energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
573 int ul, us, no_close = 0;
576 if ((
no_closingGU) && ((type2==3)||(type2==4)||(type==3)||(type==4)))
579 if (u1>u2) { ul=u1; us=u2;}
583 z = P->expstack[type][type2];
587 if (ul==1) z *= P->expstack[type][type2];
589 if (type>2) z *= P->expTermAU;
590 if (type2>2) z *= P->expTermAU;
596 return P->expint11[type][type2][si1][sj1];
600 return P->expint21[type][type2][si1][sq1][sj1];
602 return P->expint21[type2][type][sq1][si1][sp1];
605 z = P->expinternal[ul+us] * P->expmismatch1nI[type][si1][sj1] * P->expmismatch1nI[type2][sq1][sp1];
606 return z * P->expninio[2][ul-us];
611 return P->expint22[type][type2][si1][sp1][sq1][sj1];
613 z = P->expinternal[5]*P->expmismatch23I[type][si1][sj1]*P->expmismatch23I[type2][sq1][sp1];
614 return z * P->expninio[2][1];
618 z = P->expinternal[ul+us] * P->expmismatchI[type][si1][sj1] * P->expmismatchI[type2][sq1][sp1];
619 return z * P->expninio[2][ul-us];
626 E_IntLoop_Co(
int type,
640 int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
643 if(type > 2) energy += P->TerminalAU;
644 if(type_2 > 2) energy += P->TerminalAU;
646 if(!dangles)
return energy;
648 ci = (i>=cutpoint)||((i+1)<cutpoint);
649 cj = ((j-1)>=cutpoint)||(j<cutpoint);
650 cp = ((p-1)>=cutpoint)||(p<cutpoint);
651 cq = (q>=cutpoint)||((q+1)<cutpoint);
653 d3 = ci ? P->dangle3[type][si1] : 0;
654 d5 = cj ? P->dangle5[type][sj1] : 0;
655 d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
656 d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
658 tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
659 tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
661 if(dangles == 2)
return energy + tmm + tmm_2;
665 if(q+2 < j){ energy += tmm + tmm_2;}
666 else if(q+2 == j){ energy += (cj && cq) ?
MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;}
667 else energy += d3 + d5_2;
670 if(q+2 < j){ energy += (ci && cp) ?
MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;}
672 energy +=
MIN2(tmm,
MIN2(tmm_2,
MIN2(d5 + d5_2, d3 + d3_2)));
674 else energy +=
MIN2(d3, d5_2);
677 if(q+2 < j){ energy += d5 + d3_2;}
678 else if(q+2 == j){ energy +=
MIN2(d5, d3_2);}
int * ggg
Energies of g-quadruplexes.
Definition: data_structures.h:429
int * c
Energy array, given that i-j pair.
Definition: data_structures.h:422
struct vrna_hc_t * hc
The hard constraints data structure used for structure prediction.
Definition: data_structures.h:707
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:703
#define VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC
Hard constraints flag, base pair encloses a multi branch loop.
Definition: constraints.h:213
char * matrix
Upper triangular matrix encoding where a base pair or unpaired nucleotide is allowed.
Definition: constraints.h:379
int * up_int
A linear array that holds the number of allowed unpaired nucleotides in an interior loop...
Definition: constraints.h:388
#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:712
int * jindx
DP matrix accessor.
Definition: data_structures.h:716
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)
Definition: interior_loops.h:440
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:184
int ** free_energies
Energy contribution for unpaired sequence stretches.
Definition: constraints.h:402
#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:689
#define INF
Definition: energy_const.h:16
#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:709
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:702
#define VRNA_CONSTRAINT_CONTEXT_INT_LOOP
Hard constraints flag, base pair encloses an interior loop.
Definition: constraints.h:205
Various functions related to G-quadruplex computations.
char * ptype
Pair type array.
Definition: data_structures.h:740
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:41
The soft constraints data structure.
Definition: constraints.h:401
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:447
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:572
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:735
struct vrna_sc_t * sc
The soft constraints for usage in structure prediction and evaluation.
Definition: data_structures.h:754
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:502
int * en_basepair
Energy contribution for base pairs.
Definition: constraints.h:403
#define VRNA_DECOMP_PAIR_IL
Generalized constraint folding flag indicating interior loop decomposition step.
Definition: constraints.h:262
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:407
int(* f)(int, int, int, int, char, void *)
A function pointer used for pseudo energy contribution in MFE calculations.
Definition: constraints.h:411