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.*;
25 import java.awt.Component;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.Vector;
31 import javax.swing.JMenu;
32 import javax.swing.JMenuItem;
34 import jalview.api.AlignCalcManagerI;
35 import jalview.datamodel.AlignmentAnnotation;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.Annotation;
38 import jalview.gui.Jalview2XML;
39 import jalview.io.AnnotationFile;
40 import jalview.io.FormatAdapter;
41 import jalview.io.StockholmFileTest;
42 import jalview.ws.jws2.AADisorderClient;
43 import jalview.ws.jws2.Jws2Discoverer;
44 import jalview.ws.jws2.RNAalifoldClient;
45 import jalview.ws.jws2.SequenceAnnotationWSClient;
46 import jalview.ws.jws2.dm.JabaOption;
47 import jalview.ws.jws2.jabaws2.Jws2Instance;
48 import jalview.ws.params.AutoCalcSetting;
50 import org.junit.AfterClass;
51 import org.junit.BeforeClass;
52 import org.junit.Test;
54 import compbio.metadata.WrongParameterException;
56 public class RNAStructExportImport
58 public static String testseqs = "examples/unfolded_RF00031.aln";
60 public static Jws2Discoverer disc;
62 public static Jws2Instance rnaalifoldws;
64 jalview.ws.jws2.RNAalifoldClient alifoldClient;
66 public static jalview.gui.AlignFrame af = null;
69 public static void setUpBeforeClass() throws Exception
72 jalview.bin.Cache.initLogger();
73 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
75 for (Jws2Instance svc : disc.getServices())
78 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
84 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
86 if (rnaalifoldws == null)
89 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
91 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
93 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
98 public static void tearDownAfterClass() throws Exception
102 af.setVisible(false);
108 public void testRNAStructExport()
111 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
113 af.getViewport().getCalcManager().startWorker(alifoldClient);
120 } catch (InterruptedException x)
124 } while (af.getViewport().getCalcManager().isWorking());
126 AlignmentI orig_alig = af.getViewport().getAlignment();
128 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
132 public static void testAnnotationFileIO(String testname, AlignmentI al)
136 // what format would be appropriate for RNAalifold annotations?
137 String aligfileout = new FormatAdapter().formatSequences("PFAM",
138 al.getSequencesArray());
140 String anfileout = new AnnotationFile().printAnnotations(
141 al.getAlignmentAnnotation(), al.getGroups(),
146 + "\nAlignment annotation file was not regenerated. Null string",
151 + "\nAlignment annotation file was not regenerated. Empty string",
152 anfileout.length() > "JALVIEW_ANNOTATION".length());
154 System.out.println("Output annotation file:\n" + anfileout
157 // again what format would be appropriate?
158 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
159 FormatAdapter.PASTE, "PFAM");
163 + "\nregenerated annotation file did not annotate alignment.",
164 new AnnotationFile().readAnnotationFile(al_new, anfileout,
165 FormatAdapter.PASTE));
167 // test for consistency in io
168 StockholmFileTest.testAlignmentEquivalence(al, al_new);
170 } catch (Exception e)
176 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
180 public void testRnaalifoldSettingsRecovery()
182 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
183 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
184 .getRunnerConfig().getArguments())
186 if (rg.getDescription().contains("emperature"))
191 } catch (WrongParameterException q)
193 fail("Couldn't set the temperature parameter "
194 + q.getStackTrace());
198 if (rg.getDescription().contains("max"))
203 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
205 af.getViewport().getCalcManager().startWorker(alifoldClient);
212 } catch (InterruptedException x)
216 } while (af.getViewport().getCalcManager().isWorking());
217 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
218 alifoldClient.getCalcId());
219 String oldsettings = oldacs.getWsParamFile();
220 // write out parameters
221 jalview.gui.AlignFrame nalf = null;
222 assertTrue("Couldn't write out the Jar file",
223 new Jalview2XML(false).SaveAlignment(af,
224 "testRnalifold_param.jar", "trial parameter writeout"));
225 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
226 false).LoadJalviewAlign("testRnalifold_param.jar")) != null);
229 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
230 alifoldClient.getCalcId());
231 assertTrue("Calc ID settings not recovered from viewport stash",
234 "Serialised Calc ID settings not identical to those recovered from viewport stash",
235 acs.getWsParamFile().equals(oldsettings));
236 JMenu nmenu = new JMenu();
237 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
239 assertTrue("Couldn't get menu entry for service",
240 nmenu.getItemCount() > 0);
241 for (Component itm : nmenu.getMenuComponents())
243 if (itm instanceof JMenuItem)
245 JMenuItem i = (JMenuItem) itm;
246 if (i.getText().equals(
247 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
254 while (af.getViewport().isCalcInProgress())
259 } catch (Exception x)
264 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
265 alifoldClient.getCalcId());
267 "Calc ID settings after recalculation has not been recovered.",
268 acs2.getWsParamFile().equals(oldsettings));