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.Argument;
55 import compbio.metadata.WrongParameterException;
57 public class RNAStructExportImport
59 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
61 public static String testseqs = "examples/RF00031_folded.stk";
63 public static Jws2Discoverer disc;
65 public static Jws2Instance rnaalifoldws;
67 jalview.ws.jws2.RNAalifoldClient alifoldClient;
69 public static jalview.gui.AlignFrame af = null;
71 @BeforeClass(alwaysRun = true)
72 public static void setUpBeforeClass() throws Exception
74 Cache.loadProperties("test/jalview/io/testProps.jvprops");
76 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
78 for (Jws2Instance svc : disc.getServices())
81 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
87 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
89 if (rnaalifoldws == null)
91 Assert.fail("no web service");
94 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
96 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
98 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
100 // remove any existing annotation
101 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
102 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
103 .getAlignmentAnnotation())
110 for (AlignmentAnnotation rna : aal)
112 af.getViewport().getAlignment().deleteAnnotation(rna);
114 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
118 @AfterClass(alwaysRun = true)
119 public static void tearDownAfterClass() throws Exception
123 af.setVisible(false);
125 File f = new File(JAR_FILE_NAME);
133 @Test(groups = { "Functional" })
134 public void testRNAAliFoldValidStructure()
137 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
139 af.getViewport().getCalcManager().startWorker(alifoldClient);
146 } 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)
182 } while (af.getViewport().getCalcManager().isWorking());
184 AlignmentI orig_alig = af.getViewport().getAlignment();
186 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
190 public static void testAnnotationFileIO(String testname, AlignmentI al)
194 // what format would be appropriate for RNAalifold annotations?
195 String aligfileout = FileFormat.Pfam.getAlignmentFile().print(
196 al.getSequencesArray(), true);
198 String anfileout = new AnnotationFile()
199 .printAnnotationsForAlignment(al);
203 + "\nAlignment annotation file was not regenerated. Null string",
208 + "\nAlignment annotation file was not regenerated. Empty string",
209 anfileout.length() > "JALVIEW_ANNOTATION".length());
211 System.out.println("Output annotation file:\n" + anfileout
214 // again what format would be appropriate?
215 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
216 DataSourceType.PASTE, FileFormat.Pfam);
220 + "\nregenerated annotation file did not annotate alignment.",
221 new AnnotationFile().readAnnotationFile(al_new, anfileout,
222 DataSourceType.PASTE));
224 // test for consistency in io
225 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
227 } catch (Exception e)
233 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
236 @Test(groups = { "Functional" })
237 public void testRnaalifoldSettingsRecovery()
239 List<Argument> opts = new ArrayList<Argument>();
240 for (Argument rg : (List<Argument>) rnaalifoldws
241 .getRunnerConfig().getArguments())
243 if (rg.getDescription().contains("emperature"))
248 } catch (WrongParameterException q)
250 Assert.fail("Couldn't set the temperature parameter "
251 + q.getStackTrace());
255 if (rg.getDescription().contains("max"))
260 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
262 af.getViewport().getCalcManager().startWorker(alifoldClient);
269 } catch (InterruptedException x)
273 } while (af.getViewport().getCalcManager().isWorking());
274 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
275 alifoldClient.getCalcId());
276 String oldsettings = oldacs.getWsParamFile();
277 // write out parameters
278 jalview.gui.AlignFrame nalf = null;
279 assertTrue("Couldn't write out the Jar file",
280 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
281 "trial parameter writeout"));
282 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
283 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
286 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
287 alifoldClient.getCalcId());
288 assertTrue("Calc ID settings not recovered from viewport stash",
291 "Serialised Calc ID settings not identical to those recovered from viewport stash",
292 acs.getWsParamFile().equals(oldsettings));
293 JMenu nmenu = new JMenu();
294 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
296 assertTrue("Couldn't get menu entry for service",
297 nmenu.getItemCount() > 0);
298 for (Component itm : nmenu.getMenuComponents())
300 if (itm instanceof JMenuItem)
302 JMenuItem i = (JMenuItem) itm;
303 if (i.getText().equals(
304 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
311 while (af.getViewport().isCalcInProgress())
316 } catch (Exception x)
321 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
322 alifoldClient.getCalcId());
324 "Calc ID settings after recalculation has not been recovered.",
325 acs2.getWsParamFile().equals(oldsettings));