1 |
|
package jalview.datamodel.features; |
2 |
|
|
3 |
|
import static org.testng.Assert.assertEquals; |
4 |
|
import static org.testng.Assert.assertFalse; |
5 |
|
import static org.testng.Assert.assertNull; |
6 |
|
import static org.testng.Assert.assertSame; |
7 |
|
import static org.testng.Assert.assertTrue; |
8 |
|
import static org.testng.Assert.fail; |
9 |
|
|
10 |
|
import jalview.datamodel.SequenceFeature; |
11 |
|
import jalview.util.matcher.Condition; |
12 |
|
|
13 |
|
import java.util.HashMap; |
14 |
|
import java.util.Iterator; |
15 |
|
import java.util.Locale; |
16 |
|
import java.util.Map; |
17 |
|
|
18 |
|
import org.testng.annotations.Test; |
19 |
|
|
|
|
| 98.5% |
Uncovered Elements: 3 (200) |
Complexity: 12 |
Complexity Density: 0.06 |
|
20 |
|
public class FeatureMatcherSetTest |
21 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
22 |
1 |
@Test(groups = "Functional")... |
23 |
|
public void testMatches_byAttribute() |
24 |
|
{ |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2", |
29 |
|
"AF"); |
30 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
31 |
1 |
fms.and(fm); |
32 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "desc", 11, 12, "grp"); |
33 |
1 |
assertFalse(fms.matches(sf)); |
34 |
1 |
sf.setValue("AF", "foobar"); |
35 |
1 |
assertFalse(fms.matches(sf)); |
36 |
1 |
sf.setValue("AF", "-2"); |
37 |
1 |
assertTrue(fms.matches(sf)); |
38 |
1 |
sf.setValue("AF", "-1"); |
39 |
1 |
assertTrue(fms.matches(sf)); |
40 |
1 |
sf.setValue("AF", "-3"); |
41 |
1 |
assertFalse(fms.matches(sf)); |
42 |
1 |
sf.setValue("AF", ""); |
43 |
1 |
assertFalse(fms.matches(sf)); |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Contains, "Cat", "AF"); |
49 |
1 |
fms = new FeatureMatcherSet(); |
50 |
1 |
fms.and(fm); |
51 |
1 |
assertFalse(fms.matches(sf)); |
52 |
1 |
sf.setValue("AF", "raining cats and dogs"); |
53 |
1 |
assertTrue(fms.matches(sf)); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
56 |
1 |
@Test(groups = "Functional")... |
57 |
|
public void testAnd() |
58 |
|
{ |
59 |
|
|
60 |
1 |
FeatureMatcherI fm1 = FeatureMatcher.byAttribute(Condition.Contains, |
61 |
|
"dog", "AF"); |
62 |
|
|
63 |
1 |
FeatureMatcherI fm2 = FeatureMatcher.byAttribute(Condition.NotContains, |
64 |
|
"how", "CSQ"); |
65 |
|
|
66 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "helix domain", 11, 12, |
67 |
|
6.2f, "grp"); |
68 |
1 |
sf.setValue("AF", "raining cats and dogs"); |
69 |
1 |
sf.setValue("CSQ", "showers"); |
70 |
|
|
71 |
1 |
assertTrue(fm1.matches(sf)); |
72 |
1 |
assertFalse(fm2.matches(sf)); |
73 |
|
|
74 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
75 |
1 |
assertTrue(fms.matches(sf)); |
76 |
1 |
fms.and(fm1); |
77 |
1 |
assertTrue(fms.matches(sf)); |
78 |
1 |
fms.and(fm2); |
79 |
1 |
assertFalse(fms.matches(sf)); |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
1 |
fms = new FeatureMatcherSet(); |
85 |
1 |
fms.and(fm2); |
86 |
1 |
assertFalse(fms.matches(sf)); |
87 |
1 |
FeatureMatcher byLabelPass = FeatureMatcher.byLabel(Condition.Contains, |
88 |
|
"Helix"); |
89 |
1 |
fms.or(byLabelPass); |
90 |
1 |
assertTrue(fms.matches(sf)); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
1 |
fms = new FeatureMatcherSet(); |
96 |
1 |
fms.and(fm2); |
97 |
1 |
assertFalse(fms.matches(sf)); |
98 |
1 |
FeatureMatcher byScoreFail = FeatureMatcher.byScore(Condition.LT, |
99 |
|
"5.9"); |
100 |
1 |
fms.or(byScoreFail); |
101 |
1 |
assertFalse(fms.matches(sf)); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
1 |
fms = new FeatureMatcherSet(); |
107 |
1 |
fms.or(fm2); |
108 |
1 |
fms.or(byScoreFail); |
109 |
1 |
assertFalse(fms.matches(sf)); |
110 |
1 |
fms.or(byLabelPass); |
111 |
1 |
assertTrue(fms.matches(sf)); |
112 |
|
} |
113 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 2 |
Complexity Density: 0.1 |
1PASS
|
|
114 |
1 |
@Test(groups = "Functional")... |
115 |
|
public void testToString() |
116 |
|
{ |
117 |
1 |
Locale.setDefault(Locale.ENGLISH); |
118 |
1 |
FeatureMatcherI fm1 = FeatureMatcher.byAttribute(Condition.LT, "1.2", |
119 |
|
"AF"); |
120 |
1 |
assertEquals(fm1.toString(), "AF < 1.2"); |
121 |
|
|
122 |
1 |
FeatureMatcher fm2 = FeatureMatcher.byAttribute(Condition.NotContains, |
123 |
|
"path", "CLIN_SIG"); |
124 |
1 |
assertEquals(fm2.toString(), "CLIN_SIG does not contain 'path'"); |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
130 |
1 |
assertEquals(fms.toString(), ""); |
131 |
1 |
fms.and(fm1); |
132 |
1 |
assertEquals(fms.toString(), "AF < 1.2"); |
133 |
1 |
fms.and(fm2); |
134 |
1 |
assertEquals(fms.toString(), |
135 |
|
"(AF < 1.2) and (CLIN_SIG does not contain 'path')"); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
1 |
fms = new FeatureMatcherSet(); |
141 |
1 |
assertEquals(fms.toString(), ""); |
142 |
1 |
fms.or(fm1); |
143 |
1 |
assertEquals(fms.toString(), "AF < 1.2"); |
144 |
1 |
fms.or(fm2); |
145 |
1 |
assertEquals(fms.toString(), |
146 |
|
"(AF < 1.2) or (CLIN_SIG does not contain 'path')"); |
147 |
|
|
148 |
1 |
try |
149 |
|
{ |
150 |
1 |
fms.and(fm1); |
151 |
0 |
fail("Expected exception"); |
152 |
|
} catch (IllegalStateException e) |
153 |
|
{ |
154 |
|
|
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 2 |
Complexity Density: 0.1 |
1PASS
|
|
158 |
1 |
@Test(groups = "Functional")... |
159 |
|
public void testOr() |
160 |
|
{ |
161 |
|
|
162 |
1 |
FeatureMatcherI fm1 = FeatureMatcher.byAttribute(Condition.Contains, |
163 |
|
"dog", "AF"); |
164 |
|
|
165 |
1 |
FeatureMatcherI fm2 = FeatureMatcher.byAttribute(Condition.NotContains, |
166 |
|
"how", "CSQ"); |
167 |
|
|
168 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "desc", 11, 12, "grp"); |
169 |
1 |
sf.setValue("AF", "raining cats and dogs"); |
170 |
1 |
sf.setValue("CSQ", "showers"); |
171 |
|
|
172 |
1 |
assertTrue(fm1.matches(sf)); |
173 |
1 |
assertFalse(fm2.matches(sf)); |
174 |
|
|
175 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
176 |
1 |
assertTrue(fms.matches(sf)); |
177 |
1 |
fms.or(fm1); |
178 |
1 |
assertTrue(fms.matches(sf)); |
179 |
1 |
fms.or(fm2); |
180 |
1 |
assertTrue(fms.matches(sf)); |
181 |
|
|
182 |
1 |
fms = new FeatureMatcherSet(); |
183 |
1 |
fms.or(fm2); |
184 |
1 |
assertFalse(fms.matches(sf)); |
185 |
1 |
fms.or(fm1); |
186 |
1 |
assertTrue(fms.matches(sf)); |
187 |
|
|
188 |
1 |
try |
189 |
|
{ |
190 |
1 |
fms.and(fm2); |
191 |
0 |
fail("Expected exception"); |
192 |
|
} catch (IllegalStateException e) |
193 |
|
{ |
194 |
|
|
195 |
|
} |
196 |
|
} |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
198 |
1 |
@Test(groups = "Functional")... |
199 |
|
public void testIsEmpty() |
200 |
|
{ |
201 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2.0", |
202 |
|
"AF"); |
203 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
204 |
1 |
assertTrue(fms.isEmpty()); |
205 |
1 |
fms.and(fm); |
206 |
1 |
assertFalse(fms.isEmpty()); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
209 |
1 |
@Test(groups = "Functional")... |
210 |
|
public void testGetMatchers() |
211 |
|
{ |
212 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
1 |
Iterator<FeatureMatcherI> iterator = fms.getMatchers().iterator(); |
218 |
1 |
assertFalse(iterator.hasNext()); |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
1 |
FeatureMatcherI fm1 = FeatureMatcher.byAttribute(Condition.GE, "-2", |
224 |
|
"AF"); |
225 |
1 |
fms.and(fm1); |
226 |
1 |
iterator = fms.getMatchers().iterator(); |
227 |
1 |
assertSame(fm1, iterator.next()); |
228 |
1 |
assertFalse(iterator.hasNext()); |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
1 |
FeatureMatcherI fm2 = FeatureMatcher.byAttribute(Condition.LT, "8f", |
234 |
|
"AF"); |
235 |
1 |
fms.and(fm2); |
236 |
1 |
iterator = fms.getMatchers().iterator(); |
237 |
1 |
assertSame(fm1, iterator.next()); |
238 |
1 |
assertSame(fm2, iterator.next()); |
239 |
1 |
assertFalse(iterator.hasNext()); |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
246 |
1 |
@Test(groups = "Functional")... |
247 |
|
public void testMatches_compoundKey() |
248 |
|
{ |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2", |
253 |
|
"CSQ", "Consequence"); |
254 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "desc", 2, 10, "grp"); |
255 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
256 |
1 |
fms.and(fm); |
257 |
1 |
assertFalse(fms.matches(sf)); |
258 |
1 |
Map<String, String> csq = new HashMap<>(); |
259 |
1 |
sf.setValue("CSQ", csq); |
260 |
1 |
assertFalse(fms.matches(sf)); |
261 |
1 |
csq.put("Consequence", "-2"); |
262 |
1 |
assertTrue(fms.matches(sf)); |
263 |
1 |
csq.put("Consequence", "-1"); |
264 |
1 |
assertTrue(fms.matches(sf)); |
265 |
1 |
csq.put("Consequence", "-3"); |
266 |
1 |
assertFalse(fms.matches(sf)); |
267 |
1 |
csq.put("Consequence", ""); |
268 |
1 |
assertFalse(fms.matches(sf)); |
269 |
1 |
csq.put("Consequence", "junk"); |
270 |
1 |
assertFalse(fms.matches(sf)); |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Contains, "Cat", "CSQ", |
276 |
|
"Consequence"); |
277 |
1 |
fms = new FeatureMatcherSet(); |
278 |
1 |
fms.and(fm); |
279 |
1 |
assertFalse(fms.matches(sf)); |
280 |
1 |
csq.put("PolyPhen", "damaging"); |
281 |
1 |
assertFalse(fms.matches(sf)); |
282 |
1 |
csq.put("Consequence", "damaging"); |
283 |
1 |
assertFalse(fms.matches(sf)); |
284 |
1 |
csq.put("Consequence", "Catastrophic"); |
285 |
1 |
assertTrue(fms.matches(sf)); |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
@see |
293 |
|
|
|
|
| 95.7% |
Uncovered Elements: 1 (23) |
Complexity: 2 |
Complexity Density: 0.09 |
1PASS
|
|
294 |
1 |
@Test(groups = "Functional")... |
295 |
|
public void testToStableString() |
296 |
|
{ |
297 |
1 |
FeatureMatcherI fm1 = FeatureMatcher.byAttribute(Condition.LT, "1.2", |
298 |
|
"AF"); |
299 |
1 |
assertEquals(fm1.toStableString(), "AF LT 1.2"); |
300 |
|
|
301 |
1 |
FeatureMatcher fm2 = FeatureMatcher.byAttribute(Condition.NotContains, |
302 |
|
"path", "CLIN_SIG"); |
303 |
1 |
assertEquals(fm2.toStableString(), "CLIN_SIG NotContains path"); |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
1 |
FeatureMatcherSetI fms = new FeatureMatcherSet(); |
309 |
1 |
assertEquals(fms.toStableString(), ""); |
310 |
1 |
fms.and(fm1); |
311 |
|
|
312 |
1 |
assertEquals(fms.toStableString(), "AF LT 1.2"); |
313 |
|
|
314 |
1 |
fms.and(fm2); |
315 |
1 |
assertEquals(fms.toStableString(), |
316 |
|
"(AF LT 1.2) AND (CLIN_SIG NotContains path)"); |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
1 |
fms = new FeatureMatcherSet(); |
322 |
1 |
assertEquals(fms.toStableString(), ""); |
323 |
1 |
fms.or(fm1); |
324 |
1 |
assertEquals(fms.toStableString(), "AF LT 1.2"); |
325 |
1 |
fms.or(fm2); |
326 |
1 |
assertEquals(fms.toStableString(), |
327 |
|
"(AF LT 1.2) OR (CLIN_SIG NotContains path)"); |
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
1 |
FeatureMatcher fm3 = FeatureMatcher.byAttribute(Condition.NotMatches, |
333 |
|
"foo bar", "CSQ", "Poly Phen"); |
334 |
1 |
assertEquals(fm3.toStableString(), |
335 |
|
"'CSQ:Poly Phen' NotMatches 'foo bar'"); |
336 |
1 |
fms.or(fm3); |
337 |
1 |
assertEquals(fms.toStableString(), |
338 |
|
"(AF LT 1.2) OR (CLIN_SIG NotContains path) OR ('CSQ:Poly Phen' NotMatches 'foo bar')"); |
339 |
|
|
340 |
1 |
try |
341 |
|
{ |
342 |
1 |
fms.and(fm1); |
343 |
0 |
fail("Expected exception"); |
344 |
|
} catch (IllegalStateException e) |
345 |
|
{ |
346 |
|
|
347 |
|
} |
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
@see |
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
355 |
1 |
@Test(groups = "Functional")... |
356 |
|
public void testFromString() |
357 |
|
{ |
358 |
1 |
String descriptor = "AF LT 1.2"; |
359 |
1 |
FeatureMatcherSetI fms = FeatureMatcherSet.fromString(descriptor); |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
1 |
assertEquals(fms.toStableString(), descriptor); |
366 |
|
|
367 |
|
|
368 |
1 |
fms = FeatureMatcherSet.fromString("('AF' lt '1.2')"); |
369 |
1 |
assertEquals(fms.toStableString(), descriptor); |
370 |
|
|
371 |
1 |
descriptor = "(AF LT 1.2) AND (CLIN_SIG NotContains path)"; |
372 |
1 |
fms = FeatureMatcherSet.fromString(descriptor); |
373 |
1 |
assertEquals(fms.toStableString(), descriptor); |
374 |
|
|
375 |
|
|
376 |
1 |
fms = FeatureMatcherSet |
377 |
|
.fromString("(AF LT 1.2) and (CLIN_SIG NotContains path)"); |
378 |
1 |
assertEquals(fms.toStableString(), descriptor); |
379 |
|
|
380 |
1 |
descriptor = "(AF LT 1.2) OR (CLIN_SIG NotContains path)"; |
381 |
1 |
fms = FeatureMatcherSet.fromString(descriptor); |
382 |
1 |
assertEquals(fms.toStableString(), descriptor); |
383 |
|
|
384 |
|
|
385 |
1 |
fms = FeatureMatcherSet |
386 |
|
.fromString("(AF LT 1.2) or (CLIN_SIG NotContains path)"); |
387 |
1 |
assertEquals(fms.toStableString(), descriptor); |
388 |
|
|
389 |
|
|
390 |
1 |
fms = FeatureMatcherSet |
391 |
|
.fromString("(AF LT 1.2) or CLIN_SIG NotContains path"); |
392 |
1 |
assertEquals(fms.toStableString(), descriptor); |
393 |
|
|
394 |
1 |
descriptor = "(AF LT 1.2) OR (CLIN_SIG NotContains path) OR ('CSQ:Poly Phen' NotMatches 'foo bar')"; |
395 |
1 |
fms = FeatureMatcherSet.fromString(descriptor); |
396 |
1 |
assertEquals(fms.toStableString(), descriptor); |
397 |
|
|
398 |
|
|
399 |
1 |
descriptor = "(AF LT 1.2) OR (CLIN_SIG NotContains path) AND ('CSQ:Poly Phen' NotMatches 'foo bar')"; |
400 |
1 |
assertNull(FeatureMatcherSet.fromString(descriptor)); |
401 |
|
|
402 |
|
|
403 |
1 |
descriptor = "(AF LT 1.2) and (CLIN_SIG NotContains path) or ('CSQ:Poly Phen' NotMatches 'foo bar')"; |
404 |
1 |
assertNull(FeatureMatcherSet.fromString(descriptor)); |
405 |
|
|
406 |
|
|
407 |
1 |
assertNull(FeatureMatcherSet |
408 |
|
.fromString("AF LT 1.2 or CLIN_SIG NotContains path")); |
409 |
|
|
410 |
|
|
411 |
1 |
assertNull(FeatureMatcherSet.fromString("(AF LT 1.2) but (AF GT -2)")); |
412 |
|
|
413 |
|
|
414 |
1 |
assertNull(FeatureMatcherSet.fromString("('AF lt '1.2')")); |
415 |
|
|
416 |
|
|
417 |
1 |
assertNull(FeatureMatcherSet.fromString("('AF' lt '1.2)")); |
418 |
|
} |
419 |
|
} |