X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHiddenSequences.java;fp=src%2Fjalview%2Fdatamodel%2FHiddenSequences.java;h=9c02f29b06f8dcab31b592ca1e5548ea02a84909;hb=863529ed7d15dd5812cf280d82bfd53734b424a1;hp=aca0be67d36d87666dc7c352ad5ce2c74c84cc54;hpb=f3f90b8d541ef383d4f1d4cb3c1947200d6983ed;p=jalview.git diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index aca0be6..9c02f29 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -278,6 +278,41 @@ public class HiddenSequences } /** + * Find the visible row which is a given visible number of rows above another + * visible row. i.e. for a startRow x, the row which is distance 1 away will + * be row x-1. + * + * @param visibleDistance + * the number of visible rows to offset by + * @param startRow + * the row to start from + * @return the position of the row in the visible alignment + */ + public int findIndexNAboveRow(int visibleDistance, int startRow) + { + // walk upwards through the alignment + // count all the non-null sequences until we have visibleDistance counted + // then return the next visible sequence + if (hiddenSequences == null) + { + return startRow - visibleDistance; + } + + int index = startRow; + int count = 0; + while ((index > -1) && (count < visibleDistance)) + { + if (hiddenSequences[index] == null) + { + // count visible sequences + count++; + } + index--; + } + return index; + } + + /** * Convert alignment index from visible alignment to absolute alignment * * @param alignmentIndex