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,
86 void get_gquad_pattern_mfe(
short *S,
94 get_gquad_pattern_exhaustive(
short *S,
102 void get_gquad_pattern_pf(
short *S,
109 plist *get_plist_gquad_from_pr(
short *S,
116 plist *get_plist_gquad_from_pr_max(
short *S,
126 plist *get_plist_gquad_from_db(
const char *structure,
129 int get_gquad_count(
short *S,
133 int get_gquad_layer_count(
short *S,
148 int parse_gquad(
const char *struc,
int *L,
int l[3]);
203 S = vc->sequence_encoding2;
206 get_gquad_pattern_mfe(S, i, j, P, &L, l);
211 bp_stack[++(*stack_count)].i = i+a;
212 bp_stack[(*stack_count)].j = i+a;
213 bp_stack[++(*stack_count)].i = i+L+l[0]+a;
214 bp_stack[(*stack_count)].j = i+L+l[0]+a;
215 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+a;
216 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+a;
217 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+L+l[2]+a;
218 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+L+l[2]+a;
234 int energy,
dangles, *idx, ij, p, q, maxl, minl, c0, l1, *rtype, *ggg;
237 short si, sj, *S, *S1;
247 rtype = &(md->
rtype[0]);
248 type = rtype[(
unsigned char)ptype[ij]];
250 S = vc->sequence_encoding2;
258 energy += P->mismatchI[type][si][sj];
261 energy += P->TerminalAU;
265 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
266 minl = j - i + p -
MAXLOOP - 2;
267 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
268 minl =
MAX2(c0, minl);
270 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
271 maxl =
MIN2(c0, maxl);
272 for(q = minl; q < maxl; q++){
273 if(S[q] != 3)
continue;
274 if(en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1]){
275 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
282 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
285 if(l1>MAXLOOP)
break;
286 if(S1[p] != 3)
continue;
287 minl = j - i + p - MAXLOOP - 2;
288 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
289 minl =
MAX2(c0, minl);
291 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
292 maxl =
MIN2(c0, maxl);
293 for(q = minl; q < maxl; q++){
294 if(S1[q] != 3)
continue;
295 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1]){
296 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
304 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
307 if(l1>MAXLOOP)
break;
308 if(S1[p] != 3)
continue;
309 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1]){
310 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
345 int energy,
dangles, k, l, maxl, minl, c0, l1;
354 energy += P->mismatchI[type][si][sj];
357 energy += P->TerminalAU;
361 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
362 minl = j - i + k - MAXLOOP - 2;
363 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
364 minl =
MAX2(c0, minl);
366 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
367 maxl =
MIN2(c0, maxl);
368 for(l = minl; l < maxl; l++){
369 if(S[l] != 3)
continue;
370 if(c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]){
379 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
382 if(l1>MAXLOOP)
break;
383 if(S[k] != 3)
continue;
384 minl = j - i + k - MAXLOOP - 2;
385 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
386 minl =
MAX2(c0, minl);
388 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
389 maxl =
MIN2(c0, maxl);
390 for(l = minl; l < maxl; l++){
391 if(S[l] != 3)
continue;
392 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]){
402 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
405 if(l1>MAXLOOP)
break;
406 if(S[k] != 3)
continue;
407 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1]){
443 int energy,
dangles, k, l, maxl, minl, c0, l1;
452 energy += P->mismatchI[type][si][sj];
455 energy += P->TerminalAU;
459 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
460 minl = j - i + k - MAXLOOP - 2;
461 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
462 minl =
MAX2(c0, minl);
464 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
465 maxl =
MIN2(c0, maxl);
466 for(l = minl; l < maxl; l++){
467 if(S[l] != 3)
continue;
468 if(c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]){
477 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
480 if(l1>MAXLOOP)
break;
481 if(S[k] != 3)
continue;
482 minl = j - i + k - MAXLOOP - 2;
483 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
484 minl =
MAX2(c0, minl);
486 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
487 maxl =
MIN2(c0, maxl);
488 for(l = minl; l < maxl; l++){
489 if(S[l] != 3)
continue;
490 if(c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]){
500 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
503 if(l1>MAXLOOP)
break;
504 if(S[k] != 3)
continue;
505 if(c == energy + ggg[k][l - k] + P->internal_loop[l1]){
516 E_GQuad_IntLoop(
int i,
524 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
533 energy += P->mismatchI[type][si][sj];
536 energy += P->TerminalAU;
542 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
543 minq = j - i + p - MAXLOOP - 2;
544 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
545 minq =
MAX2(c0, minq);
547 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
548 maxq =
MIN2(c0, maxq);
549 for(q = minq; q < maxq; q++){
550 if(S[q] != 3)
continue;
551 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
558 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
561 if(l1>MAXLOOP)
break;
562 if(S[p] != 3)
continue;
563 minq = j - i + p - MAXLOOP - 2;
564 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
565 minq =
MAX2(c0, minq);
567 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
568 maxq =
MIN2(c0, maxq);
569 for(q = minq; q < maxq; q++){
570 if(S[q] != 3)
continue;
571 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
579 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
582 if(l1>MAXLOOP)
break;
583 if(S[p] != 3)
continue;
584 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
591 en1 = energy + P->dangle5[type][si];
592 en2 = energy + P->dangle5[type][sj];
593 en3 = energy + P->mismatchI[type][si][sj];
598 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
599 minq = j - i + p - MAXLOOP - 2;
600 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
601 minq =
MAX2(c0, minq);
603 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
604 maxq =
MIN2(c0, maxq);
605 for(q = minq; q < maxq; q++){
606 if(S[q] != 3)
continue;
607 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
613 for(p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
615 if(l1>MAXLOOP)
break;
616 if(S[p] != 3)
continue;
617 minq = j - i + p - MAXLOOP - 2;
618 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
619 minq =
MAX2(c0, minq);
621 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
622 maxq =
MIN2(c0, maxq);
623 for(q = minq; q < maxq; q++){
624 if(S[q] != 3)
continue;
625 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
632 for(p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
634 if(l1>MAXLOOP)
break;
635 if(S[p] != 3)
continue;
636 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
649 E_GQuad_IntLoop_exhaustive(
int i,
660 int energy, *ge,
dangles, p, q, l1, minq, maxq, c0;
670 energy += P->mismatchI[type][si][sj];
673 energy += P->TerminalAU;
682 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
683 minq = j - i + p - MAXLOOP - 2;
684 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
685 minq =
MAX2(c0, minq);
687 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
688 maxq =
MIN2(c0, maxq);
689 for(q = minq; q < maxq; q++){
690 if(S[q] != 3)
continue;
691 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
693 ge[cnt] = energy + P->internal_loop[j - q - 1];
702 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
705 if(l1>MAXLOOP)
break;
706 if(S[p] != 3)
continue;
707 minq = j - i + p - MAXLOOP - 2;
708 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
709 minq =
MAX2(c0, minq);
711 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
712 maxq =
MIN2(c0, maxq);
713 for(q = minq; q < maxq; q++){
714 if(S[q] != 3)
continue;
715 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
717 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
727 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
730 if(l1>MAXLOOP)
break;
731 if(S[p] != 3)
continue;
732 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
734 ge[cnt] = energy + P->internal_loop[l1];
748 E_GQuad_IntLoop_L(
int i,
756 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
765 energy += P->mismatchI[type][si][sj];
768 energy += P->TerminalAU;
774 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
775 minq = j - i + p - MAXLOOP - 2;
776 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
777 minq =
MAX2(c0, minq);
779 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
780 maxq =
MIN2(c0, maxq);
781 for(q = minq; q < maxq; q++){
782 if(S[q] != 3)
continue;
783 c0 = energy + ggg[p][q-p] + P->internal_loop[j - q - 1];
790 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
793 if(l1>MAXLOOP)
break;
794 if(S[p] != 3)
continue;
795 minq = j - i + p - MAXLOOP - 2;
796 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
797 minq =
MAX2(c0, minq);
799 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
800 maxq =
MIN2(c0, maxq);
801 for(q = minq; q < maxq; q++){
802 if(S[q] != 3)
continue;
803 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
811 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
814 if(l1>MAXLOOP)
break;
815 if(S[p] != 3)
continue;
816 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
825 exp_E_GQuad_IntLoop(
int i,
833 int k, l, minl, maxl, u, r;
841 qe = (
FLT_OR_DBL)pf->expmismatchI[type][si][sj];
842 expintern = pf->expinternal;
849 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
850 minl = j - i + k - MAXLOOP - 2;
851 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
852 minl =
MAX2(u, minl);
854 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
855 maxl =
MIN2(u, maxl);
856 for(l = minl; l < maxl; l++){
857 if(S[l] != 3)
continue;
858 if(G[index[k]-l] == 0.)
continue;
859 q += qe * G[index[k]-l] * (
FLT_OR_DBL)expintern[j - l - 1];
866 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
869 if(u > MAXLOOP)
break;
870 if(S[k] != 3)
continue;
871 minl = j - i + k - MAXLOOP - 2;
872 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
873 minl =
MAX2(r, minl);
874 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
876 maxl =
MIN2(r, maxl);
877 for(l = minl; l < maxl; l++){
878 if(S[l] != 3)
continue;
879 if(G[index[k]-l] == 0.)
continue;
880 q += qe * G[index[k]-l] * (
FLT_OR_DBL)expintern[u + j - l - 1];
886 for(k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++){
889 if(S[k] != 3)
continue;
890 if(G[index[k]-l] == 0.)
continue;
891 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:432
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:334
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