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.DataSourceType;
32 import jalview.io.FileFormat;
33 import jalview.io.FormatAdapter;
34 import jalview.io.StockholmFileTest;
35 import jalview.ws.jws2.Jws2Discoverer;
36 import jalview.ws.jws2.RNAalifoldClient;
37 import jalview.ws.jws2.SequenceAnnotationWSClient;
38 import jalview.ws.jws2.jabaws2.Jws2Instance;
39 import jalview.ws.params.AutoCalcSetting;
41 import java.awt.Component;
43 import java.util.ArrayList;
44 import java.util.List;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuItem;
49 import org.testng.Assert;
50 import org.testng.annotations.AfterClass;
51 import org.testng.annotations.BeforeClass;
52 import org.testng.annotations.Test;
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 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
95 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.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)
149 } while (af.getViewport().getCalcManager().isWorking());
151 AlignmentI orig_alig = af.getViewport().getAlignment();
152 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
154 if (alifoldClient.involves(aa))
159 "Did not create valid structure from RNAALiFold prediction",
166 @Test(groups = { "Functional" })
167 public void testRNAStructExport()
170 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
172 af.getViewport().getCalcManager().startWorker(alifoldClient);
179 } catch (InterruptedException x)
183 } while (af.getViewport().getCalcManager().isWorking());
185 AlignmentI orig_alig = af.getViewport().getAlignment();
187 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
191 public static void testAnnotationFileIO(String testname, AlignmentI al)
195 // what format would be appropriate for RNAalifold annotations?
196 String aligfileout = new FormatAdapter().formatSequences("PFAM",
197 al.getSequencesArray());
199 String anfileout = new AnnotationFile()
200 .printAnnotationsForAlignment(al);
204 + "\nAlignment annotation file was not regenerated. Null string",
209 + "\nAlignment annotation file was not regenerated. Empty string",
210 anfileout.length() > "JALVIEW_ANNOTATION".length());
212 System.out.println("Output annotation file:\n" + anfileout
215 // again what format would be appropriate?
216 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
217 DataSourceType.PASTE, FileFormat.Pfam);
221 + "\nregenerated annotation file did not annotate alignment.",
222 new AnnotationFile().readAnnotationFile(al_new, anfileout,
223 DataSourceType.PASTE));
225 // test for consistency in io
226 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
228 } catch (Exception e)
234 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
237 @Test(groups = { "Functional" })
238 public void testRnaalifoldSettingsRecovery()
240 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
241 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
242 .getRunnerConfig().getArguments())
244 if (rg.getDescription().contains("emperature"))
249 } catch (WrongParameterException q)
251 Assert.fail("Couldn't set the temperature parameter "
252 + q.getStackTrace());
256 if (rg.getDescription().contains("max"))
261 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
263 af.getViewport().getCalcManager().startWorker(alifoldClient);
270 } catch (InterruptedException x)
274 } while (af.getViewport().getCalcManager().isWorking());
275 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
276 alifoldClient.getCalcId());
277 String oldsettings = oldacs.getWsParamFile();
278 // write out parameters
279 jalview.gui.AlignFrame nalf = null;
280 assertTrue("Couldn't write out the Jar file",
281 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
282 "trial parameter writeout"));
283 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
284 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
287 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
288 alifoldClient.getCalcId());
289 assertTrue("Calc ID settings not recovered from viewport stash",
292 "Serialised Calc ID settings not identical to those recovered from viewport stash",
293 acs.getWsParamFile().equals(oldsettings));
294 JMenu nmenu = new JMenu();
295 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
297 assertTrue("Couldn't get menu entry for service",
298 nmenu.getItemCount() > 0);
299 for (Component itm : nmenu.getMenuComponents())
301 if (itm instanceof JMenuItem)
303 JMenuItem i = (JMenuItem) itm;
304 if (i.getText().equals(
305 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
312 while (af.getViewport().isCalcInProgress())
317 } catch (Exception x)
322 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
323 alifoldClient.getCalcId());
325 "Calc ID settings after recalculation has not been recovered.",
326 acs2.getWsParamFile().equals(oldsettings));