1 #ifndef VIENNA_RNA_PACKAGE_MULTIBRANCH_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_MULTIBRANCH_LOOPS_H
10 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/constraints.h>
16 # define INLINE inline
49 INLINE PRIVATE
int E_MLstem(
int type,
60 INLINE PRIVATE
double exp_E_MLstem(
int type,
82 E_mb_loop_fast(
int i,
89 unsigned char type, tt;
93 char *ptype = vc->
ptype;
95 int *indx = vc->
jindx;
102 int ij = indx[j] + i;
103 int hc_decompose = hc[ij];
108 type = (
unsigned char)ptype[ij];
114 S_i1 = ((i >= cp) || ((i + 1) < cp)) ? S[i+1] : -1;
115 S_j1 = (((j - 1) >= cp) || (j < cp)) ? S[j-1] : -1;
119 if((S_i1 >= 0) && (S_j1 >= 0)){
122 switch(dangle_model){
124 case 0:
if(decomp !=
INF){
125 decomp += E_MLstem(tt, -1, -1, P);
134 case 2: decomp += E_MLstem(tt, S_j1, S_i1, P);
142 default:
if(decomp !=
INF){
143 decomp += E_MLstem(tt, -1, -1, P);
150 if(dmli2[j-1] !=
INF){
151 en = dmli2[j-1] + E_MLstem(tt, -1, S_i1, P) + P->MLbase;
159 decomp =
MIN2(decomp, en);
162 if(hc_up[j-1] && hc_up[i+1]){
163 if(dmli2[j-2] !=
INF){
164 en = dmli2[j-2] + E_MLstem(tt, S_j1, S_i1, P) + 2*P->MLbase;
173 decomp =
MIN2(decomp, en);
177 if(dmli1[j-2] !=
INF){
178 en = dmli1[j-2] + E_MLstem(tt, S_j1, -1, P) + P->MLbase;
186 decomp =
MIN2(decomp, en);
192 e = decomp + P->MLclosing;
195 if(!((i >= cp) || (j < cp))){
196 decomp = fc[i+1] + fc[j-1];
198 switch(dangle_model){
199 case 0: decomp +=
E_ExtLoop(tt, -1, -1, P);
201 case 2: decomp +=
E_ExtLoop(tt, S_j1, S_i1, P);
203 default: decomp +=
E_ExtLoop(tt, -1, -1, P);
204 if((hc_up[i+1]) && (hc_up[j-1])){
205 en = fc[i+2] + fc[j-2] +
E_ExtLoop(tt, S_j1, S_i1, P);
206 decomp =
MIN2(decomp, en);
209 en = fc[i+2] + fc[j-1] +
E_ExtLoop(tt, -1, S_i1, P);
210 decomp =
MIN2(decomp, en);
213 en = fc[i+1] + fc[j-2] +
E_ExtLoop(tt, S_j1, -1, P);
214 decomp =
MIN2(decomp, en);
229 int e, decomp, en, i1k, k1j1, ij, k;
230 unsigned char type, type_2;
232 int *indx = vc->
jindx;
239 char *ptype = vc->
ptype;
240 int *rtype = &(md->rtype[0]);
247 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP){
249 k1j1 = indx[j-1] + i + 2 + turn + 1;
250 for (k = i+2+turn; k < j-2-turn; k++, k1j1++){
251 i1k = indx[k] + i + 1;
253 type_2 = rtype[(
unsigned char)ptype[i1k]];
254 en = c[i1k]+P->stack[type][type_2]+fML[k1j1];
255 decomp =
MIN2(decomp, en);
257 if(hc[k1j1] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC){
258 type_2 = rtype[(
unsigned char)ptype[k1j1]];
259 en = c[k1j1]+P->stack[type][type_2]+fML[i1k];
260 decomp =
MIN2(decomp, en);
264 decomp += 2*P->MLintern[1] + P->MLclosing;
276 E_ml_rightmost_stem(
int i,
284 int *indx = vc->
jindx;
291 int ij = indx[j] + i;
292 int type = vc->
ptype[ij];
293 int hc_decompose = hc[ij];
299 if((cp < 0) || (((i - 1) >= cp) || (i < cp))){
300 if((cp < 0) || ((j >= cp) || ((j + 1) < cp))){
304 switch(dangle_model){
305 case 2: e += E_MLstem(type, (i==1) ? S[length] : S[i-1], S[j+1], P);
307 default: e += E_MLstem(type, -1, -1, P);
314 if((cp < 0) || ((i >= cp) || (j < cp))){
315 en = ggg[ij] + E_MLstem(0, -1, -1, P);
321 if((cp < 0) || (((j - 1) >= cp) || (j < cp)))
323 if(fm[indx[j - 1] + i] !=
INF){
324 en = fm[indx[j - 1] + i] + P->MLbase;
337 E_ml_stems_fast(
int i,
343 int k, en, decomp, mm5, mm3, type_2, k1j, stop;
345 int length = (int)vc->
length;
346 char *ptype = vc->
ptype;
348 int *indx = vc->
jindx;
355 int ij = indx[j] + i;
358 int type = ptype[ij];
367 e = E_ml_rightmost_stem(i,j,vc);
373 if((cp < 0) || (((i - 1) >= cp) || (i < cp))){
374 switch(dangle_model){
379 case 2:
if((cp < 0) || ((i >= cp) || ((i + 1) < cp)))
381 if(fm[ij + 1] !=
INF){
382 en = fm[ij + 1] + P->MLbase;
392 default: mm5 = ((i>1) || circular) ? S[i] : -1;
393 mm3 = ((j<length) || circular) ? S[j] : -1;
394 if((cp < 0) || ((i >= cp) || ((i + 1) < cp)))
397 en = fm[ij+1] + P->MLbase;
403 if(hc[ij+1] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC){
406 en = c[ij+1] + E_MLstem(type, mm5, -1, P) + P->MLbase;
415 if((cp < 0) || (((j - 1) >= cp) || (j < cp)))
417 if(hc[indx[j-1]+i] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC){
418 if(c[indx[j-1]+i] !=
INF){
419 type = ptype[indx[j-1]+i];
420 en = c[indx[j-1]+i] + E_MLstem(type, -1, mm3, P) + P->MLbase;
430 || ( (((j - 1) >= cp) || (j < cp))
431 && ((i >= cp) || ((i + 1) < cp))))
432 if(hc[indx[j-1]+i+1] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC){
433 if(hc_up[i] && hc_up[j]){
434 if(c[indx[j-1]+i+1] !=
INF){
435 type = ptype[indx[j-1]+i+1];
436 en = c[indx[j-1]+i+1] + E_MLstem(type, mm5, mm3, P) + 2*P->MLbase;
449 k1j = indx[j] + i + turn + 2;
450 stop = (cp > 0) ? (cp - 1) : (j - 2 - turn);
451 for (decomp =
INF, k = i + 1 + turn; k <= stop; k++, k1j++){
452 if((fmi[k] !=
INF ) && (fm[k1j] !=
INF)){
453 en = fmi[k] + fm[k1j];
454 decomp =
MIN2(decomp, en);
458 for (;k <= j - 2 - turn; k++, k1j++){
459 if((fmi[k] !=
INF) && (fm[k1j] !=
INF)){
460 en = fmi[k] + fm[k1j];
461 decomp =
MIN2(decomp, en);
469 if (dangle_model==3) {
472 k1j = indx[j]+i+turn+2;
473 for (decomp =
INF, k = i + 1 + turn; k <= stop; k++, k1j++){
475 if((hc[ik] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC) && (hc[k1j] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC)){
476 type = rtype[(
unsigned char)ptype[ik]];
477 type_2 = rtype[(
unsigned char)ptype[k1j]];
478 en = c[ik] + c[k1j] + P->stack[type][type_2];
479 decomp =
MIN2(decomp, en);
483 for (; k <= j-2-turn; k++, k1j++){
485 if((hc[ik] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC) && (hc[k1j] & VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC)){
486 type = rtype[(
unsigned char)ptype[ik]];
487 type_2 = rtype[(
unsigned char)ptype[k1j]];
488 en = c[ik] + c[k1j] + P->stack[type][type_2];
489 decomp =
MIN2(decomp, en);
493 decomp += 2*P->MLintern[1];
497 DMLi[j] =
MIN2(DMLi[j], decomp);
498 DMLi[j] =
MIN2(DMLi[j], DMLi[j-1]+P->MLbase);
499 DMLi[j] =
MIN2(DMLi[j], DMLi1[j]+P->MLbase);
500 new_fML =
MIN2(new_fML, DMLi[j]);
512 INLINE PRIVATE
int E_MLstem(
int type,
int si1,
int sj1,
vrna_param_t *P){
514 if(si1 >= 0 && sj1 >= 0){
515 energy += P->mismatchM[type][si1][sj1];
518 energy += P->dangle5[type][si1];
521 energy += P->dangle3[type][sj1];
525 energy += P->TerminalAU;
527 energy += P->MLintern[type];
534 INLINE PRIVATE
double
535 exp_E_MLstem(
int type,
541 if(si1 >= 0 && sj1 >= 0){
542 energy = P->expmismatchM[type][si1][sj1];
545 energy = P->expdangle5[type][si1];
548 energy = P->expdangle3[type][sj1];
552 energy *= P->expTermAU;
554 energy *= P->expMLintern[type];
int * ggg
Energies of g-quadruplexes.
Definition: data_structures.h:429
int uniq_ML
Flag to ensure unique multibranch loop decomposition during folding.
Definition: model.h:186
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 * fM1
Second ML array, only for unique multibrnach loop decomposition.
Definition: data_structures.h:427
int cutpoint
The position of the (cofold) cutpoint within the provided sequence. If there is no cutpoint...
Definition: data_structures.h:703
char * matrix
Upper triangular matrix encoding where a base pair or unpaired nucleotide is allowed.
Definition: constraints.h:379
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 * fML
Multi-loop auxiliary energy array.
Definition: data_structures.h:426
int * up_ml
A linear array that holds the number of allowed unpaired nucleotides in a multi branched loop...
Definition: constraints.h:391
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 VRNA_CONSTRAINT_CONTEXT_MB_LOOP
Hard constraints flag, base pair is enclosed in an interior loop.
Definition: constraints.h:221
PRIVATE int E_ExtLoop(int type, int si1, int sj1, vrna_param_t *P)
Definition: exterior_loops.h:454
int * fc
Energy from i to cutpoint (and vice versa if i>cut)
Definition: data_structures.h:425
#define INF
Definition: energy_const.h:16
#define VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC
Hard constraints flag, base pair is enclosed in a multi branch loop.
Definition: constraints.h:229
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
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
int circ
Assume RNA to be circular instead of linear.
Definition: model.h:183
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:169
PRIVATE int E_mb_loop_stack(int i, int j, vrna_fold_compound *vc)
Evaluate energy of a multi branch helices stacking onto closing pair (i,j)
Definition: multibranch_loops.h:225
Here all all declarations of the global variables used throughout RNAlib.
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
int * en_basepair
Energy contribution for base pairs.
Definition: constraints.h:403
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:86