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;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
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.ws.api.ServiceWithParameters;
38 import jalview.ws.jws2.Jws2Discoverer;
39 import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
40 import jalview.ws.slivkaws.SlivkaWSDiscoverer;
42 import java.util.ArrayList;
43 import java.util.List;
45 import org.testng.Assert;
46 import org.testng.annotations.AfterClass;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.DataProvider;
49 import org.testng.annotations.Test;
52 * All methods in this class are set to the Network group because setUpBeforeClass will fail
53 * if there is no network.
55 @Test(singleThreaded = true)
56 public class DisorderAnnotExportImport
59 @BeforeClass(alwaysRun = true)
60 public void setUpJvOptionPane()
62 JvOptionPane.setInteractiveMode(false);
63 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
66 public static String testseqs = "examples/uniref50.fa";
68 public static Jws2Discoverer disc;
70 public static List<ServiceWithParameters> iupreds;
72 jalview.ws.jws2.SeqAnnotationServiceCalcWorker disorderClient;
74 public static jalview.gui.AlignFrame af = null;
76 @BeforeClass(alwaysRun = true)
77 public static void setUpBeforeClass() throws Exception
79 Cache.loadProperties("test/jalview/io/testProps.jvprops");
81 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
83 while (disc.isRunning())
85 // don't get services until discoverer has finished
89 SlivkaWSDiscoverer disc2 = SlivkaWSDiscoverer.getInstance();
90 disc2.startDiscoverer();
91 while (disc2.isRunning())
93 if (svc.getServiceTypeURI().toLowerCase(Locale.ROOT)
94 .contains("iupredws"))
99 assertTrue("Couldn't discover any IUPred services to use to test.",
101 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
102 af = fl.LoadFileWaitTillLoaded(testseqs,
103 jalview.io.DataSourceType.FILE);
104 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
107 @AfterClass(alwaysRun = true)
108 public static void tearDownAfterClass() throws Exception
112 af.setVisible(false);
118 @DataProvider(name="getIuPreds",parallel = false)
119 public static ServiceWithParameters[][] getIuPreds()
121 ServiceWithParameters[][] services = new ServiceWithParameters[iupreds
125 for (ServiceWithParameters iupred : iupreds)
127 services[i++][0] = iupred;
133 * test for patches to JAL-1294
135 @Test(groups = { "External", "Network" },dataProvider = "getIuPreds")
136 public void testDisorderAnnotExport(ServiceWithParameters iuPred)
138 disorderClient = new SeqAnnotationServiceCalcWorker(iuPred, af, null,
140 af.getViewport().getCalcManager().startWorker(disorderClient);
146 } catch (InterruptedException x)
150 } while (af.getViewport().getCalcManager().isWorking());
151 AlignmentI orig_alig = af.getViewport().getAlignment();
152 // NOTE: Consensus annotation row cannot be exported and reimported
153 // faithfully - so we remove them
154 List<AlignmentAnnotation> toremove = new ArrayList<>();
155 for (AlignmentAnnotation aa : orig_alig.getAlignmentAnnotation())
157 if (aa.autoCalculated)
162 for (AlignmentAnnotation aa : toremove)
164 orig_alig.deleteAnnotation(aa);
166 checkAnnotationFileIO("Testing IUPred Annotation IO", orig_alig);
170 static void checkAnnotationFileIO(String testname, AlignmentI al)
174 String aligfileout = FileFormat.Pfam.getWriter(al)
175 .print(al.getSequencesArray(), true);
176 String anfileout = new AnnotationFile()
177 .printAnnotationsForAlignment(al);
178 assertTrue("Test " + testname
179 + "\nAlignment annotation file was not regenerated. Null string",
181 assertTrue("Test " + testname
182 + "\nAlignment annotation file was not regenerated. Empty string",
183 anfileout.length() > "JALVIEW_ANNOTATION".length());
186 "Output annotation file:\n" + anfileout + "\n<<EOF\n");
188 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
189 DataSourceType.PASTE, FileFormat.Pfam);
190 assertTrue("Test " + testname
191 + "\nregenerated annotation file did not annotate alignment.",
192 new AnnotationFile().readAnnotationFile(al_new, anfileout,
193 DataSourceType.PASTE));
195 // test for consistency in io
196 StockholmFileTest.testAlignmentEquivalence(al, al_new, true, false,
199 } catch (Exception e)
203 Assert.fail("Test " + testname
204 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");