1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <math.h>
5
6#include <ViennaRNA/data_structures.h>
7#include <ViennaRNA/utils/strings.h>
8#include <ViennaRNA/constraints/soft.h>
9
10#suite Constraints
11
12#tcase  SoftConstraints
13
14#test test_vrna_sc_add_up_simple
15{
16  int                   i, j;
17
18  char                  *seq = vrna_random_string(10, "ACGU");
19
20  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
21
22  for (i = 1; i <= fc->length; i++)
23    vrna_sc_add_up(fc, i, -1. * i, VRNA_OPTION_DEFAULT);
24
25  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
26
27  vrna_sc_t *sc = fc->sc;
28
29  ck_assert(sc != NULL);
30  ck_assert(sc->energy_up != NULL);
31
32  for (i = 1; i <= fc->length; i++) {
33    int counter = 0;
34    for (j = 1; i + j - 1 <= fc->length; j++) {
35      counter += (j + i - 1) * -100;
36      ck_assert_int_eq(sc->energy_up[i][j], counter);
37    }
38  }
39
40  vrna_sc_remove(fc);
41  ck_assert(fc->sc == NULL);
42
43  /* clean up */
44  vrna_fold_compound_free(fc);
45  free(seq);
46}
47
48#test test_vrna_sc_add_up_addition
49{
50  int                   i, e;
51
52  char                  *seq = vrna_random_string(10, "ACGU");
53
54  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
55
56  for (e = 0, i = 1; i <= fc->length; i++) {
57    vrna_sc_add_up(fc, 1, -1. * i, VRNA_OPTION_DEFAULT);
58    e += -100 * i;
59  }
60
61  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
62
63  vrna_sc_t *sc = fc->sc;
64
65  ck_assert(sc != NULL);
66  ck_assert(sc->energy_up != NULL);
67
68  for (i = 1; i <= fc->length; i++)
69    ck_assert_int_eq(sc->energy_up[1][i], e);
70
71  vrna_sc_remove(fc);
72  ck_assert(fc->sc == NULL);
73
74  /* clean up */
75  vrna_fold_compound_free(fc);
76  free(seq);
77}
78
79#test test_vrna_sc_add_up_addition_extended
80{
81  int                   i, j, e;
82
83  char                  *seq = vrna_random_string(10, "ACGU");
84
85  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
86
87  for (i = 1, e = 0; i <= fc->length; i++) {
88    e += -100 * i;
89    for (j = 1; j <= fc->length; j++)
90      vrna_sc_add_up(fc, j, -1. * i, VRNA_OPTION_DEFAULT);
91  }
92
93  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
94
95  vrna_sc_t *sc = fc->sc;
96
97  ck_assert(sc != NULL);
98  ck_assert(sc->energy_up != NULL);
99
100  for (i = 1; i <= fc->length; i++)
101    for (j = 1; i + j - 1 <= fc->length; j++)
102      ck_assert_int_eq(sc->energy_up[i][j], j * e);
103
104  vrna_sc_remove(fc);
105  ck_assert(fc->sc == NULL);
106
107  /* clean up */
108  vrna_fold_compound_free(fc);
109  free(seq);
110}
111
112#test test_vrna_sc_add_bp
113{
114  int                   i, j, turn;
115
116  char                  *seq = vrna_random_string(10, "ACGU");
117
118  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
119  turn = fc->params->model_details.min_loop_size;
120
121  for (i = 1; i < fc->length; i++)
122    for (j = i + turn + 1; j <= fc->length; j++)
123      vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
124
125  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
126
127  vrna_sc_t *sc = fc->sc;
128
129  ck_assert(sc != NULL);
130  ck_assert(sc->energy_bp != NULL);
131
132  for (i = 1; i < fc->length; i++)
133    for (j = i + turn + 1; j <= fc->length; j++)
134      ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * (i + j));
135
136  vrna_sc_remove(fc);
137  ck_assert(fc->sc == NULL);
138
139  /* clean up */
140  vrna_fold_compound_free(fc);
141  free(seq);
142}
143
144#test test_vrna_sc_add_bp_addition
145{
146  int                   i, j, c, num, turn;
147
148  num = 10;
149
150  char                  *seq = vrna_random_string(10, "ACGU");
151
152  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
153  turn = fc->params->model_details.min_loop_size;
154
155  for (c = 0; c < num; c++)
156    for (i = 1; i < fc->length; i++)
157      for (j = i + turn + 1; j <= fc->length; j++)
158        vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
159
160  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
161
162  vrna_sc_t *sc = fc->sc;
163
164  ck_assert(sc != NULL);
165  ck_assert(sc->energy_bp != NULL);
166
167  for (i = 1; i < fc->length; i++)
168    for (j = i + turn + 1; j <= fc->length; j++)
169      ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * num * (i + j));
170
171  vrna_sc_remove(fc);
172  ck_assert(fc->sc == NULL);
173
174  /* clean up */
175  vrna_fold_compound_free(fc);
176  free(seq);
177}
178
179#test test_vrna_sc_add_bp_removal
180{
181  int                   i, j, c, num, num_r, turn;
182
183  num   = 10;
184  num_r = 3;
185
186  char                  *seq = vrna_random_string(10, "ACGU");
187
188  vrna_fold_compound_t  *fc = vrna_fold_compound(seq, NULL, VRNA_OPTION_DEFAULT);
189  turn = fc->params->model_details.min_loop_size;
190
191  for (c = 0; c < num; c++)
192    for (i = 1; i < fc->length; i++)
193      for (j = i + turn + 1; j <= fc->length; j++)
194        vrna_sc_add_bp(fc, i, j, -1. * (i + j), VRNA_OPTION_DEFAULT);
195
196  for (c = 0; c < num_r; c++)
197    for (i = 1; i < fc->length; i++)
198      for (j = i + turn + 1; j <= fc->length; j++)
199        vrna_sc_add_bp(fc, i, j, 1. * (i + j), VRNA_OPTION_DEFAULT);
200
201  vrna_sc_prepare(fc, VRNA_OPTION_MFE);
202
203  vrna_sc_t *sc = fc->sc;
204
205  ck_assert(sc != NULL);
206  ck_assert(sc->energy_bp != NULL);
207
208  for (i = 1; i < fc->length; i++)
209    for (j = i + turn + 1; j <= fc->length; j++)
210      ck_assert_int_eq(sc->energy_bp[fc->jindx[j] + i], -100 * (num - num_r) * (i + j));
211
212  vrna_sc_remove(fc);
213  ck_assert(fc->sc == NULL);
214
215  /* clean up */
216  vrna_fold_compound_free(fc);
217  free(seq);
218}
219