Clover icon

Coverage Report

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

File AAConAnnotAndSettingsIO.java

 

Code metrics

12
51
6
1
200
140
13
0.25
8.5
6
2.17

Classes

Class Line # Actions
AAConAnnotAndSettingsIO 49 51 13
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 static org.testng.AssertJUnit.assertNotNull;
24    import static org.testng.AssertJUnit.assertTrue;
25   
26    import jalview.bin.Cache;
27    import jalview.datamodel.AlignmentAnnotation;
28    import jalview.datamodel.AlignmentI;
29    import jalview.gui.AlignFrame;
30    import jalview.gui.JvOptionPane;
31    import jalview.ws.api.ServiceWithParameters;
32    import jalview.ws.jws2.Jws2Discoverer;
33    import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
34    import jalview.ws.slivkaws.SlivkaWSDiscoverer;
35   
36    import java.util.ArrayList;
37    import java.util.List;
38   
39    import org.testng.annotations.AfterClass;
40    import org.testng.annotations.BeforeClass;
41    import org.testng.annotations.DataProvider;
42    import org.testng.annotations.Test;
43   
44    /*
45    * All methods in this class are set to the Network group because setUpBeforeClass will fail
46    * if there is no network.
47    */
48    @Test(singleThreaded = true)
 
49    public class AAConAnnotAndSettingsIO
50    {
51   
 
52  0 toggle @BeforeClass(alwaysRun = true)
53    public void setUpJvOptionPane()
54    {
55  0 JvOptionPane.setInteractiveMode(false);
56  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57    }
58   
59    public static String testseqs = "examples/uniref50.fa";
60   
61    public static Jws2Discoverer disc;
62   
63    public static List<ServiceWithParameters[]> aacon;
64   
65    jalview.ws.jws2.SeqAnnotationServiceCalcWorker aaconClient;
66   
67    public static jalview.gui.AlignFrame af = null;
68   
 
69  0 toggle @BeforeClass(alwaysRun = true)
70    public static void setUpBeforeClass() throws Exception
71    {
72  0 Cache.loadProperties("test/jalview/io/testProps.jvprops");
73  0 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
74   
75  0 while (disc.isRunning())
76    {
77    // don't get services until discoverer has finished
78  0 Thread.sleep(100);
79    }
80   
81   
82  0 aacon = new ArrayList<>();
83  0 for (ServiceWithParameters svc : disc.getServices())
84    {
85  0 if (svc.getNameURI().toLowerCase().contains("aacon"))
86    {
87  0 aacon.add(new ServiceWithParameters[] { svc });
88    }
89    }
90   
91  0 for (ServiceWithParameters svc : SlivkaWSDiscoverer.getInstance()
92    .getServices())
93    {
94  0 if (svc.getNameURI().toLowerCase().contains("aacon"))
95    {
96  0 aacon.add(new ServiceWithParameters[] { svc });
97    }
98    }
99  0 assertTrue("Couldn't discover any AACon services to use to test.",
100    aacon.size() > 0);
101    }
102   
 
103  0 toggle @AfterClass(alwaysRun = true)
104    public static void tearDownAfterClass() throws Exception
105    {
106  0 if (af != null)
107    {
108  0 af.setVisible(false);
109  0 af.dispose();
110  0 af = null;
111    }
112    }
113   
 
114  0 toggle @DataProvider(name = "aacons")
115    public Object[][] getAaconArray()
116    {
117   
118  0 Object[][] rtn = new Object[aacon.size()][1];
119  0 int i = 0;
120  0 for (ServiceWithParameters[] aa : aacon)
121    {
122  0 rtn[i++] = aa;
123    }
124  0 return rtn;
125    }
126    /**
127    * Run AACon on an alignment with defaults and verify Just Shenkin annotation
128    * appears
129    */
 
130  0 toggle @Test(groups = { "External", "Network" }, dataProvider = "aacons")
131    public void testAAConAnnotAndRecovery(ServiceWithParameters service)
132    {
133  0 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
134  0 AlignFrame _af = fl.LoadFileWaitTillLoaded(testseqs,
135    jalview.io.DataSourceType.FILE);
136  0 assertNotNull("Couldn't load test data ('" + testseqs + "')", _af);
137  0 af = _af;
138  0 try
139    {
140  0 testAAConClient(_af, service);
141    } finally
142    {
143  0 af = null;
144  0 _af.setVisible(false);
145  0 _af.dispose();
146  0 _af = null;
147   
148    }
149    }
150   
151    /**
152    * triggers the given aacon worker on the alignment, waits for 5s and gives up
153    * or verifies SHENKIN annotation is produced.
154    *
155    * @param af
156    * - test data in an alignment frame
157    * @param aacon
158    * - the service to test
159    */
 
160  0 toggle static void testAAConClient(AlignFrame af, ServiceWithParameters aacon)
161    {
162  0 SeqAnnotationServiceCalcWorker aaconClient = new SeqAnnotationServiceCalcWorker(
163    aacon, af, null,
164    null);
165  0 long current = System.currentTimeMillis(), limit = 15;
166  0 af.getViewport().getCalcManager().startWorker(aaconClient);
167  0 do
168    {
169  0 try
170    {
171  0 Thread.sleep(50);
172    } catch (InterruptedException x)
173    {
174    }
175  0 ;
176  0 assertTrue(
177    "Waited " + limit + "s for " + aacon.getHostURL()
178    + " - giving up.",
179    (System.currentTimeMillis() - current) < limit * 1000);
180  0 } while (af.getViewport().getCalcManager().isWorking());
181  0 AlignmentI orig_alig = af.getViewport().getAlignment();
182  0 boolean foundShenkin = false;
183  0 Iterable<AlignmentAnnotation> _aa=orig_alig
184    .findAnnotation(aacon.getAlignAnalysisUI().getCalcId());
185  0 assertTrue("No annotation from service",
186    _aa != null && _aa.iterator().hasNext());
187   
188  0 for (AlignmentAnnotation aa : _aa)
189    {
190  0 assertTrue("AACon annotation not marked as autocalculated!",
191    aa.autoCalculated);
192  0 if ("shenkin".equals(aa.label.toLowerCase()))
193    {
194  0 foundShenkin = true;
195  0 break;
196    }
197    }
198  0 assertTrue("Failed to locate 'SHENKIN' annotation row.", foundShenkin);
199    }
200    }