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.assertNotNull; |
24 |
|
import static org.testng.AssertJUnit.assertTrue; |
25 |
|
|
26 |
|
import jalview.datamodel.AlignmentI; |
27 |
|
import jalview.datamodel.HiddenColumns; |
28 |
|
import jalview.gui.JvOptionPane; |
29 |
|
import jalview.io.AnnotationFile.ViewDef; |
30 |
|
|
31 |
|
import java.io.File; |
32 |
|
import java.util.Hashtable; |
33 |
|
|
34 |
|
import org.testng.Assert; |
35 |
|
import org.testng.annotations.BeforeClass; |
36 |
|
import org.testng.annotations.Test; |
37 |
|
|
|
|
| 87.5% |
Uncovered Elements: 5 (40) |
Complexity: 7 |
Complexity Density: 0.21 |
|
38 |
|
public class AnnotationFileIOTest |
39 |
|
{ |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
1 |
@BeforeClass(alwaysRun = true)... |
42 |
|
public void setUpJvOptionPane() |
43 |
|
{ |
44 |
1 |
JvOptionPane.setInteractiveMode(false); |
45 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
46 |
|
} |
47 |
|
|
48 |
|
static String TestFiles[][] = { |
49 |
|
{ "Test example annotation import/export", "examples/uniref50.fa", |
50 |
|
"examples/testdata/example_annot_file.jva" }, |
51 |
|
{ "Test multiple combine annotation statements import/export", |
52 |
|
"examples/uniref50.fa", |
53 |
|
"examples/testdata/test_combine_annot.jva" }, |
54 |
|
{ |
55 |
|
"Test multiple combine annotation statements with sequence_ref import/export", |
56 |
|
"examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva" }, |
57 |
|
{ |
58 |
|
"Test group only annotation file parsing results in parser indicating annotation was parsed", |
59 |
|
"examples/uniref50.fa", "examples/testdata/test_grpannot.jva" }, |
60 |
|
{ "Test hiding/showing of insertions on sequence_ref", |
61 |
|
"examples/uniref50.fa", "examples/testdata/uniref50_seqref.jva" } }; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
63 |
1 |
@Test(groups = { "Functional" })... |
64 |
|
public void exampleAnnotationFileIO() throws Exception |
65 |
|
{ |
66 |
1 |
for (String[] testPair : TestFiles) |
67 |
|
{ |
68 |
5 |
testAnnotationFileIO(testPair[0], new File(testPair[1]), new File( |
69 |
|
testPair[2])); |
70 |
|
} |
71 |
|
} |
72 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
73 |
10 |
AlignmentI readAlignmentFile(File f)... |
74 |
|
{ |
75 |
10 |
System.out.println("Reading file: " + f); |
76 |
10 |
String ff = f.getPath(); |
77 |
10 |
try |
78 |
|
{ |
79 |
10 |
FormatAdapter rf = new FormatAdapter(); |
80 |
|
|
81 |
10 |
AlignmentI al = rf.readFile(ff, DataSourceType.FILE, |
82 |
|
new IdentifyFile().identify(ff, DataSourceType.FILE)); |
83 |
|
|
84 |
|
|
85 |
160 |
for (int i = 0; i < al.getSequencesArray().length; ++i) |
86 |
|
{ |
87 |
150 |
al.getSequenceAt(i).createDatasetSequence(); |
88 |
|
} |
89 |
10 |
assertNotNull("Couldn't read supplied alignment data.", al); |
90 |
10 |
return al; |
91 |
|
} catch (Exception e) |
92 |
|
{ |
93 |
0 |
e.printStackTrace(); |
94 |
|
} |
95 |
0 |
Assert.fail("Couln't read the alignment in file '" + f.toString() + "'"); |
96 |
0 |
return null; |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
@param |
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 2 |
Complexity Density: 0.11 |
|
109 |
5 |
void testAnnotationFileIO(String testname, File f,... |
110 |
|
File annotFile) |
111 |
|
{ |
112 |
5 |
System.out.println("Test: " + testname + "\nReading annotation file '" |
113 |
|
+ annotFile + "' onto : " + f); |
114 |
5 |
String af = annotFile.getPath(); |
115 |
5 |
try |
116 |
|
{ |
117 |
5 |
AlignmentI al = readAlignmentFile(f); |
118 |
5 |
HiddenColumns cs = new HiddenColumns(); |
119 |
5 |
assertTrue( |
120 |
|
"Test " |
121 |
|
+ testname |
122 |
|
+ "\nAlignment was not annotated - annotation file not imported.", |
123 |
|
new AnnotationFile().readAnnotationFile(al, cs, af, |
124 |
|
DataSourceType.FILE)); |
125 |
|
|
126 |
5 |
AnnotationFile aff = new AnnotationFile(); |
127 |
|
|
128 |
5 |
ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs, |
129 |
|
new Hashtable()); |
130 |
5 |
String anfileout = new AnnotationFile().printAnnotations( |
131 |
|
al.getAlignmentAnnotation(), al.getGroups(), |
132 |
|
al.getProperties(), null, al, v); |
133 |
5 |
assertTrue( |
134 |
|
"Test " |
135 |
|
+ testname |
136 |
|
+ "\nAlignment annotation file was not regenerated. Null string", |
137 |
|
anfileout != null); |
138 |
5 |
assertTrue( |
139 |
|
"Test " |
140 |
|
+ testname |
141 |
|
+ "\nAlignment annotation file was not regenerated. Empty string", |
142 |
|
anfileout.length() > "JALVIEW_ANNOTATION".length()); |
143 |
|
|
144 |
5 |
System.out.println("Output annotation file:\n" + anfileout |
145 |
|
+ "\n<<EOF\n"); |
146 |
|
|
147 |
5 |
AlignmentI al_new = readAlignmentFile(f); |
148 |
5 |
assertTrue( |
149 |
|
"Test " |
150 |
|
+ testname |
151 |
|
+ "\nregenerated annotation file did not annotate alignment.", |
152 |
|
new AnnotationFile().readAnnotationFile(al_new, anfileout, |
153 |
|
DataSourceType.PASTE)); |
154 |
|
|
155 |
|
|
156 |
5 |
StockholmFileTest.testAlignmentEquivalence(al, al_new, false, false, |
157 |
|
false); |
158 |
5 |
return; |
159 |
|
} catch (Exception e) |
160 |
|
{ |
161 |
0 |
e.printStackTrace(); |
162 |
|
} |
163 |
0 |
Assert.fail("Test " |
164 |
|
+ testname |
165 |
|
+ "\nCouldn't complete Annotation file roundtrip input/output/input test for '" |
166 |
|
+ annotFile + "'."); |
167 |
|
} |
168 |
|
} |