X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FHiddenSequences.java;h=1daaf434156298986a8eb958213a47e72b7d8b34;hb=0e65ec37e2c956e0ad94feda6fd07b7c3a9003ee;hp=9e2cf72b416d1d5a69f3945305d55ce1b12ee7ae;hpb=37de9310bec3501cbc6381e0c3dcb282fcaad812;p=jalview.git diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index 9e2cf72..1daaf43 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -154,8 +154,8 @@ public class HiddenSequences hiddenSequences = new SequenceI[alignment.getHeight()]; } - int alignmentIndex = alignment.findIndex(sequence); - alignmentIndex = adjustForHiddenSeqs(alignmentIndex); + int absAlignmentIndex = alignment.findIndex(sequence); + int alignmentIndex = adjustForHiddenSeqs(absAlignmentIndex); if (hiddenSequences[alignmentIndex] != null) { @@ -164,7 +164,7 @@ public class HiddenSequences hiddenSequences[alignmentIndex] = sequence; - alignment.deleteSequence(sequence); + alignment.deleteHiddenSequence(absAlignmentIndex); } public List showAll( @@ -246,6 +246,12 @@ public class HiddenSequences return hiddenSequences == null ? null : hiddenSequences[alignmentIndex]; } + /** + * Convert absolute alignment index to visible alignment index + * + * @param alignmentIndex + * @return + */ public int findIndexWithoutHiddenSeqs(int alignmentIndex) { if (hiddenSequences == null) @@ -254,8 +260,14 @@ public class HiddenSequences } int index = 0; int hiddenSeqs = 0; + int diff = 0; if (hiddenSequences.length <= alignmentIndex) { + // if the alignmentIndex runs past the end of hidden sequences + // and therefore actually past the end of the alignment + // store the difference to add back on at the end, so that behaviour + // is consistent with hidden columns behaviour (used by overview panel) + diff = alignmentIndex - hiddenSequences.length + 1; alignmentIndex = hiddenSequences.length - 1; } @@ -268,9 +280,50 @@ public class HiddenSequences index++; } - return (alignmentIndex - hiddenSeqs); + return (alignmentIndex - hiddenSeqs + diff); + } + + /** + * 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 subtractVisibleRows(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 + * @return + */ public int adjustForHiddenSeqs(int alignmentIndex) { if (hiddenSequences == null) @@ -350,4 +403,20 @@ public class HiddenSequences return false; } + + /** + * Answers if a sequence is hidden + * + * @param seq + * (absolute) index to test + * @return true if sequence at index seq is hidden + */ + public boolean isHidden(int seq) + { + if (hiddenSequences != null) + { + return (hiddenSequences[seq] != null); + } + return false; + } }