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.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.gui.Jalview2XML;
29 import jalview.io.AnnotationFile;
30 import jalview.io.FormatAdapter;
31 import jalview.io.StockholmFileTest;
32 import jalview.ws.jws2.Jws2Discoverer;
33 import jalview.ws.jws2.RNAalifoldClient;
34 import jalview.ws.jws2.SequenceAnnotationWSClient;
35 import jalview.ws.jws2.jabaws2.Jws2Instance;
36 import jalview.ws.params.AutoCalcSetting;
38 import java.awt.Component;
40 import java.util.ArrayList;
41 import java.util.List;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
46 import org.testng.Assert;
47 import org.testng.annotations.AfterClass;
48 import org.testng.annotations.BeforeClass;
49 import org.testng.annotations.Test;
51 import compbio.metadata.WrongParameterException;
53 public class RNAStructExportImport
55 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
57 public static String testseqs = "examples/RF00031_folded.stk";
59 public static Jws2Discoverer disc;
61 public static Jws2Instance rnaalifoldws;
63 jalview.ws.jws2.RNAalifoldClient alifoldClient;
65 public static jalview.gui.AlignFrame af = null;
67 @BeforeClass(alwaysRun = true)
68 public static void setUpBeforeClass() throws Exception
71 jalview.bin.Cache.initLogger();
72 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
74 for (Jws2Instance svc : disc.getServices())
77 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
83 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
85 if (rnaalifoldws == null)
87 Assert.fail("no web service");
90 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
92 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
94 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
96 // remove any existing annotation
97 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
98 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
99 .getAlignmentAnnotation())
106 for (AlignmentAnnotation rna : aal)
108 af.getViewport().getAlignment().deleteAnnotation(rna);
110 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
114 @AfterClass(alwaysRun = true)
115 public static void tearDownAfterClass() throws Exception
119 af.setVisible(false);
121 File f = new File(JAR_FILE_NAME);
129 @Test(groups = { "Functional" })
130 public void testRNAAliFoldValidStructure()
133 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
135 af.getViewport().getCalcManager().startWorker(alifoldClient);
142 } catch (InterruptedException x)
146 } while (af.getViewport().getCalcManager().isWorking());
148 AlignmentI orig_alig = af.getViewport().getAlignment();
149 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
151 if (alifoldClient.involves(aa))
156 "Did not create valid structure from RNAALiFold prediction",
163 @Test(groups = { "Functional" })
164 public void testRNAStructExport()
167 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
169 af.getViewport().getCalcManager().startWorker(alifoldClient);
176 } catch (InterruptedException x)
180 } while (af.getViewport().getCalcManager().isWorking());
182 AlignmentI orig_alig = af.getViewport().getAlignment();
184 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
188 public static void testAnnotationFileIO(String testname, AlignmentI al)
192 // what format would be appropriate for RNAalifold annotations?
193 String aligfileout = new FormatAdapter().formatSequences("PFAM",
194 al.getSequencesArray());
196 String anfileout = new AnnotationFile()
197 .printAnnotationsForAlignment(al);
201 + "\nAlignment annotation file was not regenerated. Null string",
206 + "\nAlignment annotation file was not regenerated. Empty string",
207 anfileout.length() > "JALVIEW_ANNOTATION".length());
209 System.out.println("Output annotation file:\n" + anfileout
212 // again what format would be appropriate?
213 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
214 FormatAdapter.PASTE, "PFAM");
218 + "\nregenerated annotation file did not annotate alignment.",
219 new AnnotationFile().readAnnotationFile(al_new, anfileout,
220 FormatAdapter.PASTE));
222 // test for consistency in io
223 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
225 } catch (Exception e)
231 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
234 @Test(groups = { "Functional" })
235 public void testRnaalifoldSettingsRecovery()
237 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
238 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
239 .getRunnerConfig().getArguments())
241 if (rg.getDescription().contains("emperature"))
246 } catch (WrongParameterException q)
248 Assert.fail("Couldn't set the temperature parameter "
249 + q.getStackTrace());
253 if (rg.getDescription().contains("max"))
258 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
260 af.getViewport().getCalcManager().startWorker(alifoldClient);
267 } catch (InterruptedException x)
271 } while (af.getViewport().getCalcManager().isWorking());
272 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
273 alifoldClient.getCalcId());
274 String oldsettings = oldacs.getWsParamFile();
275 // write out parameters
276 jalview.gui.AlignFrame nalf = null;
277 assertTrue("Couldn't write out the Jar file",
278 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
279 "trial parameter writeout"));
280 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
281 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
284 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
285 alifoldClient.getCalcId());
286 assertTrue("Calc ID settings not recovered from viewport stash",
289 "Serialised Calc ID settings not identical to those recovered from viewport stash",
290 acs.getWsParamFile().equals(oldsettings));
291 JMenu nmenu = new JMenu();
292 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
294 assertTrue("Couldn't get menu entry for service",
295 nmenu.getItemCount() > 0);
296 for (Component itm : nmenu.getMenuComponents())
298 if (itm instanceof JMenuItem)
300 JMenuItem i = (JMenuItem) itm;
301 if (i.getText().equals(
302 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
309 while (af.getViewport().isCalcInProgress())
314 } catch (Exception x)
319 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
320 alifoldClient.getCalcId());
322 "Calc ID settings after recalculation has not been recovered.",
323 acs2.getWsParamFile().equals(oldsettings));