1 #ifndef __VIENNA_RNA_PACKAGE_MULTIBRANCH_LOOPS_H__
2 #define __VIENNA_RNA_PACKAGE_MULTIBRANCH_LOOPS_H__
11 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/constraints.h>
16 # define INLINE inline
45 INLINE PRIVATE
int E_MLstem(
int type,
56 INLINE PRIVATE
double exp_E_MLstem(
int type,
78 E_mb_loop_fast(
int i,
84 int k, decomp, MLenergy, en;
85 unsigned char type, type_2, tt;
89 char *ptype = vc->
ptype;
90 short *S = vc->sequence_encoding;
91 int *indx = vc->jindx;
93 int *hc_up = vc->hc->
up_ml;
95 int *c = vc->matrices->c;
96 int *fML = vc->matrices->fML;
97 int *fc = vc->matrices->fc;
100 int ij = indx[j] + i;
101 int hc_decompose = hc[ij];
106 type = (
unsigned char)ptype[ij];
112 S_i1 = ((i >= cp) || ((i + 1) < cp)) ? S[i+1] : -1;
113 S_j1 = (((j - 1) >= cp) || (j < cp)) ? S[j-1] : -1;
117 if((S_i1 >= 0) && (S_j1 >= 0)){
120 switch(dangle_model){
122 case 0: decomp += E_MLstem(tt, -1, -1, P);
130 case 2: decomp += E_MLstem(tt, S_j1, S_i1, P);
138 default: decomp += E_MLstem(tt, -1, -1, P);
144 en = dmli2[j-1] + E_MLstem(tt, -1, S_i1, P) + P->MLbase;
152 decomp =
MIN2(decomp, en);
154 if(hc_up[j-1] && hc_up[i+1]){
155 en = dmli2[j-2] + E_MLstem(tt, S_j1, S_i1, P) + 2*P->MLbase;
164 decomp =
MIN2(decomp, en);
167 en = dmli1[j-2] + E_MLstem(tt, S_j1, -1, P) + P->MLbase;
175 decomp =
MIN2(decomp, en);
179 e = decomp + P->MLclosing;
182 if(!((i >= cp) || (j < cp))){
183 decomp = fc[i+1] + fc[j-1];
185 switch(dangle_model){
186 case 0: decomp +=
E_ExtLoop(tt, -1, -1, P);
188 case 2: decomp +=
E_ExtLoop(tt, S_j1, S_i1, P);
190 default: decomp +=
E_ExtLoop(tt, -1, -1, P);
191 if((hc_up[i+1]) && (hc_up[j-1])){
192 en = fc[i+2] + fc[j-2] +
E_ExtLoop(tt, S_j1, S_i1, P);
193 decomp =
MIN2(decomp, en);
196 en = fc[i+2] + fc[j-1] +
E_ExtLoop(tt, -1, S_i1, P);
197 decomp =
MIN2(decomp, en);
200 en = fc[i+1] + fc[j-2] +
E_ExtLoop(tt, S_j1, -1, P);
201 decomp =
MIN2(decomp, en);
212 E_mb_loop_stack(
int i,
216 int e, decomp, en, i1k, k1j1, ij, k;
217 unsigned char type, type_2;
219 int *indx = vc->jindx;
220 char *hc = vc->hc->
matrix;
221 int *c = vc->matrices->c;
222 int *fML = vc->matrices->fML;
226 char *ptype = vc->
ptype;
227 int *rtype = &(md->rtype[0]);
233 if(hc[ij] & VRNA_HC_CONTEXT_MB_LOOP){
235 k1j1 = indx[j-1] + i + 2 + turn + 1;
236 for (k = i+2+turn; k < j-2-turn; k++, k1j1++){
237 i1k = indx[k] + i + 1;
239 type_2 = rtype[(
unsigned char)ptype[i1k]];
240 en = c[i1k]+P->stack[type][type_2]+fML[k1j1];
241 decomp =
MIN2(decomp, en);
243 if(hc[k1j1] & VRNA_HC_CONTEXT_MB_LOOP_ENC){
244 type_2 = rtype[(
unsigned char)ptype[k1j1]];
245 en = c[k1j1]+P->stack[type][type_2]+fML[i1k];
246 decomp =
MIN2(decomp, en);
250 decomp += 2*P->MLintern[1] + P->MLclosing;
262 E_ml_rightmost_stem(
int i,
268 int length = vc->length;
269 short *S = vc->sequence_encoding;
270 int *indx = vc->jindx;
271 char *hc = vc->hc->
matrix;
272 int *hc_up = vc->hc->
up_ml;
274 int *c = vc->matrices->c;
276 int *ggg = vc->matrices->ggg;
277 int ij = indx[j] + i;
278 int type = vc->
ptype[ij];
279 int hc_decompose = hc[ij];
285 if((cp < 0) || (((i - 1) >= cp) || (i < cp))){
286 if((cp < 0) || ((j >= cp) || ((j + 1) < cp))){
287 if(hc_decompose & VRNA_HC_CONTEXT_MB_LOOP_ENC){
289 switch(dangle_model){
290 case 2: e += E_MLstem(type, (i==1) ? S[length] : S[i-1], S[j+1], P);
292 default: e += E_MLstem(type, -1, -1, P);
298 if((cp < 0) || ((i >= cp) || (j < cp))){
299 en = ggg[ij] + E_MLstem(0, -1, -1, P);
305 if((cp < 0) || (((j - 1) >= cp) || (j < cp)))
307 en = fm[indx[j - 1] + i] + P->MLbase;
319 E_ml_stems_fast(
int i,
325 int k, en, decomp, mm5, mm3, type_2, k1j;
327 int length = (int)vc->length;
328 char *ptype = vc->
ptype;
329 short *S = vc->sequence_encoding;
330 int *indx = vc->jindx;
331 char *hc = vc->hc->
matrix;
332 int *hc_up = vc->hc->
up_ml;
334 int *c = vc->matrices->c;
335 int *fm = vc->matrices->fML;
337 int ij = indx[j] + i;
340 int type = ptype[ij];
349 e = E_ml_rightmost_stem(i,j,vc);
355 if((cp < 0) || (((i - 1) >= cp) || (i < cp))){
356 switch(dangle_model){
361 case 2:
if((cp < 0) || ((i >= cp) || ((i + 1) < cp)))
363 en = fm[ij + 1] + P->MLbase;
372 default: mm5 = ((i>1) || circular) ? S[i] : -1;
373 mm3 = ((j<length) || circular) ? S[j] : -1;
374 if((cp < 0) || ((i >= cp) || ((i + 1) < cp)))
376 en = fm[ij+1] + P->MLbase;
381 if(hc[ij+1] & VRNA_HC_CONTEXT_MB_LOOP_ENC){
383 en = c[ij+1] + E_MLstem(type, mm5, -1, P) + P->MLbase;
391 if((cp < 0) || (((j - 1) >= cp) || (j < cp)))
393 if(hc[indx[j-1]+i] & VRNA_HC_CONTEXT_MB_LOOP_ENC){
394 type = ptype[indx[j-1]+i];
395 en = c[indx[j-1]+i] + E_MLstem(type, -1, mm3, P) + P->MLbase;
404 || ( (((j - 1) >= cp) || (j < cp))
405 && ((i >= cp) || ((i + 1) < cp))))
406 if(hc[indx[j-1]+i+1] & VRNA_HC_CONTEXT_MB_LOOP_ENC){
407 if(hc_up[i] && hc_up[j]){
408 type = ptype[indx[j-1]+i+1];
409 en = c[indx[j-1]+i+1] + E_MLstem(type, mm5, mm3, P) + 2*P->MLbase;
421 k1j = indx[j] + i + turn + 2;
422 int stop = (cp > 0) ? (cp - 1) : (j - 2 - turn);
423 for (decomp =
INF, k = i + 1 + turn; k <= stop; k++, k1j++){
424 en = fmi[k] + fm[k1j];
425 decomp =
MIN2(decomp, en);
428 for (;k <= j - 2 - turn; k++, k1j++){
429 en = fmi[k] + fm[k1j];
430 decomp =
MIN2(decomp, en);
437 if (dangle_model==3) {
440 k1j = indx[j]+i+turn+2;
441 for (decomp =
INF, k = i + 1 + turn; k <= stop; k++, k1j++){
443 if((hc[ik] & VRNA_HC_CONTEXT_MB_LOOP_ENC) && (hc[k1j] & VRNA_HC_CONTEXT_MB_LOOP_ENC)){
444 type = rtype[(
unsigned char)ptype[ik]];
445 type_2 = rtype[(
unsigned char)ptype[k1j]];
446 en = c[ik] + c[k1j] + P->stack[type][type_2];
447 decomp =
MIN2(decomp, en);
451 for (; k <= j-2-turn; k++, k1j++){
453 if((hc[ik] & VRNA_HC_CONTEXT_MB_LOOP_ENC) && (hc[k1j] & VRNA_HC_CONTEXT_MB_LOOP_ENC)){
454 type = rtype[(
unsigned char)ptype[ik]];
455 type_2 = rtype[(
unsigned char)ptype[k1j]];
456 en = c[ik] + c[k1j] + P->stack[type][type_2];
457 decomp =
MIN2(decomp, en);
461 decomp += 2*P->MLintern[1];
465 DMLi[j] =
MIN2(DMLi[j], decomp);
466 DMLi[j] =
MIN2(DMLi[j], DMLi[j-1]+P->MLbase);
467 DMLi[j] =
MIN2(DMLi[j], DMLi1[j]+P->MLbase);
468 new_fML =
MIN2(new_fML, DMLi[j]);
480 INLINE PRIVATE
int E_MLstem(
int type,
int si1,
int sj1,
paramT *P){
482 if(si1 >= 0 && sj1 >= 0){
483 energy += P->mismatchM[type][si1][sj1];
486 energy += P->dangle5[type][si1];
489 energy += P->dangle3[type][sj1];
493 energy += P->TerminalAU;
495 energy += P->MLintern[type];
502 INLINE PRIVATE
double
503 exp_E_MLstem(
int type,
509 if(si1 >= 0 && sj1 >= 0){
510 energy = P->expmismatchM[type][si1][sj1];
513 energy = P->expdangle5[type][si1];
516 energy = P->expdangle3[type][sj1];
520 energy *= P->expTermAU;
522 energy *= P->expMLintern[type];
The soft constraints data structure.
Definition: data_structures.h:323
#define MIN2(A, B)
Definition: utils.h:150
int cutpoint
The position of the (cofold) cutpoint within the provided sequence. If there is no cutpoint...
Definition: data_structures.h:363
int min_loop_size
Minimum size of hairpin loops.
Definition: model.h:231
int * up_ml
A linear array that holds the number of allowed unpaired nucleotides in a multi branched loop...
Definition: data_structures.h:313
int uniq_ML
Flag to ensure unique multibranch loop decomposition during folding.
Definition: model.h:223
The datastructure that contains temperature scaled energy parameters.
Definition: data_structures.h:180
model_detailsT model_details
Model details to be used in the recursions.
Definition: data_structures.h:218
#define VRNA_HC_CONTEXT_MB_LOOP
Hard constraints flag, base pair is enclosed in an interior loop.
Definition: constraints.h:199
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: data_structures.h:225
int * en_basepair
Energy contribution for base pairs.
Definition: data_structures.h:326
Definition: data_structures.h:359
#define INF
Definition: energy_const.h:16
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:221
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:209
PRIVATE int E_ExtLoop(int type, int si1, int sj1, paramT *P)
Definition: exterior_loops.h:409
#define VRNA_HC_CONTEXT_MB_LOOP_ENC
Hard constraints flag, base pair is enclosed in a multi branch loop.
Definition: constraints.h:213
Various functions related to G-quadruplex computations.
char * ptype
Pair type array.
Definition: data_structures.h:371
char * matrix
Upper triangular matrix encoding where a base pair or unpaired nucleotide is allowed.
Definition: data_structures.h:301
Here all all declarations of the global variables used throughout RNAlib.
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:206
int circ
Assume RNA to be circular instead of linear.
Definition: model.h:220
int ** free_energies
Energy contribution for unpaired sequence stretches.
Definition: data_structures.h:325