2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignmentI;
28 import jalview.gui.Jalview2XML;
29 import jalview.io.AnnotationFile;
30 import jalview.io.FormatAdapter;
31 import jalview.io.StockholmFileTest;
32 import jalview.ws.jws2.JPred301Client;
33 import jalview.ws.jws2.JabaParamStore;
34 import jalview.ws.jws2.Jws2Discoverer;
35 import jalview.ws.jws2.SequenceAnnotationWSClient;
36 import jalview.ws.jws2.jabaws2.Jws2Instance;
37 import jalview.ws.params.AutoCalcSetting;
39 import java.awt.Component;
40 import java.util.ArrayList;
41 import java.util.List;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
46 import org.testng.Assert;
47 import org.testng.annotations.AfterClass;
48 import org.testng.annotations.BeforeClass;
49 import org.testng.annotations.Test;
51 import compbio.metadata.Argument;
52 import compbio.metadata.WrongParameterException;
54 public class JpredJabaStructExportImport
56 public static String testseqs = "examples/uniref50.fa";
58 public static Jws2Discoverer disc;
60 public static Jws2Instance jpredws;
62 jalview.ws.jws2.JPred301Client jpredClient;
64 public static jalview.gui.AlignFrame af = null;
66 @BeforeClass(alwaysRun = true)
67 public static void setUpBeforeClass() throws Exception
69 Cache.loadProperties("test/jalview/io/testProps.jvprops");
71 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
73 for (Jws2Instance svc : disc.getServices())
75 if (svc.getServiceTypeURI().toLowerCase().contains("jpred"))
81 System.out.println("State of jpredws: " + jpredws);
82 Assert.assertNotNull(jpredws, "jpredws is null!");
83 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
84 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
85 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
88 @AfterClass(alwaysRun = true)
89 public static void tearDownAfterClass() throws Exception
98 @Test(groups = { "Functional" })
99 public void testJPredStructOneSeqOnly()
101 af.selectAllSequenceMenuItem_actionPerformed(null);
105 af.getViewport().getSelectionGroup().getSequenceAt(0),
107 af.hideSelSequences_actionPerformed(null);
108 jpredClient = new JPred301Client(jpredws, af, null, null);
111 "Didn't find any default args to check for. Buggy implementation of hardwired arguments in client.",
112 jpredClient.selectDefaultArgs().size() > 0);
114 boolean success = false;
115 af.getViewport().getCalcManager().startWorker(jpredClient);
121 List<Argument> args = JabaParamStore.getJabafromJwsArgs(af
123 .getCalcIdSettingsFor(jpredClient.getCalcId())
124 .getArgumentSet()), defargs = jpredClient
125 .selectDefaultArgs();
126 for (Argument rg : args)
128 for (Argument defg : defargs)
138 jpredClient.cancelCurrentJob();
139 Assert.fail("Jpred Client didn't run with hardwired default parameters.");
142 } catch (InterruptedException x)
146 } while (af.getViewport().getCalcManager().isWorking());
150 @Test(groups = { "Functional" })
151 public void testJPredStructExport()
154 jpredClient = new JPred301Client(jpredws, af, null, null);
156 af.getViewport().getCalcManager().startWorker(jpredClient);
163 } catch (InterruptedException x)
167 } while (af.getViewport().getCalcManager().isWorking());
169 AlignmentI orig_alig = af.getViewport().getAlignment();
171 testAnnotationFileIO("Testing JPredWS Annotation IO", orig_alig);
175 public static void testAnnotationFileIO(String testname, AlignmentI al)
179 // what format would be appropriate for RNAalifold annotations?
180 String aligfileout = new FormatAdapter().formatSequences("PFAM",
181 al.getSequencesArray());
183 String anfileout = new AnnotationFile()
184 .printAnnotationsForAlignment(al);
188 + "\nAlignment annotation file was not regenerated. Null string",
193 + "\nAlignment annotation file was not regenerated. Empty string",
194 anfileout.length() > "JALVIEW_ANNOTATION".length());
196 System.out.println("Output annotation file:\n" + anfileout
199 // again what format would be appropriate?
200 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
201 FormatAdapter.PASTE, "PFAM");
205 + "\nregenerated annotation file did not annotate alignment.",
206 new AnnotationFile().readAnnotationFile(al_new, anfileout,
207 FormatAdapter.PASTE));
209 // test for consistency in io
210 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
212 } catch (Exception e)
218 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
221 @Test(groups = { "Functional" })
222 public void testJpredwsSettingsRecovery()
224 Assert.fail("not implemnented");
225 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
226 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) jpredws
227 .getRunnerConfig().getArguments())
229 if (rg.getDescription().contains("emperature"))
234 } catch (WrongParameterException q)
236 Assert.fail("Couldn't set the temperature parameter "
237 + q.getStackTrace());
241 if (rg.getDescription().contains("max"))
246 jpredClient = new JPred301Client(jpredws, af, null, opts);
248 af.getViewport().getCalcManager().startWorker(jpredClient);
255 } catch (InterruptedException x)
259 } while (af.getViewport().getCalcManager().isWorking());
260 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
261 jpredClient.getCalcId());
262 String oldsettings = oldacs.getWsParamFile();
263 // write out parameters
264 jalview.gui.AlignFrame nalf = null;
265 assertTrue("Couldn't write out the Jar file",
266 new Jalview2XML(false).saveAlignment(af,
267 "testJPredWS_param.jar", "trial parameter writeout"));
268 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
269 false).loadJalviewAlign("testJpredWS_param.jar")) != null);
272 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
273 jpredClient.getCalcId());
274 assertTrue("Calc ID settings not recovered from viewport stash",
277 "Serialised Calc ID settings not identical to those recovered from viewport stash",
278 acs.getWsParamFile().equals(oldsettings));
279 JMenu nmenu = new JMenu();
280 new SequenceAnnotationWSClient()
281 .attachWSMenuEntry(nmenu, jpredws, af);
282 assertTrue("Couldn't get menu entry for service",
283 nmenu.getItemCount() > 0);
284 for (Component itm : nmenu.getMenuComponents())
286 if (itm instanceof JMenuItem)
288 JMenuItem i = (JMenuItem) itm;
289 if (i.getText().equals(
290 jpredws.getAlignAnalysisUI().getAAconToggle()))
297 while (af.getViewport().isCalcInProgress())
302 } catch (Exception x)
307 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
308 jpredClient.getCalcId());
310 "Calc ID settings after recalculation has not been recovered.",
311 acs2.getWsParamFile().equals(oldsettings));