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.ConversionUtils.wrapDataProvider; |
24 |
|
|
25 |
|
import jalview.analysis.SequenceIdMatcher; |
26 |
|
import jalview.analysis.TreeModel; |
27 |
|
import jalview.datamodel.BinaryNode; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.datamodel.SequenceNode; |
30 |
|
import jalview.gui.JvOptionPane; |
31 |
|
|
32 |
|
import java.util.Arrays; |
33 |
|
import java.util.Collection; |
34 |
|
import java.util.Vector; |
35 |
|
|
36 |
|
import org.junit.runners.Parameterized.Parameters; |
37 |
|
import org.testng.Assert; |
38 |
|
import org.testng.AssertJUnit; |
39 |
|
import org.testng.annotations.AfterClass; |
40 |
|
import org.testng.annotations.BeforeClass; |
41 |
|
import org.testng.annotations.Factory; |
42 |
|
import org.testng.annotations.Test; |
43 |
|
|
44 |
|
|
45 |
|
@author |
46 |
|
|
47 |
|
|
|
|
| 89.7% |
Uncovered Elements: 7 (68) |
Complexity: 14 |
Complexity Density: 0.29 |
|
48 |
|
public class NewickFileTests |
49 |
|
{ |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
3 |
@BeforeClass(alwaysRun = true)... |
52 |
|
public void setUpJvOptionPane() |
53 |
|
{ |
54 |
3 |
JvOptionPane.setInteractiveMode(false); |
55 |
3 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
4 |
@Factory... |
59 |
|
public static Object[] factoryData() |
60 |
|
{ |
61 |
4 |
return wrapDataProvider(NewickFileTests.class, data()); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
4 |
@Parameters... |
65 |
|
public static Collection data() |
66 |
|
{ |
67 |
4 |
return Arrays.asList(new Object[][] { |
68 |
|
|
69 |
|
new String[] |
70 |
|
{ "Simple uniref50 newick", |
71 |
|
"(((FER_BRANA:128.0,FER3_RAPSA:128.0):50.75,FER_CAPAA:178.75):121.94443,(Q93Z60_ARATH:271.45456,((O80429_MAIZE:183.0,FER1_MAIZE:183.0):30.5,((Q7XA98_TRIPR:90.0,FER1_PEA:90.0):83.32143,(((FER2_ARATH:64.0,FER1_ARATH:64.0):94.375,(FER1_SPIOL:124.5,FER1_MESCR:124.5):33.875):6.4166718,((Q93XJ9_SOLTU:33.5,FER1_SOLLC:33.5):49.0,FER_CAPAN:82.5):82.29167):8.529755):40.178574):57.95456):29.239868);" }, |
72 |
|
new String[] |
73 |
|
{ "Tree with quotes", |
74 |
|
"('Syn_PROSU-1_IIh_3d(CA4)|CK_Syn_PROSU-1_1907':1.0638313,'Syn_MINOS11_5.3_3d(CA4)|CK_Syn_MINOS11_750':1.063831);" }, |
75 |
|
new String[] |
76 |
|
{ "Tree with double escaped comma in node", |
77 |
|
"('Syn_PROSU-1_IIh_3d(CA4)|CK_Syn_PROSU-1_1907':1.0638313,'Syn_MINOS11_5.3_3d(CA4)''|CK_Syn_MINOS11_750':1.063831);" } }); |
78 |
|
}; |
79 |
|
|
80 |
|
String name, testTree; |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
82 |
12 |
public NewickFileTests(String _name, String _testTree)... |
83 |
|
{ |
84 |
12 |
this.name = _name; |
85 |
12 |
this.testTree = _testTree; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
@throws |
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
91 |
3 |
@BeforeClass(alwaysRun = true)... |
92 |
|
public static void setUpBeforeClass() throws Exception |
93 |
|
{ |
94 |
|
} |
95 |
|
|
|
|
| 87.3% |
Uncovered Elements: 7 (55) |
Complexity: 8 |
Complexity Density: 0.19 |
1PASS
|
|
96 |
3 |
@Test(groups = { "Functional" })... |
97 |
|
public void testTreeIO() throws Exception |
98 |
|
{ |
99 |
3 |
String stage = "Init", treename = " '" + name + "' :"; |
100 |
3 |
try |
101 |
|
{ |
102 |
3 |
stage = "Parsing testTree " + treename; |
103 |
3 |
System.out.println(treename + "\n" + testTree); |
104 |
3 |
NewickFile nf = new NewickFile(testTree, DataSourceType.PASTE); |
105 |
3 |
nf.parse(); |
106 |
3 |
AssertJUnit.assertTrue( |
107 |
|
stage + "Invalid Tree '" + nf.getWarningMessage() + "'", |
108 |
|
nf.isValid()); |
109 |
3 |
BinaryNode tree = nf.getTree(); |
110 |
3 |
AssertJUnit.assertTrue(stage + "Null Tree", tree != null); |
111 |
3 |
stage = "Creating newick file from testTree " + treename; |
112 |
3 |
String gentree = new NewickFile(tree).print(nf.HasBootstrap(), |
113 |
|
nf.HasDistances()); |
114 |
3 |
AssertJUnit.assertTrue(stage + "Empty string generated", |
115 |
|
gentree != null && gentree.trim().length() > 0); |
116 |
3 |
stage = "Parsing regenerated testTree " + treename; |
117 |
3 |
NewickFile nf_regen = new NewickFile(gentree, DataSourceType.PASTE); |
118 |
3 |
nf_regen.parse(); |
119 |
3 |
AssertJUnit.assertTrue( |
120 |
|
stage + "Newick file is invalid ('" |
121 |
|
+ nf_regen.getWarningMessage() + "')", |
122 |
|
nf_regen.isValid()); |
123 |
3 |
BinaryNode tree_regen = nf.getTree(); |
124 |
3 |
AssertJUnit.assertTrue(stage + "Null Tree", tree_regen != null); |
125 |
3 |
stage = "Compare original and generated tree" + treename; |
126 |
|
|
127 |
3 |
Vector<BinaryNode> oseqs, nseqs; |
128 |
3 |
oseqs = new TreeModel(new SequenceI[0], null, nf) |
129 |
|
.findLeaves(nf.getTree()); |
130 |
3 |
AssertJUnit.assertTrue(stage + "No nodes in original tree.", |
131 |
|
oseqs.size() > 0); |
132 |
3 |
SequenceI[] olsqs = new SequenceI[oseqs.size()]; |
133 |
22 |
for (int i = 0, iSize = oseqs.size(); i < iSize; i++) |
134 |
|
{ |
135 |
19 |
olsqs[i] = (SequenceI) oseqs.get(i).element(); |
136 |
|
} |
137 |
3 |
nseqs = new TreeModel(new SequenceI[0], null, nf_regen) |
138 |
|
.findLeaves(nf_regen.getTree()); |
139 |
3 |
AssertJUnit.assertTrue(stage + "No nodes in regerated tree.", |
140 |
|
nseqs.size() > 0); |
141 |
3 |
SequenceI[] nsqs = new SequenceI[nseqs.size()]; |
142 |
22 |
for (int i = 0, iSize = nseqs.size(); i < iSize; i++) |
143 |
|
{ |
144 |
19 |
nsqs[i] = (SequenceI) nseqs.get(i).element(); |
145 |
|
} |
146 |
3 |
AssertJUnit.assertTrue( |
147 |
|
stage + " Different number of leaves (original " |
148 |
|
+ olsqs.length + " and regen " + nsqs.length + ")", |
149 |
|
olsqs.length == nsqs.length); |
150 |
3 |
SequenceIdMatcher omatcher = new SequenceIdMatcher(olsqs), |
151 |
|
nmatcher = new SequenceIdMatcher(nsqs); |
152 |
|
|
153 |
3 |
SequenceI[] osmatches = omatcher.findIdMatch(nsqs); |
154 |
3 |
SequenceI[] nsmatches = nmatcher.findIdMatch(olsqs); |
155 |
3 |
String warns = ""; |
156 |
22 |
for (int i = 0, iSize = nseqs.size(); i < iSize; i++) |
157 |
|
{ |
158 |
19 |
if (nsmatches[i] == null) |
159 |
|
{ |
160 |
0 |
warns += "\noriginal sequence ID '" + olsqs[i].getName() |
161 |
|
+ "' wasn't found in regenerated set."; |
162 |
|
} |
163 |
19 |
if (osmatches[i] == null) |
164 |
|
{ |
165 |
0 |
warns += "\nregenerated sequence ID '" + nsqs[i].getName() |
166 |
|
+ "' wasn't found in original set."; |
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
3 |
if (warns.length() > 0) |
171 |
|
{ |
172 |
0 |
Assert.fail(stage + warns); |
173 |
|
} |
174 |
|
} catch (Exception x) |
175 |
|
{ |
176 |
0 |
throw (new Exception(stage + "Exception raised", x)); |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
@throws |
182 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
183 |
3 |
@AfterClass(alwaysRun = true)... |
184 |
|
public static void tearDownAfterClass() throws Exception |
185 |
|
{ |
186 |
|
} |
187 |
|
|
188 |
|
} |