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.FileLoader;
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
60 @BeforeClass(alwaysRun = true)
61 public void setUpJvOptionPane()
63 JvOptionPane.setInteractiveMode(false);
64 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
67 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
69 public static String testseqs = "examples/RF00031_folded.stk";
71 public static Jws2Discoverer disc;
73 public static Jws2Instance rnaalifoldws;
75 jalview.ws.jws2.RNAalifoldClient alifoldClient;
77 public static jalview.gui.AlignFrame af = null;
79 @BeforeClass(alwaysRun = true)
80 public static void setUpBeforeClass() throws Exception
82 Cache.loadProperties("test/jalview/io/testProps.jvprops");
84 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
86 for (Jws2Instance svc : disc.getServices())
89 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
95 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
97 if (rnaalifoldws == null)
99 Assert.fail("no web service");
102 FileLoader fl = new FileLoader(false);
104 af = fl.LoadFileWaitTillLoaded(testseqs, FormatAdapter.FILE);
106 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
108 // remove any existing annotation
109 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
110 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
111 .getAlignmentAnnotation())
118 for (AlignmentAnnotation rna : aal)
120 af.getViewport().getAlignment().deleteAnnotation(rna);
122 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
126 @AfterClass(alwaysRun = true)
127 public static void tearDownAfterClass() throws Exception
131 af.setVisible(false);
133 File f = new File(JAR_FILE_NAME);
141 @Test(groups = { "Functional" })
142 public void testRNAAliFoldValidStructure()
145 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
147 af.getViewport().getCalcManager().startWorker(alifoldClient);
154 } catch (InterruptedException x)
157 } while (af.getViewport().getCalcManager().isWorking());
159 AlignmentI orig_alig = af.getViewport().getAlignment();
160 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
162 if (alifoldClient.involves(aa))
167 "Did not create valid structure from RNAALiFold prediction",
174 @Test(groups = { "Functional" })
175 public void testRNAStructExport()
178 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
180 af.getViewport().getCalcManager().startWorker(alifoldClient);
187 } catch (InterruptedException x)
190 } while (af.getViewport().getCalcManager().isWorking());
192 AlignmentI orig_alig = af.getViewport().getAlignment();
194 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
198 public static void testAnnotationFileIO(String testname, AlignmentI al)
202 // what format would be appropriate for RNAalifold annotations?
203 String aligfileout = new FormatAdapter().formatSequences("PFAM",
204 al.getSequencesArray());
206 String anfileout = new AnnotationFile()
207 .printAnnotationsForAlignment(al);
211 + "\nAlignment annotation file was not regenerated. Null string",
216 + "\nAlignment annotation file was not regenerated. Empty string",
217 anfileout.length() > "JALVIEW_ANNOTATION".length());
219 System.out.println("Output annotation file:\n" + anfileout
222 // again what format would be appropriate?
223 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
224 FormatAdapter.PASTE, "PFAM");
228 + "\nregenerated annotation file did not annotate alignment.",
229 new AnnotationFile().readAnnotationFile(al_new, anfileout,
230 FormatAdapter.PASTE));
232 // test for consistency in io
233 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
235 } catch (Exception e)
241 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
244 @Test(groups = { "Functional" })
245 public void testRnaalifoldSettingsRecovery()
247 List<Argument> opts = new ArrayList<Argument>();
248 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
251 if (rg.getDescription().contains("emperature"))
256 } catch (WrongParameterException q)
258 Assert.fail("Couldn't set the temperature parameter "
259 + q.getStackTrace());
263 if (rg.getDescription().contains("max"))
268 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
270 af.getViewport().getCalcManager().startWorker(alifoldClient);
277 } catch (InterruptedException x)
281 } while (af.getViewport().getCalcManager().isWorking());
282 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
283 alifoldClient.getCalcId());
284 String oldsettings = oldacs.getWsParamFile();
285 // write out parameters
286 jalview.gui.AlignFrame nalf = null;
287 assertTrue("Couldn't write out the Jar file",
288 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
289 "trial parameter writeout"));
290 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
291 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
294 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
295 alifoldClient.getCalcId());
296 assertTrue("Calc ID settings not recovered from viewport stash",
299 "Serialised Calc ID settings not identical to those recovered from viewport stash",
300 acs.getWsParamFile().equals(oldsettings));
301 JMenu nmenu = new JMenu();
302 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
304 assertTrue("Couldn't get menu entry for service",
305 nmenu.getItemCount() > 0);
306 for (Component itm : nmenu.getMenuComponents())
308 if (itm instanceof JMenuItem)
310 JMenuItem i = (JMenuItem) itm;
311 if (i.getText().equals(
312 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
319 while (af.getViewport().isCalcInProgress())
324 } catch (Exception x)
329 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
330 alifoldClient.getCalcId());
332 "Calc ID settings after recalculation has not been recovered.",
333 acs2.getWsParamFile().equals(oldsettings));