1 #ifndef VIENNA_RNA_PACKAGE_EXTERIOR_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_EXTERIOR_LOOPS_H
10 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/constraints.h>
16 # define INLINE inline
25 #define ON_SAME_STRAND(I,J,C) (((I)>=(C))||((J)<(C)))
114 INLINE PRIVATE
int E_Stem(
int type,
150 int *idx = vc->
jindx;
151 char *ptype = vc->
ptype;
154 char *hard_constraints = vc->
hc->
matrix;
160 if((cp < 0) || (((i)>=cp)||((j)<cp))){
165 case 2:
if(hard_constraints[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP)
168 default:
if(hard_constraints[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP)
171 if(hard_constraints[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
172 type = vc->
ptype[ij];
177 if(hard_constraints[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
178 type = vc->
ptype[ij];
193 int en, i, j, ij, type;
194 int length = (int)vc->
length;
195 char *ptype = vc->
ptype;
197 int *indx = vc->
jindx;
210 for(i = 1; i <= turn + 1; i++){
213 if(sc && (f5[i] !=
INF))
214 if(sc->free_energies)
215 f5[i] += sc->free_energies[i][1];
222 switch(dangle_model){
224 case 0:
for(j=turn+2; j<=length; j++){
228 if(sc && (f5[j] !=
INF))
229 if(sc->free_energies)
230 f5[j] += sc->free_energies[j][1];
232 for (i=j-turn-1; i>1; i--){
234 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
240 f5[j] =
MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
244 en = f5[i-1] + c[ij] +
E_ExtLoop(ptype[ij], -1, -1, P);
245 f5[j] =
MIN2(f5[j], en);
250 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
254 f5[j] =
MIN2(f5[j], ggg[indx[j]+1]);
258 en = c[ij] +
E_ExtLoop(ptype[ij], -1, -1, P);
259 f5[j] =
MIN2(f5[j], en);
265 case 2:
for(j=turn+2; j<length; j++){
269 if(sc && (f5[j] !=
INF))
270 if(sc->free_energies)
271 f5[j] += sc->free_energies[j][1];
273 for (i=j-turn-1; i>1; i--){
275 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
281 f5[j] =
MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
285 en = f5[i-1] + c[ij] +
E_ExtLoop(ptype[ij], S[i-1], S[j+1], P);
286 f5[j] =
MIN2(f5[j], en);
290 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
294 f5[j] =
MIN2(f5[j], ggg[indx[j]+1]);
298 en = c[ij] +
E_ExtLoop(ptype[ij], -1, S[j+1], P);
299 f5[j] =
MIN2(f5[j], en);
303 f5[length] = f5[length-1];
304 if(sc && (f5[length] !=
INF))
305 if(sc->free_energies)
306 f5[length] += sc->free_energies[length][1];
308 for (i=length-turn-1; i>1; i--){
309 ij = indx[length] + i;
310 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
316 f5[length] =
MIN2(f5[length], f5[i-1] + ggg[indx[length]+i]);
320 en = f5[i-1] + c[ij] +
E_ExtLoop(ptype[ij], S[i-1], -1, P);
321 f5[length] =
MIN2(f5[length], en);
324 ij = indx[length] + 1;
325 if(!(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP))
329 f5[length] =
MIN2(f5[length], ggg[indx[length]+1]);
333 en = c[ij] +
E_ExtLoop(ptype[ij], -1, -1, P);
334 f5[length] =
MIN2(f5[length], en);
339 default:
for(j=turn+2; j<=length; j++){
343 if(sc && (f5[j] !=
INF))
344 if(sc->free_energies)
345 f5[j] += sc->free_energies[j][1];
347 for (i=j-turn-1; i>1; i--){
349 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
353 f5[j] =
MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
358 en = f5[i-1] + c[ij] +
E_ExtLoop(type, -1, -1, P);
359 f5[j] =
MIN2(f5[j], en);
363 if((f5[i-2] !=
INF) && c[ij] !=
INF){
364 en = f5[i-2] + c[ij] +
E_ExtLoop(type, S[i-1], -1, P);
367 if(sc->free_energies)
368 en += sc->free_energies[i-1][1];
370 f5[j] =
MIN2(f5[j], en);
375 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
379 if(f5[i - 1] !=
INF){
380 en = f5[i-1] + c[ij] +
E_ExtLoop(type, -1, S[j], P);
383 if(sc->free_energies)
384 en += sc->free_energies[j][1];
386 f5[j] =
MIN2(f5[j], en);
390 if(f5[i - 2] !=
INF){
391 en = f5[i-2] + c[ij] +
E_ExtLoop(type, S[i-1], S[j], P);
394 if(sc->free_energies)
395 en += sc->free_energies[i-1][1] + sc->free_energies[j][1];
397 f5[j] =
MIN2(f5[j], en);
405 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
408 f5[j] =
MIN2(f5[j], ggg[indx[j]+1]);
414 f5[j] =
MIN2(f5[j], en);
418 if(hc[ij] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
422 en = c[ij] +
E_ExtLoop(type, -1, S[j], P);
425 if(sc->free_energies)
426 en += sc->free_energies[j][1];
428 f5[j] =
MIN2(f5[j], en);
444 int d5 = (si1 >= 0) ? P->dangle5[type][si1] : 0;
445 int d3 = (sj1 >= 0) ? P->dangle3[type][sj1] : 0;
448 energy += P->TerminalAU;
450 if(si1 >= 0 && sj1 >= 0)
451 energy += (extLoop) ? P->mismatchExt[type][si1][sj1] : P->mismatchM[type][si1][sj1];
455 if(!extLoop) energy += P->MLintern[type];
466 if(si1 >= 0 && sj1 >= 0){
467 energy += P->mismatchExt[type][si1][sj1];
470 energy += P->dangle5[type][si1];
473 energy += P->dangle3[type][sj1];
477 energy += P->TerminalAU;
482 INLINE PRIVATE
double
490 double d5 = (si1 >= 0) ? P->expdangle5[type][si1] : 1.;
491 double d3 = (sj1 >= 0) ? P->expdangle3[type][sj1] : 1.;
493 if(si1 >= 0 && sj1 >= 0)
494 energy = (extLoop) ? P->expmismatchExt[type][si1][sj1] : P->expmismatchM[type][si1][sj1];
499 energy *= P->expTermAU;
501 if(!extLoop) energy *= P->expMLintern[type];
505 INLINE PRIVATE
double
512 if(si1 >= 0 && sj1 >= 0){
513 energy = P->expmismatchExt[type][si1][sj1];
516 energy = P->expdangle5[type][si1];
519 energy = P->expdangle3[type][sj1];
523 energy *= P->expTermAU;
536 int length, cp, fij, fi, jj, u, en, *my_f5, *my_c, *my_ggg, *idx, dangle_model, turn, with_gquad;
560 with_gquad = md->
gquad;
567 fi = (hc->
up_ext[jj]) ? my_f5[jj-1] :
INF;
587 switch(dangle_model){
589 for(u = jj - turn - 1; u >= 1; u--){
592 if(fij == my_f5[u - 1] + my_ggg[idx[jj] + u]){
595 vrna_BT_gquad_mfe(vc, u, jj, bp_stack, stack_count);
600 if(hc->
matrix[idx[jj] + u] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
601 type = (
unsigned char)ptype[idx[jj] + u];
602 en = my_c[idx[jj] + u];
603 if(!ON_SAME_STRAND(u, jj, cp))
605 if(fij ==
E_ExtLoop(type, -1, -1, P) + en + my_f5[u - 1]){
609 bp_stack[++(*stack_count)].i = u;
610 bp_stack[(*stack_count)].j = jj;
617 case 2: mm3 = ((jj<length) && ON_SAME_STRAND(jj, jj + 1, cp)) ? S1[jj+1] : -1;
618 for(u = jj - turn - 1; u >= 1; u--){
621 if(fij == my_f5[u - 1] + my_ggg[idx[jj] + u]){
624 vrna_BT_gquad_mfe(vc, u, jj, bp_stack, stack_count);
629 if(hc->
matrix[idx[jj] + u] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
630 mm5 = ((u > 1) && ON_SAME_STRAND(u - 1, u, cp)) ? S1[u - 1] : -1;
631 type = (
unsigned char)ptype[idx[jj] + u];
632 en = my_c[idx[jj] + u];
633 if(!ON_SAME_STRAND(u, jj, cp))
635 if(fij ==
E_ExtLoop(type, mm5, mm3, P) + en + my_f5[u - 1]){
639 bp_stack[++(*stack_count)].i = u;
640 bp_stack[(*stack_count)].j = jj;
647 default:
if(with_gquad){
648 if(fij == my_ggg[idx[jj] + 1]){
651 vrna_BT_gquad_mfe(vc, 1, jj, bp_stack, stack_count);
656 if(hc->
matrix[idx[jj] + 1] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
657 type = (
unsigned char)ptype[idx[jj] + 1];
658 en = my_c[idx[jj] + 1];
659 if(!ON_SAME_STRAND(1, jj, cp))
661 if(fij == en +
E_ExtLoop(type, -1, -1, P)){
665 bp_stack[++(*stack_count)].i = 1;
666 bp_stack[(*stack_count)].j = jj;
671 if(hc->
matrix[idx[jj - 1] + 1] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
673 if(ON_SAME_STRAND(jj - 1, jj, cp)){
675 type = (
unsigned char)ptype[idx[jj - 1] + 1];
676 en = my_c[idx[jj - 1] + 1];
680 if(!ON_SAME_STRAND(1, jj - 1, cp))
683 if(fij == en +
E_ExtLoop(type, -1, mm3, P)){
687 bp_stack[++(*stack_count)].i = 1;
688 bp_stack[(*stack_count)].j = jj - 1;
695 for(u = jj - turn - 1; u > 1; u--){
698 if(fij == my_f5[u - 1] + my_ggg[idx[jj] + u]){
701 vrna_BT_gquad_mfe(vc, u, jj, bp_stack, stack_count);
706 if(hc->
matrix[idx[jj] + u] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
707 type = (
unsigned char)ptype[idx[jj] + u];
708 en = my_c[idx[jj] + u];
709 if(!ON_SAME_STRAND(u, jj, cp))
712 if(fij == my_f5[u - 1] + en +
E_ExtLoop(type, -1, -1, P)){
716 bp_stack[++(*stack_count)].i = u;
717 bp_stack[(*stack_count)].j = jj;
721 if(ON_SAME_STRAND(u - 1, u, cp)){
727 if(fij == my_f5[u - 2] + en +
E_ExtLoop(type, mm5, -1, P)){
731 bp_stack[++(*stack_count)].i = u;
732 bp_stack[(*stack_count)].j = jj;
738 if(hc->
matrix[idx[jj-1] + u] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP){
740 if(ON_SAME_STRAND(jj - 1, jj, cp)){
742 type = (
unsigned char)ptype[idx[jj - 1] + u];
743 en = my_c[idx[jj - 1] + u];
744 if(!ON_SAME_STRAND(u, jj - 1, cp))
751 if(fij == my_f5[u - 1] + en +
E_ExtLoop(type, -1, mm3, P)){
755 bp_stack[++(*stack_count)].i = u;
756 bp_stack[(*stack_count)].j = jj - 1;
761 mm5 = ON_SAME_STRAND(u - 1, u, cp) ? S1[u - 1] : -1;
766 if(fij == my_f5[u - 2] + en +
E_ExtLoop(type, mm5, mm3, P)){
770 bp_stack[++(*stack_count)].i = u;
771 bp_stack[(*stack_count)].j = jj - 1;
PRIVATE double exp_E_Stem(int type, int si1, int sj1, int extLoop, vrna_exp_param_t *P)
Definition: exterior_loops.h:483
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
PRIVATE double exp_E_ExtLoop(int type, int si1, int sj1, vrna_exp_param_t *P)
Definition: exterior_loops.h:506
struct vrna_hc_t * hc
The hard constraints data structure used for structure prediction.
Definition: data_structures.h:716
int cutpoint
The position of the (cofold) cutpoint within the provided sequence. If there is no cutpoint...
Definition: data_structures.h:712
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
struct vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:721
int * jindx
DP matrix accessor.
Definition: data_structures.h:725
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:184
PRIVATE int E_Stem(int type, int si1, int sj1, int extLoop, vrna_param_t *P)
Definition: exterior_loops.h:437
int * up_ext
A linear array that holds the number of allowed unpaired nucleotides in an exterior loop...
Definition: constraints.h:394
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
PRIVATE int E_ExtLoop(int type, int si1, int sj1, vrna_param_t *P)
Definition: exterior_loops.h:460
#define VRNA_CONSTRAINT_CONTEXT_EXT_LOOP
Hard constraints flag, base pair in the exterior loop.
Definition: constraints.h:201
#define INF
Definition: energy_const.h:16
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:718
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
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
Here all all declarations of the global variables used throughout RNAlib.
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
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:86
int * f5
Energy of 5' end.
Definition: data_structures.h:426