*/
package jalview.datamodel;
-import jalview.util.Comparison;
-
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Iterator;
}
/**
- * 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
{
// 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);