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 java.util.Locale;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.bin.Cache;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.gui.JvOptionPane;
32 import jalview.io.AnnotationFile;
33 import jalview.io.DataSourceType;
34 import jalview.io.FileFormat;
35 import jalview.io.FormatAdapter;
36 import jalview.io.StockholmFileTest;
37 import jalview.project.Jalview2XML;
38 import jalview.ws.jws2.Jws2Discoverer;
39 import jalview.ws.jws2.RNAalifoldClient;
40 import jalview.ws.jws2.SequenceAnnotationWSClient;
41 import jalview.ws.jws2.jabaws2.Jws2Instance;
42 import jalview.ws.params.AutoCalcSetting;
44 import java.awt.Component;
46 import java.util.ArrayList;
47 import java.util.List;
49 import javax.swing.JMenu;
50 import javax.swing.JMenuItem;
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.metadata.Argument;
58 import compbio.metadata.WrongParameterException;
61 * All methods in this class are set to the Network group because setUpBeforeClass will fail
62 * if there is no network.
64 @Test(singleThreaded = true)
65 public class RNAStructExportImport
68 @BeforeClass(alwaysRun = true)
69 public void setUpJvOptionPane()
71 JvOptionPane.setInteractiveMode(false);
72 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
75 private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
77 public static String testseqs = "examples/RF00031_folded.stk";
79 public static Jws2Discoverer disc;
81 public static Jws2Instance rnaalifoldws;
83 jalview.ws.jws2.RNAalifoldClient alifoldClient;
85 public static jalview.gui.AlignFrame af = null;
87 @BeforeClass(alwaysRun = true)
88 public static void setUpBeforeClass() throws Exception
90 Cache.loadProperties("test/jalview/io/testProps.jvprops");
92 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
94 while (disc.isRunning())
96 // don't get services until discoverer has finished
100 for (Jws2Instance svc : disc.getServices())
103 if (svc.getServiceTypeURI().toLowerCase(Locale.ROOT).contains("rnaalifoldws"))
109 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
111 if (rnaalifoldws == null)
113 Assert.fail("no web service");
116 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
118 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE);
120 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
122 // remove any existing annotation
123 List<AlignmentAnnotation> aal = new ArrayList<>();
124 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
125 .getAlignmentAnnotation())
132 for (AlignmentAnnotation rna : aal)
134 af.getViewport().getAlignment().deleteAnnotation(rna);
136 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
140 @AfterClass(alwaysRun = true)
141 public static void tearDownAfterClass() throws Exception
145 af.setVisible(false);
147 File f = new File(JAR_FILE_NAME);
155 @Test(groups = { "Network" })
156 public void testRNAAliFoldValidStructure()
159 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
161 af.getViewport().getCalcManager().startWorker(alifoldClient);
168 } catch (InterruptedException x)
171 } while (af.getViewport().getCalcManager().isWorking());
173 AlignmentI orig_alig = af.getViewport().getAlignment();
174 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
176 if (alifoldClient.involves(aa))
181 "Did not create valid structure from RNAALiFold prediction",
188 @Test(groups = { "Network" })
189 public void testRNAStructExport()
192 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
194 af.getViewport().getCalcManager().startWorker(alifoldClient);
201 } catch (InterruptedException x)
204 } while (af.getViewport().getCalcManager().isWorking());
206 AlignmentI orig_alig = af.getViewport().getAlignment();
207 // JBPNote: this assert fails (2.10.2) because the 'Reference Positions'
208 // annotation is mistakenly recognised as an RNA annotation row when read in
209 // as an annotation file.
210 verifyAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
214 static void verifyAnnotationFileIO(String testname, AlignmentI al)
218 // what format would be appropriate for RNAalifold annotations?
219 String aligfileout = FileFormat.Pfam.getWriter(null).print(
220 al.getSequencesArray(), true);
222 String anfileout = new AnnotationFile()
223 .printAnnotationsForAlignment(al);
227 + "\nAlignment annotation file was not regenerated. Null string",
232 + "\nAlignment annotation file was not regenerated. Empty string",
233 anfileout.length() > "JALVIEW_ANNOTATION".length());
235 System.out.println("Output annotation file:\n" + anfileout
238 // again what format would be appropriate?
239 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
240 DataSourceType.PASTE, FileFormat.Pfam);
244 + "\nregenerated annotation file did not annotate alignment.",
245 new AnnotationFile().readAnnotationFile(al_new, anfileout,
246 DataSourceType.PASTE));
248 // test for consistency in io
249 StockholmFileTest.testAlignmentEquivalence(al, al_new, false, false,
252 } catch (Exception e)
258 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
261 @Test(groups = { "Network" })
262 public void testRnaalifoldSettingsRecovery()
264 List<Argument> opts = new ArrayList<>();
265 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
268 if (rg.getDescription().contains("emperature"))
273 } catch (WrongParameterException q)
275 Assert.fail("Couldn't set the temperature parameter "
276 + q.getStackTrace());
280 if (rg.getDescription().contains("max"))
285 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
287 af.getViewport().getCalcManager().startWorker(alifoldClient);
294 } catch (InterruptedException x)
298 } while (af.getViewport().getCalcManager().isWorking());
299 AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(
300 alifoldClient.getCalcId());
301 String oldsettings = oldacs.getWsParamFile();
302 // write out parameters
303 jalview.gui.AlignFrame nalf = null;
304 assertTrue("Couldn't write out the Jar file",
305 new Jalview2XML(false).saveAlignment(af, JAR_FILE_NAME,
306 "trial parameter writeout"));
307 assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
308 false).loadJalviewAlign(JAR_FILE_NAME)) != null);
311 AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
312 alifoldClient.getCalcId());
313 assertTrue("Calc ID settings not recovered from viewport stash",
316 "Serialised Calc ID settings not identical to those recovered from viewport stash",
317 acs.getWsParamFile().equals(oldsettings));
318 JMenu nmenu = new JMenu();
319 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
321 assertTrue("Couldn't get menu entry for service",
322 nmenu.getItemCount() > 0);
323 for (Component itm : nmenu.getMenuComponents())
325 if (itm instanceof JMenuItem)
327 JMenuItem i = (JMenuItem) itm;
328 if (i.getText().equals(
329 rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
336 while (af.getViewport().isCalcInProgress())
341 } catch (Exception x)
346 AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(
347 alifoldClient.getCalcId());
349 "Calc ID settings after recalculation has not been recovered.",
350 acs2.getWsParamFile().equals(oldsettings));