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.io.AnnotationFile;
31 import jalview.io.FileLoader;
32 import jalview.io.FormatAdapter;
33 import jalview.io.StockholmFileTest;
34 import jalview.ws.jws2.Jws2Discoverer;
35 import jalview.ws.jws2.RNAalifoldClient;
36 import jalview.ws.jws2.SequenceAnnotationWSClient;
37 import jalview.ws.jws2.jabaws2.Jws2Instance;
38 import jalview.ws.params.AutoCalcSetting;
40 import java.awt.Component;
42 import java.util.ArrayList;
43 import java.util.List;
45 import javax.swing.JMenu;
46 import javax.swing.JMenuItem;
48 import org.testng.Assert;
49 import org.testng.annotations.AfterClass;
50 import org.testng.annotations.BeforeClass;
51 import org.testng.annotations.Test;
53 import compbio.metadata.Argument;
54 import compbio.metadata.WrongParameterException;
56 public class RNAStructExportImport
58 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
60 public static String testseqs = "examples/RF00031_folded.stk";
62 public static Jws2Discoverer disc;
64 public static Jws2Instance rnaalifoldws;
66 jalview.ws.jws2.RNAalifoldClient alifoldClient;
68 public static jalview.gui.AlignFrame af = null;
70 @BeforeClass(alwaysRun = true)
71 public static void setUpBeforeClass() throws Exception
73 Cache.loadProperties("test/jalview/io/testProps.jvprops");
75 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
77 for (Jws2Instance svc : disc.getServices())
80 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
86 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
88 if (rnaalifoldws == null)
90 Assert.fail("no web service");
93 FileLoader fl = new FileLoader(false);
95 af = fl.LoadFileWaitTillLoaded(testseqs, FormatAdapter.FILE);
97 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
99 // remove any existing annotation
100 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
101 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
102 .getAlignmentAnnotation())
109 for (AlignmentAnnotation rna : aal)
111 af.getViewport().getAlignment().deleteAnnotation(rna);
113 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
117 @AfterClass(alwaysRun = true)
118 public static void tearDownAfterClass() throws Exception
122 af.setVisible(false);
124 File f = new File(JAR_FILE_NAME);
132 @Test(groups = { "Functional" })
133 public void testRNAAliFoldValidStructure()
136 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
138 af.getViewport().getCalcManager().startWorker(alifoldClient);
145 } catch (InterruptedException x)
148 } while (af.getViewport().getCalcManager().isWorking());
150 AlignmentI orig_alig = af.getViewport().getAlignment();
151 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
153 if (alifoldClient.involves(aa))
158 "Did not create valid structure from RNAALiFold prediction",
165 @Test(groups = { "Functional" })
166 public void testRNAStructExport()
169 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
171 af.getViewport().getCalcManager().startWorker(alifoldClient);
178 } catch (InterruptedException x)
181 } while (af.getViewport().getCalcManager().isWorking());
183 AlignmentI orig_alig = af.getViewport().getAlignment();
185 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
189 public static void testAnnotationFileIO(String testname, AlignmentI al)
193 // what format would be appropriate for RNAalifold annotations?
194 String aligfileout = new FormatAdapter().formatSequences("PFAM",
195 al.getSequencesArray());
197 String anfileout = new AnnotationFile()
198 .printAnnotationsForAlignment(al);
202 + "\nAlignment annotation file was not regenerated. Null string",
207 + "\nAlignment annotation file was not regenerated. Empty string",
208 anfileout.length() > "JALVIEW_ANNOTATION".length());
210 System.out.println("Output annotation file:\n" + anfileout
213 // again what format would be appropriate?
214 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
215 FormatAdapter.PASTE, "PFAM");
219 + "\nregenerated annotation file did not annotate alignment.",
220 new AnnotationFile().readAnnotationFile(al_new, anfileout,
221 FormatAdapter.PASTE));
223 // test for consistency in io
224 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
226 } catch (Exception e)
232 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
235 @Test(groups = { "Functional" })
236 public void testRnaalifoldSettingsRecovery()
238 List<Argument> opts = new ArrayList<Argument>();
239 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
242 if (rg.getDescription().contains("emperature"))
247 } catch (WrongParameterException q)
249 Assert.fail("Couldn't set the temperature parameter "
250 + q.getStackTrace());
254 if (rg.getDescription().contains("max"))
259 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
261 af.getViewport().getCalcManager().startWorker(alifoldClient);
268 } catch (InterruptedException x)
272 } while (af.getViewport().getCalcManager().isWorking());
273 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
274 alifoldClient.getCalcId());
275 String oldsettings = oldacs.getWsParamFile();
276 // write out parameters
277 jalview.gui.AlignFrame nalf = null;
278 assertTrue("Couldn't write out the Jar file",
279 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
280 "trial parameter writeout"));
281 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
282 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
285 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
286 alifoldClient.getCalcId());
287 assertTrue("Calc ID settings not recovered from viewport stash",
290 "Serialised Calc ID settings not identical to those recovered from viewport stash",
291 acs.getWsParamFile().equals(oldsettings));
292 JMenu nmenu = new JMenu();
293 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
295 assertTrue("Couldn't get menu entry for service",
296 nmenu.getItemCount() > 0);
297 for (Component itm : nmenu.getMenuComponents())
299 if (itm instanceof JMenuItem)
301 JMenuItem i = (JMenuItem) itm;
302 if (i.getText().equals(
303 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
310 while (af.getViewport().isCalcInProgress())
315 } catch (Exception x)
320 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
321 alifoldClient.getCalcId());
323 "Calc ID settings after recalculation has not been recovered.",
324 acs2.getWsParamFile().equals(oldsettings));