RNAlib-2.1.9h
utils.h
Go to the documentation of this file.
1#ifndef __VIENNA_RNA_PACKAGE_UTILS_H__
2#define __VIENNA_RNA_PACKAGE_UTILS_H__
3
12#define VRNA_INPUT_ERROR 1U
16#define VRNA_INPUT_QUIT 2U
20#define VRNA_INPUT_MISC 4U
21
28#define VRNA_INPUT_FASTA_HEADER 8U
29
34#define VRNA_INPUT_SEQUENCE 16U
35
40#define VRNA_INPUT_CONSTRAINT 32U
41
46#define VRNA_INPUT_NO_TRUNCATION 256U
47
51#define VRNA_INPUT_NO_REST 512U
52
56#define VRNA_INPUT_NO_SPAN 1024U
57
61#define VRNA_INPUT_NOSKIP_BLANK_LINES 2048U
62
66#define VRNA_INPUT_BLANK_LINE 4096U
67
71#define VRNA_INPUT_NOSKIP_COMMENTS 128U
72
76#define VRNA_INPUT_COMMENT 8192U
77
78
79
80
84#define VRNA_CONSTRAINT_PIPE 1U
88#define VRNA_CONSTRAINT_DOT 2U
92#define VRNA_CONSTRAINT_X 4U
96#define VRNA_CONSTRAINT_ANG_BRACK 8U
100#define VRNA_CONSTRAINT_RND_BRACK 16U
104#define VRNA_CONSTRAINT_MULTILINE 32U
108#define VRNA_CONSTRAINT_NO_HEADER 64U
112#define VRNA_CONSTRAINT_ALL 128U
116#define VRNA_CONSTRAINT_G 256U
117
118
119
128#define VRNA_OPTION_MULTILINE 32U
129
130
134#define MIN2(A, B) ((A) < (B) ? (A) : (B))
138#define MAX2(A, B) ((A) > (B) ? (A) : (B))
142#define MIN3(A, B, C) (MIN2( (MIN2((A),(B))) ,(C)))
146#define MAX3(A, B, C) (MAX2( (MAX2((A),(B))) ,(C)))
147
148
152#define XSTR(s) STR(s)
156#define STR(s) #s
157
158#ifndef FILENAME_MAX_LENGTH
165#define FILENAME_MAX_LENGTH 80
172#define FILENAME_ID_LENGTH 42
173#endif
174
175
176#ifdef HAVE_CONFIG_H
177#include <config.h>
178#ifndef HAVE_STRDUP
179char *strdup(const char *s);
180#endif
181#endif
182#ifdef WITH_DMALLOC
183/* use dmalloc library to check for memory management bugs */
184#include "dmalloc.h"
185#define space(S) calloc(1,(S))
186#else
187
194/*@only@*/ /*@notnull@*/
195void *space(unsigned size) /*@ensures MaxSet(result) == (size-1);@*/;
196
204/*@only@*/ /*@notnull@*/
205void *xrealloc(/*@null@*/ /*@only@*/ /*@out@*/ /*@returned@*/ void *p,
206 unsigned size) /*@modifies *p @*/ /*@ensures MaxSet(result) == (size-1) @*/;
207#endif
208
215/*@exits@*/
216void nrerror(const char message[]);
217
225void warn_user(const char message[]);
226
230void init_rand(void);
231
240extern unsigned short xsubi[3];
241
248double urn(void);
249
257int int_urn(int from, int to);
258
259void filecopy(FILE *from, FILE *to); /* inefficient `cp' */
260
269/*@observer@*/
270char *time_stamp(void);
271
279/*@only@*/ /*@notnull@*/
280char *random_string(int l, const char symbols[]);
281
290int hamming(const char *s1, const char *s2);
291
301int hamming_bound(const char *s1, const char *s2, int n);
302
313/*@only@*/ /*@null@*/
314char *get_line(FILE *fp);
315
316int skip_comment_lines(char **line);
317
338unsigned int get_input_line(char **string,
339 unsigned int options);
340
341unsigned int get_multi_input_line(char **string,
342 unsigned int options);
343
396unsigned int read_record( char **header,
397 char **sequence,
398 char ***rest,
399 unsigned int options);
400
401
402/* \brief Extract a dot-bracket structure string from (multiline)character array
403 *
404 * This function extracts a dot-bracket structure string from the 'rest' array as
405 * returned by read_record() and returns it. All occurences of comments within the
406 * 'lines' array will be skipped as long as they do not break the structure string.
407 * If no structure could be read, this function returns NULL.
408 *
409 * \see read_record()
410 *
411 * \param lines The (multiline) character array to be parsed
412 * \param length The assumed length of the dot-bracket string (passing a value < 1 results in no length limit)
413 * \param option Some options which may be passed to alter the behavior of the function, use 0 for no options
414 * \return The dot-bracket string read from lines or NULL
415 */
416char *extract_record_rest_structure(const char **lines,
417 unsigned int length,
418 unsigned int option);
419
431char *pack_structure(const char *struc);
432
442char *unpack_structure(const char *packed);
443
453short *make_pair_table(const char *structure);
454
455short *make_pair_table_pk(const char *structure);
456
463short *copy_pair_table(const short *pt);
464
470short *alimake_pair_table(const char *structure);
471
477short *make_pair_table_snoop(const char *structure);
478
491int *make_loop_index_pt(short *pt);
492
493
494int bp_distance(const char *str1,
495 const char *str2);
496
503
512void print_tty_input_seq_str(const char *s);
513
520
537void print_tty_constraint(unsigned int option);
538
546void str_DNA2RNA(char *sequence);
547
553void str_uppercase(char *sequence);
554
568int *get_iindx(unsigned int length);
569
584int *get_indx(unsigned int length);
585
586void getConstraint( char **cstruc,
587 const char **lines,
588 unsigned int option);
589
601void constrain_ptypes(const char *constraint,
602 unsigned int length,
603 char *ptype,
604 int *BP,
605 int min_loop_size,
606 unsigned int idx_type);
607
608unsigned int *make_referenceBP_array(short *reference_pt,
609 unsigned int turn);
610
611unsigned int *compute_BPdifferences( short *pt1,
612 short *pt2,
613 unsigned int turn);
614
615#endif
int * get_iindx(unsigned int length)
Get an index mapper array (iindx) for accessing the energy matrices, e.g. in partition function relat...
void nrerror(const char message[])
Die with an error message.
void str_uppercase(char *sequence)
Convert an input sequence to uppercase.
short * copy_pair_table(const short *pt)
Get an exact copy of a pair table.
char * unpack_structure(const char *packed)
Unpack secondary structure previously packed with pack_structure()
void constrain_ptypes(const char *constraint, unsigned int length, char *ptype, int *BP, int min_loop_size, unsigned int idx_type)
Insert constraining pair types according to constraint structure string.
void print_tty_constraint(unsigned int option)
Print structure constraint characters to stdout. (constraint support is specified by option parameter...
char * time_stamp(void)
Get a timestamp.
int int_urn(int from, int to)
Generates a pseudo random integer in a specified range.
void print_tty_input_seq(void)
Print a line to stdout that asks for an input sequence.
short * alimake_pair_table(const char *structure)
void * space(unsigned size)
Allocate space safely.
void * xrealloc(void *p, unsigned size)
Reallocate space safely.
void init_rand(void)
Make random number seeds.
unsigned int get_input_line(char **string, unsigned int options)
int hamming_bound(const char *s1, const char *s2, int n)
Calculate hamming distance between two sequences up to a specified length.
char * pack_structure(const char *struc)
Pack secondary secondary structure, 5:1 compression using base 3 encoding.
char * get_line(FILE *fp)
Read a line of arbitrary length from a stream.
double urn(void)
get a random number from [0..1]
short * make_pair_table(const char *structure)
Create a pair table of a secondary structure.
short * make_pair_table_snoop(const char *structure)
int * make_loop_index_pt(short *pt)
Compute the "base pair" distance between two secondary structures s1 and s2.
void str_DNA2RNA(char *sequence)
Convert a DNA input sequence to RNA alphabet.
char * random_string(int l, const char symbols[])
Create a random string using characters from a specified symbol set.
int hamming(const char *s1, const char *s2)
Calculate hamming distance between two sequences.
int * get_indx(unsigned int length)
Get an index mapper array (indx) for accessing the energy matrices, e.g. in MFE related functions.
void print_tty_input_seq_str(const char *s)
Print a line with a user defined string and a ruler to stdout.
void print_tty_constraint_full(void)
Print structure constraint characters to stdout (full constraint support)
void warn_user(const char message[])
Print a warning message.
unsigned short xsubi[3]
Current 48 bit random number.
unsigned int read_record(char **header, char **sequence, char ***rest, unsigned int options)