JAL-2154 check that CDS panel is only nucleotide, and protein panel is only Protein...
authorJim Procter <jprocter@issues.jalview.org>
Fri, 26 Aug 2016 09:50:35 +0000 (10:50 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 26 Aug 2016 09:50:42 +0000 (10:50 +0100)
test/jalview/io/CrossRef2xmlTests.java

index 20a95d0..24074d0 100644 (file)
@@ -158,6 +158,12 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
               Assert.assertTrue(cra.getXrefViews().size() > 0,
                       "No crossrefs retrieved for " + db);
               cra_views = cra.getXrefViews();
+              assertNucleotide(cra_views.get(0),
+                      "Nucleotide panel included proteins for " + first
+                              + " -> " + db);
+              assertProtein(cra_views.get(1),
+                      "Protein panel included nucleotides for " + first
+                              + " -> " + db);
             }
             else
             {
@@ -245,6 +251,15 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
                                     + "' to " + xrefdb + " via '"
                                     + nextaf.getTitle() + "'");
                     cra_views2 = cra.getXrefViews();
+                    assertNucleotide(cra_views2.get(0),
+                            "Nucleotide panel included proteins for '"
+                                    + nextxref + "' to " + xrefdb
+                                    + " via '" + nextaf.getTitle() + "'");
+                    assertProtein(cra_views2.get(1),
+                            "Protein panel included nucleotides for '"
+                                    + nextxref + "' to " + xrefdb
+                                    + " via '" + nextaf.getTitle() + "'");
+
                   }
                   else
                   {
@@ -336,6 +351,40 @@ public class CrossRef2xmlTests extends Jalview2xmlBase
     }
   }
 
+  private void assertProtein(AlignmentViewPanel alignmentViewPanel,
+          String message)
+  {
+    assertType(true, alignmentViewPanel, message);
+  }
+
+  private void assertNucleotide(AlignmentViewPanel alignmentViewPanel,
+          String message)
+  {
+    assertType(false, alignmentViewPanel, message);
+  }
+
+  private void assertType(boolean expectProtein,
+          AlignmentViewPanel alignmentViewPanel, String message)
+  {
+    List<SequenceI> nonType = new ArrayList<SequenceI>();
+    for (SequenceI sq : alignmentViewPanel.getAlignViewport()
+            .getAlignment()
+            .getSequences())
+    {
+      if (sq.isProtein() != expectProtein)
+      {
+        nonType.add(sq);
+      }
+    }
+    if (nonType.size() > 0)
+    {
+      Assert.fail(message + " [ "
+              + (expectProtein ? "nucleotides were " : "proteins were ")
+              + nonType.toString()
+              + " ]");
+    }
+  }
+
   /**
    * first time called, record strings derived from alignment and
    * alignedcodonframes, and save view to a project file. Second time called,