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.Argument;
39 import compbio.metadata.WrongParameterException;
41 import jalview.datamodel.AlignmentI;
42 import jalview.gui.Jalview2XML;
43 import jalview.io.AnnotationFile;
44 import jalview.io.FormatAdapter;
45 import jalview.io.StockholmFileTest;
46 import jalview.ws.jws2.JPred301Client;
47 import jalview.ws.jws2.JabaParamStore;
48 import jalview.ws.jws2.Jws2Discoverer;
49 import jalview.ws.jws2.SequenceAnnotationWSClient;
50 import jalview.ws.jws2.jabaws2.Jws2Instance;
51 import jalview.ws.params.AutoCalcSetting;
53 public class JpredJabaStructExportImport
55 public static String testseqs = "examples/uniref50.fa";
57 public static Jws2Discoverer disc;
59 public static Jws2Instance jpredws;
61 jalview.ws.jws2.JPred301Client jpredClient;
63 public static jalview.gui.AlignFrame af = null;
66 public static void setUpBeforeClass() throws Exception
69 jalview.bin.Cache.initLogger();
70 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
72 for (Jws2Instance svc : disc.getServices())
75 if (svc.getServiceTypeURI().toLowerCase().contains("jpred"))
81 System.out.println("State of jpredws: " + jpredws);
88 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
90 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
92 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
97 public static void tearDownAfterClass() throws Exception
101 af.setVisible(false);
107 public void testJPredStructOneSeqOnly()
109 af.selectAllSequenceMenuItem_actionPerformed(null);
113 af.getViewport().getSelectionGroup().getSequenceAt(0),
115 af.hideSelSequences_actionPerformed(null);
116 jpredClient = new JPred301Client(jpredws, af, null, null);
119 "Didn't find any default args to check for. Buggy implementation of hardwired arguments in client.",
120 jpredClient.selectDefaultArgs().size() > 0);
122 boolean success = false;
123 af.getViewport().getCalcManager().startWorker(jpredClient);
129 List<Argument> args = JabaParamStore.getJabafromJwsArgs(af
131 .getCalcIdSettingsFor(jpredClient.getCalcId())
132 .getArgumentSet()), defargs = jpredClient
133 .selectDefaultArgs();
134 for (Argument rg : args)
136 for (Argument defg : defargs)
146 jpredClient.cancelCurrentJob();
147 fail("Jpred Client didn't run with hardwired default parameters.");
150 } catch (InterruptedException x)
154 } while (af.getViewport().getCalcManager().isWorking());
159 public void testJPredStructExport()
162 jpredClient = new JPred301Client(jpredws, af, null, null);
164 af.getViewport().getCalcManager().startWorker(jpredClient);
171 } catch (InterruptedException x)
175 } while (af.getViewport().getCalcManager().isWorking());
177 AlignmentI orig_alig = af.getViewport().getAlignment();
179 testAnnotationFileIO("Testing JPredWS Annotation IO", orig_alig);
183 public static void testAnnotationFileIO(String testname, AlignmentI al)
187 // what format would be appropriate for RNAalifold annotations?
188 String aligfileout = new FormatAdapter().formatSequences("PFAM",
189 al.getSequencesArray());
191 String anfileout = new AnnotationFile().printAnnotations(
192 al.getAlignmentAnnotation(), al.getGroups(),
197 + "\nAlignment annotation file was not regenerated. Null string",
202 + "\nAlignment annotation file was not regenerated. Empty string",
203 anfileout.length() > "JALVIEW_ANNOTATION".length());
205 System.out.println("Output annotation file:\n" + anfileout
208 // again what format would be appropriate?
209 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
210 FormatAdapter.PASTE, "PFAM");
214 + "\nregenerated annotation file did not annotate alignment.",
215 new AnnotationFile().readAnnotationFile(al_new, anfileout,
216 FormatAdapter.PASTE));
218 // test for consistency in io
219 StockholmFileTest.testAlignmentEquivalence(al, al_new);
221 } catch (Exception e)
227 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
231 public void testJpredwsSettingsRecovery()
233 fail("not implemnented");
234 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
235 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) jpredws
236 .getRunnerConfig().getArguments())
238 if (rg.getDescription().contains("emperature"))
243 } catch (WrongParameterException q)
245 fail("Couldn't set the temperature parameter "
246 + q.getStackTrace());
250 if (rg.getDescription().contains("max"))
255 jpredClient = new JPred301Client(jpredws, af, null, opts);
257 af.getViewport().getCalcManager().startWorker(jpredClient);
264 } catch (InterruptedException x)
268 } while (af.getViewport().getCalcManager().isWorking());
269 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
270 jpredClient.getCalcId());
271 String oldsettings = oldacs.getWsParamFile();
272 // write out parameters
273 jalview.gui.AlignFrame nalf = null;
274 assertTrue("Couldn't write out the Jar file",
275 new Jalview2XML(false).SaveAlignment(af,
276 "testJPredWS_param.jar", "trial parameter writeout"));
277 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
278 false).LoadJalviewAlign("testJpredWS_param.jar")) != null);
281 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
282 jpredClient.getCalcId());
283 assertTrue("Calc ID settings not recovered from viewport stash",
286 "Serialised Calc ID settings not identical to those recovered from viewport stash",
287 acs.getWsParamFile().equals(oldsettings));
288 JMenu nmenu = new JMenu();
289 new SequenceAnnotationWSClient()
290 .attachWSMenuEntry(nmenu, jpredws, af);
291 assertTrue("Couldn't get menu entry for service",
292 nmenu.getItemCount() > 0);
293 for (Component itm : nmenu.getMenuComponents())
295 if (itm instanceof JMenuItem)
297 JMenuItem i = (JMenuItem) itm;
298 if (i.getText().equals(
299 jpredws.getAlignAnalysisUI().getAAconToggle()))
306 while (af.getViewport().isCalcInProgress())
311 } catch (Exception x)
316 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
317 jpredClient.getCalcId());
319 "Calc ID settings after recalculation has not been recovered.",
320 acs2.getWsParamFile().equals(oldsettings));