RNAlib-2.2.0RC0
file_formats.h File Reference

Various functions dealing with file formats for RNA sequences, structures, and alignments. More...

+ Include dependency graph for file_formats.h:

Go to the source code of this file.

Functions

void vrna_structure_print_helix_list (const char *db, FILE *file)
 Print a secondary structure as helix list. More...
 
void vrna_structure_print_ct (const char *seq, const char *db, float energy, const char *identifier, FILE *file)
 Print a secondary structure as connect table. More...
 
void vrna_structure_print_bpseq (const char *seq, const char *db, FILE *file)
 Print a secondary structure in bpseq format. More...
 
unsigned int vrna_read_fasta_record (char **header, char **sequence, char ***rest, FILE *file, unsigned int options)
 Get a (fasta) data set from a file or stdin. More...
 
unsigned int read_record (char **header, char **sequence, char ***rest, unsigned int options)
 Get a data record from stdin. More...
 

Detailed Description

Various functions dealing with file formats for RNA sequences, structures, and alignments.

Function Documentation

void vrna_structure_print_helix_list ( const char *  db,
FILE *  file 
)

Print a secondary structure as helix list.

Parameters
dbThe structure in dot-bracket format
fileThe file handle used to print to (print defaults to 'stdout' if(file == NULL) )
void vrna_structure_print_ct ( const char *  seq,
const char *  db,
float  energy,
const char *  identifier,
FILE *  file 
)

Print a secondary structure as connect table.

Parameters
seqThe RNA sequence
dbThe structure in dot-bracket format
energyThe free energy of the structure
identifierAn optional identifier for the sequence
fileThe file handle used to print to (print defaults to 'stdout' if(file == NULL) )
void vrna_structure_print_bpseq ( const char *  seq,
const char *  db,
FILE *  file 
)

Print a secondary structure in bpseq format.

Parameters
seqThe RNA sequence
dbThe structure in dot-bracket format
fileThe file handle used to print to (print defaults to 'stdout' if(file == NULL) )
unsigned int vrna_read_fasta_record ( char **  header,
char **  sequence,
char ***  rest,
FILE *  file,
unsigned int  options 
)

Get a (fasta) data set from a file or stdin.

This function may be used to obtain complete datasets from a filehandle or stdin. A dataset is always defined to contain at least a sequence. If data starts with a fasta header, i.e. a line like

>some header info 

then vrna_read_fasta_record() will assume that the sequence that follows the header may span over several lines. To disable this behavior and to assign a single line to the argument 'sequence' one can pass VRNA_INPUT_NO_SPAN in the 'options' argument. If no fasta header is read in the beginning of a data block, a sequence must not span over multiple lines!
Unless the options VRNA_INPUT_NOSKIP_COMMENTS or VRNA_INPUT_NOSKIP_BLANK_LINES are passed, a sequence may be interrupted by lines starting with a comment character or empty lines.
A sequence is regarded as completely read if it was either assumed to not span over multiple lines, a secondary structure or structure constraint follows the sequence on the next line, or a new header marks the beginning of a new sequence...
All lines following the sequence (this includes comments) that do not initiate a new dataset according to the above definition are available through the line-array 'rest'. Here one can usually find the structure constraint or other information belonging to the current dataset. Filling of 'rest' may be prevented by passing VRNA_INPUT_NO_REST to the options argument.

Note
This function will exit any program with an error message if no sequence could be read!
This function is NOT threadsafe! It uses a global variable to store information about the next data block.

The main purpose of this function is to be able to easily parse blocks of data in the header of a loop where all calculations for the appropriate data is done inside the loop. The loop may be then left on certain return values, e.g.:

char *id, *seq, **rest;
int  i;
id = seq = NULL;
rest = NULL;
while(!(vrna_read_fasta_record(&id, &seq, &rest, NULL, 0) & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){
  if(id) printf("%s\n", id);
  printf("%s\n", seq);
  if(rest)
    for(i=0;rest[i];i++){
      printf("%s\n", rest[i]);
      free(rest[i]);
    }
  free(rest);
  free(seq);
  free(id);
} 

In the example above, the while loop will be terminated when vrna_read_fasta_record() returns either an error, EOF, or a user initiated quit request.
As long as data is read from stdin (we are passing NULL as the file pointer), the id is printed if it is available for the current block of data. The sequence will be printed in any case and if some more lines belong to the current block of data each line will be printed as well.

Note
Do not forget to free the memory occupied by header, sequence and rest!
Parameters
headerA pointer which will be set such that it points to the header of the record
sequenceA pointer which will be set such that it points to the sequence of the record
restA pointer which will be set such that it points to an array of lines which also belong to the record
fileA file handle to read from (if NULL, this function reads from stdin)
optionsSome options which may be passed to alter the behavior of the function, use 0 for no options
Returns
A flag with information about what the function actually did read
unsigned int read_record ( char **  header,
char **  sequence,
char ***  rest,
unsigned int  options 
)

Get a data record from stdin.

Deprecated:
This function is deprecated! Use vrna_read_fasta_record() as a replacment.