RNAlib-2.2.0RC0
exterior_loops.h
Go to the documentation of this file.
1 #ifndef __VIENNA_RNA_PACKAGE_EXTERIOR_LOOPS_H__
2 #define __VIENNA_RNA_PACKAGE_EXTERIOR_LOOPS_H__
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <math.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <ViennaRNA/params.h>
10 #include <ViennaRNA/fold_vars.h>
11 #include <ViennaRNA/energy_par.h>
12 #include <ViennaRNA/constraints.h>
13 #include <ViennaRNA/gquad.h>
14 
15 #ifdef __GNUC__
16 # define INLINE inline
17 #else
18 # define INLINE
19 #endif
20 
44 INLINE PRIVATE int E_ExtLoop(int type,
45  int si1,
46  int sj1,
47  paramT *P);
48 
54 INLINE PRIVATE double exp_E_ExtLoop( int type,
55  int si1,
56  int sj1,
57  pf_paramT *P);
58 
104 INLINE PRIVATE int E_Stem( int type,
105  int si1,
106  int sj1,
107  int extLoop,
108  paramT *P);
109 
118 INLINE PRIVATE double exp_E_Stem(int type,
119  int si1,
120  int sj1,
121  int extLoop,
122  pf_paramT *P);
123 
124 
125 /*
126 #################################
127 # BEGIN OF FUNCTION DEFINITIONS #
128 #################################
129 */
130 
131 INLINE PRIVATE int
132 E_ext_loop( int i,
133  int j,
134  vrna_fold_compound *vc){
135 
136  int ij, en, e, type;
137 
138  int cp = vc->cutpoint;
139  short *S = vc->sequence_encoding;
140  int *idx = vc->jindx;
141  char *ptype = vc->ptype;
142  paramT *P = vc->params;
143  model_detailsT *md = &(P->model_details);
144  char *hard_constraints = vc->hc->matrix;
145 
146  e = INF;
147  ij = idx[j] + i;
148  type = ptype[ij];
149 
150  if((cp < 0) || (((i)>=cp)||((j)<cp))){ /* regular exterior loop */
151  switch(md->dangles){
152  case 0: if(hard_constraints[ij] & VRNA_HC_CONTEXT_EXT_LOOP)
153  e = E_ExtLoop(type, -1, -1, P);
154  break;
155  case 2: if(hard_constraints[ij] & VRNA_HC_CONTEXT_EXT_LOOP)
156  e = E_ExtLoop(type, S[i-1], S[j+1], P);
157  break;
158  default: if(hard_constraints[ij] & VRNA_HC_CONTEXT_EXT_LOOP)
159  e = E_ExtLoop(type, -1, -1, P);
160  ij = idx[j - 1] + i;
161  if(hard_constraints[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
162  type = vc->ptype[ij];
163  en = E_ExtLoop(type, -1, S[j], P);
164  e = MIN2(e, en);
165  }
166  ij = idx[j] + i + 1;
167  if(hard_constraints[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
168  type = vc->ptype[ij];
169  en = E_ExtLoop(type, S[i], -1, P);
170  e = MIN2(e, en);
171  }
172  break;
173  }
174  }
175 
176  return e;
177 }
178 
179 
180 INLINE PRIVATE void
181 E_ext_loop_5( vrna_fold_compound *vc){
182 
183  int en, i, j, ij, type;
184  int length = (int)vc->length;
185  char *ptype = vc->ptype;
186  short *S = vc->sequence_encoding;
187  int *indx = vc->jindx;
188  char *hc = vc->hc->matrix;
189  int *hc_up = vc->hc->up_ext;
190  soft_constraintT *sc = vc->sc;
191  int *f5 = vc->matrices->f5;
192  int *c = vc->matrices->c;
193  paramT *P = vc->params;
194  int dangle_model = P->model_details.dangles;
195  int *ggg = vc->matrices->ggg;
196  int with_gquad = P->model_details.gquad;
197  int turn = P->model_details.min_loop_size;
198 
199  f5[0] = 0;
200  for(i = 1; i <= turn + 1; i++){
201  if(hc_up[i]){
202  f5[i] = f5[i-1];
203  if(sc)
204  if(sc->free_energies)
205  f5[i] += sc->free_energies[i][1];
206  } else {
207  f5[i] = INF;
208  }
209  }
210 
211  /* duplicated code may be faster than conditions inside loop ;) */
212  switch(dangle_model){
213  /* dont use dangling end and mismatch contributions at all */
214  case 0: for(j=turn+2; j<=length; j++){
215  f5[j] = INF;
216  if(hc_up[j]){
217  f5[j] = f5[j-1];
218  if(sc)
219  if(sc->free_energies)
220  f5[j] += sc->free_energies[j][1];
221  }
222  for (i=j-turn-1; i>1; i--){
223  ij = indx[j]+i;
224  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) continue;
225 
226  if(with_gquad){
227  f5[j] = MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
228  }
229 
230  en = f5[i-1] + c[ij] + E_ExtLoop(ptype[ij], -1, -1, P);
231  f5[j] = MIN2(f5[j], en);
232  }
233  ij = indx[j] + 1;
234  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) continue;
235 
236  if(with_gquad){
237  f5[j] = MIN2(f5[j], ggg[indx[j]+1]);
238  }
239 
240  en = c[ij] + E_ExtLoop(ptype[ij], -1, -1, P);
241  f5[j] = MIN2(f5[j], en);
242  }
243  break;
244 
245  /* always use dangles on both sides */
246  case 2: for(j=turn+2; j<length; j++){
247  f5[j] = INF;
248  if(hc_up[j]){
249  f5[j] = f5[j-1];
250  if(sc)
251  if(sc->free_energies)
252  f5[j] += sc->free_energies[j][1];
253  }
254  for (i=j-turn-1; i>1; i--){
255  ij = indx[j] + i;
256  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) continue;
257 
258  if(with_gquad){
259  f5[j] = MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
260  }
261 
262  en = f5[i-1] + c[ij] + E_ExtLoop(ptype[ij], S[i-1], S[j+1], P);
263  f5[j] = MIN2(f5[j], en);
264  }
265  ij = indx[j] + 1;
266  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) continue;
267 
268  if(with_gquad){
269  f5[j] = MIN2(f5[j], ggg[indx[j]+1]);
270  }
271 
272  en = c[ij] + E_ExtLoop(ptype[ij], -1, S[j+1], P);
273  f5[j] = MIN2(f5[j], en);
274  }
275  if(hc_up[length]){
276  f5[length] = f5[length-1];
277  if(sc)
278  if(sc->free_energies)
279  f5[length] += sc->free_energies[length][1];
280  }
281  for (i=length-turn-1; i>1; i--){
282  ij = indx[length] + i;
283  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) continue;
284 
285  if(with_gquad){
286  f5[length] = MIN2(f5[length], f5[i-1] + ggg[indx[length]+i]);
287  }
288 
289  en = f5[i-1] + c[ij] + E_ExtLoop(ptype[ij], S[i-1], -1, P);
290  f5[length] = MIN2(f5[length], en);
291  }
292  ij = indx[length] + 1;
293  if(!(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP)) break;
294 
295  if(with_gquad){
296  f5[length] = MIN2(f5[length], ggg[indx[length]+1]);
297  }
298 
299  en = c[ij] + E_ExtLoop(ptype[ij], -1, -1, P);
300  f5[length] = MIN2(f5[length], en);
301  break;
302 
303  /* normal dangles, aka dangle_model = 1 || 3 */
304  default: for(j=turn+2; j<=length; j++){
305  f5[j] = INF;
306  if(hc_up[j]){
307  f5[j] = f5[j-1];
308  if(sc)
309  if(sc->free_energies)
310  f5[j] += sc->free_energies[j][1];
311  }
312  for (i=j-turn-1; i>1; i--){
313  ij = indx[j] + i;
314  if(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
315 
316  if(with_gquad){
317  f5[j] = MIN2(f5[j], f5[i-1] + ggg[indx[j]+i]);
318  }
319 
320  type = ptype[ij];
321  en = f5[i-1] + c[ij] + E_ExtLoop(type, -1, -1, P);
322  f5[j] = MIN2(f5[j], en);
323  if(hc_up[i-1]){
324  en = f5[i-2] + c[ij] + E_ExtLoop(type, S[i-1], -1, P);
325 
326  if(sc)
327  if(sc->free_energies)
328  en += sc->free_energies[i-1][1];
329 
330  f5[j] = MIN2(f5[j], en);
331  }
332  }
333  ij = indx[j-1] + i;
334  if(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
335  if(hc_up[j]){
336  type = ptype[ij];
337  en = f5[i-1] + c[ij] + E_ExtLoop(type, -1, S[j], P);
338 
339  if(sc)
340  if(sc->free_energies)
341  en += sc->free_energies[j][1];
342 
343  f5[j] = MIN2(f5[j], en);
344 
345  if(hc_up[i-1]){
346  en = f5[i-2] + c[ij] + E_ExtLoop(type, S[i-1], S[j], P);
347 
348  if(sc)
349  if(sc->free_energies)
350  en += sc->free_energies[i-1][1] + sc->free_energies[j][1];
351 
352  f5[j] = MIN2(f5[j], en);
353  }
354  }
355  }
356  }
357  ij = indx[j] + 1;
358  if(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
359 
360  if(with_gquad){
361  f5[j] = MIN2(f5[j], ggg[indx[j]+1]);
362  }
363 
364  type = ptype[ij];
365  en = c[ij] + E_ExtLoop(type, -1, -1, P);
366  f5[j] = MIN2(f5[j], en);
367  }
368  ij = indx[j-1] + 1;
369  if(hc[ij] & VRNA_HC_CONTEXT_EXT_LOOP){
370  if(hc_up[j]){
371  type = ptype[ij];
372  en = c[ij] + E_ExtLoop(type, -1, S[j], P);
373 
374  if(sc)
375  if(sc->free_energies)
376  en += sc->free_energies[j][1];
377 
378  f5[j] = MIN2(f5[j], en);
379  }
380  }
381  }
382  }
383 }
384 
385 INLINE PRIVATE int
386 E_Stem( int type,
387  int si1,
388  int sj1,
389  int extLoop,
390  paramT *P){
391 
392  int energy = 0;
393  int d5 = (si1 >= 0) ? P->dangle5[type][si1] : 0;
394  int d3 = (sj1 >= 0) ? P->dangle3[type][sj1] : 0;
395 
396  if(type > 2)
397  energy += P->TerminalAU;
398 
399  if(si1 >= 0 && sj1 >= 0)
400  energy += (extLoop) ? P->mismatchExt[type][si1][sj1] : P->mismatchM[type][si1][sj1];
401  else
402  energy += d5 + d3;
403 
404  if(!extLoop) energy += P->MLintern[type];
405  return energy;
406 }
407 
408 INLINE PRIVATE int
409 E_ExtLoop(int type,
410  int si1,
411  int sj1,
412  paramT *P){
413 
414  int energy = 0;
415  if(si1 >= 0 && sj1 >= 0){
416  energy += P->mismatchExt[type][si1][sj1];
417  }
418  else if (si1 >= 0){
419  energy += P->dangle5[type][si1];
420  }
421  else if (sj1 >= 0){
422  energy += P->dangle3[type][sj1];
423  }
424 
425  if(type > 2)
426  energy += P->TerminalAU;
427 
428  return energy;
429 }
430 
431 INLINE PRIVATE double
432 exp_E_Stem( int type,
433  int si1,
434  int sj1,
435  int extLoop,
436  pf_paramT *P){
437 
438  double energy = 1.0;
439  double d5 = (si1 >= 0) ? P->expdangle5[type][si1] : 1.;
440  double d3 = (sj1 >= 0) ? P->expdangle3[type][sj1] : 1.;
441 
442  if(si1 >= 0 && sj1 >= 0)
443  energy = (extLoop) ? P->expmismatchExt[type][si1][sj1] : P->expmismatchM[type][si1][sj1];
444  else
445  energy = d5 * d3;
446 
447  if(type > 2)
448  energy *= P->expTermAU;
449 
450  if(!extLoop) energy *= P->expMLintern[type];
451  return energy;
452 }
453 
454 INLINE PRIVATE double
455 exp_E_ExtLoop(int type,
456  int si1,
457  int sj1,
458  pf_paramT *P){
459 
460  double energy = 1.0;
461  if(si1 >= 0 && sj1 >= 0){
462  energy = P->expmismatchExt[type][si1][sj1];
463  }
464  else if(si1 >= 0){
465  energy = P->expdangle5[type][si1];
466  }
467  else if(sj1 >= 0){
468  energy = P->expdangle3[type][sj1];
469  }
470 
471  if(type > 2)
472  energy *= P->expTermAU;
473 
474  return energy;
475 }
476 
477 
478 #endif
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
PRIVATE double exp_E_Stem(int type, int si1, int sj1, int extLoop, pf_paramT *P)
Definition: exterior_loops.h:432
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
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: data_structures.h:225
PRIVATE double exp_E_ExtLoop(int type, int si1, int sj1, pf_paramT *P)
Definition: exterior_loops.h:455
Definition: data_structures.h:359
PRIVATE int E_Stem(int type, int si1, int sj1, int extLoop, paramT *P)
Definition: exterior_loops.h:386
#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
int * up_ext
A linear array that holds the number of allowed unpaired nucleotides in an exterior loop...
Definition: data_structures.h:304
PRIVATE int E_ExtLoop(int type, int si1, int sj1, paramT *P)
Definition: exterior_loops.h:409
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
#define VRNA_HC_CONTEXT_EXT_LOOP
Hard constraints flag, base pair in the exterior loop.
Definition: constraints.h:178
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