1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertNotNull; |
25 |
|
import static org.testng.AssertJUnit.assertTrue; |
26 |
|
import static org.testng.AssertJUnit.fail; |
27 |
|
|
28 |
|
import jalview.datamodel.AlignmentAnnotation; |
29 |
|
import jalview.datamodel.AlignmentI; |
30 |
|
import jalview.datamodel.Annotation; |
31 |
|
import jalview.datamodel.SequenceFeature; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.gui.JvOptionPane; |
34 |
|
|
35 |
|
import java.io.File; |
36 |
|
import java.util.Arrays; |
37 |
|
import java.util.BitSet; |
38 |
|
import java.util.HashMap; |
39 |
|
import java.util.List; |
40 |
|
import java.util.Map; |
41 |
|
|
42 |
|
import org.testng.Assert; |
43 |
|
import org.testng.annotations.BeforeClass; |
44 |
|
import org.testng.annotations.Test; |
45 |
|
|
|
|
| 90.8% |
Uncovered Elements: 25 (271) |
Complexity: 83 |
Complexity Density: 0.47 |
|
46 |
|
public class StockholmFileTest |
47 |
|
{ |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
1 |
@BeforeClass(alwaysRun = true)... |
50 |
|
public void setUpJvOptionPane() |
51 |
|
{ |
52 |
1 |
JvOptionPane.setInteractiveMode(false); |
53 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
54 |
|
} |
55 |
|
|
56 |
|
static String PfamFile = "examples/PF00111_seed.stk", |
57 |
|
RfamFile = "examples/RF00031_folded.stk"; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
59 |
1 |
@Test(groups = { "Functional" })... |
60 |
|
public void pfamFileIO() throws Exception |
61 |
|
{ |
62 |
1 |
testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0, |
63 |
|
false, false, false); |
64 |
|
} |
65 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
66 |
1 |
@Test(groups = { "Functional" })... |
67 |
|
public void pfamFileDataExtraction() throws Exception |
68 |
|
{ |
69 |
1 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
70 |
1 |
AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE, |
71 |
|
new IdentifyFile().identify(PfamFile, DataSourceType.FILE)); |
72 |
1 |
int numpdb = 0; |
73 |
1 |
for (SequenceI sq : al.getSequences()) |
74 |
|
{ |
75 |
206 |
if (sq.getAllPDBEntries() != null) |
76 |
|
{ |
77 |
206 |
numpdb += sq.getAllPDBEntries().size(); |
78 |
|
} |
79 |
|
} |
80 |
1 |
assertTrue( |
81 |
|
"PF00111 seed alignment has at least 1 PDB file, but the reader found none.", |
82 |
|
numpdb > 0); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
85 |
1 |
@Test(groups = { "Functional" })... |
86 |
|
public void rfamFileIO() throws Exception |
87 |
|
{ |
88 |
1 |
testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1, |
89 |
|
false, false, false); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@param |
103 |
|
@param |
104 |
|
|
105 |
|
|
|
|
| 93.8% |
Uncovered Elements: 2 (32) |
Complexity: 5 |
Complexity Density: 0.19 |
|
106 |
3 |
public static void testFileIOwithFormat(File f, FileFormatI ioformat,... |
107 |
|
int naliannot, int nminseqann, boolean ignoreFeatures, |
108 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotations) |
109 |
|
{ |
110 |
3 |
System.out.println("Reading file: " + f); |
111 |
3 |
String ff = f.getPath(); |
112 |
3 |
try |
113 |
|
{ |
114 |
3 |
AppletFormatAdapter rf = new AppletFormatAdapter(); |
115 |
|
|
116 |
3 |
AlignmentI al = rf.readFile(ff, DataSourceType.FILE, |
117 |
|
new IdentifyFile().identify(ff, DataSourceType.FILE)); |
118 |
|
|
119 |
3 |
assertNotNull("Couldn't read supplied alignment data.", al); |
120 |
|
|
121 |
|
|
122 |
272 |
for (int i = 0; i < al.getSequencesArray().length; ++i) |
123 |
|
{ |
124 |
269 |
al.getSequenceAt(i).createDatasetSequence(); |
125 |
|
} |
126 |
3 |
String outputfile = rf.formatSequences(ioformat, al, true); |
127 |
3 |
System.out.println("Output file in '" + ioformat + "':\n" |
128 |
|
+ outputfile + "\n<<EOF\n"); |
129 |
|
|
130 |
3 |
AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile, |
131 |
|
DataSourceType.PASTE, ioformat); |
132 |
3 |
assertNotNull("Couldn't parse reimported alignment data.", al_input); |
133 |
|
|
134 |
3 |
FileFormatI identifyoutput = new IdentifyFile().identify(outputfile, |
135 |
|
DataSourceType.PASTE); |
136 |
3 |
assertNotNull("Identify routine failed for outputformat " + ioformat, |
137 |
|
identifyoutput); |
138 |
3 |
assertTrue( |
139 |
|
"Identify routine could not recognise output generated by '" |
140 |
|
+ ioformat + "' writer", |
141 |
|
ioformat.equals(identifyoutput)); |
142 |
3 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, |
143 |
|
ignoreRowVisibility, allowNullAnnotations); |
144 |
3 |
int numaliannot = 0, numsqswithali = 0; |
145 |
3 |
for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation()) |
146 |
|
{ |
147 |
80 |
if (ala.sequenceRef == null) |
148 |
|
{ |
149 |
4 |
numaliannot++; |
150 |
|
} |
151 |
|
else |
152 |
|
{ |
153 |
76 |
numsqswithali++; |
154 |
|
} |
155 |
|
} |
156 |
3 |
if (naliannot > -1) |
157 |
|
{ |
158 |
1 |
assertEquals("Number of alignment annotations", naliannot, |
159 |
|
numaliannot); |
160 |
|
} |
161 |
|
|
162 |
3 |
assertTrue( |
163 |
|
"Number of sequence associated annotations wasn't at least " |
164 |
|
+ nminseqann, numsqswithali >= nminseqann); |
165 |
|
|
166 |
|
} catch (Exception e) |
167 |
|
{ |
168 |
0 |
e.printStackTrace(); |
169 |
0 |
assertTrue("Couln't format the alignment for output file.", false); |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
@param |
177 |
|
|
178 |
|
@param |
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
|
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
public static void testAlignmentEquivalence(AlignmentI al,... |
185 |
|
AlignmentI al_input, boolean ignoreFeatures) |
186 |
|
{ |
187 |
0 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, false, false); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
@param |
195 |
|
|
196 |
|
@param |
197 |
|
|
198 |
|
|
199 |
|
@param |
200 |
|
|
201 |
|
|
202 |
|
@param |
203 |
|
|
204 |
|
|
205 |
|
@param |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
|
|
| 88.5% |
Uncovered Elements: 12 (104) |
Complexity: 28 |
Complexity Density: 0.42 |
|
211 |
13 |
public static void testAlignmentEquivalence(AlignmentI al,... |
212 |
|
AlignmentI al_input, boolean ignoreFeatures, |
213 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotation) |
214 |
|
{ |
215 |
13 |
assertNotNull("Original alignment was null", al); |
216 |
13 |
assertNotNull("Generated alignment was null", al_input); |
217 |
|
|
218 |
13 |
assertTrue("Alignment dimension mismatch: original: " + al.getHeight() |
219 |
|
+ "x" + al.getWidth() + ", generated: " + al_input.getHeight() |
220 |
|
+ "x" + al_input.getWidth(), |
221 |
|
al.getHeight() == al_input.getHeight() |
222 |
|
&& al.getWidth() == al_input.getWidth()); |
223 |
|
|
224 |
|
|
225 |
13 |
AlignmentAnnotation[] aa_new = al_input.getAlignmentAnnotation(); |
226 |
13 |
AlignmentAnnotation[] aa_original = al.getAlignmentAnnotation(); |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
13 |
int aa_new_size = (aa_new == null ? 0 : aa_new.length); |
232 |
13 |
int aa_original_size = (aa_original == null ? 0 : aa_original.length); |
233 |
13 |
Map<Integer, BitSet> orig_groups = new HashMap<Integer, BitSet>(); |
234 |
13 |
Map<Integer, BitSet> new_groups = new HashMap<Integer, BitSet>(); |
235 |
|
|
236 |
13 |
if (aa_new != null && aa_original != null) |
237 |
|
{ |
238 |
173 |
for (int i = 0; i < aa_original.length; i++) |
239 |
|
{ |
240 |
163 |
if (aa_new.length > i) |
241 |
|
{ |
242 |
163 |
assertEqualSecondaryStructure( |
243 |
|
"Different alignment annotation at position " + i, |
244 |
|
aa_original[i], aa_new[i], allowNullAnnotation); |
245 |
|
|
246 |
163 |
assertEquals("Graph type not identical.", aa_original[i].graph, |
247 |
|
aa_new[i].graph); |
248 |
163 |
if (!ignoreRowVisibility) |
249 |
|
{ |
250 |
158 |
assertEquals("Visibility not identical.", |
251 |
|
aa_original[i].visible, |
252 |
|
aa_new[i].visible); |
253 |
|
} |
254 |
163 |
assertEquals("Threshold line not identical.", |
255 |
|
aa_original[i].threshold, aa_new[i].threshold); |
256 |
|
|
257 |
163 |
Integer o_ggrp = new Integer(aa_original[i].graphGroup + 2); |
258 |
163 |
Integer n_ggrp = new Integer(aa_new[i].graphGroup + 2); |
259 |
163 |
BitSet orig_g = orig_groups.get(o_ggrp); |
260 |
163 |
BitSet new_g = new_groups.get(n_ggrp); |
261 |
163 |
if (orig_g == null) |
262 |
|
{ |
263 |
43 |
orig_groups.put(o_ggrp, orig_g = new BitSet()); |
264 |
|
} |
265 |
163 |
if (new_g == null) |
266 |
|
{ |
267 |
43 |
new_groups.put(n_ggrp, new_g = new BitSet()); |
268 |
|
} |
269 |
163 |
assertEquals("Graph Group pattern differs at annotation " + i, |
270 |
|
orig_g, new_g); |
271 |
163 |
orig_g.set(i); |
272 |
163 |
new_g.set(i); |
273 |
|
} |
274 |
|
else |
275 |
|
{ |
276 |
0 |
System.err.println("No matching annotation row for " |
277 |
|
+ aa_original[i].toString()); |
278 |
|
} |
279 |
|
} |
280 |
|
} |
281 |
13 |
assertEquals( |
282 |
|
"Generated and imported alignment have different annotation sets", |
283 |
|
aa_original_size, aa_new_size); |
284 |
|
|
285 |
|
|
286 |
13 |
SequenceI[] seq_original = new SequenceI[al.getSequencesArray().length]; |
287 |
13 |
seq_original = al.getSequencesArray(); |
288 |
13 |
SequenceI[] seq_new = new SequenceI[al_input.getSequencesArray().length]; |
289 |
13 |
seq_new = al_input.getSequencesArray(); |
290 |
13 |
List<SequenceFeature> sequenceFeatures_original; |
291 |
13 |
List<SequenceFeature> sequenceFeatures_new; |
292 |
13 |
AlignmentAnnotation annot_original, annot_new; |
293 |
|
|
294 |
380 |
for (int i = 0; i < al.getSequencesArray().length; i++) |
295 |
|
{ |
296 |
367 |
String name = seq_original[i].getName(); |
297 |
367 |
int start = seq_original[i].getStart(); |
298 |
367 |
int end = seq_original[i].getEnd(); |
299 |
367 |
System.out.println("Check sequence: " + name + "/" + start + "-" |
300 |
|
+ end); |
301 |
|
|
302 |
|
|
303 |
23928 |
for (int in = 0; in < al_input.getSequencesArray().length; in++) |
304 |
|
{ |
305 |
23928 |
if (name.equals(seq_new[in].getName()) |
306 |
|
&& start == seq_new[in].getStart() |
307 |
|
&& end == seq_new[in].getEnd()) |
308 |
|
{ |
309 |
367 |
String ss_original = seq_original[i].getSequenceAsString(); |
310 |
367 |
String ss_new = seq_new[in].getSequenceAsString(); |
311 |
367 |
assertEquals("The sequences " + name + "/" + start + "-" + end |
312 |
|
+ " are not equal", ss_original, ss_new); |
313 |
|
|
314 |
367 |
assertTrue( |
315 |
|
"Sequence Features were not equivalent" |
316 |
367 |
+ (ignoreFeatures ? " ignoring." : ""), |
317 |
|
ignoreFeatures |
318 |
|
|| (seq_original[i].getSequenceFeatures() == null && seq_new[in] |
319 |
|
.getSequenceFeatures() == null) |
320 |
|
|| (seq_original[i].getSequenceFeatures() != null && seq_new[in] |
321 |
|
.getSequenceFeatures() != null)); |
322 |
|
|
323 |
367 |
if (seq_original[i].getSequenceFeatures() != null |
324 |
|
&& seq_new[in].getSequenceFeatures() != null) |
325 |
|
{ |
326 |
367 |
System.out.println("There are feature!!!"); |
327 |
367 |
sequenceFeatures_original = seq_original[i] |
328 |
|
.getSequenceFeatures(); |
329 |
367 |
sequenceFeatures_new = seq_new[in].getSequenceFeatures(); |
330 |
|
|
331 |
367 |
assertEquals("different number of features", seq_original[i] |
332 |
|
.getSequenceFeatures().size(), seq_new[in] |
333 |
|
.getSequenceFeatures().size()); |
334 |
|
|
335 |
367 |
for (int feat = 0; feat < seq_original[i].getSequenceFeatures() |
336 |
|
.size(); feat++) |
337 |
|
{ |
338 |
0 |
assertEquals("Different features", |
339 |
|
sequenceFeatures_original.get(feat), |
340 |
|
sequenceFeatures_new.get(feat)); |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
367 |
if (al.getSequenceAt(i).getAnnotation() != null |
345 |
|
&& al_input.getSequenceAt(in).getAnnotation() != null) |
346 |
|
{ |
347 |
264 |
for (int j = 0; j < al.getSequenceAt(i).getAnnotation().length; j++) |
348 |
|
{ |
349 |
153 |
if (al.getSequenceAt(i).getAnnotation()[j] != null |
350 |
|
&& al_input.getSequenceAt(in).getAnnotation()[j] != null) |
351 |
|
{ |
352 |
153 |
annot_original = al.getSequenceAt(i).getAnnotation()[j]; |
353 |
153 |
annot_new = al_input.getSequenceAt(in).getAnnotation()[j]; |
354 |
153 |
assertEqualSecondaryStructure( |
355 |
|
"Different annotation elements", annot_original, |
356 |
|
annot_new, allowNullAnnotation); |
357 |
|
} |
358 |
|
} |
359 |
|
} |
360 |
256 |
else if (al.getSequenceAt(i).getAnnotation() == null |
361 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
362 |
|
{ |
363 |
256 |
System.out.println("No annotations"); |
364 |
|
} |
365 |
0 |
else if (al.getSequenceAt(i).getAnnotation() != null |
366 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
367 |
|
{ |
368 |
0 |
fail("Annotations differed between sequences (" |
369 |
|
+ al.getSequenceAt(i).getName() + ") and (" |
370 |
|
+ al_input.getSequenceAt(i).getName() + ")"); |
371 |
|
} |
372 |
367 |
break; |
373 |
|
} |
374 |
|
} |
375 |
|
} |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
@param |
385 |
|
|
386 |
|
@param |
387 |
|
|
388 |
|
@param |
389 |
|
|
390 |
|
@param |
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
|
|
| 87% |
Uncovered Elements: 6 (46) |
Complexity: 31 |
Complexity Density: 1.55 |
|
395 |
366 |
private static void assertEqualSecondaryStructure(String message,... |
396 |
|
AlignmentAnnotation annot_or, AlignmentAnnotation annot_new, |
397 |
|
boolean allowNullEqivalence) |
398 |
|
{ |
399 |
|
|
400 |
|
|
401 |
366 |
if (annot_or.annotations.length != annot_new.annotations.length) |
402 |
|
{ |
403 |
0 |
fail("Different lengths for annotation row elements: " |
404 |
|
+ annot_or.annotations.length + "!=" |
405 |
|
+ annot_new.annotations.length); |
406 |
|
} |
407 |
366 |
boolean isRna = annot_or.isRNA(); |
408 |
366 |
assertTrue("Expected " + (isRna ? " valid RNA " : " no RNA ") |
409 |
|
+ " secondary structure in the row.", |
410 |
|
isRna == annot_new.isRNA()); |
411 |
40796 |
for (int i = 0; i < annot_or.annotations.length; i++) |
412 |
|
{ |
413 |
40458 |
Annotation an_or = annot_or.annotations[i], an_new = annot_new.annotations[i]; |
414 |
40458 |
if (an_or != null && an_new != null) |
415 |
|
{ |
416 |
|
|
417 |
28788 |
if (isRna) |
418 |
|
{ |
419 |
9141 |
if (an_or.secondaryStructure != an_new.secondaryStructure |
420 |
|
|| ((Float.isNaN(an_or.value) != Float |
421 |
|
.isNaN(an_new.value)) || an_or.value != an_new.value)) |
422 |
|
{ |
423 |
0 |
fail("Different RNA secondary structure at column " + i |
424 |
|
+ " expected: [" + annot_or.annotations[i].toString() |
425 |
|
+ "] but got: [" + annot_new.annotations[i].toString() |
426 |
|
+ "]"); |
427 |
|
} |
428 |
|
} |
429 |
|
else |
430 |
|
{ |
431 |
|
|
432 |
19647 |
if ((an_or.isWhitespace() != an_new.isWhitespace()) |
433 |
|
|| !an_or.displayCharacter.trim().equals( |
434 |
|
an_new.displayCharacter.trim()) |
435 |
|
|| !("" + an_or.secondaryStructure).trim().equals( |
436 |
|
("" + an_new.secondaryStructure).trim()) |
437 |
|
|| (an_or.description != an_new.description && !((an_or.description == null && an_new.description |
438 |
|
.trim().length() == 0) |
439 |
|
|| (an_new.description == null && an_or.description |
440 |
|
.trim().length() == 0) || an_or.description |
441 |
|
.trim().equals(an_new.description.trim()))) |
442 |
|
|| !((Float.isNaN(an_or.value) && Float |
443 |
|
.isNaN(an_new.value)) || an_or.value == an_new.value)) |
444 |
|
{ |
445 |
12 |
fail("Annotation Element Mismatch\nElement " + i |
446 |
|
+ " in original: " + annot_or.annotations[i].toString() |
447 |
|
+ "\nElement " + i + " in new: " |
448 |
|
+ annot_new.annotations[i].toString()); |
449 |
|
} |
450 |
|
} |
451 |
|
} |
452 |
11670 |
else if (annot_or.annotations[i] == null |
453 |
|
&& annot_new.annotations[i] == null) |
454 |
|
{ |
455 |
11602 |
continue; |
456 |
|
} |
457 |
|
else |
458 |
|
{ |
459 |
68 |
if (allowNullEqivalence) |
460 |
|
{ |
461 |
65 |
if (an_or != null && an_or.isWhitespace()) |
462 |
|
|
463 |
|
{ |
464 |
0 |
continue; |
465 |
|
} |
466 |
65 |
if (an_new != null && an_new.isWhitespace()) |
467 |
|
{ |
468 |
62 |
continue; |
469 |
|
} |
470 |
|
} |
471 |
|
|
472 |
6 |
fail("Annotation Element Mismatch\nElement " + i + " in original: " |
473 |
6 |
+ (an_or == null ? "is null" : an_or.toString()) |
474 |
|
+ "\nElement " + i + " in new: " |
475 |
6 |
+ (an_new == null ? "is null" : an_new.toString())); |
476 |
|
} |
477 |
|
} |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
|
@see |
482 |
|
|
483 |
|
@param |
484 |
|
@param |
485 |
|
@param |
486 |
|
@param |
487 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
488 |
28 |
public static void assertNotEqualSecondaryStructure(String message,... |
489 |
|
AlignmentAnnotation an_orig, AlignmentAnnotation an_new, |
490 |
|
boolean allowNullEquivalence) |
491 |
|
{ |
492 |
28 |
boolean thrown = false; |
493 |
28 |
try |
494 |
|
{ |
495 |
28 |
assertEqualSecondaryStructure("", an_orig, an_new, |
496 |
|
allowNullEquivalence); |
497 |
|
} catch (AssertionError af) |
498 |
|
{ |
499 |
28 |
thrown = true; |
500 |
|
} |
501 |
28 |
if (!thrown) |
502 |
|
{ |
503 |
0 |
fail("Expected difference for [" + an_orig + "] and [" + an_new + "]"); |
504 |
|
} |
505 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
506 |
26 |
private AlignmentAnnotation makeAnnot(Annotation ae)... |
507 |
|
{ |
508 |
26 |
return new AlignmentAnnotation("label", "description", new Annotation[] |
509 |
|
{ ae }); |
510 |
|
} |
511 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 4 |
Complexity Density: 0.14 |
1PASS
|
|
512 |
1 |
@Test(groups={"Functional"})... |
513 |
|
public void testAnnotationEquivalence() |
514 |
|
{ |
515 |
1 |
AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1)); |
516 |
1 |
AlignmentAnnotation anotherOne = makeAnnot(new Annotation("", "", ' ', |
517 |
|
1)); |
518 |
1 |
AlignmentAnnotation sheet = makeAnnot(new Annotation("","",'E',0f)); |
519 |
1 |
AlignmentAnnotation anotherSheet = makeAnnot(new Annotation("","",'E',0f)); |
520 |
1 |
AlignmentAnnotation sheetWithLabel = makeAnnot(new Annotation("1", "", |
521 |
|
'E', 0f)); |
522 |
1 |
AlignmentAnnotation anotherSheetWithLabel = makeAnnot(new Annotation( |
523 |
|
"1", "", 'E', 0f)); |
524 |
1 |
AlignmentAnnotation rnaNoDC = makeAnnot(new Annotation("","",'<',0f)); |
525 |
1 |
AlignmentAnnotation anotherRnaNoDC = makeAnnot(new Annotation("","",'<',0f)); |
526 |
1 |
AlignmentAnnotation rnaWithDC = makeAnnot(new Annotation("B", "", '<', |
527 |
|
0f)); |
528 |
1 |
AlignmentAnnotation anotherRnaWithDC = makeAnnot(new Annotation("B", |
529 |
|
"", '<', 0f)); |
530 |
|
|
531 |
|
|
532 |
1 |
for (boolean allowNull : new boolean[] { true, false }) |
533 |
|
{ |
534 |
2 |
assertEqualSecondaryStructure("Should be equal", one, anotherOne, |
535 |
|
allowNull); |
536 |
2 |
assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet, |
537 |
|
allowNull); |
538 |
2 |
assertEqualSecondaryStructure("Should be equal", sheetWithLabel, |
539 |
|
anotherSheetWithLabel, allowNull); |
540 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, |
541 |
|
anotherRnaNoDC, allowNull); |
542 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, |
543 |
|
anotherRnaWithDC, allowNull); |
544 |
|
|
545 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC, |
546 |
|
allowNull); |
547 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC, |
548 |
|
allowNull); |
549 |
|
} |
550 |
|
|
551 |
|
|
552 |
1 |
List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet, |
553 |
|
sheetWithLabel, rnaWithDC); |
554 |
5 |
for (int p = 0; p < aaSet.size(); p++) |
555 |
|
{ |
556 |
20 |
for (int q = 0; q < aaSet.size(); q++) |
557 |
|
{ |
558 |
16 |
if (p != q) |
559 |
|
{ |
560 |
12 |
assertNotEqualSecondaryStructure("Should be different", |
561 |
|
aaSet.get(p), aaSet.get(q), false); |
562 |
|
} |
563 |
|
else |
564 |
|
{ |
565 |
4 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
566 |
|
aaSet.get(q), false); |
567 |
4 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
568 |
|
aaSet.get(q), true); |
569 |
4 |
assertNotEqualSecondaryStructure( |
570 |
|
"Should be different to empty anot", aaSet.get(p), |
571 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), false); |
572 |
4 |
assertNotEqualSecondaryStructure( |
573 |
|
"Should be different to empty annot", |
574 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q), |
575 |
|
true); |
576 |
4 |
assertNotEqualSecondaryStructure("Should be different to null", |
577 |
|
aaSet.get(p), makeAnnot(null), false); |
578 |
4 |
assertNotEqualSecondaryStructure("Should be different to null", |
579 |
|
makeAnnot(null), aaSet.get(q), true); |
580 |
|
} |
581 |
|
} |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
} |
587 |
|
|
588 |
|
String aliFile = ">Dm\nAAACCCUUUUACACACGGGAAAGGG"; |
589 |
|
String annFile = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
590 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
591 |
|
+ "(|(|(|(|, .|, .|, .|, .|)|)|)|)|\t0.0\nROWPROPERTIES\t" |
592 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
593 |
|
|
594 |
|
String annFileCurlyWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
595 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
596 |
|
+ "(|(|(|(||{|{||{|{||)|)|)|)||}|}|}|}|\t0.0\nROWPROPERTIES\t" |
597 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
598 |
|
String annFileFullWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
599 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
600 |
|
+ "(|(|(|(||{|{||[|[||)|)|)|)||}|}|]|]|\t0.0\nROWPROPERTIES\t" |
601 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
602 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
603 |
1 |
@Test(groups = { "Functional" })... |
604 |
|
public void secondaryStructureForRNASequence() throws Exception |
605 |
|
{ |
606 |
1 |
roundTripSSForRNA(aliFile, annFile); |
607 |
|
} |
608 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
609 |
1 |
@Test(groups = { "Functional" })... |
610 |
|
public void curlyWUSSsecondaryStructureForRNASequence() throws Exception |
611 |
|
{ |
612 |
1 |
roundTripSSForRNA(aliFile, annFileCurlyWuss); |
613 |
|
} |
614 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
615 |
1 |
@Test(groups = { "Functional" })... |
616 |
|
public void fullWUSSsecondaryStructureForRNASequence() throws Exception |
617 |
|
{ |
618 |
1 |
roundTripSSForRNA(aliFile, annFileFullWuss); |
619 |
|
} |
620 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
621 |
1 |
@Test(groups = { "Functional" })... |
622 |
|
public void detectWussBrackets() |
623 |
|
{ |
624 |
1 |
for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' }) |
625 |
|
{ |
626 |
8 |
Assert.assertTrue(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0), |
627 |
|
"Didn't recognise " + ch + " as a WUSS bracket"); |
628 |
|
} |
629 |
1 |
for (char ch : new char[] { '@', '!', 'V', 'Q', '*', ' ', '-', '.' }) |
630 |
|
{ |
631 |
8 |
Assert.assertFalse(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0), |
632 |
|
"Shouldn't recognise " + ch + " as a WUSS bracket"); |
633 |
|
} |
634 |
|
} |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
635 |
3 |
private static void roundTripSSForRNA(String aliFile, String annFile)... |
636 |
|
throws Exception |
637 |
|
{ |
638 |
3 |
AlignmentI al = new AppletFormatAdapter().readFile(aliFile, |
639 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
640 |
3 |
AnnotationFile aaf = new AnnotationFile(); |
641 |
3 |
aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE); |
642 |
3 |
al.getAlignmentAnnotation()[0].visible = true; |
643 |
|
|
644 |
|
|
645 |
3 |
StockholmFile sf = new StockholmFile(al); |
646 |
|
|
647 |
3 |
String stockholmFile = sf.print(al.getSequencesArray(), true); |
648 |
|
|
649 |
3 |
AlignmentI newAl = new AppletFormatAdapter().readFile(stockholmFile, |
650 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Stockholm); |
651 |
|
|
652 |
|
|
653 |
|
|
654 |
3 |
testAlignmentEquivalence(al, newAl, true, true, true); |
655 |
|
|
656 |
|
} |
657 |
|
} |