1 #ifndef VIENNA_RNA_PACKAGE_GQUAD_H 2 #define VIENNA_RNA_PACKAGE_GQUAD_H 37 int E_gquad_ali(
int i,
45 void E_gquad_ali_en(
int i,
73 int *get_gquad_ali_matrix(
short *S_cons,
84 int **get_gquad_L_matrix(
short *S,
96 void get_gquad_pattern_mfe(
short *S,
104 get_gquad_pattern_exhaustive(
short *S,
113 void get_gquad_pattern_pf(
short *S,
120 plist *get_plist_gquad_from_pr(
short *S,
129 plist *get_plist_gquad_from_pr_max(
short *S,
139 plist *get_plist_gquad_from_db(
const char *structure,
143 int get_gquad_count(
short *S,
148 int get_gquad_layer_count(
short *S,
153 void get_gquad_pattern_mfe_ali(
short **S,
172 int parse_gquad(
const char *struc,
int *L,
int l[3]);
186 INLINE PRIVATE
int backtrack_GQuad_IntLoop_comparative(
int c,
234 int l[3], L, a, n_seq;
241 S = vc->sequence_encoding2;
244 get_gquad_pattern_mfe(S, i, j, P, &L, l);
250 get_gquad_pattern_mfe_ali(vc->
S, vc->
S_cons, n_seq, i, j, P, &L, l);
256 for (a = 0; a < L; a++) {
257 bp_stack[++(*stack_count)].i = i + a;
258 bp_stack[(*stack_count)].j = i + a;
259 bp_stack[++(*stack_count)].i = i + L + l[0] + a;
260 bp_stack[(*stack_count)].j = i + L + l[0] + a;
261 bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + a;
262 bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + a;
263 bp_stack[++(*stack_count)].i = i + L + l[0] + L + l[1] + L + l[2] + a;
264 bp_stack[(*stack_count)].j = i + L + l[0] + L + l[1] + L + l[2] + a;
284 int energy,
dangles, *idx, ij, p, q, maxl, minl, c0, l1, *rtype, *ggg;
287 short si, sj, *S, *S1;
297 rtype = &(md->
rtype[0]);
298 type = rtype[(
unsigned char)ptype[ij]];
300 S = vc->sequence_encoding2;
308 energy += P->mismatchI[type][si][sj];
311 energy += P->TerminalAU;
315 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
316 minl = j - i + p -
MAXLOOP - 2;
317 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
318 minl =
MAX2(c0, minl);
320 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
321 maxl =
MIN2(c0, maxl);
322 for (q = minl; q < maxl; q++) {
326 if (en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1])
327 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
333 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
342 minl = j - i + p - MAXLOOP - 2;
343 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
344 minl =
MAX2(c0, minl);
346 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
347 maxl =
MIN2(c0, maxl);
348 for (q = minl; q < maxl; q++) {
352 if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1])
353 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
360 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
369 if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1])
370 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
406 int energy,
dangles, k, l, maxl, minl, c0, l1;
415 energy += P->mismatchI[type][si][sj];
418 energy += P->TerminalAU;
422 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
423 minl = j - i + k - MAXLOOP - 2;
424 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
425 minl =
MAX2(c0, minl);
427 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
428 maxl =
MIN2(c0, maxl);
429 for (l = minl; l < maxl; l++) {
433 if (c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]) {
443 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
452 minl = j - i + k - MAXLOOP - 2;
453 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
454 minl =
MAX2(c0, minl);
456 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
457 maxl =
MIN2(c0, maxl);
458 for (l = minl; l < maxl; l++) {
462 if (c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]) {
473 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
482 if (c == energy + ggg[index[l] + k] + P->internal_loop[l1]) {
494 backtrack_GQuad_IntLoop_comparative(
int c,
508 int energy,
dangles, k, l, maxl, minl, c0, l1, ss, tt;
513 for (ss = 0; ss < n_seq; ss++) {
519 energy += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
522 energy += P->TerminalAU;
526 if (S_cons[k] == 3) {
527 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
528 minl = j - i + k - MAXLOOP - 2;
529 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
530 minl =
MAX2(c0, minl);
532 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
533 maxl =
MIN2(c0, maxl);
534 for (l = minl; l < maxl; l++) {
538 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[j - l - 1]) {
548 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
557 minl = j - i + k - MAXLOOP - 2;
558 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
559 minl =
MAX2(c0, minl);
561 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
562 maxl =
MIN2(c0, maxl);
563 for (l = minl; l < maxl; l++) {
567 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1 + j - l - 1]) {
578 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
587 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1]) {
626 int energy,
dangles, k, l, maxl, minl, c0, l1;
635 energy += P->mismatchI[type][si][sj];
638 energy += P->TerminalAU;
642 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
643 minl = j - i + k - MAXLOOP - 2;
644 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
645 minl =
MAX2(c0, minl);
647 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
648 maxl =
MIN2(c0, maxl);
649 for (l = minl; l < maxl; l++) {
653 if (c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]) {
663 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
672 minl = j - i + k - MAXLOOP - 2;
673 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
674 minl =
MAX2(c0, minl);
676 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
677 maxl =
MIN2(c0, maxl);
678 for (l = minl; l < maxl; l++) {
682 if (c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]) {
693 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
702 if (c == energy + ggg[k][l - k] + P->internal_loop[l1]) {
714 backtrack_GQuad_IntLoop_L_comparative(
int c,
733 int mm, dangle_model, k, l, maxl, minl, c0, l1, ss, tt;
738 for (ss = 0; ss < n_seq; ss++) {
741 if (dangle_model == 2)
742 mm += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
749 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
758 minl = j - i + k - MAXLOOP - 2;
759 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
760 minl =
MAX2(c0, minl);
762 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
763 maxl =
MIN2(c0, maxl);
764 for (l = minl; l < maxl; l++) {
768 c0 = mm + ggg[k][l - k] + n_seq * P->internal_loop[l1 + j - l - 1];
777 if (S_cons[k] == 3) {
778 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
779 minl = j - i + k - MAXLOOP - 2;
780 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
781 minl =
MAX2(c0, minl);
783 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
784 maxl =
MIN2(c0, maxl);
785 for (l = minl; l < maxl; l++) {
789 if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[j - l - 1]) {
799 if (S_cons[l] == 3) {
800 for (k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
808 if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[l1]) {
822 E_GQuad_IntLoop(
int i,
830 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
839 energy += P->mismatchI[type][si][sj];
842 energy += P->TerminalAU;
848 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
849 minq = j - i + p - MAXLOOP - 2;
850 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
851 minq =
MAX2(c0, minq);
853 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
854 maxq =
MIN2(c0, maxq);
855 for (q = minq; q < maxq; q++) {
859 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
866 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
875 minq = j - i + p - MAXLOOP - 2;
876 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
877 minq =
MAX2(c0, minq);
879 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
880 maxq =
MIN2(c0, maxq);
881 for (q = minq; q < maxq; q++) {
885 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
893 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
902 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
909 en1 = energy + P->dangle5[type][si];
910 en2 = energy + P->dangle5[type][sj];
911 en3 = energy + P->mismatchI[type][si][sj];
916 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
917 minq = j - i + p - MAXLOOP - 2;
918 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
919 minq =
MAX2(c0, minq);
921 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
922 maxq =
MIN2(c0, maxq);
923 for (q = minq; q < maxq; q++) {
927 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
933 for (p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
941 minq = j - i + p - MAXLOOP - 2;
942 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
943 minq =
MAX2(c0, minq);
945 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
946 maxq =
MIN2(c0, maxq);
947 for (q = minq; q < maxq; q++) {
951 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
958 for (p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
966 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
980 E_GQuad_IntLoop_exhaustive(
int i,
991 int energy, *ge,
dangles, p, q, l1, minq, maxq, c0;
1001 energy += P->mismatchI[type][si][sj];
1004 energy += P->TerminalAU;
1013 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1014 minq = j - i + p - MAXLOOP - 2;
1015 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1016 minq =
MAX2(c0, minq);
1018 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1019 maxq =
MIN2(c0, maxq);
1020 for (q = minq; q < maxq; q++) {
1024 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1025 if (c0 <= threshold) {
1026 ge[cnt] = energy + P->internal_loop[j - q - 1];
1035 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1044 minq = j - i + p - MAXLOOP - 2;
1045 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1046 minq =
MAX2(c0, minq);
1048 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1049 maxq =
MIN2(c0, maxq);
1050 for (q = minq; q < maxq; q++) {
1054 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1055 if (c0 <= threshold) {
1056 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
1066 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1075 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
1076 if (c0 <= threshold) {
1077 ge[cnt] = energy + P->internal_loop[l1];
1091 E_GQuad_IntLoop_L(
int i,
1099 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
1108 energy += P->mismatchI[type][si][sj];
1111 energy += P->TerminalAU;
1117 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1118 minq = j - i + p - MAXLOOP - 2;
1119 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1120 minq =
MAX2(c0, minq);
1122 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1123 maxq =
MIN2(c0, maxq);
1124 for (q = minq; q < maxq; q++) {
1128 c0 = energy + ggg[p][q - p] + P->internal_loop[j - q - 1];
1135 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1144 minq = j - i + p - MAXLOOP - 2;
1145 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1146 minq =
MAX2(c0, minq);
1148 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1149 maxq =
MIN2(c0, maxq);
1150 for (q = minq; q < maxq; q++) {
1154 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
1162 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1171 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
1181 exp_E_GQuad_IntLoop(
int i,
1190 int k, l, minl, maxl, u, r;
1198 qe = (
FLT_OR_DBL)pf->expmismatchI[type][si][sj];
1199 expintern = &(pf->expinternal[0]);
1206 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1207 minl = j - MAXLOOP - 1;
1208 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1209 minl =
MAX2(u, minl);
1211 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1212 maxl =
MIN2(u, maxl);
1213 for (l = minl; l < maxl; l++) {
1217 if (G[index[k] - l] == 0.)
1229 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1238 minl = j - i + k - MAXLOOP - 2;
1239 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1240 minl =
MAX2(r, minl);
1241 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1243 maxl =
MIN2(r, maxl);
1244 for (l = minl; l < maxl; l++) {
1248 if (G[index[k] - l] == 0.)
1254 * scale[u + j - l + 1];
1260 for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1268 if (G[index[k] - l] == 0.)
void * vrna_alloc(unsigned size)
Allocate space safely.
short ** S
Numerical encoding of the sequences in the alignment.
Definition: data_structures.h:595
short * S_cons
Numerical encoding of the consensus sequence.
Definition: data_structures.h:592
char * ptype
Pair type array.
Definition: data_structures.h:550
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: data_structures.h:545
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:192
#define MAXLOOP
Definition: energy_const.h:29
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:95
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structure_utils.h:69
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:48
The most basic data structure required by many functions throughout the RNAlib.
Definition: data_structures.h:463
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:57
int parse_gquad(const char *struc, int *L, int l[3])
int * jindx
DP matrix accessor.
Definition: data_structures.h:491
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:395
Various data structures and pre-processor macros.
#define INF
Definition: energy_const.h:17
Functions to deal with sets of energy parameters.
The data structure that contains temperature scaled Boltzmann weights of the energy parameters...
Definition: params.h:101
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:189
Definition: data_structures.h:447
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:121
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: data_structures.h:487
unsigned int n_seq
The number of sequences in the alignment.
Definition: data_structures.h:586
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: data_structures.h:484
Definition: data_structures.h:446
Base pair stack element.
Definition: data_structures.h:229
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:116
int rtype[8]
Reverse base pair type array.
Definition: model.h:241
vrna_fc_type_e type
The type of the vrna_fold_compound_t.
Definition: data_structures.h:468
int dangles
Switch the energy model for dangling end contributions (0, 1, 2, 3)
int * get_gquad_matrix(short *S, vrna_param_t *P)
Get a triangular matrix prefilled with minimum free energy contributions of G-quadruplexes.
int * ggg
Energies of g-quadruplexes.
Definition: dp_matrices.h:72
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:615