package jalview.analysis;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Range;
import jalview.datamodel.SearchResultMatchI;
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
}
/**
- * Answers the start-end column range of the visible region starting at or
- * after the given column. if there are no hidden columns, this just returns
- * the remaining width of the alignment. Answers null if there are no visible
- * columns at or after <code>column</code>.
+ * Answers the start-end column range of the visible region of
+ * <code>sequence</code> starting at or after the given <code>column</code>.
+ * If there are no hidden columns, this just returns the remaining width of
+ * the sequence. The range is restricted to the current <code>selection</code>
+ * if there is one. Answers null if there are no visible columns at or after
+ * <code>column</code>.
*/
- protected int[] getNextVisibleRegion(int column)
+ protected Range getNextVisibleSequenceRegion(SequenceI sequence,
+ int column)
{
+ int seqColStart = column;
+ int seqColEnd = sequence.getLength() - 1;
+
+ /*
+ * restrict search to (next) visible column region,
+ * in case there are hidden columns
+ */
VisibleContigsIterator visibleRegions = alignment.getHiddenColumns()
.getVisContigsIterator(column, alignment.getWidth(),
false);
- return visibleRegions.hasNext() ? visibleRegions.next() : null;
+ int[] visible = visibleRegions.hasNext() ? visibleRegions.next() : null;
+ if (visible == null)
+ {
+ columnIndex = seqColEnd + 1;
+ return null;
+ }
+ seqColStart = Math.max(seqColStart, visible[0]);
+ seqColEnd = Math.min(seqColEnd, visible[1]);
+
+ /*
+ * restrict search to selected region if there is one
+ */
+ if (selection != null)
+ {
+ int selectionStart = selection.getStartRes();
+ int selectionEnd = selection.getEndRes();
+ if (selectionStart > seqColEnd || selectionEnd < seqColStart)
+ {
+ /*
+ * sequence region doesn't overlap selection region
+ */
+ columnIndex = seqColEnd + 1;
+ return null;
+ }
+ seqColStart = Math.max(seqColStart, selectionStart);
+ seqColEnd = Math.min(seqColEnd, selectionEnd);
+ }
+
+ return new Range(seqColStart, seqColEnd);
}
/**
*/
protected boolean searchNextVisibleRegion(SequenceI seq, Regex searchPattern)
{
- /*
- * sequence columns to search (working in absolute column
- * positions, base 0, including any hidden columns)
- */
- int seqColStart = columnIndex;
- int seqColEnd = seq.getLength() - 1;
-
- /*
- * restrict search to (next) visible column region,
- * in case there are hidden columns
- */
- int[] visible = getNextVisibleRegion(columnIndex);
- if (visible != null)
- {
- seqColStart = Math.max(seqColStart, visible[0]);
- seqColEnd = Math.min(seqColEnd, visible[1]);
- }
- else
+ Range visible = getNextVisibleSequenceRegion(seq, columnIndex);
+ if (visible == null)
{
- columnIndex = seqColEnd + 1;
return false;
}
-
- /*
- * restrict search to selected region if there is one
- */
- if (selection != null)
- {
- int selectionStart = selection.getStartRes();
- int selectionEnd = selection.getEndRes();
- if (selectionStart > seqColEnd || selectionEnd < seqColStart)
- {
- /*
- * sequence region doesn't overlap selection region -
- * no match, advance to next visible region
- */
- columnIndex = seqColEnd + 1;
- return false;
- }
- seqColStart = Math.max(seqColStart, selectionStart);
- seqColEnd = Math.min(seqColEnd, selectionEnd);
- }
-
- String seqString = seq.getSequenceAsString(seqColStart, seqColEnd + 1);
+ String seqString = seq.getSequenceAsString(visible.start, visible.end + 1);
String noGaps = AlignSeq.extractGaps(Comparison.GapChars, seqString);
if (searchPattern.search(noGaps))
{
- int sequenceStartPosition = seq.findPosition(seqColStart);
+ int sequenceStartPosition = seq.findPosition(visible.start);
recordMatch(seq, searchPattern, sequenceStartPosition);
return true;
}
* no match - advance columnIndex past this visible region
* so the next visible region (if any) is searched next
*/
- columnIndex = seqColEnd + 1;
+ columnIndex = visible.end + 1;
}
return false;