1 #ifndef VIENNA_RNA_PACKAGE_CONSTRAINTS_HARD_H
2 #define VIENNA_RNA_PACKAGE_CONSTRAINTS_HARD_H
3 
4 #ifdef VRNA_WARN_DEPRECATED
5 # if defined(__clang__)
6 #  define DEPRECATED(func, msg) func __attribute__ ((deprecated("", msg)))
7 # elif defined(__GNUC__)
8 #  define DEPRECATED(func, msg) func __attribute__ ((deprecated(msg)))
9 # else
10 #  define DEPRECATED(func, msg) func
11 # endif
12 #else
13 # define DEPRECATED(func, msg) func
14 #endif
15 
16 
17 /**
18  *  @file       constraints/hard.h
19  *  @ingroup    hard_constraints
20  *  @brief      Functions and data structures for handling of secondary structure hard constraints
21  */
22 
23 /**
24  *  @addtogroup hard_constraints
25  *
26  *  @brief  This module covers all functionality for hard constraints in secondary
27  *          structure prediction
28  */
29 
30 /**
31  *  @brief Typename for the hard constraints data structure #vrna_hc_s
32  *  @ingroup  hard_constraints
33  */
34 typedef struct  vrna_hc_s vrna_hc_t;
35 
36 /**
37  *  @brief Typename for the single nucleotide hard constraint data structure #vrna_hc_up_s
38  *  @ingroup  hard_constraints
39  */
40 typedef struct vrna_hc_up_s vrna_hc_up_t;
41 
42 typedef struct vrna_hc_depot_s  vrna_hc_depot_t;
43 
44 #include <ViennaRNA/fold_compound.h>
45 #include <ViennaRNA/constraints/basic.h>
46 
47 /**
48  * @brief Callback to evaluate whether or not a particular decomposition step is contributing to the solution space
49  *
50  * @ingroup hard_constraints
51  *
52  * This is the prototype for callback functions used by the folding recursions to evaluate generic
53  * hard constraints. The first four parameters passed indicate the delimiting nucleotide positions
54  * of the decomposition, and the parameter @p denotes the decomposition step. The last parameter
55  * @p data is the auxiliary data structure associated to the hard constraints via vrna_hc_add_data(),
56  * or NULL if no auxiliary data was added.
57  *
58  * @callback
59  * @parblock
60  * This callback enables one to over-rule default hard constraints in secondary structure
61  * decompositions.
62  * @endparblock
63  *
64  * @see #VRNA_DECOMP_PAIR_HP, #VRNA_DECOMP_PAIR_IL, #VRNA_DECOMP_PAIR_ML, #VRNA_DECOMP_ML_ML_ML,
65  *      #VRNA_DECOMP_ML_STEM, #VRNA_DECOMP_ML_ML, #VRNA_DECOMP_ML_UP, #VRNA_DECOMP_ML_ML_STEM,
66  *      #VRNA_DECOMP_ML_COAXIAL, #VRNA_DECOMP_EXT_EXT, #VRNA_DECOMP_EXT_UP, #VRNA_DECOMP_EXT_STEM,
67  *      #VRNA_DECOMP_EXT_EXT_EXT, #VRNA_DECOMP_EXT_STEM_EXT, #VRNA_DECOMP_EXT_EXT_STEM,
68  *      #VRNA_DECOMP_EXT_EXT_STEM1, vrna_hc_add_f(), vrna_hc_add_data()
69  *
70  * @param i         Left (5') delimiter position of substructure
71  * @param j         Right (3') delimiter position of substructure
72  * @param k         Left delimiter of decomposition
73  * @param l         Right delimiter of decomposition
74  * @param d         Decomposition step indicator
75  * @param data      Auxiliary data
76  * @return          A non-zero value if the decomposition is valid, 0 otherwise
77  */
78 typedef unsigned char (vrna_callback_hc_evaluate)(int           i,
79                                                   int           j,
80                                                   int           k,
81                                                   int           l,
82                                                   unsigned char d,
83                                                   void          *data);
84 
85 /**
86  *  @brief  do not print the header information line
87  *  @deprecated   This mode is not supported anymore!
88  *
89  */
90 #define VRNA_CONSTRAINT_NO_HEADER         0
91 
92 /**
93  *  @brief  Flag for vrna_constraints_add() to indicate that constraint is passed in pseudo dot-bracket notation
94  *
95  *  @see vrna_constraints_add(), vrna_message_constraint_options(), vrna_message_constraint_options_all()
96  *
97  *  @ingroup  hard_constraints
98  *
99  */
100 #define VRNA_CONSTRAINT_DB                16384U
101 
102 /**
103  *  @brief Switch for dot-bracket structure constraint to enforce base pairs
104  *
105  *  This flag should be used to really enforce base pairs given in dot-bracket constraint rather than
106  *  just weakly-enforcing them.
107  *
108  *  @ingroup  hard_constraints
109  *
110  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
111  *        vrna_message_constraint_options_all()
112  */
113 #define VRNA_CONSTRAINT_DB_ENFORCE_BP           32768U
114 
115 /**
116  *  @brief  Flag that is used to indicate the pipe '|' sign in pseudo dot-bracket
117  *  notation of hard constraints.
118  *
119  *  Use this definition to indicate the pipe sign '|' (paired with another base)
120  *
121  *  @ingroup  hard_constraints
122  *
123  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
124  *        vrna_message_constraint_options_all()
125  */
126 #define VRNA_CONSTRAINT_DB_PIPE              65536U
127 
128 /**
129  *  @brief  dot '.' switch for structure constraints (no constraint at all)
130  *
131  *  @ingroup  hard_constraints
132  *
133  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
134  *        vrna_message_constraint_options_all()
135  */
136 #define VRNA_CONSTRAINT_DB_DOT               131072U
137 /**
138  *  @brief  'x' switch for structure constraint (base must not pair)
139  *
140  *  @ingroup  hard_constraints
141  *
142  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
143  *        vrna_message_constraint_options_all()
144  */
145 #define VRNA_CONSTRAINT_DB_X                 262144U
146 /**
147  *  @brief  angle brackets '<', '>' switch for structure constraint (paired downstream/upstream)
148  *
149  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
150  *        vrna_message_constraint_options_all()
151  */
152 #define VRNA_CONSTRAINT_DB_ANG_BRACK         524288U
153 /**
154  *  @brief  round brackets '(',')' switch for structure constraint (base i pairs base j)
155  *
156  *  @ingroup  hard_constraints
157  *
158  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
159  *        vrna_message_constraint_options_all()
160  */
161 #define VRNA_CONSTRAINT_DB_RND_BRACK         1048576U
162 
163 /**
164  *  @brief  Flag that is used to indicate the character 'l' in pseudo dot-bracket
165  *  notation of hard constraints.
166  *
167  *  Use this definition to indicate the usage of 'l' character (intramolecular pairs only)
168  *
169  *  @ingroup  hard_constraints
170  *
171  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
172  *        vrna_message_constraint_options_all()
173  */
174 #define VRNA_CONSTRAINT_DB_INTRAMOL    2097152U
175 
176 /**
177  *  @brief  Flag that is used to indicate the character 'e' in pseudo dot-bracket
178  *  notation of hard constraints.
179  *
180  *  Use this definition to indicate the usage of 'e' character (intermolecular pairs only)
181  *
182  *  @ingroup  hard_constraints
183  *
184  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
185  *        vrna_message_constraint_options_all()
186  */
187 #define VRNA_CONSTRAINT_DB_INTERMOL    4194304U
188 
189 /**
190  *  @brief '+' switch for structure constraint (base is involved in a gquad)
191  *
192  *  @ingroup  hard_constraints
193  *
194  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
195  *        vrna_message_constraint_options_all()
196  *
197  *  @warning  This flag is for future purposes only! No implementation recognizes it yet.
198  */
199 #define VRNA_CONSTRAINT_DB_GQUAD                8388608U
200 
201 #define VRNA_CONSTRAINT_DB_CANONICAL_BP         16777216U
202 
203 /**
204  *  @brief  Flag to indicate Washington University Secondary Structure (WUSS) notation of the hard constraint string
205  *
206  *  This secondary structure notation for RNAs is usually used as consensus secondary structure (SS_cons) entry
207  *  in Stockholm formatted files
208  *
209  *  @ingroup  hard_constraints
210  */
211 #define VRNA_CONSTRAINT_DB_WUSS                 33554432U
212 
213 
214 /**
215  *  @brief Switch for dot-bracket structure constraint with default symbols
216  *
217  *  This flag conveniently combines all possible symbols in dot-bracket notation
218  *  for hard constraints and #VRNA_CONSTRAINT_DB
219  *
220  *  @ingroup  hard_constraints
221  *
222  *  @see  vrna_hc_add_from_db(), vrna_constraints_add(), vrna_message_constraint_options(),
223  *        vrna_message_constraint_options_all()
224  */
225 #define VRNA_CONSTRAINT_DB_DEFAULT \
226   (VRNA_CONSTRAINT_DB \
227    | VRNA_CONSTRAINT_DB_PIPE \
228    | VRNA_CONSTRAINT_DB_DOT \
229    | VRNA_CONSTRAINT_DB_X \
230    | VRNA_CONSTRAINT_DB_ANG_BRACK \
231    | VRNA_CONSTRAINT_DB_RND_BRACK \
232    | VRNA_CONSTRAINT_DB_INTRAMOL \
233    | VRNA_CONSTRAINT_DB_INTERMOL \
234    | VRNA_CONSTRAINT_DB_GQUAD \
235   )
236 
237 /**
238  *  @brief  Hard constraints flag, base pair in the exterior loop
239  *
240  *  @ingroup  hard_constraints
241  *
242  */
243 #define VRNA_CONSTRAINT_CONTEXT_EXT_LOOP      (unsigned char)0x01
244 
245 /**
246  *  @brief  Hard constraints flag, base pair encloses hairpin loop
247  *
248  *  @ingroup  hard_constraints
249  *
250  */
251 #define VRNA_CONSTRAINT_CONTEXT_HP_LOOP       (unsigned char)0x02
252 
253 /**
254  *  @brief  Hard constraints flag, base pair encloses an interior loop
255  *
256  *  @ingroup  hard_constraints
257  *
258  */
259 #define VRNA_CONSTRAINT_CONTEXT_INT_LOOP      (unsigned char)0x04
260 
261 /**
262  *  @brief  Hard constraints flag, base pair encloses a multi branch loop
263  *
264  *  @ingroup  hard_constraints
265  *
266  */
267 #define VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC  (unsigned char)0x08
268 
269 /**
270  *  @brief  Hard constraints flag, base pair is enclosed in an interior loop
271  *
272  *  @ingroup  hard_constraints
273  *
274  */
275 #define VRNA_CONSTRAINT_CONTEXT_MB_LOOP       (unsigned char)0x10
276 
277 /**
278  *  @brief  Hard constraints flag, base pair is enclosed in a multi branch loop
279  *
280  *  @ingroup  hard_constraints
281  *
282  */
283 #define VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC   (unsigned char)0x20
284 
285 /**
286  *  @brief  Hard constraint flag to indicate enforcement of constraints
287  */
288 #define VRNA_CONSTRAINT_CONTEXT_ENFORCE       (unsigned char)0x40
289 
290 /**
291  *  @brief  Hard constraint flag to indicate not to remove base pairs that conflict with a given constraint
292  */
293 #define VRNA_CONSTRAINT_CONTEXT_NO_REMOVE     (unsigned char)0x80
294 
295 
296 /**
297  *  @brief  Constraint context flag that forbids any loop
298  */
299 #define VRNA_CONSTRAINT_CONTEXT_NONE          (unsigned char)0
300 
301 /**
302  *  @brief  Constraint context flag indicating base pairs that close any loop
303  */
304 #define VRNA_CONSTRAINT_CONTEXT_CLOSING_LOOPS (unsigned char)(VRNA_CONSTRAINT_CONTEXT_EXT_LOOP | \
305                                                               VRNA_CONSTRAINT_CONTEXT_HP_LOOP | \
306                                                               VRNA_CONSTRAINT_CONTEXT_INT_LOOP | \
307                                                               VRNA_CONSTRAINT_CONTEXT_MB_LOOP)
308 
309 /**
310  *  @brief  Constraint context flag indicating base pairs enclosed by any loop
311  */
312 #define VRNA_CONSTRAINT_CONTEXT_ENCLOSED_LOOPS  (unsigned char)(VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC | \
313                                                                 VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC)
314 
315 /**
316  * @brief  Constraint context flag indicating any loop context
317  *
318  *  @ingroup  hard_constraints
319  *
320  */
321 #define VRNA_CONSTRAINT_CONTEXT_ALL_LOOPS     (unsigned char)(VRNA_CONSTRAINT_CONTEXT_CLOSING_LOOPS | \
322                                                               VRNA_CONSTRAINT_CONTEXT_ENCLOSED_LOOPS)
323 
324 
325 #define VRNA_CONSTRAINT_WINDOW_UPDATE_5       1U
326 
327 #define VRNA_CONSTRAINT_WINDOW_UPDATE_3       2U
328 
329 /**
330  *  @brief  The hard constraints type
331  *
332  *  Global and local structure prediction methods use a slightly different way to
333  *  handle hard constraints internally. This enum is used to distinguish both types.
334  */
335 typedef enum {
336   VRNA_HC_DEFAULT,  /**<  @brief  Default Hard Constraints */
337   VRNA_HC_WINDOW    /**<  @brief  Hard Constraints suitable for local structure prediction using
338                      *    window approach.
339                      *    @see    vrna_mfe_window(), vrna_mfe_window_zscore(), pfl_fold()
340                      */
341 } vrna_hc_type_e;
342 
343 
344 /**
345  *  @brief  The hard constraints data structure
346  *
347  *  The content of this data structure determines the decomposition pattern
348  *  used in the folding recursions. Attribute 'matrix' is used as source for
349  *  the branching pattern of the decompositions during all folding recursions.
350  *  Any entry in matrix[i,j] consists of the 6 LSB that allows one to distinguish the
351  *  following types of base pairs:
352  *  - in the exterior loop (#VRNA_CONSTRAINT_CONTEXT_EXT_LOOP)
353  *  - enclosing a hairpin (#VRNA_CONSTRAINT_CONTEXT_HP_LOOP)
354  *  - enclosing an interior loop (#VRNA_CONSTRAINT_CONTEXT_INT_LOOP)
355  *  - enclosed by an exterior loop (#VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC)
356  *  - enclosing a multi branch loop (#VRNA_CONSTRAINT_CONTEXT_MB_LOOP)
357  *  - enclosed by a multi branch loop (#VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC)
358  *
359  *  The four linear arrays 'up_xxx' provide the number of available unpaired
360  *  nucleotides (including position i) 3' of each position in the sequence.
361  *
362  *  @see  vrna_hc_init(), vrna_hc_free(), #VRNA_CONSTRAINT_CONTEXT_EXT_LOOP,
363  *        #VRNA_CONSTRAINT_CONTEXT_HP_LOOP, #VRNA_CONSTRAINT_CONTEXT_INT_LOOP,
364  *        #VRNA_CONSTRAINT_CONTEXT_MB_LOOP, #VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC
365  *
366  *  @ingroup hard_constraints
367  */
368 struct vrna_hc_s {
369   vrna_hc_type_e  type;
370   unsigned int    n;
371 
372   unsigned char   state;
373 
374 #ifndef VRNA_DISABLE_C11_FEATURES
375   /* C11 support for unnamed unions/structs */
376   union {
377     struct {
378 #endif
379       unsigned char *mx;
380 #ifndef VRNA_DISABLE_C11_FEATURES
381     };
382     struct {
383 #endif
384       unsigned char         **matrix_local;
385 #ifndef VRNA_DISABLE_C11_FEATURES
386     };
387   };
388 #endif
389 
390   int                         *up_ext;    /**<  @brief  A linear array that holds the number of allowed
391                                            *            unpaired nucleotides in an exterior loop
392                                            */
393   int                         *up_hp;     /**<  @brief  A linear array that holds the number of allowed
394                                            *            unpaired nucleotides in a hairpin loop
395                                            */
396   int                         *up_int;    /**<  @brief  A linear array that holds the number of allowed
397                                            *            unpaired nucleotides in an interior loop
398                                            */
399   int                         *up_ml;     /**<  @brief  A linear array that holds the number of allowed
400                                            *            unpaired nucleotides in a multi branched loop
401                                            */
402 
403   vrna_callback_hc_evaluate   *f;         /**<  @brief  A function pointer that returns whether or
404                                            *            not a certain decomposition may be evaluated
405                                            */
406 
407   void                        *data;      /**<  @brief  A pointer to some structure where the user
408                                            *            may store necessary data to evaluate its
409                                            *            generic hard constraint function
410                                            */
411 
412   vrna_callback_free_auxdata  *free_data; /**<  @brief  A pointer to a function to free memory
413                                            *            occupied by auxiliary data
414                                            *
415                                            *    The function this pointer is pointing to will be
416                                            *    called upon destruction of the #vrna_hc_s, and
417                                            *    provided with the vrna_hc_s.data pointer that
418                                            *    may hold auxiliary data. Hence, to avoid leaking
419                                            *    memory, the user may use this pointer to free
420                                            *    memory occupied by auxiliary data.
421                                            */
422 
423   vrna_hc_depot_t             *depot;
424 };
425 
426 /**
427  *  @brief  A single hard constraint for a single nucleotide
428  *
429  *  @ingroup hard_constraints
430  */
431 struct vrna_hc_up_s {
432   int   position;           /**<  @brief The sequence position (1-based)  */
433   int   strand;
434   unsigned char options;  /**<  @brief The hard constraint option       */
435 };
436 
437 /**
438  *  @brief Print a help message for pseudo dot-bracket structure constraint characters to stdout.
439  *  (constraint support is specified by option parameter)
440  *
441  *  Currently available options are:\n
442  *  #VRNA_CONSTRAINT_DB_PIPE (paired with another base)\n
443  *  #VRNA_CONSTRAINT_DB_DOT (no constraint at all)\n
444  *  #VRNA_CONSTRAINT_DB_X (base must not pair)\n
445  *  #VRNA_CONSTRAINT_DB_ANG_BRACK (paired downstream/upstream)\n
446  *  #VRNA_CONSTRAINT_DB_RND_BRACK (base i pairs base j)\n
447  *
448  *  pass a collection of options as one value like this:
449  *  @verbatim vrna_message_constraints(option_1 | option_2 | option_n) @endverbatim
450  *
451  *  @ingroup  constraints
452  *
453  *  @see  vrna_message_constraint_options_all(), vrna_constraints_add(), #VRNA_CONSTRAINT_DB,
454  *        #VRNA_CONSTRAINT_DB_PIPE, #VRNA_CONSTRAINT_DB_DOT, #VRNA_CONSTRAINT_DB_X, #VRNA_CONSTRAINT_DB_ANG_BRACK,
455  *        #VRNA_CONSTRAINT_DB_RND_BRACK, #VRNA_CONSTRAINT_DB_INTERMOL, #VRNA_CONSTRAINT_DB_INTRAMOL
456  *
457  *  @param option Option switch that tells which constraint help will be printed
458  */
459 void vrna_message_constraint_options(unsigned int option);
460 
461 
462 /**
463  *  @brief Print structure constraint characters to stdout
464  *  (full constraint support)
465  *
466  *  @ingroup  constraints
467  *
468  *  @see  vrna_message_constraint_options(), vrna_constraints_add(), #VRNA_CONSTRAINT_DB,
469  *        #VRNA_CONSTRAINT_DB_PIPE, #VRNA_CONSTRAINT_DB_DOT, #VRNA_CONSTRAINT_DB_X, #VRNA_CONSTRAINT_DB_ANG_BRACK,
470  *        #VRNA_CONSTRAINT_DB_RND_BRACK, #VRNA_CONSTRAINT_DB_INTERMOL, #VRNA_CONSTRAINT_DB_INTRAMOL
471  */
472 void vrna_message_constraint_options_all(void);
473 
474 
475 /**
476  *  @brief  Initialize/Reset hard constraints to default values
477  *
478  *  This function resets the hard constraints to their default values, i.e.
479  *  all positions may be unpaired in all contexts, and base pairs are
480  *  allowed in all contexts, if they resemble canonical pairs.
481  *  Previously set hard constraints will be removed before initialization.
482  *
483  *  @ingroup  hard_constraints
484  *
485  *  @see  vrna_hc_add_bp(), vrna_hc_add_bp_nonspecific(), vrna_hc_add_up()
486  *
487  *  @param  vc  The fold compound
488  */
489 void vrna_hc_init(vrna_fold_compound_t *vc);
490 
491 
492 void vrna_hc_init_window(vrna_fold_compound_t *vc);
493 
494 
495 int
496 vrna_hc_prepare(vrna_fold_compound_t *fc,
497                 unsigned int         options);
498 
499 void
500 vrna_hc_update(vrna_fold_compound_t *fc,
501                unsigned int         i,
502                unsigned int         options);
503 
504 
505 /**
506  *  @brief  Make a certain nucleotide unpaired
507  *
508  *  @ingroup  hard_constraints
509  *
510  *  @see  vrna_hc_add_bp(), vrna_hc_add_bp_nonspecific(), vrna_hc_init(),
511  *        #VRNA_CONSTRAINT_CONTEXT_EXT_LOOP, #VRNA_CONSTRAINT_CONTEXT_HP_LOOP,
512  *        #VRNA_CONSTRAINT_CONTEXT_INT_LOOP, #VRNA_CONSTRAINT_CONTEXT_MB_LOOP,
513  *        #VRNA_CONSTRAINT_CONTEXT_ALL_LOOPS
514  *
515  *  @param  vc      The #vrna_fold_compound_t the hard constraints are associated with
516  *  @param  i       The position that needs to stay unpaired (1-based)
517  *  @param  option  The options flag indicating how/where to store the hard constraints
518  */
519 void vrna_hc_add_up(vrna_fold_compound_t  *vc,
520                     int                   i,
521                     unsigned char         option);
522 
523 
524 int
525 vrna_hc_add_up_strand(vrna_fold_compound_t *fc,
526                       unsigned int         i,
527                       unsigned int         strand,
528                       unsigned char        option);
529 
530 /**
531  *  @brief Apply a list of hard constraints for single nucleotides
532  *
533  *  @ingroup  hard_constraints
534  *
535  *  @param  vc          The #vrna_fold_compound_t the hard constraints are associated with
536  *  @param  constraints The list off constraints to apply, last entry must have position
537  *                      attribute set to 0
538  */
539 int
540 vrna_hc_add_up_batch(vrna_fold_compound_t *vc,
541                      vrna_hc_up_t         *constraints);
542 
543 int
544 vrna_hc_add_up_strand_batch(vrna_fold_compound_t *fc,
545                             vrna_hc_up_t         *constraints);
546 
547 /**
548  *  @brief  Favorize/Enforce  a certain base pair (i,j)
549  *
550  *  @ingroup  hard_constraints
551  *
552  *  @see  vrna_hc_add_bp_nonspecific(), vrna_hc_add_up(), vrna_hc_init(),
553  *        #VRNA_CONSTRAINT_CONTEXT_EXT_LOOP, #VRNA_CONSTRAINT_CONTEXT_HP_LOOP,
554  *        #VRNA_CONSTRAINT_CONTEXT_INT_LOOP, #VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC,
555  *        #VRNA_CONSTRAINT_CONTEXT_MB_LOOP, #VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC,
556  *        #VRNA_CONSTRAINT_CONTEXT_ENFORCE, #VRNA_CONSTRAINT_CONTEXT_ALL_LOOPS
557  *
558  *  @param  vc      The #vrna_fold_compound_t the hard constraints are associated with
559  *  @param  i       The 5' located nucleotide position of the base pair (1-based)
560  *  @param  j       The 3' located nucleotide position of the base pair (1-based)
561  *  @param  option  The options flag indicating how/where to store the hard constraints
562  */
563 int vrna_hc_add_bp(vrna_fold_compound_t  *vc,
564                     int                   i,
565                     int                   j,
566                     unsigned char         option);
567 
568 
569 int
570 vrna_hc_add_bp_strand(vrna_fold_compound_t *fc,
571                       unsigned int         i,
572                       unsigned int         strand_i,
573                       unsigned int         j,
574                       unsigned int         strand_j,
575                       unsigned char        option);
576 
577 /**
578  *  @brief  Enforce a nucleotide to be paired (upstream/downstream)
579  *
580  *  @ingroup  hard_constraints
581  *
582  *  @see  vrna_hc_add_bp(), vrna_hc_add_up(), vrna_hc_init(),
583  *        #VRNA_CONSTRAINT_CONTEXT_EXT_LOOP, #VRNA_CONSTRAINT_CONTEXT_HP_LOOP,
584  *        #VRNA_CONSTRAINT_CONTEXT_INT_LOOP, #VRNA_CONSTRAINT_CONTEXT_INT_LOOP_ENC,
585  *        #VRNA_CONSTRAINT_CONTEXT_MB_LOOP, #VRNA_CONSTRAINT_CONTEXT_MB_LOOP_ENC,
586  *        #VRNA_CONSTRAINT_CONTEXT_ALL_LOOPS
587  *
588  *  @param  vc      The #vrna_fold_compound_t the hard constraints are associated with
589  *  @param  i       The position that needs to stay unpaired (1-based)
590  *  @param  d       The direction of base pairing (@f$ d < 0 @f$: pairs upstream,
591  *                  @f$ d > 0 @f$: pairs downstream, @f$ d == 0 @f$: no direction)
592  *  @param  option  The options flag indicating in which loop type context the pairs may appear
593  */
594 void vrna_hc_add_bp_nonspecific(vrna_fold_compound_t  *vc,
595                                 int                   i,
596                                 int                   d,
597                                 unsigned char         option);
598 
599 
600 /**
601  *  @brief  Free the memory allocated by a #vrna_hc_t data structure
602  *
603  *  Use this function to free all memory that was allocated for a data structure
604  *  of type #vrna_hc_t .
605  *
606  *  @see get_hard_constraints(), #vrna_hc_t
607  *
608  *  @ingroup  hard_constraints
609  *
610  */
611 void vrna_hc_free(vrna_hc_t *hc);
612 
613 
614 /**
615  *  @brief  Add a function pointer pointer for the generic hard constraint
616  *          feature
617  */
618 void vrna_hc_add_f(vrna_fold_compound_t       *vc,
619                    vrna_callback_hc_evaluate  *f);
620 
621 
622 /**
623  *  @brief Add an auxiliary data structure for the generic hard constraints callback function
624  *
625  *  @ingroup generic_hc
626  *
627  *  @see vrna_hc_add_f()
628  *
629  *  @param  vc        The fold compound the generic hard constraint function should be bound to
630  *  @param  data      A pointer to the data structure that holds required data for function 'f'
631  *  @param  f         A pointer to a function that free's the memory occupied by @p data (Maybe @p NULL)
632  */
633 void vrna_hc_add_data(vrna_fold_compound_t        *vc,
634                       void                        *data,
635                       vrna_callback_free_auxdata  *f);
636 
637 
638 /**
639  *  @brief Add hard constraints from pseudo dot-bracket notation
640  *
641  *  This function allows one to apply hard constraints from a pseudo dot-bracket
642  *  notation. The @p options parameter controls, which characters are recognized
643  *  by the parser. Use the #VRNA_CONSTRAINT_DB_DEFAULT convenience macro, if you
644  *  want to allow all known characters
645  *
646  *  @ingroup  hard_constraints
647  *
648  *  @see  #VRNA_CONSTRAINT_DB_PIPE, #VRNA_CONSTRAINT_DB_DOT, #VRNA_CONSTRAINT_DB_X,
649  *        #VRNA_CONSTRAINT_DB_ANG_BRACK, #VRNA_CONSTRAINT_DB_RND_BRACK, #VRNA_CONSTRAINT_DB_INTRAMOL,
650  *        #VRNA_CONSTRAINT_DB_INTERMOL, #VRNA_CONSTRAINT_DB_GQUAD
651  *
652  *  @param  vc            The fold compound
653  *  @param  constraint    A pseudo dot-bracket notation of the hard constraint.
654  *  @param  options       The option flags
655  */
656 int
657 vrna_hc_add_from_db(vrna_fold_compound_t  *vc,
658                     const char            *constraint,
659                     unsigned int          options);
660 
661 
662 #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY
663 
664 /**
665  *  @brief Print structure constraint characters to stdout.
666  *  (constraint support is specified by option parameter)
667  *
668  *  @deprecated Use vrna_message_constraints() instead!
669  *  @param option Option switch that tells which constraint help will be printed
670  */
671 DEPRECATED(void print_tty_constraint(unsigned int option),
672           "Use vrna_message_constraint_options() instead");
673 
674 /**
675  *  @brief Print structure constraint characters to stdout
676  *  (full constraint support)
677  *
678  *  @deprecated Use vrna_message_constraint_options_all() instead!
679  */
680 DEPRECATED(void print_tty_constraint_full(void),
681           "Use vrna_message_constraint_options_all() instead");
682 
683 /**
684  *  @brief Insert constraining pair types according to constraint structure string
685  *
686  *  @deprecated   Do not use this function anymore! Structure constraints are now handled through #vrna_hc_t and related functions.
687  *
688  *  @param constraint     The structure constraint string
689  *  @param length         The actual length of the sequence (constraint may be shorter)
690  *  @param ptype          A pointer to the basepair type array
691  *  @param BP             (not used anymore)
692  *  @param min_loop_size  The minimal loop size (usually #TURN )
693  *  @param idx_type       Define the access type for base pair type array (0 = indx, 1 = iindx)
694  */
695 DEPRECATED(void constrain_ptypes(const char   *constraint,
696                                  unsigned int length,
697                                  char         *ptype,
698                                  int          *BP,
699                                  int          min_loop_size,
700                                  unsigned int idx_type),
701           "Use the new API and the hard constraint framework instead");
702 
703 #endif
704 
705 #endif
706