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 jalview.bin.Cache.initLogger();
44 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
46 for (Jws2Instance svc : disc.getServices())
49 System.out.println("Service type: " + svc.serviceType);
51 if (svc.getServiceTypeURI().toLowerCase().contains("rnaalifoldws"))
57 System.out.println("State of rnaalifoldws: " + rnaalifoldws);
59 if (rnaalifoldws == null) System.exit(0);
61 jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
63 // Following this method a long way we find some (probably important!)
64 // code that I have just commented out!
65 af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
67 assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
72 public static void tearDownAfterClass() throws Exception
82 * test for patches to JAL-1294
85 public void testRNAStructExport()
87 alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
90 System.out.println("START FOLDING");
91 af.getViewport().getCalcManager().startWorker(alifoldClient);
99 } catch (InterruptedException x)
103 } while (af.getViewport().getCalcManager().isWorking());
105 System.out.println("END FOLDING");
108 AlignCalcManagerI test = af.getViewport().getCalcManager();
109 RNAalifoldClient testWorker = ((RNAalifoldClient)test.getRegisteredWorkersOfClass(RNAalifoldClient.class).get(0));
110 testWorker.updateResultAnnotation(true);
111 System.out.println("Annotation from RNAalifoldclient");
112 for (Annotation ann : testWorker.ourAnnots.get(0).annotations) {
113 System.out.print(ann.toString()+"|");
115 System.out.println();
118 // Why are the AlignViewport.alignment and the RNAalifoldClient alignment
119 // Annotations different
120 AlignmentI orig_alig = af.getViewport().getAlignment();
122 System.out.println("orig_alig has class: " + orig_alig.getClass());
124 // some time before here but after the RNAalifoldClient Update method
125 // the alignment annotation is replaced....
127 System.out.println("orig_alig annotation:\n");
128 for (AlignmentAnnotation an : orig_alig.getAlignmentAnnotation()) {
129 for (Annotation ann : an.annotations) {
130 System.out.print(ann.toString()+"|");
132 System.out.println();
136 testAnnotationFileIO("Testing RNAalifold Annotation IO", orig_alig);
140 public static void testAnnotationFileIO(String testname, AlignmentI al)
144 String aligfileout = new FormatAdapter().formatSequences("CLUSTAL",
145 al.getSequencesArray());
148 // System.out.println("aligfileout:\n" + aligfileout);
150 String anfileout = new AnnotationFile().printAnnotations(
151 al.getAlignmentAnnotation(), al.getGroups(),
156 + "\nAlignment annotation file was not regenerated. Null string",
161 + "\nAlignment annotation file was not regenerated. Empty string",
162 anfileout.length() > "JALVIEW_ANNOTATION".length());
164 System.out.println("Output annotation file:\n" + anfileout
167 AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
168 FormatAdapter.PASTE, "CLUSTAL");
172 + "\nregenerated annotation file did not annotate alignment.",
173 new AnnotationFile().readAnnotationFile(al_new, anfileout,
174 FormatAdapter.PASTE));
176 // test for consistency in io
177 StockholmFileTest.testAlignmentEquivalence(al, al_new);
179 } catch (Exception e)
185 + "\nCouldn't complete Annotation file roundtrip input/output/input test.");