JAL-192 fix bounds when no hidden regions, and when sequence contained in hidden...
authorJim Procter <jprocter@issues.jalview.org>
Fri, 29 Apr 2016 11:41:31 +0000 (12:41 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 29 Apr 2016 11:46:11 +0000 (12:46 +0100)
src/jalview/datamodel/ColumnSelection.java
src/jalview/gui/ScalePanel.java
test/jalview/datamodel/ColumnSelectionTest.java

index c232781..624e083 100644 (file)
@@ -1091,11 +1091,11 @@ public class ColumnSelection
   {
     int fpos=seq.getStart(),lpos= seq.getEnd();
     int start = 0;
-    int end = seq.getLength();
     
     if (hiddenColumns == null || hiddenColumns.size() == 0)
     {
-      return new int[] { seq.findIndex(fpos), seq.findIndex(lpos), fpos,
+      return new int[] { seq.findIndex(fpos) - 1, seq.findIndex(lpos) - 1,
+          fpos,
           lpos };
     }
 
@@ -1104,7 +1104,7 @@ public class ColumnSelection
     List<int[]> regions = getHiddenColumns();
     int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq
             .getLength(), hideEnd = -1;
-    int visPrev = 0, visNext = 0, base = 0;
+    int visPrev = 0, visNext = 0;
     boolean foundStart = false;
     for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
             && p < pLen; p++)
@@ -1115,8 +1115,8 @@ public class ColumnSelection
         while (hideEnd < p && rcount < regions.size())
         {
           int[] region = regions.get(rcount++);
-          visNext += region[1] + 1 - region[0];
-          visPrev = visNext-1;
+          visPrev = visNext;
+          visNext += region[0] - visPrev;
           hideStart = region[0];
           hideEnd = region[1];
         }
index e595e65..f266d36 100755 (executable)
@@ -502,8 +502,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       int[] refbounds = av.getColumnSelection()
               .locateVisibleBoundsOfSequence(refSeq);
 
-      refSp = refbounds[0] - 1;
-      refEp = refbounds[1] - 1;
+      refSp = refbounds[0];
+      refEp = refbounds[1];
       scalestartx = refSp + ((scalestartx - refSp) / 10) * 10;
     }
 
index 0e7678b..36932d1 100644 (file)
@@ -100,17 +100,50 @@ public class ColumnSelectionTest
   public void testLocateVisibleBoundsofSequence()
   {
     ColumnSelection cs = new ColumnSelection();
-    SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E");
+    SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
     assertEquals(2, seq.findIndex(seq.getStart()));
-    assertEquals(Arrays.toString(new int[] { seq.findIndex(seq.getStart()),
-        seq.findIndex(seq.getEnd()), seq.getStart(), seq.getEnd() }),
+
+    // no hidden columns
+    assertEquals(
+            Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1,
+                seq.findIndex(seq.getEnd()) - 1, seq.getStart(),
+                seq.getEnd() }),
+            Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
+
+    // hidden column on gap after end of sequence - should not affect bounds
+    cs.hideColumns(13);
+    assertEquals(
+            Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1,
+                seq.findIndex(seq.getEnd()) - 1, seq.getStart(),
+                seq.getEnd() }),
+            Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
+
+    cs.revealAllHiddenColumns();
+    // hidden column on gap before beginning of sequence - should vis bounds by
+    // one
+    cs.hideColumns(0);
+    assertEquals(
+            Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2,
+                seq.findIndex(seq.getEnd()) - 2, seq.getStart(),
+                seq.getEnd() }),
             Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
+
+    cs.revealAllHiddenColumns();
+    // hide columns around most of sequence - leave one residue remaining
     cs.hideColumns(1, 3);
     cs.hideColumns(6, 11);
     assertEquals("-D",
             cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]);
     assertEquals(Arrays.toString(new int[] { 1, 1, 3, 3 }),
             Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
+    cs.revealAllHiddenColumns();
+
+    // hide whole sequence - should just get location of hidden region
+    // containing sequence
+    cs.hideColumns(1, 11);
+    assertEquals(Arrays.toString(new int[] { 0, 1, 0, 0 }),
+            Arrays.toString(cs.locateVisibleBoundsOfSequence(seq)));
+
   }
 
   @Test(groups = { "Functional" })