2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.AlignmentI;
27 import jalview.gui.Jalview2XML;
28 import jalview.io.AnnotationFile;
29 import jalview.io.FormatAdapter;
30 import jalview.io.StockholmFileTest;
31 import jalview.ws.jws2.Jws2Discoverer;
32 import jalview.ws.jws2.RNAalifoldClient;
33 import jalview.ws.jws2.SequenceAnnotationWSClient;
34 import jalview.ws.jws2.jabaws2.Jws2Instance;
35 import jalview.ws.params.AutoCalcSetting;
37 import java.awt.Component;
38 import java.util.ArrayList;
39 import java.util.List;
41 import javax.swing.JMenu;
42 import javax.swing.JMenuItem;
44 import org.junit.AfterClass;
45 import org.junit.BeforeClass;
46 import org.junit.Test;
48 import compbio.metadata.WrongParameterException;
50 public class RNAStructExportImport
52 public static String testseqs = "examples/unfolded_RF00031.aln";
54 public static Jws2Discoverer disc;
56 public static Jws2Instance rnaalifoldws;
58 jalview.ws.jws2.RNAalifoldClient alifoldClient;
60 public static jalview.gui.AlignFrame af = null;
63 public static void setUpBeforeClass() throws Exception
66 jalview.bin.Cache.initLogger();
67 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
69 for (Jws2Instance svc : disc.getServices())
72 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
78 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
80 if (rnaalifoldws == null)
85 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
87 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
89 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
94 public static void tearDownAfterClass() throws Exception
104 public void testRNAStructExport()
107 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
109 af.getViewport().getCalcManager().startWorker(alifoldClient);
116 } catch (InterruptedException x)
120 } while (af.getViewport().getCalcManager().isWorking());
122 AlignmentI orig_alig = af.getViewport().getAlignment();
124 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
128 public static void testAnnotationFileIO(String testname, AlignmentI al)
132 // what format would be appropriate for RNAalifold annotations?
133 String aligfileout = new FormatAdapter().formatSequences("PFAM",
134 al.getSequencesArray());
136 String anfileout = new AnnotationFile()
137 .printAnnotationsForAlignment(al);
141 + "\nAlignment annotation file was not regenerated. Null string",
146 + "\nAlignment annotation file was not regenerated. Empty string",
147 anfileout.length() > "JALVIEW_ANNOTATION".length());
149 System.out.println("Output annotation file:\n" + anfileout
152 // again what format would be appropriate?
153 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
154 FormatAdapter.PASTE, "PFAM");
158 + "\nregenerated annotation file did not annotate alignment.",
159 new AnnotationFile().readAnnotationFile(al_new, anfileout,
160 FormatAdapter.PASTE));
162 // test for consistency in io
163 StockholmFileTest.testAlignmentEquivalence(al, al_new);
165 } catch (Exception e)
171 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
175 public void testRnaalifoldSettingsRecovery()
177 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
178 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
179 .getRunnerConfig().getArguments())
181 if (rg.getDescription().contains("emperature"))
186 } catch (WrongParameterException q)
188 fail("Couldn't set the temperature parameter "
189 + q.getStackTrace());
193 if (rg.getDescription().contains("max"))
198 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
200 af.getViewport().getCalcManager().startWorker(alifoldClient);
207 } catch (InterruptedException x)
211 } while (af.getViewport().getCalcManager().isWorking());
212 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
213 alifoldClient.getCalcId());
214 String oldsettings = oldacs.getWsParamFile();
215 // write out parameters
216 jalview.gui.AlignFrame nalf = null;
217 assertTrue("Couldn't write out the Jar file",
218 new Jalview2XML(false).saveAlignment(af,
219 "testRnalifold_param.jar", "trial parameter writeout"));
220 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
221 false).loadJalviewAlign("testRnalifold_param.jar")) != null);
224 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
225 alifoldClient.getCalcId());
226 assertTrue("Calc ID settings not recovered from viewport stash",
229 "Serialised Calc ID settings not identical to those recovered from viewport stash",
230 acs.getWsParamFile().equals(oldsettings));
231 JMenu nmenu = new JMenu();
232 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
234 assertTrue("Couldn't get menu entry for service",
235 nmenu.getItemCount() > 0);
236 for (Component itm : nmenu.getMenuComponents())
238 if (itm instanceof JMenuItem)
240 JMenuItem i = (JMenuItem) itm;
241 if (i.getText().equals(
242 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
249 while (af.getViewport().isCalcInProgress())
254 } catch (Exception x)
259 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
260 alifoldClient.getCalcId());
262 "Calc ID settings after recalculation has not been recovered.",
263 acs2.getWsParamFile().equals(oldsettings));