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> #include <ViennaRNA/utils.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; }
Simple MFE prediction for a multiple sequence alignment
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <ViennaRNA/alifold.h> #include <ViennaRNA/aln_util.h> #include <ViennaRNA/utils.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; }
Simple Base Pair Probability computation
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <ViennaRNA/fold.h> #include <ViennaRNA/part_func.h> #include <ViennaRNA/utils.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; }
Deviating from the Default Model
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <ViennaRNA/mfe.h> #include <ViennaRNA/fold_compound.h> #include <ViennaRNA/model.h> #include <ViennaRNA/string_utils.h> #include <ViennaRNA/utils.h> int main() { /* initialize random number generator */ vrna_init_rand(); /* 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 */ vrna_md_t md; /* ALWAYS set default model settings first! */ vrna_md_set_default(&md); /* 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 */ vrna_fold_compound_t *fc = vrna_fold_compound(seq, &md, VRNA_OPTION_DEFAULT); /* 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); vrna_fold_compound_free(fc); return 0; }
See also:
examples/helloworld_mfe.c
in the source code tarball
examples/helloworld_mfe_comparative.c
in the source code tarball
examples/helloworld_probabilities.c
in the source code tarball
examples/fold_compound_md.c
in the source code tarball