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 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
82 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
84 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
89 public static void tearDownAfterClass() throws Exception
99 public void testRNAStructExport()
102 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
104 af.getViewport().getCalcManager().startWorker(alifoldClient);
111 } catch (InterruptedException x)
115 } while (af.getViewport().getCalcManager().isWorking());
117 AlignmentI orig_alig = af.getViewport().getAlignment();
119 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
123 public static void testAnnotationFileIO(String testname, AlignmentI al)
127 // what format would be appropriate for RNAalifold annotations?
128 String aligfileout = new FormatAdapter().formatSequences("PFAM",
129 al.getSequencesArray());
131 String anfileout = new AnnotationFile().printAnnotations(
132 al.getAlignmentAnnotation(), al.getGroups(),
137 + "\nAlignment annotation file was not regenerated. Null string",
142 + "\nAlignment annotation file was not regenerated. Empty string",
143 anfileout.length() > "JALVIEW_ANNOTATION".length());
145 System.out.println("Output annotation file:\n" + anfileout
148 // again what format would be appropriate?
149 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
150 FormatAdapter.PASTE, "PFAM");
154 + "\nregenerated annotation file did not annotate alignment.",
155 new AnnotationFile().readAnnotationFile(al_new, anfileout,
156 FormatAdapter.PASTE));
158 // test for consistency in io
159 StockholmFileTest.testAlignmentEquivalence(al, al_new);
161 } catch (Exception e)
167 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
171 public void testRnaalifoldSettingsRecovery()
173 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
174 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
175 .getRunnerConfig().getArguments())
177 if (rg.getDescription().contains("emperature"))
182 } catch (WrongParameterException q)
184 fail("Couldn't set the temperature parameter "
185 + q.getStackTrace());
189 if (rg.getDescription().contains("max"))
195 assertNotNull(rnaalifoldws);
196 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
198 af.getViewport().getCalcManager().startWorker(alifoldClient);
205 } catch (InterruptedException x)
209 } while (af.getViewport().getCalcManager().isWorking());
210 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
211 alifoldClient.getCalcId());
212 String oldsettings = oldacs.getWsParamFile();
213 // write out parameters
214 jalview.gui.AlignFrame nalf = null;
215 assertTrue("Couldn't write out the Jar file",
216 new Jalview2XML(false).SaveAlignment(af,
217 "testRnalifold_param.jar", "trial parameter writeout"));
218 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
219 false).LoadJalviewAlign("testRnalifold_param.jar")) != null);
222 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
223 alifoldClient.getCalcId());
224 assertTrue("Calc ID settings not recovered from viewport stash",
227 "Serialised Calc ID settings not identical to those recovered from viewport stash",
228 acs.getWsParamFile().equals(oldsettings));
229 JMenu nmenu = new JMenu();
230 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
232 assertTrue("Couldn't get menu entry for service",
233 nmenu.getItemCount() > 0);
234 for (Component itm : nmenu.getMenuComponents())
236 if (itm instanceof JMenuItem)
238 JMenuItem i = (JMenuItem) itm;
239 if (i.getText().equals(
240 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
247 while (af.getViewport().isCalcInProgress())
252 } catch (Exception x)
257 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
258 alifoldClient.getCalcId());
260 "Calc ID settings after recalculation has not been recovered.",
261 acs2.getWsParamFile().equals(oldsettings));