Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.ws.jabaws

File RNAStructExportImport.java

 

Code metrics

34
97
7
1
353
275
30
0.31
13.86
7
4.29

Classes

Class Line # Actions
RNAStructExportImport 67 97 30
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.jabaws;
22   
23    import java.util.Locale;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.bin.Cache;
28    import jalview.bin.Console;
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.api.ServiceWithParameters;
39    import jalview.ws.jws2.JabaParamStore;
40    import jalview.ws.jws2.Jws2Discoverer;
41    import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
42    import jalview.ws.jws2.SequenceAnnotationWSClient;
43    import jalview.ws.jws2.jabaws2.Jws2Instance;
44    import jalview.ws.params.AutoCalcSetting;
45   
46    import java.awt.Component;
47    import java.io.File;
48    import java.util.ArrayList;
49    import java.util.List;
50   
51    import javax.swing.JMenu;
52    import javax.swing.JMenuItem;
53   
54    import org.testng.Assert;
55    import org.testng.annotations.AfterClass;
56    import org.testng.annotations.BeforeClass;
57    import org.testng.annotations.Test;
58   
59    import compbio.metadata.Argument;
60    import compbio.metadata.WrongParameterException;
61   
62    /*
63    * All methods in this class are set to the Network group because setUpBeforeClass will fail
64    * if there is no network.
65    */
66    @Test(singleThreaded = true)
 
67    public class RNAStructExportImport
68    {
69   
 
70  0 toggle @BeforeClass(alwaysRun = true)
71    public void setUpJvOptionPane()
72    {
73  0 JvOptionPane.setInteractiveMode(false);
74  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
75    }
76   
77    private static final String JAR_FILE_NAME = "testRnalifold_param.jar";
78   
79    public static String testseqs = "examples/RF00031_folded.stk";
80   
81    public static Jws2Discoverer disc;
82   
83    public static Jws2Instance rnaalifoldws;
84   
85    SeqAnnotationServiceCalcWorker alifoldClient;
86   
87    public static jalview.gui.AlignFrame af = null;
88   
 
89  0 toggle @BeforeClass(alwaysRun = true)
90    public static void setUpBeforeClass() throws Exception
91    {
92  0 Cache.loadProperties("test/jalview/io/testProps.jvprops");
93  0 Console.initLogger();
94  0 disc = JalviewJabawsTestUtils.getJabawsDiscoverer(false);
95   
96  0 while (disc.isRunning())
97    {
98    // don't get services until discoverer has finished
99  0 Thread.sleep(100);
100    }
101   
102  0 for (ServiceWithParameters svc : disc.getServices())
103    {
104   
105  0 if (svc.getServiceType().toLowerCase(Locale.ROOT)
106    .contains("rnaalifoldws"))
107    {
108  0 rnaalifoldws = (Jws2Instance) svc;
109    }
110    }
111   
112  0 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
113   
114  0 if (rnaalifoldws == null)
115    {
116  0 Assert.fail("no web service");
117    }
118   
119  0 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
120   
121  0 af = fl.LoadFileWaitTillLoaded(testseqs,
122    jalview.io.DataSourceType.FILE);
123   
124  0 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
125   
126    // remove any existing annotation
127  0 List<AlignmentAnnotation> aal = new ArrayList<>();
128  0 for (AlignmentAnnotation rna : af.getViewport().getAlignment()
129    .getAlignmentAnnotation())
130    {
131  0 if (rna.isRNA())
132    {
133  0 aal.add(rna);
134    }
135    }
136  0 for (AlignmentAnnotation rna : aal)
137    {
138  0 af.getViewport().getAlignment().deleteAnnotation(rna);
139    }
140  0 af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
141    // public?
142    }
143   
 
144  0 toggle @AfterClass(alwaysRun = true)
145    public static void tearDownAfterClass() throws Exception
146    {
147  0 if (af != null)
148    {
149  0 af.setVisible(false);
150  0 af.dispose();
151  0 File f = new File(JAR_FILE_NAME);
152  0 if (f.exists())
153    {
154  0 f.delete();
155    }
156    }
157    }
158   
 
159  0 toggle @Test(groups = { "Network" })
160    public void testRNAAliFoldValidStructure()
161    {
162   
163  0 alifoldClient = new SeqAnnotationServiceCalcWorker(rnaalifoldws, af, null,
164    null);
165   
166  0 af.getViewport().getCalcManager().startWorker(alifoldClient);
167   
168  0 do
169    {
170  0 try
171    {
172  0 Thread.sleep(50);
173    } catch (InterruptedException x)
174    {
175    }
176  0 } while (af.getViewport().getCalcManager().isWorking());
177   
178  0 AlignmentI orig_alig = af.getViewport().getAlignment();
179  0 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
180    {
181  0 if (alifoldClient.involves(aa))
182    {
183  0 if (aa.isRNA())
184    {
185  0 assertTrue(
186    "Did not create valid structure from RNAALiFold prediction",
187    aa.isValidStruc());
188    }
189    }
190    }
191    }
192   
 
193  0 toggle @Test(groups = { "Network" })
194    public void testRNAStructExport()
195    {
196   
197  0 alifoldClient = new SeqAnnotationServiceCalcWorker(rnaalifoldws, af, null,
198    null);
199   
200  0 af.getViewport().getCalcManager().startWorker(alifoldClient);
201   
202  0 do
203    {
204  0 try
205    {
206  0 Thread.sleep(50);
207    } catch (InterruptedException x)
208    {
209    }
210  0 } while (af.getViewport().getCalcManager().isWorking());
211   
212  0 AlignmentI orig_alig = af.getViewport().getAlignment();
213    // JBPNote: this assert fails (2.10.2) because the 'Reference Positions'
214    // annotation is mistakenly recognised as an RNA annotation row when read in
215    // as an annotation file. bug is JAL-3122
216  0 verifyAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
217   
218    }
219   
 
220  0 toggle static void verifyAnnotationFileIO(String testname, AlignmentI al)
221    {
222  0 try
223    {
224    // what format would be appropriate for RNAalifold annotations?
225  0 String aligfileout = FileFormat.Pfam.getWriter(null)
226    .print(al.getSequencesArray(), true);
227   
228  0 String anfileout = new AnnotationFile()
229    .printAnnotationsForAlignment(al);
230  0 assertNotNull("Test " + testname
231    + "\nAlignment annotation file was not regenerated. Null string",
232    anfileout);
233  0 assertTrue("Test " + testname
234    + "\nAlignment annotation file was not regenerated. Empty string",
235    anfileout.length() > "JALVIEW_ANNOTATION".length());
236   
237  0 System.out.println(
238    "Output annotation file:\n" + anfileout + "\n<<EOF\n");
239   
240    // again what format would be appropriate?
241  0 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
242    DataSourceType.PASTE, FileFormat.Pfam);
243  0 assertTrue("Test " + testname
244    + "\nregenerated annotation file did not annotate alignment.",
245    new AnnotationFile().readAnnotationFile(al_new, anfileout,
246    DataSourceType.PASTE));
247   
248    // test for consistency in io
249  0 StockholmFileTest.testAlignmentEquivalence(al, al_new, false, false,
250    false);
251  0 return;
252    } catch (Exception e)
253    {
254  0 e.printStackTrace();
255    }
256  0 Assert.fail("Test " + testname
257    + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
258    }
259   
 
260  0 toggle @Test(groups = { "Network" })
261    public void testRnaalifoldSettingsRecovery()
262    {
263  0 List<Argument> opts = new ArrayList<>();
264  0 for (Argument rg : (List<Argument>) rnaalifoldws.getRunnerConfig()
265    .getArguments())
266    {
267  0 if (rg.getDescription().contains("emperature"))
268    {
269  0 try
270    {
271  0 rg.setValue("292");
272    } catch (WrongParameterException q)
273    {
274  0 Assert.fail("Couldn't set the temperature parameter "
275    + q.getStackTrace());
276    }
277  0 opts.add(rg);
278    }
279  0 if (rg.getDescription().contains("max"))
280    {
281  0 opts.add(rg);
282    }
283    }
284  0 alifoldClient = new SeqAnnotationServiceCalcWorker(rnaalifoldws, af, null,
285    JabaParamStore.getJwsArgsfromJaba(opts));
286   
287  0 af.getViewport().getCalcManager().startWorker(alifoldClient);
288   
289  0 do
290    {
291  0 try
292    {
293  0 Thread.sleep(50);
294    } catch (InterruptedException x)
295    {
296    }
297  0 ;
298  0 } while (af.getViewport().getCalcManager().isWorking());
299  0 AutoCalcSetting oldacs = af.getViewport()
300    .getCalcIdSettingsFor(alifoldClient.getCalcId());
301  0 String oldsettings = oldacs.getWsParamFile();
302    // write out parameters
303  0 jalview.gui.AlignFrame nalf = null;
304  0 assertTrue("Couldn't write out the Jar file", new Jalview2XML(false)
305    .saveAlignment(af, JAR_FILE_NAME, "trial parameter writeout"));
306  0 assertTrue("Couldn't read back the Jar file",
307    (nalf = new Jalview2XML(false)
308    .loadJalviewAlign(JAR_FILE_NAME)) != null);
309  0 if (nalf != null)
310    {
311  0 AutoCalcSetting acs = af.getViewport()
312    .getCalcIdSettingsFor(alifoldClient.getCalcId());
313  0 assertTrue("Calc ID settings not recovered from viewport stash",
314    acs.equals(oldacs));
315  0 assertTrue(
316    "Serialised Calc ID settings not identical to those recovered from viewport stash",
317    acs.getWsParamFile().equals(oldsettings));
318  0 JMenu nmenu = new JMenu();
319  0 new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu,
320    rnaalifoldws, af);
321  0 assertTrue("Couldn't get menu entry for service",
322    nmenu.getItemCount() > 0);
323  0 for (Component itm : nmenu.getMenuComponents())
324    {
325  0 if (itm instanceof JMenuItem)
326    {
327  0 JMenuItem i = (JMenuItem) itm;
328  0 if (i.getText().equals(
329    rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
330    {
331  0 i.doClick();
332  0 break;
333    }
334    }
335    }
336  0 while (af.getViewport().isCalcInProgress())
337    {
338  0 try
339    {
340  0 Thread.sleep(200);
341    } catch (Exception x)
342    {
343    }
344  0 ;
345    }
346  0 AutoCalcSetting acs2 = af.getViewport()
347    .getCalcIdSettingsFor(alifoldClient.getCalcId());
348  0 assertTrue(
349    "Calc ID settings after recalculation has not been recovered.",
350    acs2.getWsParamFile().equals(oldsettings));
351    }
352    }
353    }