1 package jalview.ws.jabaws;
3 import static org.junit.Assert.*;
5 import java.util.ArrayList;
6 import java.util.Arrays;
8 import java.util.Vector;
10 import jalview.api.AlignCalcManagerI;
11 import jalview.datamodel.AlignmentAnnotation;
12 import jalview.datamodel.AlignmentI;
13 import jalview.datamodel.Annotation;
14 import jalview.io.AnnotationFile;
15 import jalview.io.FormatAdapter;
16 import jalview.io.StockholmFileTest;
17 import jalview.ws.jws2.AADisorderClient;
18 import jalview.ws.jws2.Jws2Discoverer;
19 import jalview.ws.jws2.RNAalifoldClient;
20 import jalview.ws.jws2.jabaws2.Jws2Instance;
22 import org.junit.AfterClass;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
26 public class RNAStructExportImport
28 public static String testseqs = "examples/unfolded_RF00031.aln";
30 public static Jws2Discoverer disc;
32 public static Jws2Instance rnaalifoldws;
34 jalview.ws.jws2.RNAalifoldClient alifoldClient;
36 public static jalview.gui.AlignFrame af = null;
39 public static void setUpBeforeClass() throws Exception
43 System.out.println("test1");
45 jalview.bin.Cache.initLogger();
46 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
48 System.out.println("test2");
50 for (Jws2Instance svc : disc.getServices())
53 System.out.println("Service type: " + svc.serviceType);
55 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
61 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
63 if (rnaalifoldws == null) System.exit(0);
65 System.out.println("test3");
67 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
69 // Following this method a long way we find some (probably important!)
70 // code that I have just commented out!
71 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
73 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
75 System.out.println("test5");
80 public static void tearDownAfterClass() throws Exception
90 * test for patches to JAL-1294
93 public void testRNAStructExport()
95 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
97 System.out.println("Service action text:\n" + alifoldClient.getServiceActionText());
100 System.out.println("START FOLDING");
101 af.getViewport().getCalcManager().startWorker(alifoldClient);
109 } catch (InterruptedException x)
113 } while (af.getViewport().getCalcManager().isWorking());
115 System.out.println("END FOLDING");
118 AlignCalcManagerI test = af.getViewport().getCalcManager();
119 RNAalifoldClient testWorker = ((RNAalifoldClient)test.getRegisteredWorkersOfClass(RNAalifoldClient.class).get(0));
120 testWorker.updateResultAnnotation(true);
121 System.out.println("Annotation from RNAalifoldclient");
122 for (Annotation ann : testWorker.ourAnnots.get(0).annotations) {
123 System.out.print(ann.toString()+"|");
125 System.out.println();
128 // Why are the AlignViewport.alignment and the RNAalifoldClient alignment
129 // Annotations different
130 AlignmentI orig_alig = af.getViewport().getAlignment();
132 System.out.println("orig_alig has class: " + orig_alig.getClass());
134 // some time before here but after the RNAalifoldClient Update method
135 // the alignment annotation is replaced....
137 System.out.println("orig_alig annotation:\n");
138 for (AlignmentAnnotation an : orig_alig.getAlignmentAnnotation()) {
139 for (Annotation ann : an.annotations) {
140 System.out.print(ann.toString()+"|");
142 System.out.println();
146 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
150 public static void testAnnotationFileIO(String testname, AlignmentI al)
154 String aligfileout = new FormatAdapter().formatSequences("CLUSTAL",
155 al.getSequencesArray());
158 // System.out.println("aligfileout:\n" + aligfileout);
160 String anfileout = new AnnotationFile().printAnnotations(
161 al.getAlignmentAnnotation(), al.getGroups(),
166 + "\nAlignment annotation file was not regenerated. Null string",
171 + "\nAlignment annotation file was not regenerated. Empty string",
172 anfileout.length() > "JALVIEW_ANNOTATION".length());
174 System.out.println("Output annotation file:\n" + anfileout
177 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
178 FormatAdapter.PASTE, "CLUSTAL");
182 + "\nregenerated annotation file did not annotate alignment.",
183 new AnnotationFile().readAnnotationFile(al_new, anfileout,
184 FormatAdapter.PASTE));
186 // test for consistency in io
187 StockholmFileTest.testAlignmentEquivalence(al, al_new);
189 } catch (Exception e)
195 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");