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.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
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.junit.AfterClass;
46 import org.junit.Assert;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
50 import compbio.metadata.WrongParameterException;
52 public class RNAStructExportImport
54 public static String testseqs = "examples/RF00031_folded.stk";
56 public static Jws2Discoverer disc;
58 public static Jws2Instance rnaalifoldws;
60 jalview.ws.jws2.RNAalifoldClient alifoldClient;
62 public static jalview.gui.AlignFrame af = null;
65 public static void setUpBeforeClass() throws Exception
68 jalview.bin.Cache.initLogger();
69 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
71 for (Jws2Instance svc : disc.getServices())
74 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
80 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
82 if (rnaalifoldws == null)
84 fail("no web service");
87 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
89 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
91 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
93 // remove any existing annotation
94 List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
95 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
96 .getAlignmentAnnotation())
103 for (AlignmentAnnotation rna : aal)
105 af.getViewport().getAlignment().deleteAnnotation(rna);
107 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
112 public static void tearDownAfterClass() throws Exception
116 af.setVisible(false);
122 public void testRNAAliFoldValidStructure()
125 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
127 af.getViewport().getCalcManager().startWorker(alifoldClient);
134 } catch (InterruptedException x)
138 } while (af.getViewport().getCalcManager().isWorking());
140 AlignmentI orig_alig = af.getViewport().getAlignment();
141 for (AlignmentAnnotation aa:orig_alig.getAlignmentAnnotation())
143 if (alifoldClient.involves(aa))
147 Assert.assertTrue("Did not create valid structure from RNAALiFold prediction", aa.isValidStruc());
154 public void testRNAStructExport()
157 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
159 af.getViewport().getCalcManager().startWorker(alifoldClient);
166 } catch (InterruptedException x)
170 } while (af.getViewport().getCalcManager().isWorking());
172 AlignmentI orig_alig = af.getViewport().getAlignment();
174 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
178 public static void testAnnotationFileIO(String testname, AlignmentI al)
182 // what format would be appropriate for RNAalifold annotations?
183 String aligfileout = new FormatAdapter().formatSequences("PFAM",
184 al.getSequencesArray());
186 String anfileout = new AnnotationFile()
187 .printAnnotationsForAlignment(al);
191 + "\nAlignment annotation file was not regenerated. Null string",
196 + "\nAlignment annotation file was not regenerated. Empty string",
197 anfileout.length() > "JALVIEW_ANNOTATION".length());
199 System.out.println("Output annotation file:\n" + anfileout
202 // again what format would be appropriate?
203 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
204 FormatAdapter.PASTE, "PFAM");
208 + "\nregenerated annotation file did not annotate alignment.",
209 new AnnotationFile().readAnnotationFile(al_new, anfileout,
210 FormatAdapter.PASTE));
212 // test for consistency in io
213 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
215 } catch (Exception e)
221 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
225 public void testRnaalifoldSettingsRecovery()
227 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
228 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
229 .getRunnerConfig().getArguments())
231 if (rg.getDescription().contains("emperature"))
236 } catch (WrongParameterException q)
238 fail("Couldn't set the temperature parameter "
239 + q.getStackTrace());
243 if (rg.getDescription().contains("max"))
248 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
250 af.getViewport().getCalcManager().startWorker(alifoldClient);
257 } catch (InterruptedException x)
261 } while (af.getViewport().getCalcManager().isWorking());
262 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
263 alifoldClient.getCalcId());
264 String oldsettings = oldacs.getWsParamFile();
265 // write out parameters
266 jalview.gui.AlignFrame nalf = null;
267 assertTrue("Couldn't write out the Jar file",
268 new Jalview2XML(false).saveAlignment(af,
269 "testRnalifold_param.jar", "trial parameter writeout"));
270 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
271 false).loadJalviewAlign("testRnalifold_param.jar")) != null);
274 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
275 alifoldClient.getCalcId());
276 assertTrue("Calc ID settings not recovered from viewport stash",
279 "Serialised Calc ID settings not identical to those recovered from viewport stash",
280 acs.getWsParamFile().equals(oldsettings));
281 JMenu nmenu = new JMenu();
282 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
284 assertTrue("Couldn't get menu entry for service",
285 nmenu.getItemCount() > 0);
286 for (Component itm : nmenu.getMenuComponents())
288 if (itm instanceof JMenuItem)
290 JMenuItem i = (JMenuItem) itm;
291 if (i.getText().equals(
292 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
299 while (af.getViewport().isCalcInProgress())
304 } catch (Exception x)
309 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
310 alifoldClient.getCalcId());
312 "Calc ID settings after recalculation has not been recovered.",
313 acs2.getWsParamFile().equals(oldsettings));