JAL-1295 test to demonstrate JAL-1294 (caused by JAL-1297)
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Thu, 23 May 2013 11:04:24 +0000 (12:04 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Fri, 24 May 2013 14:10:55 +0000 (15:10 +0100)
test/jalview/ws/jabaws/DisorderAnnotExportImport.java [new file with mode: 0644]

diff --git a/test/jalview/ws/jabaws/DisorderAnnotExportImport.java b/test/jalview/ws/jabaws/DisorderAnnotExportImport.java
new file mode 100644 (file)
index 0000000..fa19d00
--- /dev/null
@@ -0,0 +1,144 @@
+package jalview.ws.jabaws;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.io.AnnotationFile;
+import jalview.io.FormatAdapter;
+import jalview.io.StockholmFileTest;
+import jalview.ws.jws2.AADisorderClient;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class DisorderAnnotExportImport
+{
+  public static String testseqs = "examples/uniref50.fa";
+
+  public static Jws2Discoverer disc;
+
+  public static List<Jws2Instance> iupreds;
+
+  jalview.ws.jws2.AADisorderClient disorderClient;
+
+  public static jalview.gui.AlignFrame af = null;
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception
+  {
+
+    jalview.bin.Cache.initLogger();
+    disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
+    iupreds = new ArrayList<Jws2Instance>();
+    for (Jws2Instance svc : disc.getServices())
+    {
+      if (svc.getServiceTypeURI().toLowerCase().contains("iupredws"))
+      {
+        iupreds.add(svc);
+      }
+    }
+    assertTrue("Couldn't discover any IUPred services to use to test.",
+            iupreds.size() > 0);
+    jalview.io.FileLoader fl = new jalview.io.FileLoader(false);
+    af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE);
+    assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception
+  {
+    if (af != null)
+    {
+      af.setVisible(false);
+      af.dispose();
+    }
+  }
+
+  /**
+   * test for patches to JAL-1294
+   */
+  @Test
+  public void testDisorderAnnotExport()
+  {
+    disorderClient = new AADisorderClient(iupreds.get(0), af, null, null);
+    af.getViewport().getCalcManager().startWorker(disorderClient);
+    do
+    {
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
+      {
+      }
+      ;
+    } while (af.getViewport().getCalcManager().isWorking());
+    AlignmentI orig_alig = af.getViewport().getAlignment();
+    // NOTE: Consensus annotation row cannot be exported and reimported faithfully - so we remove them
+    List<AlignmentAnnotation> toremove = new ArrayList<AlignmentAnnotation>();
+    for (AlignmentAnnotation aa:orig_alig.getAlignmentAnnotation())
+    {
+      if (aa.autoCalculated)
+      {
+        toremove.add(aa);
+      }
+    }
+    for (AlignmentAnnotation aa:toremove)
+    {
+      orig_alig.deleteAnnotation(aa);
+    }
+    testAnnotationFileIO("Testing IUPred Annotation IO", orig_alig);
+
+  }
+
+  public static void testAnnotationFileIO(String testname, AlignmentI al)
+  {
+    try
+    {
+      String aligfileout = new FormatAdapter().formatSequences("PFAM",
+              al.getSequencesArray());
+      String anfileout = new AnnotationFile().printAnnotations(
+              al.getAlignmentAnnotation(), al.getGroups(),
+              al.getProperties());
+      assertTrue(
+              "Test "
+                      + testname
+                      + "\nAlignment annotation file was not regenerated. Null string",
+              anfileout != null);
+      assertTrue(
+              "Test "
+                      + testname
+                      + "\nAlignment annotation file was not regenerated. Empty string",
+              anfileout.length() > "JALVIEW_ANNOTATION".length());
+
+      System.out.println("Output annotation file:\n" + anfileout
+              + "\n<<EOF\n");
+
+      AlignmentI al_new = new FormatAdapter().readFile(aligfileout,
+              FormatAdapter.PASTE, "PFAM");
+      assertTrue(
+              "Test "
+                      + testname
+                      + "\nregenerated annotation file did not annotate alignment.",
+              new AnnotationFile().readAnnotationFile(al_new, anfileout,
+                      FormatAdapter.PASTE));
+
+      // test for consistency in io
+      StockholmFileTest.testAlignmentEquivalence(al, al_new);
+      return;
+    } catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+    fail("Test "
+            + testname
+            + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
+  }
+
+}