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, *ggg;
287 short si, sj, *S, *S1;
297 type = (
unsigned char)ptype[ij];
299 S = vc->sequence_encoding2;
307 energy += P->mismatchI[type][si][sj];
310 energy += P->TerminalAU;
314 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
315 minl = j - i + p -
MAXLOOP - 2;
316 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
317 minl =
MAX2(c0, minl);
319 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
320 maxl =
MIN2(c0, maxl);
321 for (q = minl; q < maxl; q++) {
325 if (en == energy + ggg[idx[q] + p] + P->internal_loop[j - q - 1])
326 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
332 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
341 minl = j - i + p - MAXLOOP - 2;
342 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
343 minl =
MAX2(c0, minl);
345 maxl = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
346 maxl =
MIN2(c0, maxl);
347 for (q = minl; q < maxl; q++) {
351 if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1 + j - q - 1])
352 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
359 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
368 if (en == energy + ggg[idx[q] + p] + P->internal_loop[l1])
369 return vrna_BT_gquad_mfe(vc, p, q, bp_stack, stack_count);
405 int energy,
dangles, k, l, maxl, minl, c0, l1;
414 energy += P->mismatchI[type][si][sj];
417 energy += P->TerminalAU;
421 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
422 minl = j - i + k - MAXLOOP - 2;
423 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
424 minl =
MAX2(c0, minl);
426 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
427 maxl =
MIN2(c0, maxl);
428 for (l = minl; l < maxl; l++) {
432 if (c == energy + ggg[index[l] + k] + P->internal_loop[j - l - 1]) {
442 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
451 minl = j - i + k - MAXLOOP - 2;
452 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
453 minl =
MAX2(c0, minl);
455 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
456 maxl =
MIN2(c0, maxl);
457 for (l = minl; l < maxl; l++) {
461 if (c == energy + ggg[index[l] + k] + P->internal_loop[l1 + j - l - 1]) {
472 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
481 if (c == energy + ggg[index[l] + k] + P->internal_loop[l1]) {
493 backtrack_GQuad_IntLoop_comparative(
int c,
507 int energy,
dangles, k, l, maxl, minl, c0, l1, ss, tt;
512 for (ss = 0; ss < n_seq; ss++) {
518 energy += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
521 energy += P->TerminalAU;
525 if (S_cons[k] == 3) {
526 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
527 minl = j - i + k - MAXLOOP - 2;
528 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
529 minl =
MAX2(c0, minl);
531 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
532 maxl =
MIN2(c0, maxl);
533 for (l = minl; l < maxl; l++) {
537 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[j - l - 1]) {
547 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
556 minl = j - i + k - MAXLOOP - 2;
557 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
558 minl =
MAX2(c0, minl);
560 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
561 maxl =
MIN2(c0, maxl);
562 for (l = minl; l < maxl; l++) {
566 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1 + j - l - 1]) {
577 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
586 if (c == energy + ggg[index[l] + k] + n_seq * P->internal_loop[l1]) {
625 int energy,
dangles, k, l, maxl, minl, c0, l1;
634 energy += P->mismatchI[type][si][sj];
637 energy += P->TerminalAU;
641 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
642 minl = j - i + k - MAXLOOP - 2;
643 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
644 minl =
MAX2(c0, minl);
646 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
647 maxl =
MIN2(c0, maxl);
648 for (l = minl; l < maxl; l++) {
652 if (c == energy + ggg[k][l - k] + P->internal_loop[j - l - 1]) {
662 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
671 minl = j - i + k - MAXLOOP - 2;
672 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
673 minl =
MAX2(c0, minl);
675 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
676 maxl =
MIN2(c0, maxl);
677 for (l = minl; l < maxl; l++) {
681 if (c == energy + ggg[k][l - k] + P->internal_loop[l1 + j - l - 1]) {
692 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
701 if (c == energy + ggg[k][l - k] + P->internal_loop[l1]) {
713 backtrack_GQuad_IntLoop_L_comparative(
int c,
732 int mm, dangle_model, k, l, maxl, minl, c0, l1, ss, tt;
737 for (ss = 0; ss < n_seq; ss++) {
740 if (dangle_model == 2)
741 mm += P->mismatchI[tt][S3[ss][i]][S5[ss][j]];
748 k < j - VRNA_GQUAD_MIN_BOX_SIZE;
757 minl = j - i + k - MAXLOOP - 2;
758 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
759 minl =
MAX2(c0, minl);
761 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
762 maxl =
MIN2(c0, maxl);
763 for (l = minl; l < maxl; l++) {
767 c0 = mm + ggg[k][l - k] + n_seq * P->internal_loop[l1 + j - l - 1];
776 if (S_cons[k] == 3) {
777 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
778 minl = j - i + k - MAXLOOP - 2;
779 c0 = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
780 minl =
MAX2(c0, minl);
782 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
783 maxl =
MIN2(c0, maxl);
784 for (l = minl; l < maxl; l++) {
788 if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[j - l - 1]) {
798 if (S_cons[l] == 3) {
799 for (k = i + 4; k < j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
807 if (c == mm + ggg[k][l - k] + n_seq * P->internal_loop[l1]) {
821 E_GQuad_IntLoop(
int i,
829 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
838 energy += P->mismatchI[type][si][sj];
841 energy += P->TerminalAU;
847 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
848 minq = j - i + p - MAXLOOP - 2;
849 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
850 minq =
MAX2(c0, minq);
852 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
853 maxq =
MIN2(c0, maxq);
854 for (q = minq; q < maxq; q++) {
858 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
865 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
874 minq = j - i + p - MAXLOOP - 2;
875 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
876 minq =
MAX2(c0, minq);
878 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
879 maxq =
MIN2(c0, maxq);
880 for (q = minq; q < maxq; q++) {
884 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
892 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
901 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
908 en1 = energy + P->dangle5[type][si];
909 en2 = energy + P->dangle5[type][sj];
910 en3 = energy + P->mismatchI[type][si][sj];
915 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
916 minq = j - i + p - MAXLOOP - 2;
917 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
918 minq =
MAX2(c0, minq);
920 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
921 maxq =
MIN2(c0, maxq);
922 for (q = minq; q < maxq; q++) {
926 c0 = en1 + ggg[index[q] + p] + P->internal_loop[j - q - 1];
932 for (p = i + 2; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
940 minq = j - i + p - MAXLOOP - 2;
941 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
942 minq =
MAX2(c0, minq);
944 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
945 maxq =
MIN2(c0, maxq);
946 for (q = minq; q < maxq; q++) {
950 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
957 for (p = i + 4; p < j - VRNA_GQUAD_MIN_BOX_SIZE; p++) {
965 c0 = en1 + ggg[index[q] + p] + P->internal_loop[l1 + 1];
979 E_GQuad_IntLoop_exhaustive(
int i,
990 int energy, *ge,
dangles, p, q, l1, minq, maxq, c0;
1000 energy += P->mismatchI[type][si][sj];
1003 energy += P->TerminalAU;
1012 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1013 minq = j - i + p - MAXLOOP - 2;
1014 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1015 minq =
MAX2(c0, minq);
1017 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1018 maxq =
MIN2(c0, maxq);
1019 for (q = minq; q < maxq; q++) {
1023 c0 = energy + ggg[index[q] + p] + P->internal_loop[j - q - 1];
1024 if (c0 <= threshold) {
1025 ge[cnt] = energy + P->internal_loop[j - q - 1];
1034 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1043 minq = j - i + p - MAXLOOP - 2;
1044 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1045 minq =
MAX2(c0, minq);
1047 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1048 maxq =
MIN2(c0, maxq);
1049 for (q = minq; q < maxq; q++) {
1053 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1 + j - q - 1];
1054 if (c0 <= threshold) {
1055 ge[cnt] = energy + P->internal_loop[l1 + j - q - 1];
1065 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1074 c0 = energy + ggg[index[q] + p] + P->internal_loop[l1];
1075 if (c0 <= threshold) {
1076 ge[cnt] = energy + P->internal_loop[l1];
1090 E_GQuad_IntLoop_L(
int i,
1098 int energy, ge,
dangles, p, q, l1, minq, maxq, c0;
1107 energy += P->mismatchI[type][si][sj];
1110 energy += P->TerminalAU;
1116 if (p < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1117 minq = j - i + p - MAXLOOP - 2;
1118 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1119 minq =
MAX2(c0, minq);
1121 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1122 maxq =
MIN2(c0, maxq);
1123 for (q = minq; q < maxq; q++) {
1127 c0 = energy + ggg[p][q - p] + P->internal_loop[j - q - 1];
1134 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1143 minq = j - i + p - MAXLOOP - 2;
1144 c0 = p + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1145 minq =
MAX2(c0, minq);
1147 maxq = p + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1148 maxq =
MIN2(c0, maxq);
1149 for (q = minq; q < maxq; q++) {
1153 c0 = energy + ggg[p][q - p] + P->internal_loop[l1 + j - q - 1];
1161 p < j - VRNA_GQUAD_MIN_BOX_SIZE;
1170 c0 = energy + ggg[p][q - p] + P->internal_loop[l1];
1180 exp_E_GQuad_IntLoop(
int i,
1189 int k, l, minl, maxl, u, r;
1197 qe = (
FLT_OR_DBL)pf->expmismatchI[type][si][sj];
1198 expintern = &(pf->expinternal[0]);
1205 if (k < j - VRNA_GQUAD_MIN_BOX_SIZE) {
1206 minl = j - MAXLOOP - 1;
1207 u = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1208 minl =
MAX2(u, minl);
1210 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1211 maxl =
MIN2(u, maxl);
1212 for (l = minl; l < maxl; l++) {
1216 if (G[index[k] - l] == 0.)
1228 k <= j - VRNA_GQUAD_MIN_BOX_SIZE;
1237 minl = j - i + k - MAXLOOP - 2;
1238 r = k + VRNA_GQUAD_MIN_BOX_SIZE - 1;
1239 minl =
MAX2(r, minl);
1240 maxl = k + VRNA_GQUAD_MAX_BOX_SIZE + 1;
1242 maxl =
MIN2(r, maxl);
1243 for (l = minl; l < maxl; l++) {
1247 if (G[index[k] - l] == 0.)
1253 * scale[u + j - l + 1];
1259 for (k = i + 4; k <= j - VRNA_GQUAD_MIN_BOX_SIZE; k++) {
1267 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: fold_compound.h:269
short * S_cons
Numerical encoding of the consensus sequence.
Definition: fold_compound.h:266
char * ptype
Pair type array.
Definition: fold_compound.h:224
short * sequence_encoding
Numerical encoding of the input sequence.
Definition: fold_compound.h:219
#define MAXLOOP
Definition: energy_const.h:29
vrna_md_t model_details
Model details to be used in the recursions.
Definition: params.h:94
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structure_utils.h:114
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: data_structures.h:43
The most basic data structure required by many functions throughout the RNAlib.
Definition: fold_compound.h:131
The datastructure that contains temperature scaled energy parameters.
Definition: params.h:56
#define MIN2(A, B)
Get the minimum of two comparable values.
Definition: utils.h:115
int parse_gquad(const char *struc, int *L, int l[3])
int * jindx
DP matrix accessor.
Definition: fold_compound.h:165
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:394
Various data structures and pre-processor macros.
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:177
#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
Definition: fold_compound.h:115
#define MAX2(A, B)
Get the maximum of two comparable values.
Definition: utils.h:120
vrna_param_t * params
The precomputed free energy contributions for each type of loop.
Definition: fold_compound.h:161
unsigned int n_seq
The number of sequences in the alignment.
Definition: fold_compound.h:260
vrna_mx_mfe_t * matrices
The MFE DP matrices.
Definition: fold_compound.h:158
Definition: fold_compound.h:114
int dangles
Specifies the dangle model used in any energy evaluation (0,1,2 or 3)
Definition: model.h:180
Base pair stack element.
Definition: data_structures.h:141
FLT_OR_DBL * pr
A pointer to the base pair probability matrix.
vrna_fc_type_e type
The type of the vrna_fold_compound_t.
Definition: fold_compound.h:136
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:614