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;
39 import java.util.ArrayList;
40 import java.util.List;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
45 import org.testng.Assert;
46 import org.testng.annotations.AfterClass;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.Test;
50 import compbio.metadata.WrongParameterException;
53 public class RNAStructExportImport
55 public static String testseqs = "examples/RF00031_folded.stk";
57 public static Jws2Discoverer disc;
59 public static Jws2Instance rnaalifoldws;
61 jalview.ws.jws2.RNAalifoldClient alifoldClient;
63 public static jalview.gui.AlignFrame af = null;
65 @BeforeClass(alwaysRun = true)
66 public static void setUpBeforeClass() throws Exception
69 jalview.bin.Cache.initLogger();
70 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
72 for (Jws2Instance svc : disc.getServices())
75 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
81 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
83 if (rnaalifoldws == null)
85 Assert.fail("no web service");
88 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
90 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
92 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
94 // remove any existing annotation
95 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
96 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
97 .getAlignmentAnnotation())
104 for (AlignmentAnnotation rna : aal)
106 af.getViewport().getAlignment().deleteAnnotation(rna);
108 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
113 public static void tearDownAfterClass() throws Exception
117 af.setVisible(false);
122 @Test(groups ={ "Functional" })
123 public void testRNAAliFoldValidStructure()
126 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
128 af.getViewport().getCalcManager().startWorker(alifoldClient);
135 } catch (InterruptedException x)
139 } while (af.getViewport().getCalcManager().isWorking());
141 AlignmentI orig_alig = af.getViewport().getAlignment();
142 for (AlignmentAnnotation aa:orig_alig.getAlignmentAnnotation())
144 if (alifoldClient.involves(aa))
149 "Did not create valid structure from RNAALiFold prediction",
156 @Test(groups ={ "Functional" })
157 public void testRNAStructExport()
160 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
162 af.getViewport().getCalcManager().startWorker(alifoldClient);
169 } catch (InterruptedException x)
173 } while (af.getViewport().getCalcManager().isWorking());
175 AlignmentI orig_alig = af.getViewport().getAlignment();
177 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
181 public static void testAnnotationFileIO(String testname, AlignmentI al)
185 // what format would be appropriate for RNAalifold annotations?
186 String aligfileout = new FormatAdapter().formatSequences("PFAM",
187 al.getSequencesArray());
189 String anfileout = new AnnotationFile()
190 .printAnnotationsForAlignment(al);
194 + "\nAlignment annotation file was not regenerated. Null string",
199 + "\nAlignment annotation file was not regenerated. Empty string",
200 anfileout.length() > "JALVIEW_ANNOTATION".length());
202 System.out.println("Output annotation file:\n" + anfileout
205 // again what format would be appropriate?
206 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
207 FormatAdapter.PASTE, "PFAM");
211 + "\nregenerated annotation file did not annotate alignment.",
212 new AnnotationFile().readAnnotationFile(al_new, anfileout,
213 FormatAdapter.PASTE));
215 // test for consistency in io
216 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
218 } catch (Exception e)
224 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
227 @Test(groups ={ "Functional" })
228 public void testRnaalifoldSettingsRecovery()
230 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
231 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
232 .getRunnerConfig().getArguments())
234 if (rg.getDescription().contains("emperature"))
239 } catch (WrongParameterException q)
241 Assert.fail("Couldn't set the temperature parameter "
242 + q.getStackTrace());
246 if (rg.getDescription().contains("max"))
251 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
253 af.getViewport().getCalcManager().startWorker(alifoldClient);
260 } catch (InterruptedException x)
264 } while (af.getViewport().getCalcManager().isWorking());
265 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
266 alifoldClient.getCalcId());
267 String oldsettings = oldacs.getWsParamFile();
268 // write out parameters
269 jalview.gui.AlignFrame nalf = null;
270 assertTrue("Couldn't write out the Jar file",
271 new Jalview2XML(false).saveAlignment(af,
272 "testRnalifold_param.jar", "trial parameter writeout"));
273 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
274 false).loadJalviewAlign("testRnalifold_param.jar")) != null);
277 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
278 alifoldClient.getCalcId());
279 assertTrue("Calc ID settings not recovered from viewport stash",
282 "Serialised Calc ID settings not identical to those recovered from viewport stash",
283 acs.getWsParamFile().equals(oldsettings));
284 JMenu nmenu = new JMenu();
285 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
287 assertTrue("Couldn't get menu entry for service",
288 nmenu.getItemCount() > 0);
289 for (Component itm : nmenu.getMenuComponents())
291 if (itm instanceof JMenuItem)
293 JMenuItem i = (JMenuItem) itm;
294 if (i.getText().equals(
295 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
302 while (af.getViewport().isCalcInProgress())
307 } catch (Exception x)
312 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
313 alifoldClient.getCalcId());
315 "Calc ID settings after recalculation has not been recovered.",
316 acs2.getWsParamFile().equals(oldsettings));