1 #ifndef VIENNA_RNA_PACKAGE_GQUAD_H
2 #define VIENNA_RNA_PACKAGE_GQUAD_H
33 int E_gquad_ali(
int i,
41 void E_gquad_ali_en(
int i,
67 int *get_gquad_ali_matrix(
short *S_cons,
76 int **get_gquad_L_matrix(
short *S,
85 void get_gquad_pattern_mfe(
short *S,
93 get_gquad_pattern_exhaustive(
short *S,
101 void get_gquad_pattern_pf(
short *S,
108 plist *get_plist_gquad_from_pr(
short *S,
115 plist *get_plist_gquad_from_pr_max(
short *S,
125 plist *get_plist_gquad_from_db(
const char *structure,
128 int get_gquad_count(
short *S,
132 int get_gquad_layer_count(
short *S,
147 int parse_gquad(
const char *struc,
int *L,
int l[3]);
202 S = vc->sequence_encoding2;
205 get_gquad_pattern_mfe(S, i, j, P, &L, l);
210 bp_stack[++(*stack_count)].i = i+a;
211 bp_stack[(*stack_count)].j = i+a;
212 bp_stack[++(*stack_count)].i = i+L+l[0]+a;
213 bp_stack[(*stack_count)].j = i+L+l[0]+a;
214 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+a;
215 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+a;
216 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+L+l[2]+a;
217 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+L+l[2]+a;
233 int energy,
dangles, *idx, ij, p, q, maxl, minl, c0, l1, *rtype, *ggg;
236 short si, sj, *S, *S1;
246 rtype = &(md->
rtype[0]);
247 type = rtype[(
unsigned char)ptype[ij]];
249 S = vc->sequence_encoding2;
257 energy += P->mismatchI[type][si][sj];
260 energy += P->TerminalAU;
264 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
265 minl = j - i + p -
MAXLOOP - 2;
266 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
267 minl =
MAX2(c0, minl);
269 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
270 maxl =
MIN2(c0, maxl);
271 for(q = minl; q < maxl; q++){
272 if(S[q] != 3)
continue;
273 if(en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1]){
274 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
281 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
284 if(l1>MAXLOOP)
break;
285 if(S1[p] != 3)
continue;
286 minl = j - i + p - MAXLOOP - 2;
287 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
288 minl =
MAX2(c0, minl);
290 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
291 maxl =
MIN2(c0, maxl);
292 for(q = minl; q < maxl; q++){
293 if(S1[q] != 3)
continue;
294 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1]){
295 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
303 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
306 if(l1>MAXLOOP)
break;
307 if(S1[p] != 3)
continue;
308 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1]){
309 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
344 int energy,
dangles, k, l, maxl, minl, c0, l1;
353 energy += P->mismatchI[type][si][sj];
356 energy += P->TerminalAU;
360 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
361 minl = j - i + k - MAXLOOP - 2;
362 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
363 minl =
MAX2(c0, minl);
365 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
366 maxl =
MIN2(c0, maxl);
367 for(l = minl; l < maxl; l++){
368 if(S[l] != 3)
continue;
369 if(c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]){
378 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
381 if(l1>MAXLOOP)
break;
382 if(S[k] != 3)
continue;
383 minl = j - i + k - MAXLOOP - 2;
384 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
385 minl =
MAX2(c0, minl);
387 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
388 maxl =
MIN2(c0, maxl);
389 for(l = minl; l < maxl; l++){
390 if(S[l] != 3)
continue;
391 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]){
401 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
404 if(l1>MAXLOOP)
break;
405 if(S[k] != 3)
continue;
406 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1]){
442 int energy,
dangles, k, l, maxl, minl, c0, l1;
451 energy += P->mismatchI[type][si][sj];
454 energy += P->TerminalAU;
458 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
459 minl = j - i + k - MAXLOOP - 2;
460 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
461 minl =
MAX2(c0, minl);
463 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
464 maxl =
MIN2(c0, maxl);
465 for(l = minl; l < maxl; l++){
466 if(S[l] != 3)
continue;
467 if(c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]){
476 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
479 if(l1>MAXLOOP)
break;
480 if(S[k] != 3)
continue;
481 minl = j - i + k - MAXLOOP - 2;
482 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
483 minl =
MAX2(c0, minl);
485 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
486 maxl =
MIN2(c0, maxl);
487 for(l = minl; l < maxl; l++){
488 if(S[l] != 3)
continue;
489 if(c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]){
499 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
502 if(l1>MAXLOOP)
break;
503 if(S[k] != 3)
continue;
504 if(c == energy + ggg[k][l - k] + P->internal_loop[l1]){
515 E_GQuad_IntLoop(
int i,
523 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
532 energy += P->mismatchI[type][si][sj];
535 energy += P->TerminalAU;
541 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
542 minq = j - i + p - MAXLOOP - 2;
543 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
544 minq =
MAX2(c0, minq);
546 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
547 maxq =
MIN2(c0, maxq);
548 for(q = minq; q < maxq; q++){
549 if(S[q] != 3)
continue;
550 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
557 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
560 if(l1>MAXLOOP)
break;
561 if(S[p] != 3)
continue;
562 minq = j - i + p - MAXLOOP - 2;
563 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
564 minq =
MAX2(c0, minq);
566 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
567 maxq =
MIN2(c0, maxq);
568 for(q = minq; q < maxq; q++){
569 if(S[q] != 3)
continue;
570 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
578 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
581 if(l1>MAXLOOP)
break;
582 if(S[p] != 3)
continue;
583 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
590 en1 = energy + P->dangle5[type][si];
591 en2 = energy + P->dangle5[type][sj];
592 en3 = energy + P->mismatchI[type][si][sj];
597 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
598 minq = j - i + p - MAXLOOP - 2;
599 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
600 minq =
MAX2(c0, minq);
602 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
603 maxq =
MIN2(c0, maxq);
604 for(q = minq; q < maxq; q++){
605 if(S[q] != 3)
continue;
606 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
612 for(p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
614 if(l1>MAXLOOP)
break;
615 if(S[p] != 3)
continue;
616 minq = j - i + p - MAXLOOP - 2;
617 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
618 minq =
MAX2(c0, minq);
620 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
621 maxq =
MIN2(c0, maxq);
622 for(q = minq; q < maxq; q++){
623 if(S[q] != 3)
continue;
624 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
631 for(p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
633 if(l1>MAXLOOP)
break;
634 if(S[p] != 3)
continue;
635 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
648 E_GQuad_IntLoop_exhaustive(
int i,
659 int energy, *ge,
dangles, p, q, l1, minq, maxq, c0;
669 energy += P->mismatchI[type][si][sj];
672 energy += P->TerminalAU;
681 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
682 minq = j - i + p - MAXLOOP - 2;
683 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
684 minq =
MAX2(c0, minq);
686 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
687 maxq =
MIN2(c0, maxq);
688 for(q = minq; q < maxq; q++){
689 if(S[q] != 3)
continue;
690 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
692 ge[cnt] = energy + P->internal_loop[j - q - 1];
701 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
704 if(l1>MAXLOOP)
break;
705 if(S[p] != 3)
continue;
706 minq = j - i + p - MAXLOOP - 2;
707 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
708 minq =
MAX2(c0, minq);
710 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
711 maxq =
MIN2(c0, maxq);
712 for(q = minq; q < maxq; q++){
713 if(S[q] != 3)
continue;
714 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
716 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
726 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
729 if(l1>MAXLOOP)
break;
730 if(S[p] != 3)
continue;
731 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
733 ge[cnt] = energy + P->internal_loop[l1];
747 E_GQuad_IntLoop_L(
int i,
755 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
764 energy += P->mismatchI[type][si][sj];
767 energy += P->TerminalAU;
773 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
774 minq = j - i + p - MAXLOOP - 2;
775 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
776 minq =
MAX2(c0, minq);
778 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
779 maxq =
MIN2(c0, maxq);
780 for(q = minq; q < maxq; q++){
781 if(S[q] != 3)
continue;
782 c0 = energy + ggg[p][q-p] + P->internal_loop[j - q - 1];
789 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
792 if(l1>MAXLOOP)
break;
793 if(S[p] != 3)
continue;
794 minq = j - i + p - MAXLOOP - 2;
795 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
796 minq =
MAX2(c0, minq);
798 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
799 maxq =
MIN2(c0, maxq);
800 for(q = minq; q < maxq; q++){
801 if(S[q] != 3)
continue;
802 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
810 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
813 if(l1>MAXLOOP)
break;
814 if(S[p] != 3)
continue;
815 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
824 exp_E_GQuad_IntLoop(
int i,
832 int k, l, minl, maxl, u, r;
840 qe = (
FLT_OR_DBL)pf->expmismatchI[type][si][sj];
841 expintern = pf->expinternal;
848 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
849 minl = j - i + k - MAXLOOP - 2;
850 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
851 minl =
MAX2(u, minl);
853 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
854 maxl =
MIN2(u, maxl);
855 for(l = minl; l < maxl; l++){
856 if(S[l] != 3)
continue;
857 if(G[index[k]-l] == 0.)
continue;
858 q += qe * G[index[k]-l] * (
FLT_OR_DBL)expintern[j - l - 1];
865 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
868 if(u > MAXLOOP)
break;
869 if(S[k] != 3)
continue;
870 minl = j - i + k - MAXLOOP - 2;
871 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
872 minl =
MAX2(r, minl);
873 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
875 maxl =
MIN2(r, maxl);
876 for(l = minl; l < maxl; l++){
877 if(S[l] != 3)
continue;
878 if(G[index[k]-l] == 0.)
continue;
879 q += qe * G[index[k]-l] * (
FLT_OR_DBL)expintern[u + j - l - 1];
885 for(k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++){
888 if(S[k] != 3)
continue;
889 if(G[index[k]-l] == 0.)
continue;
890 q += qe * G[index[k]-l] * (
FLT_OR_DBL)expintern[u];
void * vrna_alloc(unsigned size)
Allocate space safely.
char * ptype
Pair type array.
Definition: data_structures.h:460
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:455
#define MAXLOOP
Definition: energy_const.h:28
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:88
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:39
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:390
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:50
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:112
int * jindx
DP matrix accessor.
Definition: data_structures.h:417
PRIVATE int backtrack_GQuad_IntLoop_L(int c, int i, int j, int type, short *S, int **ggg, int maxdist, int *p, int *q, vrna_param_t *P)
Definition: gquad.h:431
int rtype[8]
Reverse base pair type array.
Definition: model.h:240
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:187
#define INF
Definition: energy_const.h:16
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:94
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:117
this datastructure is used as input parameter in functions of PS_dot.h and others ...
Definition: data_structures.h:164
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:413
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:410
int * get_gquad_matrix(short *S, vrna_param_t *P)
Get a triangular matrix prefilled with minimum free energy contributions of G-quadruplexes.
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:190
Base pair stack element.
Definition: data_structures.h:192
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
int parse_gquad(const char *struc, int *L, int l[3])
PRIVATE int backtrack_GQuad_IntLoop(int c, int i, int j, int type, short *S, int *ggg, int *index, int *p, int *q, vrna_param_t *P)
Definition: gquad.h:333
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
int * ggg
Energies of g-quadruplexes.
Definition: dp_matrices.h:66