1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include <ViennaRNA/fold_compound.h>
5 #include <ViennaRNA/utils/basic.h>
6 #include <ViennaRNA/utils/strings.h>
7 #include <ViennaRNA/subopt.h>
8
9
10 void
subopt_callback(const char * structure,float energy,void * data)11 subopt_callback(const char *structure,
12 float energy,
13 void *data)
14 {
15 /* simply print the result and increase the counter variable by 1 */
16 if (structure)
17 printf("%d.\t%s\t%6.2f\n", (*((int *)data))++, structure, energy);
18 }
19
20
21 int
main()22 main()
23 {
24 /* initialize random number generator */
25 vrna_init_rand();
26
27 /* Generate a random sequence of 50 nucleotides */
28 char *seq = vrna_random_string(50, "ACGU");
29
30 /* Create a fold compound for the sequence */
31 vrna_fold_compound_t *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
32
33 int counter = 0;
34
35 /*
36 * call subopt to enumerate all secondary structures in an energy band of
37 * 5 kcal/mol of the MFE and pass it the address of the callback and counter
38 * variable
39 */
40 vrna_subopt_cb(fc, 500, &subopt_callback, (void *)&counter);
41
42 /* cleanup memory */
43 free(seq);
44 vrna_fold_compound_free(fc);
45
46 return 0;
47 }
48