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()
141 .printAnnotationsForAlignment(al);
145 + "\nAlignment annotation file was not regenerated. Null string",
150 + "\nAlignment annotation file was not regenerated. Empty string",
151 anfileout.length() > "JALVIEW_ANNOTATION".length());
153 System.out.println("Output annotation file:\n" + anfileout
156 // again what format would be appropriate?
157 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
158 FormatAdapter.PASTE, "PFAM");
162 + "\nregenerated annotation file did not annotate alignment.",
163 new AnnotationFile().readAnnotationFile(al_new, anfileout,
164 FormatAdapter.PASTE));
166 // test for consistency in io
167 StockholmFileTest.testAlignmentEquivalence(al, al_new);
169 } catch (Exception e)
175 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
179 public void testRnaalifoldSettingsRecovery()
181 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
182 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
183 .getRunnerConfig().getArguments())
185 if (rg.getDescription().contains("emperature"))
190 } catch (WrongParameterException q)
192 fail("Couldn't set the temperature parameter "
193 + q.getStackTrace());
197 if (rg.getDescription().contains("max"))
202 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
204 af.getViewport().getCalcManager().startWorker(alifoldClient);
211 } catch (InterruptedException x)
215 } while (af.getViewport().getCalcManager().isWorking());
216 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
217 alifoldClient.getCalcId());
218 String oldsettings = oldacs.getWsParamFile();
219 // write out parameters
220 jalview.gui.AlignFrame nalf = null;
221 assertTrue("Couldn't write out the Jar file",
222 new Jalview2XML(false).SaveAlignment(af,
223 "testRnalifold_param.jar", "trial parameter writeout"));
224 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
225 false).LoadJalviewAlign("testRnalifold_param.jar")) != null);
228 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
229 alifoldClient.getCalcId());
230 assertTrue("Calc ID settings not recovered from viewport stash",
233 "Serialised Calc ID settings not identical to those recovered from viewport stash",
234 acs.getWsParamFile().equals(oldsettings));
235 JMenu nmenu = new JMenu();
236 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
238 assertTrue("Couldn't get menu entry for service",
239 nmenu.getItemCount() > 0);
240 for (Component itm : nmenu.getMenuComponents())
242 if (itm instanceof JMenuItem)
244 JMenuItem i = (JMenuItem) itm;
245 if (i.getText().equals(
246 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
253 while (af.getViewport().isCalcInProgress())
258 } catch (Exception x)
263 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
264 alifoldClient.getCalcId());
266 "Calc ID settings after recalculation has not been recovered.",
267 acs2.getWsParamFile().equals(oldsettings));