2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
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;
27 import java.awt.Component;
28 import java.util.ArrayList;
29 import java.util.List;
31 import javax.swing.JMenu;
32 import javax.swing.JMenuItem;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
38 import compbio.metadata.WrongParameterException;
40 import jalview.datamodel.AlignmentI;
41 import jalview.gui.Jalview2XML;
42 import jalview.io.AnnotationFile;
43 import jalview.io.FormatAdapter;
44 import jalview.io.StockholmFileTest;
45 import jalview.ws.jws2.Jws2Discoverer;
46 import jalview.ws.jws2.RNAalifoldClient;
47 import jalview.ws.jws2.SequenceAnnotationWSClient;
48 import jalview.ws.jws2.jabaws2.Jws2Instance;
49 import jalview.ws.params.AutoCalcSetting;
51 public class RNAStructExportImport
53 public static String testseqs = "examples/unfolded_RF00031.aln";
55 public static Jws2Discoverer disc;
57 public static Jws2Instance rnaalifoldws;
59 jalview.ws.jws2.RNAalifoldClient alifoldClient;
61 public static jalview.gui.AlignFrame af = null;
64 public static void setUpBeforeClass() throws Exception
67 jalview.bin.Cache.initLogger();
68 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
70 for (Jws2Instance svc : disc.getServices())
73 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
79 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
81 if (rnaalifoldws == null)
83 fail("rnaalifoldws null");
86 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
88 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
90 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
95 public static void tearDownAfterClass() throws Exception
105 public void testRNAStructExport()
108 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
110 af.getViewport().getCalcManager().startWorker(alifoldClient);
117 } catch (InterruptedException x)
121 } while (af.getViewport().getCalcManager().isWorking());
123 AlignmentI orig_alig = af.getViewport().getAlignment();
125 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
129 public static void testAnnotationFileIO(String testname, AlignmentI al)
133 // what format would be appropriate for RNAalifold annotations?
134 String aligfileout = new FormatAdapter().formatSequences("PFAM",
135 al.getSequencesArray());
137 String anfileout = new AnnotationFile().printAnnotations(
138 al.getAlignmentAnnotation(), al.getGroups(),
143 + "\nAlignment annotation file was not regenerated. Null string",
148 + "\nAlignment annotation file was not regenerated. Empty string",
149 anfileout.length() > "JALVIEW_ANNOTATION".length());
151 System.out.println("Output annotation file:\n" + anfileout
154 // again what format would be appropriate?
155 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
156 FormatAdapter.PASTE, "PFAM");
160 + "\nregenerated annotation file did not annotate alignment.",
161 new AnnotationFile().readAnnotationFile(al_new, anfileout,
162 FormatAdapter.PASTE));
164 // test for consistency in io
165 StockholmFileTest.testAlignmentEquivalence(al, al_new);
167 } catch (Exception e)
173 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
177 public void testRnaalifoldSettingsRecovery()
179 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
180 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
181 .getRunnerConfig().getArguments())
183 if (rg.getDescription().contains("emperature"))
188 } catch (WrongParameterException q)
190 fail("Couldn't set the temperature parameter "
191 + q.getStackTrace());
195 if (rg.getDescription().contains("max"))
200 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
202 af.getViewport().getCalcManager().startWorker(alifoldClient);
209 } catch (InterruptedException x)
213 } while (af.getViewport().getCalcManager().isWorking());
214 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
215 alifoldClient.getCalcId());
216 String oldsettings = oldacs.getWsParamFile();
217 // write out parameters
218 jalview.gui.AlignFrame nalf = null;
219 assertTrue("Couldn't write out the Jar file",
220 new Jalview2XML(false).SaveAlignment(af,
221 "testRnalifold_param.jar", "trial parameter writeout"));
222 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
223 false).LoadJalviewAlign("testRnalifold_param.jar")) != null);
226 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
227 alifoldClient.getCalcId());
228 assertTrue("Calc ID settings not recovered from viewport stash",
231 "Serialised Calc ID settings not identical to those recovered from viewport stash",
232 acs.getWsParamFile().equals(oldsettings));
233 JMenu nmenu = new JMenu();
234 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
236 assertTrue("Couldn't get menu entry for service",
237 nmenu.getItemCount() > 0);
238 for (Component itm : nmenu.getMenuComponents())
240 if (itm instanceof JMenuItem)
242 JMenuItem i = (JMenuItem) itm;
243 if (i.getText().equals(
244 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
251 while (af.getViewport().isCalcInProgress())
256 } catch (Exception x)
261 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
262 alifoldClient.getCalcId());
264 "Calc ID settings after recalculation has not been recovered.",
265 acs2.getWsParamFile().equals(oldsettings));