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.AlignFrame;
29 import jalview.gui.Jalview2XML;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.AnnotationFile;
32 import jalview.io.DataSourceType;
33 import jalview.io.FileFormat;
34 import jalview.io.FileLoader;
35 import jalview.io.FormatAdapter;
36 import jalview.io.StockholmFileTest;
37 import jalview.ws.jws2.JPred301Client;
38 import jalview.ws.jws2.JabaParamStore;
39 import jalview.ws.jws2.SequenceAnnotationWSClient;
40 import jalview.ws.jws2.jabaws2.Jws2Instance;
41 import jalview.ws.params.AutoCalcSetting;
43 import java.awt.Component;
44 import java.net.ConnectException;
45 import java.util.ArrayList;
46 import java.util.List;
48 import javax.swing.JMenu;
49 import javax.swing.JMenuItem;
50 import javax.xml.ws.WebServiceException;
52 import org.testng.Assert;
53 import org.testng.annotations.AfterClass;
54 import org.testng.annotations.BeforeClass;
55 import org.testng.annotations.Test;
57 import compbio.data.msa.Category;
58 import compbio.data.msa.JABAService;
59 import compbio.metadata.Argument;
60 import compbio.metadata.WrongParameterException;
61 import compbio.ws.client.Jws2Client;
62 import compbio.ws.client.Services;
64 public class JpredJabaStructExportImport
67 @BeforeClass(alwaysRun = true)
68 public void setUpJvOptionPane()
70 JvOptionPane.setInteractiveMode(false);
71 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
74 private static String testseqs = "examples/uniref50.fa";
76 private static Jws2Instance jpredws;
78 private static AlignFrame af = null;
80 @BeforeClass(alwaysRun = true)
81 public static void setUpBeforeClass() throws ConnectException,
84 Cache.loadProperties("test/jalview/io/testProps.jvprops");
85 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
86 Boolean.TRUE.toString());
87 Cache.applicationProperties.setProperty("SHOW_QUALITY",
88 Boolean.FALSE.toString());
89 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
90 Boolean.FALSE.toString());
91 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
92 Boolean.FALSE.toString());
96 FileLoader fl = new FileLoader(false);
97 af = fl.LoadFileWaitTillLoaded(testseqs, DataSourceType.FILE);
98 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
102 * @throws WebServiceException
103 * @throws ConnectException
106 static void getJabaws() throws ConnectException, WebServiceException
108 String jabaws = "http://www.compbio.dundee.ac.uk/jabaws";
109 JABAService service = null;
110 for (Category category : Category.getCategories())
112 for (Services srv : category.getServices())
114 if ("JpredWS".equals(srv.name()))
116 service = Jws2Client.connect(jabaws, srv);
120 jpredws = new Jws2Instance(jabaws, "JpredWs",
121 "Secondary Structure Prediction",
122 "SERVICE: JpredWS version 3.0.3", service);
123 Assert.assertNotNull(jpredws, "jpredws is null!");
126 @AfterClass(alwaysRun = true)
127 public static void tearDownAfterClass() throws Exception
131 af.setVisible(false);
136 @Test(groups = { "Network" })
137 public void testJPredStructOneSeqOnly()
139 af.selectAllSequenceMenuItem_actionPerformed(null);
143 af.getViewport().getSelectionGroup().getSequenceAt(0),
145 af.hideSelSequences_actionPerformed(null);
146 JPred301Client jpredClient = new JPred301Client(jpredws, af, null, null);
149 "Didn't find any default args to check for. Buggy implementation of hardwired arguments in client.",
150 jpredClient.selectDefaultArgs().size() > 0);
152 boolean success = false;
153 af.getViewport().getCalcManager().startWorker(jpredClient);
159 List<Argument> args = JabaParamStore.getJabafromJwsArgs(af
161 .getCalcIdSettingsFor(jpredClient.getCalcId())
162 .getArgumentSet()), defargs = jpredClient
163 .selectDefaultArgs();
164 for (Argument rg : args)
166 for (Argument defg : defargs)
176 jpredClient.cancelCurrentJob();
177 Assert.fail("Jpred Client didn't run with hardwired default parameters.");
180 } catch (InterruptedException x)
184 } while (af.getViewport().getCalcManager().isWorking());
189 * test disabled pending completion of JAL-1601
190 * (JPred301Client is currently hidden in Jalview in
193 @Test(groups = { "Network" })
194 public void testJPredStructExport() throws InterruptedException
197 JPred301Client jpredClient = new JPred301Client(jpredws, af, null, null);
199 af.getViewport().getCalcManager().startWorker(jpredClient);
206 } catch (InterruptedException x)
210 } while (af.getViewport().getCalcManager().isWorking());
216 AlignmentI orig_alig = af.getViewport().getAlignment();
217 System.out.println("Alignment now has "
218 + orig_alig.getAlignmentAnnotation().length + " annotations");
219 verifyAnnotationFileIO("Testing JPredWS Annotation IO", orig_alig);
223 protected static void verifyAnnotationFileIO(String testname,
228 // what format would be appropriate for RNAalifold annotations?
229 String aligfileout = FileFormat.Fasta.getWriter(null).print(
230 al.getSequencesArray(), true);
232 String anfileout = new AnnotationFile()
233 .printAnnotationsForAlignment(al);
237 + "\nAlignment annotation file was not regenerated. Null string",
242 + "\nAlignment annotation file was not regenerated. Empty string",
243 anfileout.length() > "JALVIEW_ANNOTATION".length());
245 System.out.println("Output annotation file:\n" + anfileout
248 // again what format would be appropriate?
249 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
250 DataSourceType.PASTE, FileFormat.Fasta);
254 + "\nregenerated annotation file did not annotate alignment.",
255 new AnnotationFile().readAnnotationFile(al_new, anfileout,
256 DataSourceType.PASTE));
258 // test for consistency in io
259 StockholmFileTest.testAlignmentEquivalence(al, al_new, false);
261 } catch (Exception e)
266 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
270 @Test(groups = { "Network" }, enabled = false)
271 public void testJpredwsSettingsRecovery()
273 Assert.fail("not implemented");
274 List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
275 for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) jpredws
276 .getRunnerConfig().getArguments())
278 if (rg.getDescription().contains("emperature"))
283 } catch (WrongParameterException q)
285 Assert.fail("Couldn't set the temperature parameter "
286 + q.getStackTrace());
290 if (rg.getDescription().contains("max"))
295 JPred301Client jpredClient = new JPred301Client(jpredws, af, null, opts);
297 af.getViewport().getCalcManager().startWorker(jpredClient);
304 } catch (InterruptedException x)
308 } while (af.getViewport().getCalcManager().isWorking());
309 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
310 jpredClient.getCalcId());
311 String oldsettings = oldacs.getWsParamFile();
312 // write out parameters
313 jalview.gui.AlignFrame nalf = null;
314 assertTrue("Couldn't write out the Jar file",
315 new Jalview2XML(false).saveAlignment(af,
316 "testJPredWS_param.jar", "trial parameter writeout"));
317 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
318 false).loadJalviewAlign("testJpredWS_param.jar")) != null);
321 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
322 jpredClient.getCalcId());
323 assertTrue("Calc ID settings not recovered from viewport stash",
326 "Serialised Calc ID settings not identical to those recovered from viewport stash",
327 acs.getWsParamFile().equals(oldsettings));
328 JMenu nmenu = new JMenu();
329 new SequenceAnnotationWSClient()
330 .attachWSMenuEntry(nmenu, jpredws, af);
331 assertTrue("Couldn't get menu entry for service",
332 nmenu.getItemCount() > 0);
333 for (Component itm : nmenu.getMenuComponents())
335 if (itm instanceof JMenuItem)
337 JMenuItem i = (JMenuItem) itm;
338 if (i.getText().equals(
339 jpredws.getAlignAnalysisUI().getAAconToggle()))
346 while (af.getViewport().isCalcInProgress())
351 } catch (Exception x)
356 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
357 jpredClient.getCalcId());
359 "Calc ID settings after recalculation has not been recovered.",
360 acs2.getWsParamFile().equals(oldsettings));