1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <ctype.h>
9 #include <string.h>
10 #include "ViennaRNA/fold_vars.h"
11 #include "ViennaRNA/params/default.h"
12 #include "ViennaRNA/datastructures/basic.h"
13 #include "ViennaRNA/params/basic.h"
14 #include "ViennaRNA/utils/basic.h"
15 #include "ViennaRNA/constraints/hard.h"
16 #include "ViennaRNA/constraints/soft.h"
17 #include "ViennaRNA/loops/external.h"
18 #include "ViennaRNA/gquad.h"
19 #include "ViennaRNA/structured_domains.h"
20 #include "ViennaRNA/unstructured_domains.h"
21 #include "ViennaRNA/alphabet.h"
22 #include "ViennaRNA/loops/hairpin.h"
23
24 #ifdef __GNUC__
25 # define INLINE inline
26 #else
27 # define INLINE
28 #endif
29
30 #include "hairpin_hc.inc"
31
32 /*
33 #################################
34 # PRIVATE FUNCTION DECLARATIONS #
35 #################################
36 */
37
38 /*
39 #################################
40 # BEGIN OF FUNCTION DEFINITIONS #
41 #################################
42 */
43
44 /**
45 * @brief Backtrack a hairpin loop closed by @f$ (i,j) @f$
46 *
47 * @note This function is polymorphic! The provided #vrna_fold_compound_t may be of type
48 * #VRNA_FC_TYPE_SINGLE or #VRNA_FC_TYPE_COMPARATIVE
49 *
50 */
51 PUBLIC int
vrna_BT_hp_loop(vrna_fold_compound_t * fc,int i,int j,int en,vrna_bp_stack_t * bp_stack,int * stack_count)52 vrna_BT_hp_loop(vrna_fold_compound_t *fc,
53 int i,
54 int j,
55 int en,
56 vrna_bp_stack_t *bp_stack,
57 int *stack_count)
58 {
59 int e, u;
60 vrna_sc_t *sc;
61
62 sc = NULL;
63
64 u = j - i - 1;
65
66 if (fc->hc->up_hp[i + 1] < u)
67 return 0;
68
69 e = vrna_E_hp_loop(fc, i, j);
70
71 if (e == en) {
72 switch (fc->type) {
73 case VRNA_FC_TYPE_SINGLE:
74 sc = fc->sc;
75 break;
76
77 case VRNA_FC_TYPE_COMPARATIVE:
78 if (fc->scs)
79 sc = fc->scs[0];
80
81 break;
82
83 default:
84 break;
85 }
86
87 if (sc) {
88 if (sc->bt) {
89 vrna_basepair_t *ptr, *aux_bps;
90 aux_bps = sc->bt(i, j, i, j, VRNA_DECOMP_PAIR_HP, sc->data);
91 for (ptr = aux_bps; ptr && ptr->i != 0; ptr++) {
92 bp_stack[++(*stack_count)].i = ptr->i;
93 bp_stack[(*stack_count)].j = ptr->j;
94 }
95 free(aux_bps);
96 }
97 }
98
99 return 1;
100 }
101
102 return 0;
103 }
104