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 |
|
|
|
|
| 0% |
Uncovered Elements: 68 (68) |
Complexity: 14 |
Complexity Density: 0.29 |
|
48 |
|
public class NewickFileTests |
49 |
|
{ |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
0 |
@BeforeClass(alwaysRun = true)... |
52 |
|
public void setUpJvOptionPane() |
53 |
|
{ |
54 |
0 |
JvOptionPane.setInteractiveMode(false); |
55 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
@Factory... |
59 |
|
public static Object[] factoryData() |
60 |
|
{ |
61 |
0 |
return wrapDataProvider(NewickFileTests.class, data()); |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Parameters... |
65 |
|
public static Collection data() |
66 |
|
{ |
67 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
82 |
0 |
public NewickFileTests(String _name, String _testTree)... |
83 |
|
{ |
84 |
0 |
this.name = _name; |
85 |
0 |
this.testTree = _testTree; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
@throws |
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
91 |
0 |
@BeforeClass(alwaysRun = true)... |
92 |
|
public static void setUpBeforeClass() throws Exception |
93 |
|
{ |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 8 |
Complexity Density: 0.19 |
4-
|
|
96 |
0 |
@Test(groups = { "Functional" })... |
97 |
|
public void testTreeIO() throws Exception |
98 |
|
{ |
99 |
0 |
String stage = "Init", treename = " '" + name + "' :"; |
100 |
0 |
try |
101 |
|
{ |
102 |
0 |
stage = "Parsing testTree " + treename; |
103 |
0 |
System.out.println(treename + "\n" + testTree); |
104 |
0 |
NewickFile nf = new NewickFile(testTree, DataSourceType.PASTE); |
105 |
0 |
nf.parse(); |
106 |
0 |
AssertJUnit.assertTrue( |
107 |
|
stage + "Invalid Tree '" + nf.getWarningMessage() + "'", |
108 |
|
nf.isValid()); |
109 |
0 |
BinaryNode tree = nf.getTree(); |
110 |
0 |
AssertJUnit.assertTrue(stage + "Null Tree", tree != null); |
111 |
0 |
stage = "Creating newick file from testTree " + treename; |
112 |
0 |
String gentree = new NewickFile(tree).print(nf.HasBootstrap(), |
113 |
|
nf.HasDistances()); |
114 |
0 |
AssertJUnit.assertTrue(stage + "Empty string generated", |
115 |
|
gentree != null && gentree.trim().length() > 0); |
116 |
0 |
stage = "Parsing regenerated testTree " + treename; |
117 |
0 |
NewickFile nf_regen = new NewickFile(gentree, DataSourceType.PASTE); |
118 |
0 |
nf_regen.parse(); |
119 |
0 |
AssertJUnit.assertTrue( |
120 |
|
stage + "Newick file is invalid ('" |
121 |
|
+ nf_regen.getWarningMessage() + "')", |
122 |
|
nf_regen.isValid()); |
123 |
0 |
BinaryNode tree_regen = nf.getTree(); |
124 |
0 |
AssertJUnit.assertTrue(stage + "Null Tree", tree_regen != null); |
125 |
0 |
stage = "Compare original and generated tree" + treename; |
126 |
|
|
127 |
0 |
Vector<BinaryNode> oseqs, nseqs; |
128 |
0 |
oseqs = new TreeModel(new SequenceI[0], null, nf) |
129 |
|
.findLeaves(nf.getTree()); |
130 |
0 |
AssertJUnit.assertTrue(stage + "No nodes in original tree.", |
131 |
|
oseqs.size() > 0); |
132 |
0 |
SequenceI[] olsqs = new SequenceI[oseqs.size()]; |
133 |
0 |
for (int i = 0, iSize = oseqs.size(); i < iSize; i++) |
134 |
|
{ |
135 |
0 |
olsqs[i] = (SequenceI) oseqs.get(i).element(); |
136 |
|
} |
137 |
0 |
nseqs = new TreeModel(new SequenceI[0], null, nf_regen) |
138 |
|
.findLeaves(nf_regen.getTree()); |
139 |
0 |
AssertJUnit.assertTrue(stage + "No nodes in regerated tree.", |
140 |
|
nseqs.size() > 0); |
141 |
0 |
SequenceI[] nsqs = new SequenceI[nseqs.size()]; |
142 |
0 |
for (int i = 0, iSize = nseqs.size(); i < iSize; i++) |
143 |
|
{ |
144 |
0 |
nsqs[i] = (SequenceI) nseqs.get(i).element(); |
145 |
|
} |
146 |
0 |
AssertJUnit.assertTrue( |
147 |
|
stage + " Different number of leaves (original " |
148 |
|
+ olsqs.length + " and regen " + nsqs.length + ")", |
149 |
|
olsqs.length == nsqs.length); |
150 |
0 |
SequenceIdMatcher omatcher = new SequenceIdMatcher(olsqs), |
151 |
|
nmatcher = new SequenceIdMatcher(nsqs); |
152 |
|
|
153 |
0 |
SequenceI[] osmatches = omatcher.findIdMatch(nsqs); |
154 |
0 |
SequenceI[] nsmatches = nmatcher.findIdMatch(olsqs); |
155 |
0 |
String warns = ""; |
156 |
0 |
for (int i = 0, iSize = nseqs.size(); i < iSize; i++) |
157 |
|
{ |
158 |
0 |
if (nsmatches[i] == null) |
159 |
|
{ |
160 |
0 |
warns += "\noriginal sequence ID '" + olsqs[i].getName() |
161 |
|
+ "' wasn't found in regenerated set."; |
162 |
|
} |
163 |
0 |
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 |
0 |
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 |
0 |
@AfterClass(alwaysRun = true)... |
184 |
|
public static void tearDownAfterClass() throws Exception |
185 |
|
{ |
186 |
|
} |
187 |
|
|
188 |
|
} |