Hello World Examples
helloworld_mfe.c
The following is an example showing the minimal requirements to compute the Minimum Free Energy (MFE) and corresponding secondary structure of an RNA sequence
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
main()
{
char *seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
char *structure = (
char *)
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
free(structure);
return 0;
}
MFE calculations for single RNA sequences.
float vrna_fold(const char *sequence, char *structure)
Compute Minimum Free Energy (MFE), and a corresponding secondary structure for an RNA sequence.
void * vrna_alloc(unsigned size)
Allocate space safely.
General utility- and helper-functions used throughout the ViennaRNA Package.
- See also
examples/helloworld_mfe.c
in the source code tarball
helloworld_mfe_comparative.c
Instead of using a single sequence as done above, this example predicts a consensus structure for a multiple sequence alignment
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
main()
{
const char *sequences[] = {
"CUGCCUCACAACGUUUGUGCCUCAGUUACCCGUAGAUGUAGUGAGGGU",
"CUGCCUCACAACAUUUGUGCCUCAGUUACUCAUAGAUGUAGUGAGGGU",
"---CUCGACACCACU---GCCUCGGUUACCCAUCGGUGCAGUGCGGGU",
NULL
};
char *cons = consensus(sequences);
char *structure = (
char *)
vrna_alloc(
sizeof(
char) * (strlen(sequences[0]) + 1));
printf("%s\n%s [ %6.2f ]\n", cons, structure, mfe);
free(cons);
free(structure);
return 0;
}
Functions for comparative structure prediction using RNA sequence alignments.
float vrna_alifold(const char **sequences, char *structure)
Compute Minimum Free Energy (MFE), and a corresponding consensus secondary structure for an RNA seque...
Various utility- and helper-functions for sequence alignments and comparative structure prediction.
- See also
examples/helloworld_mfe_comparative.c
in the source code tarball
helloworld_probabilities.c
This example shows how to compute the partition function and base pair probabilities with minimal implementation effort.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
main()
{
char *seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
char *propensity = (
char *)
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
float en =
vrna_pf_fold(seq, propensity, &pair_probabilities);
printf("%s\n%s [ %6.2f ]\n", seq, propensity, en);
for (ptr = pair_probabilities; ptr->
i != 0; ptr++)
printf(
"p(%d, %d) = %g\n", ptr->
i, ptr->
j, ptr->
p);
free(pair_probabilities);
free(propensity);
return 0;
}
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...
int i
Start position (usually 5' nucleotide that starts the element, e.g. base pair)
Definition: structures.h:483
float p
Probability of the element.
Definition: structures.h:485
int j
End position (usually 3' nucleotide that ends the element, e.g. base pair)
Definition: structures.h:484
Data structure representing a single entry of an element probability list (e.g. list of pair probabil...
Definition: structures.h:482
Partition function implementations.
- See also
examples/helloworld_probabilities.c
in the source code tarball
First Steps with the Fold Compound
fold_compound_mfe.c
Instead of calling the simple MFE folding interface vrna_fold(), this example shows how to first create a vrna_fold_compound_t container with the RNA sequence to finally compute the MFE using this container. This is especially useful if non-default model settings are applied or the dynamic programming (DP) matrices of the MFE prediction are required for post-processing operations, or other tasks on the same sequence will be performed.
#include <stdlib.h>
#include <stdio.h>
int
main()
{
char *structure = (
char *)
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
free(seq);
free(structure);
return 0;
}
The Basic Fold Compound API.
void vrna_fold_compound_free(vrna_fold_compound_t *fc)
Free memory occupied by a vrna_fold_compound_t.
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.
#define VRNA_OPTION_DEFAULT
Option flag to specify default settings/requirements.
Definition: fold_compound.h:375
The most basic data structure required by many functions throughout the RNAlib.
Definition: fold_compound.h:148
float vrna_mfe(vrna_fold_compound_t *vc, char *structure)
Compute minimum free energy and an appropriate secondary structure of an RNA sequence,...
char * vrna_random_string(int l, const char symbols[])
Create a random string using characters from a specified symbol set.
void vrna_init_rand(void)
Initialize seed for random number generator.
Compute Minimum Free energy (MFE) and backtrace corresponding secondary structures from RNA sequence ...
General utility- and helper-functions for RNA sequence and structure strings used throughout the Vien...
- See also
examples/fold_compound_mfe.c
in the source code tarball
fold_compound_md.c
In the following, we change the model settings (model details) to a temperature of 25 Degree Celcius, and activate G-Quadruplex precition.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
main()
{
char *structure = (
char *)
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
free(structure);
return 0;
}
double temperature
The temperature used to scale the thermodynamic parameters.
Definition: model.h:181
int gquad
Include G-quadruplexes in structure prediction.
Definition: model.h:214
void vrna_md_set_default(vrna_md_t *md)
Apply default model details to a provided vrna_md_t data structure.
The data structure that contains the complete model details used throughout the calculations.
Definition: model.h:180
The model details data structure and its corresponding modifiers.
- See also
examples/fold_compound_md.c
in the source code tarball
Writing Callback Functions
callback_subopt.c
Here is a basic example how to use the callback mechanism in vrna_subopt_cb(). It simply defines a callback function (see interface definition for vrna_subopt_callback) that prints the result and increases a counter variable.
#include <stdlib.h>
#include <stdio.h>
void
subopt_callback(const char *structure,
float energy,
void *data)
{
if (structure)
printf("%d.\t%s\t%6.2f\n", (*((int *)data))++, structure, energy);
}
int
main()
{
int counter = 0;
free(seq);
return 0;
}
void vrna_subopt_cb(vrna_fold_compound_t *fc, int delta, vrna_subopt_callback *cb, void *data)
Generate suboptimal structures within an energy band arround the MFE.
RNAsubopt and density of states declarations.
- See also
examples/callback_subopt.c
in the source code tarball
Application of Soft Constraints
soft_constraints_up.c
In this example, a random RNA sequence is generated to predict its MFE under the constraint that a particular nucleotide receives an additional bonus energy if it remains unpaired.
#include <stdlib.h>
#include <stdio.h>
int
main()
{
char *structure = (
char *)
vrna_alloc(
sizeof(
char) * 51);
printf("%s\n%s [ %6.2f ]\n", seq, structure, mfe);
free(seq);
free(structure);
return 0;
}
int vrna_sc_add_up(vrna_fold_compound_t *vc, int i, FLT_OR_DBL energy, unsigned int options)
Add soft constraints for unpaired nucleotides.
Functions and data structures for secondary structure soft constraints.
- See also
examples/soft_constraints_up.c
in the source code tarball
Other Examples
example1.c
A more extensive example including MFE, Partition Function, and Centroid structure prediction.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc,
char *argv[])
{
char *seq =
"AGACGACAAGGUUGAAUCGCACCCACAGUCUAUGAGUCGGUGACAACAUUACGAAAGGCUGUAAAAUCAAUUAUUCACCACAGGGGGCCCCCGUGUCUAG";
char *mfe_structure =
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
char *prob_string =
vrna_alloc(
sizeof(
char) * (strlen(seq) + 1));
double mfe = (double)
vrna_mfe(vc, mfe_structure);
printf("%s\n%s (%6.2f)\n", seq, mfe_structure, mfe);
printf("%s (%6.2f)\n", prob_string, en);
double dist;
free(cent);
free(prob_string);
free(mfe_structure);
return EXIT_SUCCESS;
}
Use ViennaRNA/datastructures/basic.h instead.
Functions and variables related to energy evaluation of sequence/structure pairs.
char * vrna_centroid(vrna_fold_compound_t *vc, double *dist)
Get the centroid structure of the ensemble.
double FLT_OR_DBL
Typename for floating point number in partition function computations.
Definition: basic.h:43
void vrna_exp_params_rescale(vrna_fold_compound_t *vc, double *mfe)
Rescale Boltzmann factors for partition function computations.
float vrna_eval_structure(vrna_fold_compound_t *fc, const char *structure)
Calculate the free energy of an already folded RNA.
FLT_OR_DBL vrna_pf(vrna_fold_compound_t *vc, char *structure)
Compute the partition function for a given RNA sequence, or sequence alignment.
Functions to deal with sets of energy parameters.
- See also
examples/example1.c
in the source code tarball
Deprecated Examples
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "utils.h"
void
main()
{
char *seq1 = "CGCAGGGAUACCCGCG", *seq2 = "GCGCCCAUAGGGACGC",
*struct1, *struct2, *xstruc;
float e1, e2, tree_dist, string_dist, profile_dist, kT;
float *pf1, *pf2;
struct1 = (
char *)
space(
sizeof(
char) * (strlen(seq1) + 1));
e1 =
fold(seq1, struct1);
struct2 = (
char *)
space(
sizeof(
char) * (strlen(seq2) + 1));
e2 =
fold(seq2, struct2);
free(xstruc);
free(xstruc);
free(S1);
free(S2);
printf("%s mfe=%5.2f\n%s mfe=%5.2f dist=%3.2f\n",
pf_scale = exp(-e1 / kT / strlen(seq1));
printf("%s free energy=%5.2f\n%s free energy=%5.2f dist=%3.2f\n",
}
Parsing and Coarse Graining of Structures.
int edit_backtrack
Produce an alignment of the two structures being compared by tracing the editing path giving the mini...
char * aligned_line[4]
Contains the two aligned structures after a call to one of the distance functions with edit_backtrack...
Here all all declarations of the global variables used throughout RNAlib.
void free_arrays(void)
Free arrays for mfe folding.
float fold(const char *sequence, char *structure)
Compute minimum free energy and an appropriate secondary structure of an RNA sequence.
double temperature
Rescale energy parameters to a temperature in degC.
double pf_scale
A scaling factor used by pf_fold() to avoid overflows.
FLT_OR_DBL * export_bppm(void)
Get a pointer to the base pair probability array.
float pf_fold(const char *sequence, char *structure)
Compute the partition function of an RNA sequence.
void free_pf_arrays(void)
Free arrays for the partition function recursions.
void unexpand_aligned_F(char *align[2])
Converts two aligned structures in expanded notation.
char * expand_Full(const char *structure)
Convert the full structure from bracket notation to the expanded notation including root.
Inverse folding routines.
float * Make_bp_profile_bppm(FLT_OR_DBL *bppm, int length)
condense pair probability matrix into a vector containing probabilities for unpaired,...
void free_profile(float *T)
free space allocated in Make_bp_profile
float profile_edit_distance(const float *T1, const float *T2)
Align the 2 probability profiles T1, T2 .
Functions for String Alignment.
swString * Make_swString(char *string)
Convert a structure into a format suitable for string_edit_distance().
float string_edit_distance(swString *T1, swString *T2)
Calculate the string edit distance of T1 and T2.
Tree data structure.
Definition: dist_vars.h:49
Some other data structure.
Definition: dist_vars.h:57
Functions for Tree Edit Distances.
Tree * make_tree(char *struc)
Constructs a Tree ( essentially the postorder list ) of the structure 'struc', for use in tree_edit_d...
float tree_edit_distance(Tree *T1, Tree *T2)
Calculates the edit distance of the two trees.
void free_tree(Tree *t)
Free the memory allocated for Tree t.
void * space(unsigned size)
Allocate space safely.
- See also
examples/example_old.c
in the source code tarball