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;
58 public class RNAStructExportImport
61 @BeforeClass(alwaysRun = true)
62 public void setUpJvOptionPane()
64 JvOptionPane.setInteractiveMode(false);
65 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
68 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
70 public static String testseqs = "examples/RF00031_folded.stk";
72 public static Jws2Discoverer disc;
74 public static Jws2Instance rnaalifoldws;
76 jalview.ws.jws2.RNAalifoldClient alifoldClient;
78 public static jalview.gui.AlignFrame af = null;
80 @BeforeClass(alwaysRun = true)
81 public static void setUpBeforeClass() throws Exception
83 Cache.loadProperties("test/jalview/io/testProps.jvprops");
85 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
87 for (Jws2Instance svc : disc.getServices())
90 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
96 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
98 if (rnaalifoldws == null)
100 Assert.fail("no web service");
103 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
105 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
107 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
109 // remove any existing annotation
110 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
111 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
112 .getAlignmentAnnotation())
119 for (AlignmentAnnotation rna : aal)
121 af.getViewport().getAlignment().deleteAnnotation(rna);
123 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
127 @AfterClass(alwaysRun = true)
128 public static void tearDownAfterClass() throws Exception
132 af.setVisible(false);
134 File f = new File(JAR_FILE_NAME);
142 @Test(groups = { "Functional" })
143 public void testRNAAliFoldValidStructure()
146 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
148 af.getViewport().getCalcManager().startWorker(alifoldClient);
155 } catch (InterruptedException x)
158 } while (af.getViewport().getCalcManager().isWorking());
160 AlignmentI orig_alig = af.getViewport().getAlignment();
161 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
163 if (alifoldClient.involves(aa))
168 "Did not create valid structure from RNAALiFold prediction",
175 @Test(groups = { "Functional" })
176 public void testRNAStructExport()
179 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
181 af.getViewport().getCalcManager().startWorker(alifoldClient);
188 } catch (InterruptedException x)
191 } while (af.getViewport().getCalcManager().isWorking());
193 AlignmentI orig_alig = af.getViewport().getAlignment();
195 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
199 public static void testAnnotationFileIO(String testname, AlignmentI al)
203 // what format would be appropriate for RNAalifold annotations?
204 String aligfileout = FileFormat.Pfam.getWriter(null).print(
205 al.getSequencesArray(), true);
207 String anfileout = new AnnotationFile()
208 .printAnnotationsForAlignment(al);
212 + "\nAlignment annotation file was not regenerated. Null string",
217 + "\nAlignment annotation file was not regenerated. Empty string",
218 anfileout.length() > "JALVIEW_ANNOTATION".length());
220 System.out.println("Output annotation file:\n" + anfileout
223 // again what format would be appropriate?
224 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
225 DataSourceType.PASTE, FileFormat.Pfam);
229 + "\nregenerated annotation file did not annotate alignment.",
230 new AnnotationFile().readAnnotationFile(al_new, anfileout,
231 DataSourceType.PASTE));
233 // test for consistency in io
234 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
236 } catch (Exception e)
242 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
245 @Test(groups = { "Functional" })
246 public void testRnaalifoldSettingsRecovery()
248 List<Argument> opts = new ArrayList<Argument>();
249 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
252 if (rg.getDescription().contains("emperature"))
257 } catch (WrongParameterException q)
259 Assert.fail("Couldn't set the temperature parameter "
260 + q.getStackTrace());
264 if (rg.getDescription().contains("max"))
269 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
271 af.getViewport().getCalcManager().startWorker(alifoldClient);
278 } catch (InterruptedException x)
282 } while (af.getViewport().getCalcManager().isWorking());
283 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
284 alifoldClient.getCalcId());
285 String oldsettings = oldacs.getWsParamFile();
286 // write out parameters
287 jalview.gui.AlignFrame nalf = null;
288 assertTrue("Couldn't write out the Jar file",
289 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
290 "trial parameter writeout"));
291 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
292 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
295 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
296 alifoldClient.getCalcId());
297 assertTrue("Calc ID settings not recovered from viewport stash",
300 "Serialised Calc ID settings not identical to those recovered from viewport stash",
301 acs.getWsParamFile().equals(oldsettings));
302 JMenu nmenu = new JMenu();
303 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
305 assertTrue("Couldn't get menu entry for service",
306 nmenu.getItemCount() > 0);
307 for (Component itm : nmenu.getMenuComponents())
309 if (itm instanceof JMenuItem)
311 JMenuItem i = (JMenuItem) itm;
312 if (i.getText().equals(
313 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
320 while (af.getViewport().isCalcInProgress())
325 } catch (Exception x)
330 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
331 alifoldClient.getCalcId());
333 "Calc ID settings after recalculation has not been recovered.",
334 acs2.getWsParamFile().equals(oldsettings));