RNAlib-2.4.17
HelloWorld

Below, you'll find some more or less simple C programs showing first steps into using RNAlib. A complete list of example C programs can be found in the C Examples section.

Simple MFE prediction for a given sequence

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ViennaRNA/fold.h>
int
main()
{
/* The RNA sequence */
char *seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
/* allocate memory for MFE structure (length + 1) */
char *structure = (char *)vrna_alloc(sizeof(char) * (strlen(seq) + 1));
/* predict Minmum Free Energy and corresponding secondary structure */
float mfe = vrna_fold(seq, structure);
/* print sequence, structure and MFE */
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
/* cleanup memory */
free(structure);
return 0;
}
See also
examples/helloworld_mfe.c in the source code tarball

Simple MFE prediction for a multiple sequence alignment

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
main()
{
/* The RNA sequence alignment */
const char *sequences[] = {
"CUGCCUCACAACGUUUGUGCCUCAGUUACCCGUAGAUGUAGUGAGGGU",
"CUGCCUCACAACAUUUGUGCCUCAGUUACUCAUAGAUGUAGUGAGGGU",
"---CUCGACACCACU---GCCUCGGUUACCCAUCGGUGCAGUGCGGGU",
NULL /* indicates end of alignment */
};
/* compute the consensus sequence */
char *cons = consensus(sequences);
/* allocate memory for MFE consensus structure (length + 1) */
char *structure = (char *)vrna_alloc(sizeof(char) * (strlen(sequences[0]) + 1));
/* predict Minmum Free Energy and corresponding secondary structure */
float mfe = vrna_alifold(sequences, structure);
/* print consensus sequence, structure and MFE */
printf("%s\n%s [ %6.2f ]\n", cons, structure, mfe);
/* cleanup memory */
free(cons);
free(structure);
return 0;
}
See also
examples/helloworld_mfe_comparative.c in the source code tarball

Simple Base Pair Probability computation

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ViennaRNA/fold.h>
int
main()
{
/* The RNA sequence */
char *seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
/* allocate memory for pairing propensity string (length + 1) */
char *propensity = (char *)vrna_alloc(sizeof(char) * (strlen(seq) + 1));
/* pointers for storing and navigating through base pair probabilities */
vrna_ep_t *ptr, *pair_probabilities = NULL;
float en = vrna_pf_fold(seq, propensity, &pair_probabilities);
/* print sequence, pairing propensity string and ensemble free energy */
printf("%s\n%s [ %6.2f ]\n", seq, propensity, en);
/* print all base pairs with probability above 50% */
for (ptr = pair_probabilities; ptr->i != 0; ptr++)
if (ptr->p > 0.5)
printf("p(%d, %d) = %g\n", ptr->i, ptr->j, ptr->p);
/* cleanup memory */
free(pair_probabilities);
free(propensity);
return 0;
}
See also
examples/helloworld_probabilities.c in the source code tarball

Deviating from the Default Model

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ViennaRNA/mfe.h>
int
main()
{
/* initialize random number generator */
/* Generate a random sequence of 50 nucleotides */
char *seq = vrna_random_string(50, "ACGU");
/* allocate memory for MFE structure (length + 1) */
char *structure = (char *)vrna_alloc(sizeof(char) * (strlen(seq) + 1));
/* create a new model details structure to store the Model Settings */
/* ALWAYS set default model settings first! */
/* change temperature and activate G-Quadruplex prediction */
md.temperature = 25.0; /* 25 Deg Celcius */
md.gquad = 1; /* Turn-on G-Quadruples support */
/* create a fold compound */
/* predict Minmum Free Energy and corresponding secondary structure */
float mfe = vrna_mfe(fc, structure);
/* print sequence, structure and MFE */
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
/* cleanup memory */
free(structure);
return 0;
}
See also
examples/fold_compound_md.c in the source code tarball
model.h
The model details data structure and its corresponding modifiers.
vrna_elem_prob_s
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structures.h:453
vrna_md_s::gquad
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:214
alignments.h
Various utility- and helper-functions for sequence alignments and comparative structure prediction.
vrna_fold_compound_free
void vrna_fold_compound_free(vrna_fold_compound_t *fc)
Free memory occupied by a vrna_fold_compound_t.
alifold.h
Functions for comparative structure prediction using RNA sequence alignments.
vrna_random_string
char * vrna_random_string(int l, const char symbols[])
Create a random string using characters from a specified symbol set.
vrna_init_rand
void vrna_init_rand(void)
Initialize seed for random number generator.
vrna_md_s::temperature
double temperature
The temperature used to scale the thermodynamic parameters.
Definition: model.h:181
vrna_elem_prob_s::p
float p
Probability of the element.
Definition: structures.h:456
basic.h
General utility- and helper-functions used throughout the ViennaRNA Package.
vrna_md_set_default
void vrna_md_set_default(vrna_md_t *md)
Apply default model details to a provided vrna_md_t data structure.
vrna_fold
float vrna_fold(const char *sequence, char *structure)
Compute Minimum Free Energy (MFE), and a corresponding secondary structure for an RNA sequence.
strings.h
General utility- and helper-functions for RNA sequence and structure strings used throughout the Vien...
vrna_md_s
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:180
vrna_fc_s
The most basic data structure required by many functions throughout the RNAlib.
Definition: fold_compound.h:137
mfe.h
Compute Minimum Free energy (MFE) and backtrace corresponding secondary structures from RNA sequence ...
vrna_pf_fold
float vrna_pf_fold(const char *sequence, char *structure, vrna_ep_t **pl)
Compute Partition function (and base pair probabilities) for an RNA sequence using a comparative met...
VRNA_OPTION_DEFAULT
#define VRNA_OPTION_DEFAULT
Option flag to specify default settings/requirements.
Definition: fold_compound.h:355
vrna_alifold
float vrna_alifold(const char **sequences, char *structure)
Compute Minimum Free Energy (MFE), and a corresponding consensus secondary structure for an RNA seque...
vrna_mfe
float vrna_mfe(vrna_fold_compound_t *vc, char *structure)
Compute minimum free energy and an appropriate secondary structure of an RNA sequence,...
fold.h
MFE calculations for single RNA sequences.
vrna_elem_prob_s::i
int i
Start position (usually 5' nucleotide that starts the element, e.g. base pair)
Definition: structures.h:454
part_func.h
Partition function implementations.
fold_compound.h
The Basic Fold Compound API.
vrna_fold_compound
vrna_fold_compound_t * vrna_fold_compound(const char *sequence, const vrna_md_t *md_p, unsigned int options)
Retrieve a vrna_fold_compound_t data structure for single sequences and hybridizing sequences.
vrna_elem_prob_s::j
int j
End position (usually 3' nucleotide that ends the element, e.g. base pair)
Definition: structures.h:455
vrna_alloc
void * vrna_alloc(unsigned size)
Allocate space safely.