RNAlib-2.1.5

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

- File List
- Globals

gquad.h
Go to the documentation of this file.
1 #ifndef __VIENNA_RNA_PACKAGE_GQUAD_H__
2 #define __VIENNA_RNA_PACKAGE_GQUAD_H__
3
4 #include "data_structures.h"
5
6 #ifndef INLINE
7 #ifdef __GNUC__
8 # define INLINE inline
9 #else
10 # define INLINE
11 #endif
12 #endif
13
20 int E_gquad(int L,
21 int l[3],
22 paramT *P);
23
24 FLT_OR_DBL exp_E_gquad( int L,
25 int l[3],
26 pf_paramT *pf);
27
28 int E_gquad_ali(int i,
29 int L,
30 int l[3],
31 const short **S,
32 int n_seq,
33 paramT *P);
34
35
36 void E_gquad_ali_en( int i,
37 int L,
38 int l[3],
39 const short **S,
40 int n_seq,
41 int en[2],
42 paramT *P);
43
60 int *get_gquad_matrix(short *S, paramT *P);
61
62 int *get_gquad_ali_matrix(short *S_cons,
63 short **S,
64 int n_seq,
65 paramT *P);
66
67 FLT_OR_DBL *get_gquad_pf_matrix( short *S,
68 FLT_OR_DBL *scale,
69 pf_paramT *pf);
70
71 int **get_gquad_L_matrix( short *S,
72 int start,
73 int maxdist,
74 int **g,
75 paramT *P);
76
77 void get_gquad_pattern_mfe(short *S,
78 int i,
79 int j,
80 paramT *P,
81 int *L,
82 int l[3]);
83
84 void
85 get_gquad_pattern_exhaustive( short *S,
86 int i,
87 int j,
88 paramT *P,
89 int *L,
90 int *l,
91 int threshold);
92
93 void get_gquad_pattern_pf( short *S,
94 int i,
95 int j,
96 pf_paramT *pf,
97 int *L,
98 int l[3]);
99
100 plist *get_plist_gquad_from_pr( short *S,
101 int gi,
102 int gj,
103 FLT_OR_DBL *G,
104 FLT_OR_DBL *probs,
105 FLT_OR_DBL *scale,
106 pf_paramT *pf);
107 plist *get_plist_gquad_from_pr_max(short *S,
108 int gi,
109 int gj,
110 FLT_OR_DBL *G,
111 FLT_OR_DBL *probs,
112 FLT_OR_DBL *scale,
113 int *L,
114 int l[3],
115 pf_paramT *pf);
116
117 plist *get_plist_gquad_from_db( const char *structure,
118 float pr);
119
120 int get_gquad_count(short *S,
121 int i,
122 int j);
123
124 int get_gquad_layer_count(short *S,
125 int i,
126 int j);
127
128
139 int parse_gquad(const char *struc, int *L, int l[3]);
140
141
142
160 INLINE PRIVATE int backtrack_GQuad_IntLoop(int c,
161 int i,
162 int j,
163 int type,
164 short *S,
165 int *ggg,
166 int *index,
167 int *p,
168 int *q,
169 paramT *P){
170
171 int energy, dangles, k, l, maxl, minl, c0, l1;
172 short si, sj;
173
174 dangles = P->model_details.dangles;
175 si = S[i + 1];
176 sj = S[j - 1];
177 energy = 0;
178
179 if(dangles == 2)
180 energy += P->mismatchI[type][si][sj];
181
182 if(type > 2)
183 energy += P->TerminalAU;
184
185 k = i + 1;
186 if(S[k] == 3){
187 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
188 minl = j - i + k - MAXLOOP - 2;
189 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
190 minl = MAX2(c0, minl);
191 c0 = j - 3;
192 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
193 maxl = MIN2(c0, maxl);
194 for(l = minl; l < maxl; l++){
195 if(S[l] != 3) continue;
196 if(c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]){
197 *p = k; *q = l;
198 return 1;
199 }
200 }
201 }
202 }
203
204 for(k = i + 2;
205 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
206 k++){
207 l1 = k - i - 1;
208 if(l1>MAXLOOP) break;
209 if(S[k] != 3) continue;
210 minl = j - i + k - MAXLOOP - 2;
211 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
212 minl = MAX2(c0, minl);
213 c0 = j - 1;
214 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
215 maxl = MIN2(c0, maxl);
216 for(l = minl; l < maxl; l++){
217 if(S[l] != 3) continue;
218 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]){
219 *p = k; *q = l;
220 return 1;
221 }
222 }
223 }
224
225 l = j - 1;
226 if(S[l] == 3)
227 for(k = i + 4;
228 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
229 k++){
230 l1 = k - i - 1;
231 if(l1>MAXLOOP) break;
232 if(S[k] != 3) continue;
233 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1]){
234 *p = k; *q = l;
235 return 1;
236 }
237 }
238
239 return 0;
240 }
241
258 INLINE PRIVATE int backtrack_GQuad_IntLoop_L(int c,
259 int i,
260 int j,
261 int type,
262 short *S,
263 int **ggg,
264 int maxdist,
265 int *p,
266 int *q,
267 paramT *P){
268
269 int energy, dangles, k, l, maxl, minl, c0, l1;
270 short si, sj;
271
272 dangles = P->model_details.dangles;
273 si = S[i + 1];
274 sj = S[j - 1];
275 energy = 0;
276
277 if(dangles == 2)
278 energy += P->mismatchI[type][si][sj];
279
280 if(type > 2)
281 energy += P->TerminalAU;
282
283 k = i + 1;
284 if(S[k] == 3){
285 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
286 minl = j - i + k - MAXLOOP - 2;
287 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
288 minl = MAX2(c0, minl);
289 c0 = j - 3;
290 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
291 maxl = MIN2(c0, maxl);
292 for(l = minl; l < maxl; l++){
293 if(S[l] != 3) continue;
294 if(c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]){
295 *p = k; *q = l;
296 return 1;
297 }
298 }
299 }
300 }
301
302 for(k = i + 2;
303 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
304 k++){
305 l1 = k - i - 1;
306 if(l1>MAXLOOP) break;
307 if(S[k] != 3) continue;
308 minl = j - i + k - MAXLOOP - 2;
309 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
310 minl = MAX2(c0, minl);
311 c0 = j - 1;
312 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
313 maxl = MIN2(c0, maxl);
314 for(l = minl; l < maxl; l++){
315 if(S[l] != 3) continue;
316 if(c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]){
317 *p = k; *q = l;
318 return 1;
319 }
320 }
321 }
322
323 l = j - 1;
324 if(S[l] == 3)
325 for(k = i + 4;
326 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
327 k++){
328 l1 = k - i - 1;
329 if(l1>MAXLOOP) break;
330 if(S[k] != 3) continue;
331 if(c == energy + ggg[k][l - k] + P->internal_loop[l1]){
332 *p = k; *q = l;
333 return 1;
334 }
335 }
336
337 return 0;
338 }
339
340 INLINE PRIVATE
341 int
342 E_GQuad_IntLoop(int i,
343 int j,
344 int type,
345 short *S,
346 int *ggg,
347 int *index,
348 paramT *P){
349
350 int energy, ge, en1, en2, dangles, p, q, l1, minq, maxq;
351 int c0, c1, c2, c3, up, d53, d5, d3;
352 short si, sj;
353
354 dangles = P->model_details.dangles;
355 si = S[i + 1];
356 sj = S[j - 1];
357 energy = 0;
358
359 if(dangles == 2)
360 energy += P->mismatchI[type][si][sj];
361
362 if(type > 2)
363 energy += P->TerminalAU;
364
365 ge = INF;
366
367 p = i + 1;
368 if(S[p] == 3){
369 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
370 minq = j - i + p - MAXLOOP - 2;
371 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
372 minq = MAX2(c0, minq);
373 c0 = j - 3;
374 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
375 maxq = MIN2(c0, maxq);
376 for(q = minq; q < maxq; q++){
377 if(S[q] != 3) continue;
378 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
379 ge = MIN2(ge, c0);
380 }
381 }
382 }
383
384 for(p = i + 2;
385 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
386 p++){
387 l1 = p - i - 1;
388 if(l1>MAXLOOP) break;
389 if(S[p] != 3) continue;
390 minq = j - i + p - MAXLOOP - 2;
391 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
392 minq = MAX2(c0, minq);
393 c0 = j - 1;
394 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
395 maxq = MIN2(c0, maxq);
396 for(q = minq; q < maxq; q++){
397 if(S[q] != 3) continue;
398 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
399 ge = MIN2(ge, c0);
400 }
401 }
402
403 q = j - 1;
404 if(S[q] == 3)
405 for(p = i + 4;
406 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
407 p++){
408 l1 = p - i - 1;
409 if(l1>MAXLOOP) break;
410 if(S[p] != 3) continue;
411 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
412 ge = MIN2(ge, c0);
413 }
414
415 #if 0
416 /* here comes the additional stuff for the odd dangle models */
417 if(dangles % 1){
418 en1 = energy + P->dangle5[type][si];
419 en2 = energy + P->dangle5[type][sj];
420 en3 = energy + P->mismatchI[type][si][sj];
421
422 /* first case with 5' dangle (i.e. j-1) onto enclosing pair */
423 p = i + 1;
424 if(S[p] == 3){
425 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
426 minq = j - i + p - MAXLOOP - 2;
427 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
428 minq = MAX2(c0, minq);
429 c0 = j - 4;
430 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
431 maxq = MIN2(c0, maxq);
432 for(q = minq; q < maxq; q++){
433 if(S[q] != 3) continue;
434 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
435 ge = MIN2(ge, c0);
436 }
437 }
438 }
439
440 for(p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
441 l1 = p - i - 1;
442 if(l1>MAXLOOP) break;
443 if(S[p] != 3) continue;
444 minq = j - i + p - MAXLOOP - 2;
445 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
446 minq = MAX2(c0, minq);
447 c0 = j - 2;
448 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
449 maxq = MIN2(c0, maxq);
450 for(q = minq; q < maxq; q++){
451 if(S[q] != 3) continue;
452 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
453 ge = MIN2(ge, c0);
454 }
455 }
456
457 q = j - 2;
458 if(S[q] == 3)
459 for(p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
460 l1 = p - i - 1;
461 if(l1>MAXLOOP) break;
462 if(S[p] != 3) continue;
463 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
464 ge = MIN2(ge, c0);
465 }
466
467 /* second case with 3' dangle (i.e. i+1) onto enclosing pair */
468
469 }
470 #endif
471 return ge;
472 }
473
474 INLINE PRIVATE
475 int *
476 E_GQuad_IntLoop_exhaustive( int i,
477 int j,
478 int **p_p,
479 int **q_p,
480 int type,
481 short *S,
482 int *ggg,
483 int threshold,
484 int *index,
485 paramT *P){
486
487 int energy, *ge, en1, en2, dangles, p, q, l1, minq, maxq;
488 int c0, c1, c2, c3, up, d53, d5, d3;
489 short si, sj;
490 int cnt = 0;
491
492 dangles = P->model_details.dangles;
493 si = S[i + 1];
494 sj = S[j - 1];
495 energy = 0;
496
497 if(dangles == 2)
498 energy += P->mismatchI[type][si][sj];
499
500 if(type > 2)
501 energy += P->TerminalAU;
502
503 /* guess how many gquads are possible in interval [i+1,j-1] */
504 *p_p = (int *)space(sizeof(int) * 256);
505 *q_p = (int *)space(sizeof(int) * 256);
506 ge = (int *)space(sizeof(int) * 256);
507
508 p = i + 1;
509 if(S[p] == 3){
510 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
511 minq = j - i + p - MAXLOOP - 2;
512 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
513 minq = MAX2(c0, minq);
514 c0 = j - 3;
515 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
516 maxq = MIN2(c0, maxq);
517 for(q = minq; q < maxq; q++){
518 if(S[q] != 3) continue;
519 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
520 if(c0 <= threshold){
521 ge[cnt] = energy + P->internal_loop[j - q - 1];
522 (*p_p)[cnt] = p;
523 (*q_p)[cnt++] = q;
524 }
525 }
526 }
527 }
528
529 for(p = i + 2;
530 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
531 p++){
532 l1 = p - i - 1;
533 if(l1>MAXLOOP) break;
534 if(S[p] != 3) continue;
535 minq = j - i + p - MAXLOOP - 2;
536 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
537 minq = MAX2(c0, minq);
538 c0 = j - 1;
539 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
540 maxq = MIN2(c0, maxq);
541 for(q = minq; q < maxq; q++){
542 if(S[q] != 3) continue;
543 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
544 if(c0 <= threshold){
545 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
546 (*p_p)[cnt] = p;
547 (*q_p)[cnt++] = q;
548 }
549 }
550 }
551
552 q = j - 1;
553 if(S[q] == 3)
554 for(p = i + 4;
555 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
556 p++){
557 l1 = p - i - 1;
558 if(l1>MAXLOOP) break;
559 if(S[p] != 3) continue;
560 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
561 if(c0 <= threshold){
562 ge[cnt] = energy + P->internal_loop[l1];
563 (*p_p)[cnt] = p;
564 (*q_p)[cnt++] = q;
565 }
566 }
567
568
569 (*p_p)[cnt] = -1;
570
571 return ge;
572 }
573
574 INLINE PRIVATE
575 int
576 E_GQuad_IntLoop_L(int i,
577 int j,
578 int type,
579 short *S,
580 int **ggg,
581 int maxdist,
582 paramT *P){
583
584 int energy, ge, en1, en2, dangles, p, q, l1, minq, maxq;
585 int c0, c1, c2, c3, up, d53, d5, d3;
586 short si, sj;
587
588 dangles = P->model_details.dangles;
589 si = S[i + 1];
590 sj = S[j - 1];
591 energy = 0;
592
593 if(dangles == 2)
594 energy += P->mismatchI[type][si][sj];
595
596 if(type > 2)
597 energy += P->TerminalAU;
598
599 ge = INF;
600
601 p = i + 1;
602 if(S[p] == 3){
603 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
604 minq = j - i + p - MAXLOOP - 2;
605 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
606 minq = MAX2(c0, minq);
607 c0 = j - 3;
608 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
609 maxq = MIN2(c0, maxq);
610 for(q = minq; q < maxq; q++){
611 if(S[q] != 3) continue;
612 c0 = energy + ggg[p][q-p] + P->internal_loop[j - q - 1];
613 ge = MIN2(ge, c0);
614 }
615 }
616 }
617
618 for(p = i + 2;
619 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
620 p++){
621 l1 = p - i - 1;
622 if(l1>MAXLOOP) break;
623 if(S[p] != 3) continue;
624 minq = j - i + p - MAXLOOP - 2;
625 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
626 minq = MAX2(c0, minq);
627 c0 = j - 1;
628 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
629 maxq = MIN2(c0, maxq);
630 for(q = minq; q < maxq; q++){
631 if(S[q] != 3) continue;
632 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
633 ge = MIN2(ge, c0);
634 }
635 }
636
637 q = j - 1;
638 if(S[q] == 3)
639 for(p = i + 4;
640 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
641 p++){
642 l1 = p - i - 1;
643 if(l1>MAXLOOP) break;
644 if(S[p] != 3) continue;
645 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
646 ge = MIN2(ge, c0);
647 }
648
649 return ge;
650 }
651
652 INLINE PRIVATE
653 FLT_OR_DBL
654 exp_E_GQuad_IntLoop(int i,
655 int j,
656 int type,
657 short *S,
658 FLT_OR_DBL *G,
659 int *index,
660 pf_paramT *pf){
661
662 int k, l, minl, maxl, u, r;
663 FLT_OR_DBL q, qe, *expintern;
664 short si, sj;
665
666 q = 0;
667 si = S[i + 1];
668 sj = S[j - 1];
669 qe = pf->expmismatchI[type][si][sj];
670 expintern = pf->expinternal;
671
672 if(type > 2)
673 qe *= pf->expTermAU;
674
675 k = i + 1;
676 if(S[k] == 3){
677 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
678 minl = j - i + k - MAXLOOP - 2;
679 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
680 minl = MAX2(u, minl);
681 u = j - 3;
682 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
683 maxl = MIN2(u, maxl);
684 for(l = minl; l < maxl; l++){
685 if(S[l] != 3) continue;
686 if(G[index[k]-l] == 0.) continue;
687 q += qe * G[index[k]-l] * expintern[j - l - 1];
688 }
689 }
690 }
691
692
693 for(k = i + 2;
694 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
695 k++){
696 u = k - i - 1;
697 if(u > MAXLOOP) break;
698 if(S[k] != 3) continue;
699 minl = j - i + k - MAXLOOP - 2;
700 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
701 minl = MAX2(r, minl);
702 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
703 r = j - 1;
704 maxl = MIN2(r, maxl);
705 for(l = minl; l < maxl; l++){
706 if(S[l] != 3) continue;
707 if(G[index[k]-l] == 0.) continue;
708 q += qe * G[index[k]-l] * expintern[u + j - l - 1];
709 }
710 }
711
712 l = j - 1;
713 if(S[l] == 3)
714 for(k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++){
715 u = k - i - 1;
716 if(u>MAXLOOP) break;
717 if(S[k] != 3) continue;
718 if(G[index[k]-l] == 0.) continue;
719 q += qe * G[index[k]-l] * expintern[u];
720 }
721
722 return q;
723 }
724
725 #endif