JAL-192 need visible and actual sequence limits for scale
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index c062884..e3a8472 100644 (file)
@@ -1082,21 +1082,22 @@ public class ColumnSelection
   /**
    * 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
+   * boundary region, and the corresponding alignment column indices for the
+   * extent of the sequence
    * 
    * @param seq
-   * @return int[] { visible start, visible end, first seqpos, last seqpos }
+   * @return int[] { visible start, visible end, first seqpos, last seqpos,
+   *         alignment index for seq start, alignment index for seq end }
    */
   public int[] locateVisibleBoundsOfSequence(SequenceI seq)
   {
     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,
-          lpos };
+      int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1;
+      return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
     }
 
     // Simply walk along the sequence whilst watching for hidden column
@@ -1104,19 +1105,26 @@ 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, firstP = -1, lastP = -1;
     boolean foundStart = false;
     for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
             && p < pLen; p++)
     {
       if (!Comparison.isGap(seq.getCharAt(p)))
       {
+        // keep track of first/last column
+        // containing sequence data regardless of visibility
+        if (firstP == -1)
+        {
+          firstP = p;
+        }
+        lastP = p;
         // update hidden region start/end
         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];
         }
@@ -1143,10 +1151,10 @@ public class ColumnSelection
     if (foundStart)
     {
       return new int[] { findColumnPosition(start),
-          findColumnPosition(lastvispos), fpos, lpos };
+          findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
     }
     // otherwise, sequence was completely hidden
-    return new int[] { visPrev, visNext, 0, 0 };
+    return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
   }
 
   /**
@@ -1520,6 +1528,8 @@ public class ColumnSelection
   public boolean filterAnnotations(Annotation[] annotations,
           AnnotationFilterParameter filterParams)
   {
+    // JBPNote - this method needs to be refactored to become independent of
+    // viewmodel package
     this.revealAllHiddenColumns();
     this.clear();
     int count = 0;
@@ -1601,4 +1611,5 @@ public class ColumnSelection
     } while (count < annotations.length);
     return false;
   }
+
 }