JAL-2674 more adjustments to locateVisibleBoundsOfSequence
authorkiramt <k.mourao@dundee.ac.uk>
Wed, 4 Oct 2017 12:39:50 +0000 (13:39 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Wed, 4 Oct 2017 12:39:50 +0000 (13:39 +0100)
src/jalview/datamodel/HiddenColumns.java
src/jalview/renderer/ScaleRenderer.java
test/jalview/datamodel/HiddenColumnsTest.java

index 09f2ec5..b9e67ef 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.datamodel;
 
-import jalview.util.Comparison;
-
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Iterator;
@@ -687,15 +685,14 @@ public class HiddenColumns
   }
 
   /**
-   * Locate the first and last position visible for this sequence. if seq isn't
-   * visible then return the position of the left and right of the hidden
-   * boundary region, and the corresponding alignment column indices for the
-   * extent of the sequence
+   * Locate the first position visible for this sequence. If seq isn't visible
+   * then return the position of the left side of the hidden boundary region.
    * 
    * @param seq
-   * @return int[] { visible start, first seqpos, last seqpos }
+   *          sequence to find position for
+   * @return visible start position
    */
-  public int locateVisibleBoundsOfSequence(SequenceI seq)
+  public int locateVisibleStartOfSequence(SequenceI seq)
   {
     try
     {
@@ -710,40 +707,39 @@ public class HiddenColumns
       // Simply walk along the sequence whilst watching for hidden column
       // boundaries
       Iterator<int[]> regions = iterator();
-      int spos = seq.getStart();
       int hideStart = seq.getLength();
       int hideEnd = -1;
       int visPrev = 0;
       int visNext = 0;
-
       boolean foundStart = false;
-      for (int p = 0; spos <= seq.getEnd() && p < seq.getLength(); p++)
+
+      // step through the non-gapped positions of the sequence
+      for (int i = seq.getStart(); i <= seq.getEnd() && (!foundStart); i++)
       {
-        if (!Comparison.isGap(seq.getCharAt(p)))
+        // get alignment position of this residue in the sequence
+        int p = seq.findIndex(i) - 1;
+
+        // update hidden region start/end
+        while (hideEnd < p && regions.hasNext())
         {
-          // update hidden region start/end
-          while (hideEnd < p && regions.hasNext())
-          {
-            int[] region = regions.next();
-            visPrev = visNext;
-            visNext += region[0] - visPrev;
-            hideStart = region[0];
-            hideEnd = region[1];
-          }
-          if (hideEnd < p)
-          {
-            hideStart = seq.getLength();
-          }
-          // update visible boundary for sequence
-          if ((p < hideStart) && (!foundStart))
-          {
-              start = p;
-              foundStart = true;
-          }
-          // look for next sequence position
-          spos++;
+          int[] region = regions.next();
+          visPrev = visNext;
+          visNext += region[0] - visPrev;
+          hideStart = region[0];
+          hideEnd = region[1];
+        }
+        if (hideEnd < p)
+        {
+          hideStart = seq.getLength();
+        }
+        // update visible boundary for sequence
+        if (p < hideStart)
+        {
+          start = p;
+          foundStart = true;
         }
       }
+
       if (foundStart)
       {
         return findColumnPosition(start);
index 6d4edd9..63e5fa4 100644 (file)
@@ -76,7 +76,7 @@ public class ScaleRenderer
       // find bounds and set origin appropriately
       // locate first visible position for this sequence
       refSp = av.getAlignment().getHiddenColumns()
-              .locateVisibleBoundsOfSequence(refSeq);
+              .locateVisibleStartOfSequence(refSeq);
 
       refStartI = refSeq.findIndex(refSeq.getStart()) - 1;
 
index bc1e7b7..95c9fc6 100644 (file)
@@ -329,17 +329,17 @@ public class HiddenColumnsTest
     assertEquals(2, seq.findIndex(seq.getStart()));
 
     // no hidden columns
-    assertEquals(seq.findIndex(seq.getStart()) - 1, cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(seq.findIndex(seq.getStart()) - 1, cs.locateVisibleStartOfSequence(seq));
 
     // hidden column on gap after end of sequence - should not affect bounds
     colsel.hideSelectedColumns(13, al.getHiddenColumns());
-    assertEquals(seq.findIndex(seq.getStart()) - 1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(seq.findIndex(seq.getStart()) - 1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     // hidden column on gap before beginning of sequence - should vis bounds by
     // one
     colsel.hideSelectedColumns(0, al.getHiddenColumns());
-    assertEquals(seq.findIndex(seq.getStart()) - 2,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(seq.findIndex(seq.getStart()) - 2,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     // hide columns around most of sequence - leave one residue remaining
@@ -349,117 +349,117 @@ public class HiddenColumnsTest
             cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
     { seq })[0]);
 
-    assertEquals(1, cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1, cs.locateVisibleStartOfSequence(seq));
     cs.revealAllHiddenColumns(colsel);
 
     // hide whole sequence - should just get location of hidden region
     // containing sequence
     cs.hideColumns(1, 11);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 15);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---");
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(7, 17);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq2));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq2));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(3, 17);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq2));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq2));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(3, 19);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq2));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq2));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 0);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 1);
-    assertEquals(1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 2);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(1, 1);
-    assertEquals(2,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(2,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(1, 2);
-    assertEquals(1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(1, 3);
-    assertEquals(1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 2);
     cs.hideColumns(5, 6);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 2);
     cs.hideColumns(5, 6);
     cs.hideColumns(9, 10);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 2);
     cs.hideColumns(7, 11);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(2, 4);
     cs.hideColumns(7, 11);
-    assertEquals(1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(2, 4);
     cs.hideColumns(7, 12);
-    assertEquals(1,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(1,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(1, 11);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 12);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 4);
     cs.hideColumns(6, 12);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 1);
     cs.hideColumns(3, 12);
-    assertEquals(0,cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(0,cs.locateVisibleStartOfSequence(seq));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(3, 14);
     cs.hideColumns(17, 19);
-    assertEquals(3,cs.locateVisibleBoundsOfSequence(seq2));
+    assertEquals(3,cs.locateVisibleStartOfSequence(seq2));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(3, 7);
     cs.hideColumns(9, 14);
     cs.hideColumns(17, 19);
-    assertEquals(9,cs.locateVisibleBoundsOfSequence(seq2));
+    assertEquals(9,cs.locateVisibleStartOfSequence(seq2));
 
     cs.revealAllHiddenColumns(colsel);
     cs.hideColumns(0, 1);
     cs.hideColumns(3, 4);
     cs.hideColumns(6, 8);
     cs.hideColumns(10, 12);
-    assertEquals(6, cs.locateVisibleBoundsOfSequence(seq));
+    assertEquals(6, cs.locateVisibleStartOfSequence(seq));
 
   }