2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jabaws;
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.gui.Jalview2XML;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.AnnotationFile;
32 import jalview.io.DataSourceType;
33 import jalview.io.FileFormat;
34 import jalview.io.FormatAdapter;
35 import jalview.io.StockholmFileTest;
36 import jalview.ws.jws2.Jws2Discoverer;
37 import jalview.ws.jws2.RNAalifoldClient;
38 import jalview.ws.jws2.SequenceAnnotationWSClient;
39 import jalview.ws.jws2.jabaws2.Jws2Instance;
40 import jalview.ws.params.AutoCalcSetting;
42 import java.awt.Component;
44 import java.util.ArrayList;
45 import java.util.List;
47 import javax.swing.JMenu;
48 import javax.swing.JMenuItem;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.BeforeClass;
53 import org.testng.annotations.Test;
55 import compbio.metadata.Argument;
56 import compbio.metadata.WrongParameterException;
59 * All methods in this class are set to the Network group because setUpBeforeClass will fail
60 * if there is no network.
62 @Test(singleThreaded = true)
63 public class RNAStructExportImport
66 @BeforeClass(alwaysRun = true)
67 public void setUpJvOptionPane()
69 JvOptionPane.setInteractiveMode(false);
70 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
73 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
75 public static String testseqs = "examples/RF00031_folded.stk";
77 public static Jws2Discoverer disc;
79 public static Jws2Instance rnaalifoldws;
81 jalview.ws.jws2.RNAalifoldClient alifoldClient;
83 public static jalview.gui.AlignFrame af = null;
85 @BeforeClass(alwaysRun = true)
86 public static void setUpBeforeClass() throws Exception
88 Cache.loadProperties("test/jalview/io/testProps.jvprops");
90 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
92 while (disc.isRunning())
94 // don't get services until discoverer has finished
98 for (Jws2Instance svc : disc.getServices())
101 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
107 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
109 if (rnaalifoldws == null)
111 Assert.fail("no web service");
114 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
116 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
118 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
120 // remove any existing annotation
121 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
122 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
123 .getAlignmentAnnotation())
130 for (AlignmentAnnotation rna : aal)
132 af.getViewport().getAlignment().deleteAnnotation(rna);
134 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
138 @AfterClass(alwaysRun = true)
139 public static void tearDownAfterClass() throws Exception
143 af.setVisible(false);
145 File f = new File(JAR_FILE_NAME);
153 @Test(groups = { "Network" })
154 public void testRNAAliFoldValidStructure()
157 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
159 af.getViewport().getCalcManager().startWorker(alifoldClient);
166 } catch (InterruptedException x)
169 } while (af.getViewport().getCalcManager().isWorking());
171 AlignmentI orig_alig = af.getViewport().getAlignment();
172 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
174 if (alifoldClient.involves(aa))
179 "Did not create valid structure from RNAALiFold prediction",
186 @Test(groups = { "Network" })
187 public void testRNAStructExport()
190 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
192 af.getViewport().getCalcManager().startWorker(alifoldClient);
199 } catch (InterruptedException x)
202 } while (af.getViewport().getCalcManager().isWorking());
204 AlignmentI orig_alig = af.getViewport().getAlignment();
206 verifyAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
210 static void verifyAnnotationFileIO(String testname, AlignmentI al)
214 // what format would be appropriate for RNAalifold annotations?
215 String aligfileout = FileFormat.Pfam.getWriter(null).print(
216 al.getSequencesArray(), true);
218 String anfileout = new AnnotationFile()
219 .printAnnotationsForAlignment(al);
223 + "\nAlignment annotation file was not regenerated. Null string",
228 + "\nAlignment annotation file was not regenerated. Empty string",
229 anfileout.length() > "JALVIEW_ANNOTATION".length());
231 System.out.println("Output annotation file:\n" + anfileout
234 // again what format would be appropriate?
235 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
236 DataSourceType.PASTE, FileFormat.Pfam);
240 + "\nregenerated annotation file did not annotate alignment.",
241 new AnnotationFile().readAnnotationFile(al_new, anfileout,
242 DataSourceType.PASTE));
244 // test for consistency in io
245 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
247 } catch (Exception e)
253 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
256 @Test(groups = { "Network" })
257 public void testRnaalifoldSettingsRecovery()
259 List<Argument> opts = new ArrayList<Argument>();
260 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
263 if (rg.getDescription().contains("emperature"))
268 } catch (WrongParameterException q)
270 Assert.fail("Couldn't set the temperature parameter "
271 + q.getStackTrace());
275 if (rg.getDescription().contains("max"))
280 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
282 af.getViewport().getCalcManager().startWorker(alifoldClient);
289 } catch (InterruptedException x)
293 } while (af.getViewport().getCalcManager().isWorking());
294 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
295 alifoldClient.getCalcId());
296 String oldsettings = oldacs.getWsParamFile();
297 // write out parameters
298 jalview.gui.AlignFrame nalf = null;
299 assertTrue("Couldn't write out the Jar file",
300 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
301 "trial parameter writeout"));
302 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
303 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
306 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
307 alifoldClient.getCalcId());
308 assertTrue("Calc ID settings not recovered from viewport stash",
311 "Serialised Calc ID settings not identical to those recovered from viewport stash",
312 acs.getWsParamFile().equals(oldsettings));
313 JMenu nmenu = new JMenu();
314 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
316 assertTrue("Couldn't get menu entry for service",
317 nmenu.getItemCount() > 0);
318 for (Component itm : nmenu.getMenuComponents())
320 if (itm instanceof JMenuItem)
322 JMenuItem i = (JMenuItem) itm;
323 if (i.getText().equals(
324 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
331 while (af.getViewport().isCalcInProgress())
336 } catch (Exception x)
341 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
342 alifoldClient.getCalcId());
344 "Calc ID settings after recalculation has not been recovered.",
345 acs2.getWsParamFile().equals(oldsettings));