1 #ifndef VIENNA_RNA_PACKAGE_GQUAD_H
2 #define VIENNA_RNA_PACKAGE_GQUAD_H
29 FLT_OR_DBL exp_E_gquad(
int L,
33 int E_gquad_ali(
int i,
41 void E_gquad_ali_en(
int i,
67 int *get_gquad_ali_matrix(
short *S_cons,
72 FLT_OR_DBL *get_gquad_pf_matrix(
short *S,
76 int **get_gquad_L_matrix(
short *S,
82 void get_gquad_pattern_mfe(
short *S,
90 get_gquad_pattern_exhaustive(
short *S,
98 void get_gquad_pattern_pf(
short *S,
105 plist *get_plist_gquad_from_pr(
short *S,
112 plist *get_plist_gquad_from_pr_max(
short *S,
122 plist *get_plist_gquad_from_db(
const char *structure,
125 int get_gquad_count(
short *S,
129 int get_gquad_layer_count(
short *S,
144 int parse_gquad(
const char *struc,
int *L,
int l[3]);
199 S = vc->sequence_encoding2;
202 get_gquad_pattern_mfe(S, i, j, P, &L, l);
207 bp_stack[++(*stack_count)].i = i+a;
208 bp_stack[(*stack_count)].j = i+a;
209 bp_stack[++(*stack_count)].i = i+L+l[0]+a;
210 bp_stack[(*stack_count)].j = i+L+l[0]+a;
211 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+a;
212 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+a;
213 bp_stack[++(*stack_count)].i = i+L+l[0]+L+l[1]+L+l[2]+a;
214 bp_stack[(*stack_count)].j = i+L+l[0]+L+l[1]+L+l[2]+a;
230 int energy,
dangles, *idx, ij, p, q, maxl, minl, c0, l1, *rtype, *ggg;
233 short si, sj, *S, *S1;
243 rtype = &(md->rtype[0]);
244 type = rtype[(
unsigned char)ptype[ij]];
246 S = vc->sequence_encoding2;
254 energy += P->mismatchI[type][si][sj];
257 energy += P->TerminalAU;
261 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
262 minl = j - i + p -
MAXLOOP - 2;
263 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
264 minl =
MAX2(c0, minl);
266 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
267 maxl =
MIN2(c0, maxl);
268 for(q = minl; q < maxl; q++){
269 if(S[q] != 3)
continue;
270 if(en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1]){
271 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
278 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
281 if(l1>MAXLOOP)
break;
282 if(S1[p] != 3)
continue;
283 minl = j - i + p - MAXLOOP - 2;
284 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
285 minl =
MAX2(c0, minl);
287 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
288 maxl =
MIN2(c0, maxl);
289 for(q = minl; q < maxl; q++){
290 if(S1[q] != 3)
continue;
291 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1]){
292 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
300 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
303 if(l1>MAXLOOP)
break;
304 if(S1[p] != 3)
continue;
305 if(en == energy + ggg[idx[q] + p] + P->internal_loop[l1]){
306 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
341 int energy,
dangles, k, l, maxl, minl, c0, l1;
350 energy += P->mismatchI[type][si][sj];
353 energy += P->TerminalAU;
357 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
358 minl = j - i + k - MAXLOOP - 2;
359 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
360 minl =
MAX2(c0, minl);
362 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
363 maxl =
MIN2(c0, maxl);
364 for(l = minl; l < maxl; l++){
365 if(S[l] != 3)
continue;
366 if(c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]){
375 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
378 if(l1>MAXLOOP)
break;
379 if(S[k] != 3)
continue;
380 minl = j - i + k - MAXLOOP - 2;
381 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
382 minl =
MAX2(c0, minl);
384 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
385 maxl =
MIN2(c0, maxl);
386 for(l = minl; l < maxl; l++){
387 if(S[l] != 3)
continue;
388 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]){
398 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
401 if(l1>MAXLOOP)
break;
402 if(S[k] != 3)
continue;
403 if(c == energy + ggg[index[l] + k] + P->internal_loop[l1]){
439 int energy,
dangles, k, l, maxl, minl, c0, l1;
448 energy += P->mismatchI[type][si][sj];
451 energy += P->TerminalAU;
455 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
456 minl = j - i + k - MAXLOOP - 2;
457 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
458 minl =
MAX2(c0, minl);
460 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
461 maxl =
MIN2(c0, maxl);
462 for(l = minl; l < maxl; l++){
463 if(S[l] != 3)
continue;
464 if(c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]){
473 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
476 if(l1>MAXLOOP)
break;
477 if(S[k] != 3)
continue;
478 minl = j - i + k - MAXLOOP - 2;
479 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
480 minl =
MAX2(c0, minl);
482 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
483 maxl =
MIN2(c0, maxl);
484 for(l = minl; l < maxl; l++){
485 if(S[l] != 3)
continue;
486 if(c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]){
496 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
499 if(l1>MAXLOOP)
break;
500 if(S[k] != 3)
continue;
501 if(c == energy + ggg[k][l - k] + P->internal_loop[l1]){
512 E_GQuad_IntLoop(
int i,
520 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
529 energy += P->mismatchI[type][si][sj];
532 energy += P->TerminalAU;
538 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
539 minq = j - i + p - MAXLOOP - 2;
540 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
541 minq =
MAX2(c0, minq);
543 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
544 maxq =
MIN2(c0, maxq);
545 for(q = minq; q < maxq; q++){
546 if(S[q] != 3)
continue;
547 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
554 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
557 if(l1>MAXLOOP)
break;
558 if(S[p] != 3)
continue;
559 minq = j - i + p - MAXLOOP - 2;
560 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
561 minq =
MAX2(c0, minq);
563 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
564 maxq =
MIN2(c0, maxq);
565 for(q = minq; q < maxq; q++){
566 if(S[q] != 3)
continue;
567 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
575 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
578 if(l1>MAXLOOP)
break;
579 if(S[p] != 3)
continue;
580 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
587 en1 = energy + P->dangle5[type][si];
588 en2 = energy + P->dangle5[type][sj];
589 en3 = energy + P->mismatchI[type][si][sj];
594 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
595 minq = j - i + p - MAXLOOP - 2;
596 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
597 minq =
MAX2(c0, minq);
599 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
600 maxq =
MIN2(c0, maxq);
601 for(q = minq; q < maxq; q++){
602 if(S[q] != 3)
continue;
603 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
609 for(p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
611 if(l1>MAXLOOP)
break;
612 if(S[p] != 3)
continue;
613 minq = j - i + p - MAXLOOP - 2;
614 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
615 minq =
MAX2(c0, minq);
617 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
618 maxq =
MIN2(c0, maxq);
619 for(q = minq; q < maxq; q++){
620 if(S[q] != 3)
continue;
621 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
628 for(p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++){
630 if(l1>MAXLOOP)
break;
631 if(S[p] != 3)
continue;
632 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
645 E_GQuad_IntLoop_exhaustive(
int i,
656 int energy, *ge,
dangles, p, q, l1, minq, maxq, c0;
666 energy += P->mismatchI[type][si][sj];
669 energy += P->TerminalAU;
678 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
679 minq = j - i + p - MAXLOOP - 2;
680 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
681 minq =
MAX2(c0, minq);
683 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
684 maxq =
MIN2(c0, maxq);
685 for(q = minq; q < maxq; q++){
686 if(S[q] != 3)
continue;
687 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
689 ge[cnt] = energy + P->internal_loop[j - q - 1];
698 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
701 if(l1>MAXLOOP)
break;
702 if(S[p] != 3)
continue;
703 minq = j - i + p - MAXLOOP - 2;
704 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
705 minq =
MAX2(c0, minq);
707 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
708 maxq =
MIN2(c0, maxq);
709 for(q = minq; q < maxq; q++){
710 if(S[q] != 3)
continue;
711 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
713 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
723 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
726 if(l1>MAXLOOP)
break;
727 if(S[p] != 3)
continue;
728 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
730 ge[cnt] = energy + P->internal_loop[l1];
744 E_GQuad_IntLoop_L(
int i,
752 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
761 energy += P->mismatchI[type][si][sj];
764 energy += P->TerminalAU;
770 if(p < j - VRNA_GQUAD_MIN_BOX_SIZE){
771 minq = j - i + p - MAXLOOP - 2;
772 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
773 minq =
MAX2(c0, minq);
775 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
776 maxq =
MIN2(c0, maxq);
777 for(q = minq; q < maxq; q++){
778 if(S[q] != 3)
continue;
779 c0 = energy + ggg[p][q-p] + P->internal_loop[j - q - 1];
786 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
789 if(l1>MAXLOOP)
break;
790 if(S[p] != 3)
continue;
791 minq = j - i + p - MAXLOOP - 2;
792 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
793 minq =
MAX2(c0, minq);
795 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
796 maxq =
MIN2(c0, maxq);
797 for(q = minq; q < maxq; q++){
798 if(S[q] != 3)
continue;
799 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
807 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
810 if(l1>MAXLOOP)
break;
811 if(S[p] != 3)
continue;
812 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
821 exp_E_GQuad_IntLoop(
int i,
829 int k, l, minl, maxl, u, r;
830 FLT_OR_DBL q, qe, *expintern;
836 qe = pf->expmismatchI[type][si][sj];
837 expintern = pf->expinternal;
844 if(k < j - VRNA_GQUAD_MIN_BOX_SIZE){
845 minl = j - i + k - MAXLOOP - 2;
846 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
847 minl =
MAX2(u, minl);
849 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
850 maxl =
MIN2(u, maxl);
851 for(l = minl; l < maxl; l++){
852 if(S[l] != 3)
continue;
853 if(G[index[k]-l] == 0.)
continue;
854 q += qe * G[index[k]-l] * expintern[j - l - 1];
861 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
864 if(u > MAXLOOP)
break;
865 if(S[k] != 3)
continue;
866 minl = j - i + k - MAXLOOP - 2;
867 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
868 minl =
MAX2(r, minl);
869 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
871 maxl =
MIN2(r, maxl);
872 for(l = minl; l < maxl; l++){
873 if(S[l] != 3)
continue;
874 if(G[index[k]-l] == 0.)
continue;
875 q += qe * G[index[k]-l] * expintern[u + j - l - 1];
881 for(k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++){
884 if(S[k] != 3)
continue;
885 if(G[index[k]-l] == 0.)
continue;
886 q += qe * G[index[k]-l] * expintern[u];
void * vrna_alloc(unsigned size)
Allocate space safely.
int * ggg
Energies of g-quadruplexes.
Definition: data_structures.h:432
#define MAXLOOP
Definition: energy_const.h:28
struct vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:721
int * jindx
DP matrix accessor.
Definition: data_structures.h:725
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:118
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:79
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:428
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:698
this datastructure is used as input parameter in functions of PS_dot.h and others ...
Definition: data_structures.h:45
#define INF
Definition: energy_const.h:16
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:123
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:718
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:172
char * ptype
Pair type array.
Definition: data_structures.h:749
Base pair.
Definition: data_structures.h:73
int * get_gquad_matrix(short *S, vrna_param_t *P)
Get a triangular matrix prefilled with minimum free energy contributions of G-quadruplexes.
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:41
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:169
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:330
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:744
The datastructure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:86