RNAlib-2.2.9

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

interior_loops.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
2 #define VIENNA_RNA_PACKAGE_INTERIOR_LOOPS_H
3
4 #include <ViennaRNA/utils.h>
5 #include "ViennaRNA/energy_par.h"
6 #include <ViennaRNA/data_structures.h>
7 #include <ViennaRNA/params.h>
8 #include <ViennaRNA/constraints.h>
9
10 #ifdef __GNUC__
11 # define INLINE inline
12 #else
13 # define INLINE
14 #endif
15
16 #ifdef ON_SAME_STRAND
17 #undef ON_SAME_STRAND
18 #endif
19
20 #define ON_SAME_STRAND(I,J,C) (((I)>=(C))||((J)<(C)))
21
75 PRIVATE INLINE int E_IntLoop(int n1,
76 int n2,
77 int type,
78 int type_2,
79 int si1,
80 int sj1,
81 int sp1,
82 int sq1,
83 vrna_param_t *P);
84
104 PRIVATE INLINE FLT_OR_DBL exp_E_IntLoop(int u1,
105 int u2,
106 int type,
107 int type2,
108 short si1,
109 short sj1,
110 short sp1,
111 short sq1,
112 vrna_exp_param_t *P);
113
114
115 PRIVATE INLINE int E_IntLoop_Co(int type,
116 int type_2,
117 int i,
118 int j,
119 int p,
120 int q,
121 int cutpoint,
122 short si1,
123 short sj1,
124 short sp1,
125 short sq1,
126 int dangles,
127 vrna_param_t *P);
128
129
133 int E_stack(int i, int j, vrna_fold_compound_t *vc);
134
135 /*
136 #################################
137 # BEGIN OF FUNCTION DEFINITIONS #
138 #################################
139 */
140
141 /*
142 * ugly but fast interior loop evaluation
143 *
144 * Avoid including this function in your own code. It only serves
145 * as a fast inline block internally re-used throughout the RNAlib. It
146 * evalutes the free energy of interior loops in single sequences or sequence
147 * hybrids. Soft constraints are also applied if available.
148 *
149 * NOTE: do not include into doxygen reference manual!
150 */
151 PRIVATE INLINE int
152 ubf_eval_int_loop( int i,
153 int j,
154 int p,
155 int q,
156 int i1,
157 int j1,
158 int p1,
159 int q1,
160 short si,
161 short sj,
162 short sp,
163 short sq,
164 unsigned char type,
165 unsigned char type_2,
166 int *rtype,
167 int ij,
168 int cp,
169 vrna_param_t *P,
170 vrna_sc_t *sc){
171
172 int energy, u1, u2;
173
174 u1 = p1 - i;
175 u2 = j1 - q;
176
177 if((cp < 0) || (ON_SAME_STRAND(i, p, cp) && ON_SAME_STRAND(q, j, cp))){ /* regular interior loop */
178 energy = E_IntLoop(u1, u2, type, type_2, si, sj, sp, sq, P);
179 } else { /* interior loop like cofold structure */
180 short Si, Sj;
181 Si = ON_SAME_STRAND(i, i1, cp) ? si : -1;
182 Sj = ON_SAME_STRAND(j1, j, cp) ? sj : -1;
183 energy = E_IntLoop_Co(rtype[type], rtype[type_2],
184 i, j, p, q,
185 cp,
186 Si, Sj,
187 sp, sq,
188 P->model_details.dangles,
189 P);
190 }
191
192 /* add soft constraints */
193 if(sc){
194 if(sc->energy_up)
195 energy += sc->energy_up[i1][u1]
196 + sc->energy_up[q1][u2];
197
198 if(sc->energy_bp)
199 energy += sc->energy_bp[ij];
200
201 if(sc->energy_stack)
202 if(u1 + u2 == 0){
203 int a = sc->energy_stack[i]
204 + sc->energy_stack[p]
205 + sc->energy_stack[q]
206 + sc->energy_stack[j];
207 energy += a;
208 }
209 if(sc->f)
210 energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
211 }
212
213 return energy;
214
215 }
216
217 /*
218 * ugly but fast exterior interior loop evaluation
219 *
220 * Avoid including this function in your own code. It only serves
221 * as a fast inline block internally re-used throughout the RNAlib. It
222 * evalutes the free energy of interior loops in single sequences or sequence
223 * hybrids. Soft constraints are also applied if available.
224 *
225 * NOTE: do not include into doxygen reference manual!
226 */
227 PRIVATE INLINE int
228 ubf_eval_ext_int_loop(int i,
229 int j,
230 int p,
231 int q,
232 int i1,
233 int j1,
234 int p1,
235 int q1,
236 short si,
237 short sj,
238 short sp,
239 short sq,
240 unsigned char type,
241 unsigned char type_2,
242 int length,
243 vrna_param_t *P,
244 vrna_sc_t *sc){
245
246 int energy, u1, u2, u3;
247
248 u1 = i1;
249 u2 = p1 - j;
250 u3 = length - q;
251
252 energy = E_IntLoop(u2, u1 + u3, type, type_2, si, sj, sp, sq, P);
253
254 /* add soft constraints */
255 if(sc){
256 if(sc->energy_up)
257 energy += sc->energy_up[j1][u2]
258 + sc->energy_up[q1][u3]
259 + sc->energy_up[1][u1];
260
261 if(sc->energy_stack)
262 if(u1 + u2 + u3 == 0)
263 energy += sc->energy_stack[i]
264 + sc->energy_stack[p]
265 + sc->energy_stack[q]
266 + sc->energy_stack[j];
267
268 if(sc->f)
269 energy += sc->f(i, j, p, q, VRNA_DECOMP_PAIR_IL, sc->data);
270 }
271
272 return energy;
273
274 }
275
276 PRIVATE INLINE int
277 E_IntLoop(int n1,
278 int n2,
279 int type,
280 int type_2,
281 int si1,
282 int sj1,
283 int sp1,
284 int sq1,
285 vrna_param_t *P){
286
287 /* compute energy of degree 2 loop (stack bulge or interior) */
288 int nl, ns, u, energy;
289 energy = INF;
290
291 if (n1>n2) { nl=n1; ns=n2;}
292 else {nl=n2; ns=n1;}
293
294 if (nl == 0)
295 return P->stack[type][type_2]; /* stack */
296
297 if (ns==0) { /* bulge */
298 energy = (nl<=MAXLOOP)?P->bulge[nl]:
299 (P->bulge[30]+(int)(P->lxc*log(nl/30.)));
300 if (nl==1) energy += P->stack[type][type_2];
301 else {
302 if (type>2) energy += P->TerminalAU;
303 if (type_2>2) energy += P->TerminalAU;
304 }
305 return energy;
306 }
307 else { /* interior loop */
308 if (ns==1) {
309 if (nl==1) /* 1x1 loop */
310 return P->int11[type][type_2][si1][sj1];
311 if (nl==2) { /* 2x1 loop */
312 if (n1==1)
313 energy = P->int21[type][type_2][si1][sq1][sj1];
314 else
315 energy = P->int21[type_2][type][sq1][si1][sp1];
316 return energy;
317 }
318 else { /* 1xn loop */
319 energy = (nl+1<=MAXLOOP)?(P->internal_loop[nl+1]) : (P->internal_loop[30]+(int)(P->lxc*log((nl+1)/30.)));
320 energy += MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
321 energy += P->mismatch1nI[type][si1][sj1] + P->mismatch1nI[type_2][sq1][sp1];
322 return energy;
323 }
324 }
325 else if (ns==2) {
326 if(nl==2) { /* 2x2 loop */
327 return P->int22[type][type_2][si1][sp1][sq1][sj1];}
328 else if (nl==3){ /* 2x3 loop */
329 energy = P->internal_loop[5]+P->ninio[2];
330 energy += P->mismatch23I[type][si1][sj1] + P->mismatch23I[type_2][sq1][sp1];
331 return energy;
332 }
333
334 }
335 { /* generic interior loop (no else here!)*/
336 u = nl + ns;
337 energy = (u <= MAXLOOP) ? (P->internal_loop[u]) : (P->internal_loop[30]+(int)(P->lxc*log((u)/30.)));
338
339 energy += MIN2(MAX_NINIO, (nl-ns)*P->ninio[2]);
340
341 energy += P->mismatchI[type][si1][sj1] + P->mismatchI[type_2][sq1][sp1];
342 }
343 }
344 return energy;
345 }
346
347 PRIVATE INLINE FLT_OR_DBL
348 exp_E_IntLoop(int u1,
349 int u2,
350 int type,
351 int type2,
352 short si1,
353 short sj1,
354 short sp1,
355 short sq1,
356 vrna_exp_param_t *P){
357
358 int ul, us, no_close = 0;
359 double z = 0.;
360
361 if ((no_closingGU) && ((type2==3)||(type2==4)||(type==3)||(type==4)))
362 no_close = 1;
363
364 if (u1>u2) { ul=u1; us=u2;}
365 else {ul=u2; us=u1;}
366
367 if (ul==0) /* stack */
368 z = P->expstack[type][type2];
369 else if(!no_close){
370 if (us==0) { /* bulge */
371 z = P->expbulge[ul];
372 if (ul==1) z *= P->expstack[type][type2];
373 else {
374 if (type>2) z *= P->expTermAU;
375 if (type2>2) z *= P->expTermAU;
376 }
377 return (FLT_OR_DBL)z;
378 }
379 else if (us==1) {
380 if (ul==1){ /* 1x1 loop */
381 return (FLT_OR_DBL)(P->expint11[type][type2][si1][sj1]);
382 }
383 if (ul==2) { /* 2x1 loop */
384 if (u1==1)
385 return (FLT_OR_DBL)(P->expint21[type][type2][si1][sq1][sj1]);
386 else
387 return (FLT_OR_DBL)(P->expint21[type2][type][sq1][si1][sp1]);
388 }
389 else { /* 1xn loop */
390 z = P->expinternal[ul+us] * P->expmismatch1nI[type][si1][sj1] * P->expmismatch1nI[type2][sq1][sp1];
391 return (FLT_OR_DBL)(z * P->expninio[2][ul-us]);
392 }
393 }
394 else if (us==2) {
395 if(ul==2) /* 2x2 loop */
396 return (FLT_OR_DBL)(P->expint22[type][type2][si1][sp1][sq1][sj1]);
397 else if(ul==3){ /* 2x3 loop */
398 z = P->expinternal[5]*P->expmismatch23I[type][si1][sj1]*P->expmismatch23I[type2][sq1][sp1];
399 return (FLT_OR_DBL)(z * P->expninio[2][1]);
400 }
401 }
402 /* generic interior loop (no else here!)*/
403 z = P->expinternal[ul+us] * P->expmismatchI[type][si1][sj1] * P->expmismatchI[type2][sq1][sp1];
404 return (FLT_OR_DBL)(z * P->expninio[2][ul-us]);
405
406 }
407 return (FLT_OR_DBL)z;
408 }
409
410 PRIVATE INLINE int
411 E_IntLoop_Co( int type,
412 int type_2,
413 int i,
414 int j,
415 int p,
416 int q,
417 int cutpoint,
418 short si1,
419 short sj1,
420 short sp1,
421 short sq1,
422 int dangles,
423 vrna_param_t *P){
424
425 int energy, ci, cj, cp, cq, d3, d5, d5_2, d3_2, tmm, tmm_2;
426
427 energy = 0;
428 if(type > 2) energy += P->TerminalAU;
429 if(type_2 > 2) energy += P->TerminalAU;
430
431 if(!dangles) return energy;
432
433 ci = ON_SAME_STRAND(i, i + 1, cutpoint);
434 cj = ON_SAME_STRAND(j - 1, j, cutpoint);
435 cp = ON_SAME_STRAND(p - 1, p, cutpoint);
436 cq = ON_SAME_STRAND(q, q + 1, cutpoint);
437
438 d3 = ci ? P->dangle3[type][si1] : 0;
439 d5 = cj ? P->dangle5[type][sj1] : 0;
440 d5_2 = cp ? P->dangle5[type_2][sp1] : 0;
441 d3_2 = cq ? P->dangle3[type_2][sq1] : 0;
442
443 tmm = (cj && ci) ? P->mismatchExt[type][sj1][si1] : d5 + d3;
444 tmm_2 = (cp && cq) ? P->mismatchExt[type_2][sp1][sq1] : d5_2 + d3_2;
445
446 if(dangles == 2) return energy + tmm + tmm_2;
447
448 /* now we may have non-double dangles only */
449 if(i+2 < p){
450 if(q+2 < j){ energy += tmm + tmm_2;}
451 else if(q+2 == j){ energy += (cj && cq) ? MIN2(tmm + d5_2, tmm_2 + d3) : tmm + tmm_2;}
452 else energy += d3 + d5_2;
453 }
454 else if(i+2 == p){
455 if(q+2 < j){ energy += (ci && cp) ? MIN2(tmm + d3_2, tmm_2 + d5) : tmm + tmm_2;}
456 else if(q+2 == j){
457 energy += MIN2(tmm, MIN2(tmm_2, MIN2(d5 + d5_2, d3 + d3_2)));
458 }
459 else energy += MIN2(d3, d5_2);
460 }
461 else{
462 if(q+2 < j){ energy += d5 + d3_2;}
463 else if(q+2 == j){ energy += MIN2(d5, d3_2);}
464 }
465 return energy;
466 }
467
468 int
469 vrna_E_int_loop(vrna_fold_compound_t *vc,
470 int i,
471 int j);
472
473 FLT_OR_DBL
474 vrna_exp_E_int_loop(vrna_fold_compound_t *vc,
475 int i,
476 int j);
477
478 int
479 vrna_E_ext_int_loop(vrna_fold_compound_t *vc,
480 int i,
481 int j,
482 int *ip,
483 int *iq);
484
485 int
486 vrna_E_stack( vrna_fold_compound_t *vc,
487 int i,
488 int j);
489
490
491 int
492 E_IntLoop(int n1,
493 int n2,
494 int type,
495 int type_2,
496 int si1,
497 int sj1,
498 int sp1,
499 int sq1,
500 vrna_param_t *P);
501
502
503 FLT_OR_DBL
504 exp_E_IntLoop(int u1,
505 int u2,
506 int type,
507 int type2,
508 short si1,
509 short sj1,
510 short sp1,
511 short sq1,
512 vrna_exp_param_t *P);
513
514 int
515 E_IntLoop_Co( int type,
516 int type_2,
517 int i,
518 int j,
519 int p,
520 int q,
521 int cutpoint,
522 short si1,
523 short sj1,
524 short sp1,
525 short sq1,
526 int dangles,
527 vrna_param_t *P);
528
529
534 int
535 vrna_BT_stack(vrna_fold_compound_t *vc,
536 int *i,
537 int *j,
538 int *en,
539 vrna_bp_stack_t *bp_stack,
540 int *stack_count);
545 int
546 vrna_BT_int_loop( vrna_fold_compound_t *vc,
547 int *i,
548 int *j,
549 int en,
550 vrna_bp_stack_t *bp_stack,
551 int *stack_count);
552
553
559 #endif
E_IntLoop
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:277
MAXLOOP
#define MAXLOOP
Definition: energy_const.h:28
vrna_param_s::model_details
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:88
FLT_OR_DBL
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:39
vrna_fc_s
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:424
vrna_param_s
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:50
vrna_sc_s::energy_stack
int * energy_stack
Pseudo Energy contribution per base pair involved in a stack.
Definition: constraints_soft.h:117
vrna_sc_s::f
vrna_callback_sc_energy * f
A function pointer used for pseudo energy contribution in MFE calculations.
Definition: constraints_soft.h:121
utils.h
General utility- and helper-functions used throughout the ViennaRNA Package.
data_structures.h
vrna_sc_s
The soft constraints data structure.
Definition: constraints_soft.h:111
INF
#define INF
Definition: energy_const.h:16
params.h
vrna_exp_param_s
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:94
vrna_sc_s::energy_up
int ** energy_up
Energy contribution for stretches of unpaired nucleotides.
Definition: constraints_soft.h:112
VRNA_DECOMP_PAIR_IL
#define VRNA_DECOMP_PAIR_IL
Indicator for interior loop decomposition step.
Definition: constraints.h:80
vrna_md_s::dangles
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:191
vrna_bp_stack_s
Base pair stack element.
Definition: data_structures.h:192
constraints.h
Functions and data structures for constraining secondary structure predictions and evaluation...
vrna_sc_s::energy_bp
int * energy_bp
Energy contribution for base pairs.
Definition: constraints_soft.h:113
exp_E_IntLoop
PRIVATE FLT_OR_DBL 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:348
vrna_BT_stack
int vrna_BT_stack(vrna_fold_compound_t *vc, int *i, int *j, int *en, vrna_bp_stack_t *bp_stack, int *stack_count)
Backtrack a stacked pair closed by .
no_closingGU
int no_closingGU
GU allowed only inside stacks if set to 1.
MIN2
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:112
vrna_BT_int_loop
int vrna_BT_int_loop(vrna_fold_compound_t *vc, int *i, int *j, int en, vrna_bp_stack_t *bp_stack, int *stack_count)
Backtrack an interior loop closed by .
E_stack
int E_stack(int i, int j, vrna_fold_compound_t *vc)
Evaluate energy of a base pair stack closed by (i,j)
dangles
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
vrna_sc_s::data
void * data
A pointer to the data object provided for for pseudo energy contribution functions of the generic sof...
Definition: constraints_soft.h:138