X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FFinder.java;h=ab718949b2362a625938d1f9690dc61b84aedb2d;hb=319d88f9dc025099158ac9193f5af7d827ea474b;hp=3cbef6d89175201f0f9029cf3dfca2260bf0295c;hpb=74f21ca6ca8fa17d53708e457d191e15904f8310;p=jalview.git diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index 3cbef6d..ab71894 100644 --- a/src/jalview/analysis/Finder.java +++ b/src/jalview/analysis/Finder.java @@ -162,35 +162,54 @@ public class Finder implements FinderI } /** - * Answers the start-end column range of the visible region of - * sequence starting at or after the given column. - * If there are no hidden columns, this just returns the remaining width of - * the sequence. The range is restricted to the current selection - * if there is one. Answers null if there are no visible columns at or after - * column. + * Answers the start-end column range of the contiguous visible regions of + * {@code sequence} starting at or after the given {@code column}. If there are + * no hidden columns, this just returns the remaining width of the sequence. + * Otherwise, visible columns are added as long as they are contiguous on the + * sequence (hidden regions only contain gaps). The range is restricted to the + * current {@code selection} if there is one. Answers null if there are no + * visible columns at or after {@code column}. + * + * @param sequence + * @param column + * @return */ protected Range getNextVisibleSequenceRegion(SequenceI sequence, - int column) + final int column) { - int seqColStart = column; - int seqColEnd = sequence.getLength() - 1; - - /* - * restrict search to (next) visible column region, - * in case there are hidden columns - */ AlignmentI alignment = viewport.getAlignment(); VisibleContigsIterator visibleRegions = alignment.getHiddenColumns() .getVisContigsIterator(column, alignment.getWidth(), false); - int[] visible = visibleRegions.hasNext() ? visibleRegions.next() : null; - if (visible == null) + if (!visibleRegions.hasNext()) { - columnIndex = seqColEnd + 1; + // off the end of the sequence - force search to next sequence + columnIndex = sequence.getLength(); return null; } - seqColStart = Math.max(seqColStart, visible[0]); - seqColEnd = Math.min(seqColEnd, visible[1]); + + int[] visible = visibleRegions.next(); + int seqColStart = Math.max(column, visible[0]); + int seqColEnd = visible[1]; + // end residue of region (next residue if end position is gapped) + int endSeqPos = sequence.findPosition(visible[1]); + if (Comparison.isGap(sequence.getCharAt(visible[1]))) + { + endSeqPos--; + } + while (visibleRegions.hasNext()) + { + visible = visibleRegions.next(); + int startSeqPos = sequence.findPosition(visible[0]); + if (startSeqPos - endSeqPos > 1) + { + // this visible region is not contiguous - ignore it + break; + } + endSeqPos = sequence.findPosition(visible[1]); + seqColEnd = visible[1]; + } + seqColEnd = Math.min(sequence.getLength() - 1, seqColEnd); /* * restrict search to selected region if there is one