JAL-3010 expanded unit tests for hideFeatureColumns
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jun 2018 13:26:43 +0000 (14:26 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jun 2018 13:26:43 +0000 (14:26 +0100)
test/jalview/gui/AlignFrameTest.java

index 8fe2cbd..5018e4b 100644 (file)
@@ -70,15 +70,18 @@ public class AlignFrameTest
   @Test(groups = "Functional")
   public void testHideFeatureColumns()
   {
-    SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
-    SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
-    seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5, 0f, null));
-    seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10, 10f,
-            null));
-    seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4,
-            Float.NaN, null));
-    seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
-            Float.NaN, null));
+    SequenceI seq1 = new Sequence("Seq1/01-10", "A---BCDEFG-HIJ");
+    SequenceI seq2 = new Sequence("Seq2/11-20", "-AB-CDEF--GHIJ");
+    String METAL = "Metal";
+    String TURN = "Turn";
+    seq1.addSequenceFeature(
+            new SequenceFeature(METAL, "", 1, 5, 0f, null));
+    seq2.addSequenceFeature(
+            new SequenceFeature(METAL, "", 16, 20, 10f, null));
+    seq1.addSequenceFeature(
+            new SequenceFeature(TURN, "", 2, 4, Float.NaN, null));
+    seq2.addSequenceFeature(
+            new SequenceFeature(TURN, "", 17, 19, Float.NaN, null));
     AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
     AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
             al.getHeight());
@@ -93,60 +96,89 @@ public class AlignFrameTest
      */
     assertFalse(alignFrame.hideFeatureColumns(true, "exon"));
     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
-
     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
             .getNumberOfRegions(), 0);
 
     assertFalse(alignFrame.hideFeatureColumns(false, "exon"));
     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
-
     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
             .getNumberOfRegions(), 0);
 
     /*
      * hiding a feature in all columns does nothing
      */
-    assertFalse(alignFrame.hideFeatureColumns(true, "Metal"));
+    assertFalse(alignFrame.hideFeatureColumns(true, METAL));
     assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
-
     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
             .getNumberOfRegions(), 0);
 
 
     /*
      * threshold Metal to hide features where score < 5
-     * seq1 feature in columns 1-5 is hidden
-     * seq2 feature in columns 6-10 is shown
+     * seq1 feature in columns 1-8 is hidden
+     * seq2 feature in columns 8-14 is shown
+     * result: columns 8-14 are hidden
+     * note this includes gapped columns spanned by the feature
      */
     FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f);
     fc.setAboveThreshold(true);
     fc.setThreshold(5f);
-    alignFrame.getFeatureRenderer().setColour("Metal", fc);
-    assertTrue(alignFrame.hideFeatureColumns(true, "Metal"));
+    alignFrame.getFeatureRenderer().setColour(METAL, fc);
+    assertTrue(alignFrame.hideFeatureColumns(true, METAL));
     HiddenColumns hidden = alignFrame.getViewport().getAlignment().getHiddenColumns();
     assertEquals(hidden.getNumberOfRegions(), 1);
     Iterator<int[]> regions = hidden.iterator();
-    int[] next = regions.next();
-    assertEquals(next[0], 5);
-    assertEquals(next[1], 9);
+    assertEquals(regions.next(), new int[] { 7, 13 }); // base 0
+    assertFalse(regions.hasNext());
 
     /*
      * hide a feature present in some columns
-     * sequence positions [2-4], [7-9] are column positions
-     * [1-3], [6-8] base zero
+     * seq1 positions [2-4] are column positions [4-6] base zero
+     * seq2 positions [17-19] are column positions [10-12] base zero
      */
     alignFrame.getViewport().showAllHiddenColumns();
-    assertTrue(alignFrame.hideFeatureColumns(true, "Turn"));
+    assertTrue(alignFrame.hideFeatureColumns(true, TURN));
     regions = alignFrame.getViewport().getAlignment()
             .getHiddenColumns().iterator();
     assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
             .getNumberOfRegions(), 2);
-    next = regions.next();
-    assertEquals(next[0], 1);
-    assertEquals(next[1], 3);
-    next = regions.next();
-    assertEquals(next[0], 6);
-    assertEquals(next[1], 8);
+    assertEquals(regions.next(), new int[] { 4, 6 });
+    assertEquals(regions.next(), new int[] { 10, 12 });
+    assertFalse(regions.hasNext());
+    
+    /*
+     * hiding a contact feature should only hide start and end positions,
+     * not the intermediate columns
+     */
+    String DISULFIDE = "Disulfide Bond";
+    seq1.addSequenceFeature(
+            new SequenceFeature(DISULFIDE, "", 1, 5, 0f, null));
+    alignFrame.getViewport().showAllHiddenColumns();
+    assertTrue(alignFrame.hideFeatureColumns(true, DISULFIDE));
+    regions = alignFrame.getViewport().getAlignment().getHiddenColumns()
+            .iterator();
+    assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+            .getNumberOfRegions(), 2);
+    assertEquals(regions.next(), new int[] { 0, 0 });
+    assertEquals(regions.next(), new int[] { 7, 7 });
+    assertFalse(regions.hasNext());
+
+    /*
+     * hide multiple feature types:
+     * TURN columns hides 4-6, 10-12
+     * DISULFIDE columns hides 0, 7
+     * combined is { 0-0, 4-7, 10-12 }
+     */
+    alignFrame.getViewport().showAllHiddenColumns();
+    assertTrue(alignFrame.hideFeatureColumns(true, TURN, DISULFIDE));
+    regions = alignFrame.getViewport().getAlignment().getHiddenColumns()
+            .iterator();
+    assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+            .getNumberOfRegions(), 3);
+    assertEquals(regions.next(), new int[] { 0, 0 });
+    assertEquals(regions.next(), new int[] { 4, 7 });
+    assertEquals(regions.next(), new int[] { 10, 12 });
+    assertFalse(regions.hasNext());
   }
 
   @BeforeClass(alwaysRun = true)
@@ -155,8 +187,9 @@ public class AlignFrameTest
     /*
      * use read-only test properties file
      */
-    Cache.loadProperties("test/jalview/io/testProps.jvprops");
-    Jalview.main(new String[] { "-nonews" });
+    Jalview.main(
+            new String[]
+            { "-nonews", "-props", "test/jalview/io/testProps.jvprops" });
   }
 
   @AfterMethod(alwaysRun = true)