1 | /* |
---|
2 | Copyright (c) 2012-2013 Arne Boeckman |
---|
3 | Copyright (c) 2012-2013 Elmar Pruesse |
---|
4 | |
---|
5 | This file is part of SINA. |
---|
6 | |
---|
7 | SINA is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 3 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | */ |
---|
20 | |
---|
21 | #define BOOST_TEST_MODULE CSEQ_COMPARATOR_module |
---|
22 | #include <boost/test/unit_test.hpp> |
---|
23 | |
---|
24 | #include "../cseq_comparator.h" |
---|
25 | using namespace sina; |
---|
26 | |
---|
27 | #include <string> |
---|
28 | using std::string; |
---|
29 | |
---|
30 | #define EQUAL BOOST_CHECK_EQUAL |
---|
31 | #define CASE BOOST_AUTO_TEST_CASE |
---|
32 | #define FCASE BOOST_FIXTURE_TEST_CASE |
---|
33 | |
---|
34 | BOOST_AUTO_TEST_SUITE(CSEQ_COMPARATOR_test); |
---|
35 | |
---|
36 | |
---|
37 | cseq c1 ("", "----AGCUAGCU-------"); |
---|
38 | cseq c2 ("", "--------AGCUAGCU---"); |
---|
39 | cseq c3 ("", "----AGCUAGCUAGCU---"); |
---|
40 | cseq c4 ("", "--------AGCU-------"); |
---|
41 | cseq c5 ("", "----AGAGAGAG-------"); |
---|
42 | cseq c6 ("", "--------AGAGAGAG---"); |
---|
43 | cseq c7 ("", "----agagAGAGagag---"); |
---|
44 | cseq c8 ("", "----AG-CU-A-G-CU---"); |
---|
45 | cseq c9 ("", "----MGCU-A-G-CU--"); |
---|
46 | cseq c10("", "----NNCUBADG-CU----"); |
---|
47 | cseq c11("", "---VVVCUAGCU-----"); |
---|
48 | |
---|
49 | CASE(cover_basic) { |
---|
50 | cseq_comparator comp(CMP_IUPAC_OPTIMISTIC, |
---|
51 | CMP_DIST_NONE, |
---|
52 | CMP_COVER_ABS, false); |
---|
53 | |
---|
54 | EQUAL(comp(c1,c1), 8); |
---|
55 | EQUAL(comp(c1,c2), 4); |
---|
56 | EQUAL(comp(c1,c3), 8); |
---|
57 | EQUAL(comp(c1,c4), 4); |
---|
58 | EQUAL(comp(c1,c5), 4); |
---|
59 | EQUAL(comp(c1,c6), 2); |
---|
60 | EQUAL(comp(c1,c7), 4); |
---|
61 | EQUAL(comp(c2,c2), 8); |
---|
62 | EQUAL(comp(c2,c3), 8); |
---|
63 | EQUAL(comp(c2,c4), 4); |
---|
64 | EQUAL(comp(c2,c5), 2); |
---|
65 | EQUAL(comp(c2,c6), 4); |
---|
66 | EQUAL(comp(c2,c7), 4); |
---|
67 | EQUAL(comp(c3,c3), 12); |
---|
68 | EQUAL(comp(c3,c4), 4); |
---|
69 | EQUAL(comp(c3,c5), 4); |
---|
70 | EQUAL(comp(c3,c6), 4); |
---|
71 | EQUAL(comp(c3,c7), 6); |
---|
72 | EQUAL(comp(c4,c4), 4); |
---|
73 | EQUAL(comp(c4,c5), 2); |
---|
74 | EQUAL(comp(c4,c6), 2); |
---|
75 | EQUAL(comp(c4,c7), 2); |
---|
76 | EQUAL(comp(c5,c5), 8); |
---|
77 | EQUAL(comp(c5,c6), 4); |
---|
78 | EQUAL(comp(c5,c7), 8); |
---|
79 | EQUAL(comp(c6,c6), 8); |
---|
80 | EQUAL(comp(c6,c7), 8); |
---|
81 | EQUAL(comp(c7,c7), 12); |
---|
82 | } |
---|
83 | |
---|
84 | CASE(cover_lowercase) { |
---|
85 | cseq_comparator comp(CMP_IUPAC_OPTIMISTIC, |
---|
86 | CMP_DIST_NONE, |
---|
87 | CMP_COVER_ABS, true); |
---|
88 | |
---|
89 | EQUAL(comp(c1,c7),2); |
---|
90 | EQUAL(comp(c2,c7),2); |
---|
91 | EQUAL(comp(c3,c7),2); |
---|
92 | EQUAL(comp(c4,c7),2); |
---|
93 | EQUAL(comp(c5,c7),4); |
---|
94 | EQUAL(comp(c6,c7),4); |
---|
95 | EQUAL(comp(c7,c7),4); |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | CASE(iupac_compare) { |
---|
100 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
101 | CMP_DIST_NONE, |
---|
102 | CMP_COVER_ABS, false); |
---|
103 | |
---|
104 | //pessimistic tests |
---|
105 | EQUAL(comp(c1,c9), 3); |
---|
106 | EQUAL(comp(c1,c2), 4); |
---|
107 | EQUAL(comp(c1,c10),2); |
---|
108 | EQUAL(comp(c1,c11),6); |
---|
109 | |
---|
110 | |
---|
111 | //optimistic tests |
---|
112 | cseq_comparator comp2(CMP_IUPAC_OPTIMISTIC, |
---|
113 | CMP_DIST_NONE, |
---|
114 | CMP_COVER_ABS, false); |
---|
115 | EQUAL(comp2(c1,c9), 4); |
---|
116 | EQUAL(comp2(c1,c2), 4); |
---|
117 | EQUAL(comp2(c1,c10),4); |
---|
118 | EQUAL(comp2(c1,c11),8); |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | CASE(cover_either) { |
---|
123 | |
---|
124 | // CMP_COVER_QUERY and CMP_COVER_TARGET |
---|
125 | // should be the same, just reversed parameters |
---|
126 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
127 | CMP_DIST_NONE, |
---|
128 | CMP_COVER_QUERY, false); |
---|
129 | |
---|
130 | cseq_comparator comp2(CMP_IUPAC_PESSIMISTIC, |
---|
131 | CMP_DIST_NONE, |
---|
132 | CMP_COVER_TARGET, false); |
---|
133 | |
---|
134 | EQUAL(comp(c1,c1), comp2(c1,c1)); |
---|
135 | EQUAL(comp(c1,c2), comp2(c2,c1)); |
---|
136 | EQUAL(comp(c1,c3), comp2(c3,c1)); |
---|
137 | EQUAL(comp(c1,c4), comp2(c4,c1)); |
---|
138 | EQUAL(comp(c1,c5), comp2(c5,c1)); |
---|
139 | EQUAL(comp(c1,c6), comp2(c6,c1)); |
---|
140 | EQUAL(comp(c1,c7), comp2(c7,c1)); |
---|
141 | EQUAL(comp(c2,c2), comp2(c2,c2)); |
---|
142 | EQUAL(comp(c2,c3), comp2(c3,c2)); |
---|
143 | EQUAL(comp(c2,c4), comp2(c4,c2)); |
---|
144 | EQUAL(comp(c2,c5), comp2(c5,c2)); |
---|
145 | EQUAL(comp(c2,c6), comp2(c6,c2)); |
---|
146 | EQUAL(comp(c2,c7), comp2(c7,c2)); |
---|
147 | EQUAL(comp(c3,c3), comp2(c3,c3)); |
---|
148 | EQUAL(comp(c3,c4), comp2(c4,c3)); |
---|
149 | EQUAL(comp(c3,c5), comp2(c5,c3)); |
---|
150 | EQUAL(comp(c3,c6), comp2(c6,c3)); |
---|
151 | EQUAL(comp(c3,c7), comp2(c7,c3)); |
---|
152 | EQUAL(comp(c4,c4), comp2(c4,c4)); |
---|
153 | EQUAL(comp(c4,c5), comp2(c5,c4)); |
---|
154 | EQUAL(comp(c4,c6), comp2(c6,c4)); |
---|
155 | EQUAL(comp(c4,c7), comp2(c7,c4)); |
---|
156 | EQUAL(comp(c5,c5), comp2(c5,c5)); |
---|
157 | EQUAL(comp(c5,c6), comp2(c6,c5)); |
---|
158 | EQUAL(comp(c5,c7), comp2(c7,c5)); |
---|
159 | EQUAL(comp(c6,c6), comp2(c6,c6)); |
---|
160 | EQUAL(comp(c6,c7), comp2(c7,c6)); |
---|
161 | EQUAL(comp(c7,c7), comp2(c7,c7)); |
---|
162 | |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | CASE(cover_overlap) { |
---|
167 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
168 | CMP_DIST_NONE, |
---|
169 | CMP_COVER_OVERLAP, false); |
---|
170 | |
---|
171 | //OVERLAP: relative to length of overlapping part |
---|
172 | EQUAL(comp(c1,c1), 1); |
---|
173 | EQUAL(comp(c1,c2), 1); |
---|
174 | EQUAL(comp(c1,c3), 1); |
---|
175 | EQUAL(comp(c1,c4), 1); |
---|
176 | EQUAL(comp(c1,c5), 4.0f/8); |
---|
177 | EQUAL(comp(c1,c6), 2.0f/4); |
---|
178 | EQUAL(comp(c1,c8), 2.0f/8); |
---|
179 | EQUAL(comp(c2,c2), 1); |
---|
180 | EQUAL(comp(c2,c3), 1); |
---|
181 | EQUAL(comp(c2,c4), 1); |
---|
182 | EQUAL(comp(c2,c5), 2.0f/4); |
---|
183 | EQUAL(comp(c2,c6), 2.0f/4); |
---|
184 | EQUAL(comp(c2,c7), 2.0f/4); |
---|
185 | EQUAL(comp(c2,c11), 1); |
---|
186 | EQUAL(comp(c10,c11), 2.0f/8); |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | CASE(cover_all) { |
---|
191 | |
---|
192 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
193 | CMP_DIST_NONE, |
---|
194 | CMP_COVER_ALL, false); |
---|
195 | |
---|
196 | |
---|
197 | EQUAL(comp(c1,c2), 4/12.0f); |
---|
198 | EQUAL(comp(c1,c3), 8/12.0f); |
---|
199 | EQUAL(comp(c1,c4), 4/8.0f); |
---|
200 | EQUAL(comp(c1,c5), 4/8.0f); |
---|
201 | EQUAL(comp(c1,c6), 2/12.0f); |
---|
202 | EQUAL(comp(c1,c7), 4/12.0f); |
---|
203 | EQUAL(comp(c2,c2), 8/8.0f); |
---|
204 | EQUAL(comp(c2,c3), 8/12.0f); |
---|
205 | EQUAL(comp(c2,c4), 4/8.0f); |
---|
206 | EQUAL(comp(c2,c5), 2/12.0f); |
---|
207 | EQUAL(comp(c2,c6), 4/8.0f); |
---|
208 | EQUAL(comp(c2,c7), 4/12.0f); |
---|
209 | EQUAL(comp(c3,c3), 12/12.0f); |
---|
210 | EQUAL(comp(c3,c4), 4/12.0f); |
---|
211 | EQUAL(comp(c3,c5), 4/12.0f); |
---|
212 | EQUAL(comp(c3,c6), 4/12.0f); |
---|
213 | EQUAL(comp(c3,c7), 6/12.0f); |
---|
214 | EQUAL(comp(c4,c4), 4/4.0f); |
---|
215 | EQUAL(comp(c4,c5), 2/8.0f); |
---|
216 | EQUAL(comp(c4,c6), 2/8.0f); |
---|
217 | EQUAL(comp(c4,c7), 2/12.0f); |
---|
218 | EQUAL(comp(c5,c5), 8/8.0f); |
---|
219 | EQUAL(comp(c5,c6), 4/12.0f); |
---|
220 | EQUAL(comp(c5,c7), 8/12.0f); |
---|
221 | EQUAL(comp(c6,c6), 8/8.0f); |
---|
222 | |
---|
223 | } |
---|
224 | |
---|
225 | CASE(cover_min){ |
---|
226 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
227 | CMP_DIST_NONE, |
---|
228 | CMP_COVER_MIN, false); |
---|
229 | |
---|
230 | |
---|
231 | EQUAL(comp(c1,c2), 4/8.0f); |
---|
232 | EQUAL(comp(c1,c3), 1); |
---|
233 | EQUAL(comp(c1,c4), 1); |
---|
234 | EQUAL(comp(c1,c5), 4/8.0f); |
---|
235 | EQUAL(comp(c1,c6), 2/8.0f); |
---|
236 | EQUAL(comp(c1,c7), 4/8.0f); |
---|
237 | EQUAL(comp(c2,c2), 1); |
---|
238 | EQUAL(comp(c2,c3), 1); |
---|
239 | |
---|
240 | } |
---|
241 | |
---|
242 | CASE(cover_max){ |
---|
243 | cseq_comparator comp(CMP_IUPAC_PESSIMISTIC, |
---|
244 | CMP_DIST_NONE, |
---|
245 | CMP_COVER_MAX, false); |
---|
246 | |
---|
247 | |
---|
248 | |
---|
249 | // cseq c1 ("",0, "----AGCUAGCU-------"); |
---|
250 | // cseq c3 ("",0, "----AGCUAGCUAGCU---"); |
---|
251 | |
---|
252 | EQUAL(comp(c1,c2), 4/8.0f); |
---|
253 | EQUAL(comp(c1,c3), 8/12.0f); |
---|
254 | |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | BOOST_AUTO_TEST_SUITE_END(); // CSEQ_COMPARATOR_test |
---|
259 | |
---|
260 | /* |
---|
261 | Local Variables: |
---|
262 | mode:c++ |
---|
263 | c-file-style:"stroustrup" |
---|
264 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
---|
265 | indent-tabs-mode:nil |
---|
266 | fill-column:99 |
---|
267 | End: |
---|
268 | */ |
---|
269 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
---|