1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.jabaws; |
22 |
|
|
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import static org.testng.AssertJUnit.assertNotNull; |
26 |
|
import static org.testng.AssertJUnit.assertTrue; |
27 |
|
|
28 |
|
import jalview.bin.Cache; |
29 |
|
import jalview.bin.Console; |
30 |
|
import jalview.datamodel.AlignmentAnnotation; |
31 |
|
import jalview.datamodel.AlignmentI; |
32 |
|
import jalview.gui.JvOptionPane; |
33 |
|
import jalview.io.AnnotationFile; |
34 |
|
import jalview.io.DataSourceType; |
35 |
|
import jalview.io.FileFormat; |
36 |
|
import jalview.io.FormatAdapter; |
37 |
|
import jalview.io.StockholmFileTest; |
38 |
|
import jalview.project.Jalview2XML; |
39 |
|
import jalview.ws.jws2.Jws2Discoverer; |
40 |
|
import jalview.ws.jws2.RNAalifoldClient; |
41 |
|
import jalview.ws.jws2.SequenceAnnotationWSClient; |
42 |
|
import jalview.ws.jws2.jabaws2.Jws2Instance; |
43 |
|
import jalview.ws.params.AutoCalcSetting; |
44 |
|
|
45 |
|
import java.awt.Component; |
46 |
|
import java.io.File; |
47 |
|
import java.util.ArrayList; |
48 |
|
import java.util.List; |
49 |
|
|
50 |
|
import javax.swing.JMenu; |
51 |
|
import javax.swing.JMenuItem; |
52 |
|
|
53 |
|
import org.testng.Assert; |
54 |
|
import org.testng.annotations.AfterClass; |
55 |
|
import org.testng.annotations.BeforeClass; |
56 |
|
import org.testng.annotations.Test; |
57 |
|
|
58 |
|
import compbio.metadata.Argument; |
59 |
|
import compbio.metadata.WrongParameterException; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@Test(singleThreaded = true) |
|
|
| 0% |
Uncovered Elements: 138 (138) |
Complexity: 30 |
Complexity Density: 0.31 |
|
66 |
|
public class RNAStructExportImport |
67 |
|
{ |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
0 |
@BeforeClass(alwaysRun = true)... |
70 |
|
public void setUpJvOptionPane() |
71 |
|
{ |
72 |
0 |
JvOptionPane.setInteractiveMode(false); |
73 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
74 |
|
} |
75 |
|
|
76 |
|
private static final String JAR_FILE_NAME = "testRnalifold_param.jar"; |
77 |
|
|
78 |
|
public static String testseqs = "examples/RF00031_folded.stk"; |
79 |
|
|
80 |
|
public static Jws2Discoverer disc; |
81 |
|
|
82 |
|
public static Jws2Instance rnaalifoldws; |
83 |
|
|
84 |
|
jalview.ws.jws2.RNAalifoldClient alifoldClient; |
85 |
|
|
86 |
|
public static jalview.gui.AlignFrame af = null; |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 5 |
Complexity Density: 0.24 |
|
88 |
0 |
@BeforeClass(alwaysRun = true)... |
89 |
|
public static void setUpBeforeClass() throws Exception |
90 |
|
{ |
91 |
0 |
Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
92 |
0 |
Console.initLogger(); |
93 |
0 |
disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false); |
94 |
|
|
95 |
0 |
while (disc.isRunning()) |
96 |
|
{ |
97 |
|
|
98 |
0 |
Thread.sleep(100); |
99 |
|
} |
100 |
|
|
101 |
0 |
for (Jws2Instance svc : disc.getServices()) |
102 |
|
{ |
103 |
|
|
104 |
0 |
if (svc.getServiceTypeURI().toLowerCase(Locale.ROOT) |
105 |
|
.contains("rnaalifoldws")) |
106 |
|
{ |
107 |
0 |
rnaalifoldws = svc; |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
0 |
System.out.println("State of rnaalifoldws: " + rnaalifoldws); |
112 |
|
|
113 |
0 |
if (rnaalifoldws == null) |
114 |
|
{ |
115 |
0 |
Assert.fail("no web service"); |
116 |
|
} |
117 |
|
|
118 |
0 |
jalview.io.FileLoader fl = new jalview.io.FileLoader(false); |
119 |
|
|
120 |
0 |
af = fl.LoadFileWaitTillLoaded(testseqs, |
121 |
|
jalview.io.DataSourceType.FILE); |
122 |
|
|
123 |
0 |
assertNotNull("Couldn't load test data ('" + testseqs + "')", af); |
124 |
|
|
125 |
|
|
126 |
0 |
List<AlignmentAnnotation> aal = new ArrayList<>(); |
127 |
0 |
for (AlignmentAnnotation rna : af.getViewport().getAlignment() |
128 |
|
.getAlignmentAnnotation()) |
129 |
|
{ |
130 |
0 |
if (rna.isRNA()) |
131 |
|
{ |
132 |
0 |
aal.add(rna); |
133 |
|
} |
134 |
|
} |
135 |
0 |
for (AlignmentAnnotation rna : aal) |
136 |
|
{ |
137 |
0 |
af.getViewport().getAlignment().deleteAnnotation(rna); |
138 |
|
} |
139 |
0 |
af.getViewport().alignmentChanged(af.alignPanel); |
140 |
|
|
141 |
|
} |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
143 |
0 |
@AfterClass(alwaysRun = true)... |
144 |
|
public static void tearDownAfterClass() throws Exception |
145 |
|
{ |
146 |
0 |
if (af != null) |
147 |
|
{ |
148 |
0 |
af.setVisible(false); |
149 |
0 |
af.dispose(); |
150 |
0 |
File f = new File(JAR_FILE_NAME); |
151 |
0 |
if (f.exists()) |
152 |
|
{ |
153 |
0 |
f.delete(); |
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
4-
|
|
158 |
0 |
@Test(groups = { "Network" })... |
159 |
|
public void testRNAAliFoldValidStructure() |
160 |
|
{ |
161 |
|
|
162 |
0 |
alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null); |
163 |
|
|
164 |
0 |
af.getViewport().getCalcManager().startWorker(alifoldClient); |
165 |
|
|
166 |
0 |
do |
167 |
|
{ |
168 |
0 |
try |
169 |
|
{ |
170 |
0 |
Thread.sleep(50); |
171 |
|
} catch (InterruptedException x) |
172 |
|
{ |
173 |
|
} |
174 |
0 |
} while (af.getViewport().getCalcManager().isWorking()); |
175 |
|
|
176 |
0 |
AlignmentI orig_alig = af.getViewport().getAlignment(); |
177 |
0 |
for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation()) |
178 |
|
{ |
179 |
0 |
if (alifoldClient.involves(aa)) |
180 |
|
{ |
181 |
0 |
if (aa.isRNA()) |
182 |
|
{ |
183 |
0 |
assertTrue( |
184 |
|
"Did not create valid structure from RNAALiFold prediction", |
185 |
|
aa.isValidStruc()); |
186 |
|
} |
187 |
|
} |
188 |
|
} |
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
4-
|
|
191 |
0 |
@Test(groups = { "Network" })... |
192 |
|
public void testRNAStructExport() |
193 |
|
{ |
194 |
|
|
195 |
0 |
alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null); |
196 |
|
|
197 |
0 |
af.getViewport().getCalcManager().startWorker(alifoldClient); |
198 |
|
|
199 |
0 |
do |
200 |
|
{ |
201 |
0 |
try |
202 |
|
{ |
203 |
0 |
Thread.sleep(50); |
204 |
|
} catch (InterruptedException x) |
205 |
|
{ |
206 |
|
} |
207 |
0 |
} while (af.getViewport().getCalcManager().isWorking()); |
208 |
|
|
209 |
0 |
AlignmentI orig_alig = af.getViewport().getAlignment(); |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
0 |
verifyAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig); |
214 |
|
|
215 |
|
} |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
|
217 |
0 |
static void verifyAnnotationFileIO(String testname, AlignmentI al)... |
218 |
|
{ |
219 |
0 |
try |
220 |
|
{ |
221 |
|
|
222 |
0 |
String aligfileout = FileFormat.Pfam.getWriter(null) |
223 |
|
.print(al.getSequencesArray(), true); |
224 |
|
|
225 |
0 |
String anfileout = new AnnotationFile() |
226 |
|
.printAnnotationsForAlignment(al); |
227 |
0 |
assertNotNull("Test " + testname |
228 |
|
+ "\nAlignment annotation file was not regenerated. Null string", |
229 |
|
anfileout); |
230 |
0 |
assertTrue("Test " + testname |
231 |
|
+ "\nAlignment annotation file was not regenerated. Empty string", |
232 |
|
anfileout.length() > "JALVIEW_ANNOTATION".length()); |
233 |
|
|
234 |
0 |
System.out.println( |
235 |
|
"Output annotation file:\n" + anfileout + "\n<<EOF\n"); |
236 |
|
|
237 |
|
|
238 |
0 |
AlignmentI al_new = new FormatAdapter().readFile(aligfileout, |
239 |
|
DataSourceType.PASTE, FileFormat.Pfam); |
240 |
0 |
assertTrue("Test " + testname |
241 |
|
+ "\nregenerated annotation file did not annotate alignment.", |
242 |
|
new AnnotationFile().readAnnotationFile(al_new, anfileout, |
243 |
|
DataSourceType.PASTE)); |
244 |
|
|
245 |
|
|
246 |
0 |
StockholmFileTest.testAlignmentEquivalence(al, al_new, false, false, |
247 |
|
false); |
248 |
0 |
return; |
249 |
|
} catch (Exception e) |
250 |
|
{ |
251 |
0 |
e.printStackTrace(); |
252 |
|
} |
253 |
0 |
Assert.fail("Test " + testname |
254 |
|
+ "\nCouldn't complete Annotation file roundtrip input/output/input test."); |
255 |
|
} |
256 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 11 |
Complexity Density: 0.28 |
4-
|
|
257 |
0 |
@Test(groups = { "Network" })... |
258 |
|
public void testRnaalifoldSettingsRecovery() |
259 |
|
{ |
260 |
0 |
List<Argument> opts = new ArrayList<>(); |
261 |
0 |
for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig() |
262 |
|
.getArguments()) |
263 |
|
{ |
264 |
0 |
if (rg.getDescription().contains("emperature")) |
265 |
|
{ |
266 |
0 |
try |
267 |
|
{ |
268 |
0 |
rg.setValue("292"); |
269 |
|
} catch (WrongParameterException q) |
270 |
|
{ |
271 |
0 |
Assert.fail("Couldn't set the temperature parameter " |
272 |
|
+ q.getStackTrace()); |
273 |
|
} |
274 |
0 |
opts.add(rg); |
275 |
|
} |
276 |
0 |
if (rg.getDescription().contains("max")) |
277 |
|
{ |
278 |
0 |
opts.add(rg); |
279 |
|
} |
280 |
|
} |
281 |
0 |
alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts); |
282 |
|
|
283 |
0 |
af.getViewport().getCalcManager().startWorker(alifoldClient); |
284 |
|
|
285 |
0 |
do |
286 |
|
{ |
287 |
0 |
try |
288 |
|
{ |
289 |
0 |
Thread.sleep(50); |
290 |
|
} catch (InterruptedException x) |
291 |
|
{ |
292 |
|
} |
293 |
0 |
; |
294 |
0 |
} while (af.getViewport().getCalcManager().isWorking()); |
295 |
0 |
AutoCalcSetting oldacs = af.getViewport() |
296 |
|
.getCalcIdSettingsFor(alifoldClient.getCalcId()); |
297 |
0 |
String oldsettings = oldacs.getWsParamFile(); |
298 |
|
|
299 |
0 |
jalview.gui.AlignFrame nalf = null; |
300 |
0 |
assertTrue("Couldn't write out the Jar file", new Jalview2XML(false) |
301 |
|
.saveAlignment(af, JAR_FILE_NAME, "trial parameter writeout")); |
302 |
0 |
assertTrue("Couldn't read back the Jar file", |
303 |
|
(nalf = new Jalview2XML(false) |
304 |
|
.loadJalviewAlign(JAR_FILE_NAME)) != null); |
305 |
0 |
if (nalf != null) |
306 |
|
{ |
307 |
0 |
AutoCalcSetting acs = af.getViewport() |
308 |
|
.getCalcIdSettingsFor(alifoldClient.getCalcId()); |
309 |
0 |
assertTrue("Calc ID settings not recovered from viewport stash", |
310 |
|
acs.equals(oldacs)); |
311 |
0 |
assertTrue( |
312 |
|
"Serialised Calc ID settings not identical to those recovered from viewport stash", |
313 |
|
acs.getWsParamFile().equals(oldsettings)); |
314 |
0 |
JMenu nmenu = new JMenu(); |
315 |
0 |
new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu, |
316 |
|
rnaalifoldws, af); |
317 |
0 |
assertTrue("Couldn't get menu entry for service", |
318 |
|
nmenu.getItemCount() > 0); |
319 |
0 |
for (Component itm : nmenu.getMenuComponents()) |
320 |
|
{ |
321 |
0 |
if (itm instanceof JMenuItem) |
322 |
|
{ |
323 |
0 |
JMenuItem i = (JMenuItem) itm; |
324 |
0 |
if (i.getText().equals( |
325 |
|
rnaalifoldws.getAlignAnalysisUI().getAAconToggle())) |
326 |
|
{ |
327 |
0 |
i.doClick(); |
328 |
0 |
break; |
329 |
|
} |
330 |
|
} |
331 |
|
} |
332 |
0 |
while (af.getViewport().isCalcInProgress()) |
333 |
|
{ |
334 |
0 |
try |
335 |
|
{ |
336 |
0 |
Thread.sleep(200); |
337 |
|
} catch (Exception x) |
338 |
|
{ |
339 |
|
} |
340 |
0 |
; |
341 |
|
} |
342 |
0 |
AutoCalcSetting acs2 = af.getViewport() |
343 |
|
.getCalcIdSettingsFor(alifoldClient.getCalcId()); |
344 |
0 |
assertTrue( |
345 |
|
"Calc ID settings after recalculation has not been recovered.", |
346 |
|
acs2.getWsParamFile().equals(oldsettings)); |
347 |
|
} |
348 |
|
} |
349 |
|
} |