RNAlib-2.2.0-RC3
utils.h
Go to the documentation of this file.
1 #ifndef VIENNA_RNA_PACKAGE_UTILS_H
2 #define VIENNA_RNA_PACKAGE_UTILS_H
3 
4 /* make this interface backward compatible with RNAlib < 2.2.0 */
5 #define VRNA_BACKWARD_COMPAT
6 
7 #ifdef __GNUC__
8 #define DEPRECATED(func) func __attribute__ ((deprecated))
9 #else
10 #define DEPRECATED(func) func
11 #endif
12 
22 #include <stdio.h>
23 
26 
27 /* two helper macros to indicate whether a function should be exported in
28 the library or stays hidden */
29 #define PUBLIC
30 #define PRIVATE static
31 
35 #define VRNA_INPUT_ERROR 1U
36 
39 #define VRNA_INPUT_QUIT 2U
40 
43 #define VRNA_INPUT_MISC 4U
44 
52 #define VRNA_INPUT_FASTA_HEADER 8U
53 
54 /*
55  * @brief Input flag for get_input_line():\n
56  * Tell get_input_line() that we assume to read a nucleotide sequence
57  *
58  */
59 #define VRNA_INPUT_SEQUENCE 16U
60 
65 #define VRNA_INPUT_CONSTRAINT 32U
66 
71 #define VRNA_INPUT_NO_TRUNCATION 256U
72 
76 #define VRNA_INPUT_NO_REST 512U
77 
81 #define VRNA_INPUT_NO_SPAN 1024U
82 
86 #define VRNA_INPUT_NOSKIP_BLANK_LINES 2048U
87 
91 #define VRNA_INPUT_BLANK_LINE 4096U
92 
96 #define VRNA_INPUT_NOSKIP_COMMENTS 128U
97 
101 #define VRNA_INPUT_COMMENT 8192U
102 
112 #define VRNA_OPTION_MULTILINE 32U
113 
114 
118 #define MIN2(A, B) ((A) < (B) ? (A) : (B))
119 
123 #define MAX2(A, B) ((A) > (B) ? (A) : (B))
124 
128 #define MIN3(A, B, C) (MIN2( (MIN2((A),(B))) ,(C)))
129 
133 #define MAX3(A, B, C) (MAX2( (MAX2((A),(B))) ,(C)))
134 
135 
139 #define XSTR(s) STR(s)
140 
144 #define STR(s) #s
145 
146 #ifndef FILENAME_MAX_LENGTH
147 
154 #define FILENAME_MAX_LENGTH 80
155 
162 #define FILENAME_ID_LENGTH 42
163 
164 #endif
165 
166 
167 #ifdef HAVE_CONFIG_H
168 #include <config.h>
169 #ifndef HAVE_STRDUP
170 char *strdup(const char *s);
171 #endif
172 #endif
173 
174 #ifdef WITH_DMALLOC
175 /* use dmalloc library to check for memory management bugs */
176 #include "dmalloc.h"
177 #define vrna_alloc(S) calloc(1,(S))
178 #define vrna_realloc(p, S) xrealloc(p, S)
179 #else
180 
187 void *vrna_alloc(unsigned size);
188 
196 void *vrna_realloc(void *p, unsigned size);
197 
198 #endif
199 
206 void vrna_message_error(const char message[]);
207 
215 void vrna_message_warning(const char message[]);
216 
220 void vrna_init_rand(void);
221 
230 extern unsigned short xsubi[3];
231 
239 double vrna_urn(void);
240 
249 int vrna_int_urn(int from, int to);
250 
254 void vrna_file_copy(FILE *from, FILE *to);
255 
264 char *vrna_time_stamp(void);
265 
273 char *vrna_random_string(int l, const char symbols[]);
274 
282 int vrna_hamming_distance(const char *s1, const char *s2);
283 
293 int vrna_hamming_distance_bound(const char *s1, const char *s2, int n);
294 
305 /*@only@*/ /*@null@*/
306 char *get_line(FILE *fp);
307 
328 unsigned int get_input_line(char **string,
329  unsigned int options);
330 
331 
338 
339 
348 void vrna_message_input_seq(const char *s);
349 
350 
351 
359 void vrna_seq_toRNA(char *sequence);
360 
366 void vrna_seq_toupper(char *sequence);
367 
368 
382 int *vrna_get_iindx(unsigned int length);
383 
398 int *vrna_get_indx(unsigned int length);
399 
404 short *vrna_seq_encode( const char *sequence,
405  vrna_md_t *md);
406 
411 short *vrna_seq_encode_simple(const char *sequence,
412  vrna_md_t *md);
413 
414 
426 int vrna_nucleotide_encode( char c,
427  vrna_md_t *md);
428 
440 char vrna_nucleotide_decode(int enc,
441  vrna_md_t *md);
442 
443 void vrna_ali_encode( const char *sequence,
444  short **S_p,
445  short **s5_p,
446  short **s3_p,
447  char **ss_p,
448  unsigned short **as_p,
449  vrna_md_t *md);
450 
459 char *vrna_get_ptypes( const short *S,
460  vrna_md_t *md);
461 
466 #ifdef VRNA_BACKWARD_COMPAT
467 
468 DEPRECATED(char *get_ptypes(const short *S, vrna_md_t *md, unsigned int idx_type));
469 
470 DEPRECATED(int *get_indx(unsigned int length));
471 
472 DEPRECATED(int *get_iindx(unsigned int length));
473 
478 DEPRECATED(void str_uppercase(char *sequence));
479 
485 DEPRECATED(void str_DNA2RNA(char *sequence));
486 
493 DEPRECATED(void print_tty_input_seq(void));
494 
503 DEPRECATED(void print_tty_input_seq_str(const char *s));
504 
512 DEPRECATED(void warn_user(const char message[]));
513 
519 DEPRECATED(void nrerror(const char message[]));
520 
526 DEPRECATED(void *space(unsigned size));
527 
533 DEPRECATED(void *xrealloc(void *p, unsigned size));
534 
539 DEPRECATED(void init_rand(void));
540 
546 DEPRECATED(double urn(void));
547 
553 DEPRECATED(int int_urn(int from, int to));
554 
560 DEPRECATED(char *random_string(int l, const char symbols[]));
561 
567 DEPRECATED(void filecopy(FILE *from, FILE *to));
568 
574 DEPRECATED(char *time_stamp(void));
575 
581 DEPRECATED(int hamming(const char *s1, const char *s2));
582 
588 DEPRECATED(int hamming_bound(const char *s1, const char *s2, int n));
589 
590 #endif
591 
592 #endif
void * vrna_alloc(unsigned size)
Allocate space safely.
void vrna_message_input_seq(const char *s)
Print a line with a user defined string and a ruler to stdout.
void vrna_seq_toupper(char *sequence)
Convert an input sequence to uppercase.
unsigned int get_input_line(char **string, unsigned int options)
void * space(unsigned size)
Allocate space safely.
int vrna_hamming_distance_bound(const char *s1, const char *s2, int n)
Calculate hamming distance between two sequences up to a specified length.
char * vrna_random_string(int l, const char symbols[])
Create a random string using characters from a specified symbol set.
char * get_line(FILE *fp)
Read a line of arbitrary length from a stream.
void warn_user(const char message[])
Print a warning message.
void vrna_message_input_seq_simple(void)
Print a line to stdout that asks for an input sequence.
void vrna_message_warning(const char message[])
Print a warning message.
char * time_stamp(void)
Get a timestamp.
char vrna_nucleotide_decode(int enc, vrna_md_t *md)
Decode a numerical representation of a nucleotide back into nucleotide alphabet.
int int_urn(int from, int to)
Generates a pseudo random integer in a specified range.
void vrna_file_copy(FILE *from, FILE *to)
Inefficient `cp'.
void filecopy(FILE *from, FILE *to)
Inefficient cp
void vrna_init_rand(void)
Initialize seed for random number generator.
void print_tty_input_seq(void)
Print a line to stdout that asks for an input sequence.
char * vrna_time_stamp(void)
Get a timestamp.
short * vrna_seq_encode_simple(const char *sequence, vrna_md_t *md)
Get a numerical representation of the nucleotide sequence (simple version)
char * random_string(int l, const char symbols[])
Create a random string using characters from a specified symbol set.
void str_DNA2RNA(char *sequence)
Convert a DNA input sequence to RNA alphabet.
Various utility- and helper-functions for secondary structure parsing, converting, etc.
int * vrna_get_indx(unsigned int length)
Get an index mapper array (indx) for accessing the energy matrices, e.g. in MFE related functions...
int * vrna_get_iindx(unsigned int length)
Get an index mapper array (iindx) for accessing the energy matrices, e.g. in partition function relat...
short * vrna_seq_encode(const char *sequence, vrna_md_t *md)
Get a numerical representation of the nucleotide sequence.
int hamming_bound(const char *s1, const char *s2, int n)
Calculate hamming distance between two sequences up to a specified length.
void nrerror(const char message[])
Die with an error message.
void * xrealloc(void *p, unsigned size)
Reallocate space safely.
void * vrna_realloc(void *p, unsigned size)
Reallocate space safely.
void vrna_seq_toRNA(char *sequence)
Convert an input sequence (possibly containing DNA alphabet characters) to RNA alphabet.
int vrna_int_urn(int from, int to)
Generates a pseudo random integer in a specified range.
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:169
void print_tty_input_seq_str(const char *s)
Print a line with a user defined string and a ruler to stdout.
void vrna_message_error(const char message[])
Die with an error message.
double urn(void)
get a random number from [0..1]
unsigned short xsubi[3]
Current 48 bit random number.
int vrna_nucleotide_encode(char c, vrna_md_t *md)
Encode a nucleotide character to numerical value.
void init_rand(void)
Make random number seeds.
char * vrna_get_ptypes(const short *S, vrna_md_t *md)
Get an array of the numerical encoding for each possible base pair (i,j)
double vrna_urn(void)
get a random number from [0..1]
void str_uppercase(char *sequence)
Convert an input sequence to uppercase.
int hamming(const char *s1, const char *s2)
Calculate hamming distance between two sequences.
int vrna_hamming_distance(const char *s1, const char *s2)
Calculate hamming distance between two sequences.