X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHiddenSequences.java;h=32443d820f3aaccd57b076f5d5d78043b5a1d6f7;hb=21fb81914f40016a2860c71948a4a2759c9e153c;hp=aca0be67d36d87666dc7c352ad5ce2c74c84cc54;hpb=f3f90b8d541ef383d4f1d4cb3c1947200d6983ed;p=jalview.git diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index aca0be6..32443d8 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -157,9 +157,10 @@ public class HiddenSequences int absAlignmentIndex = alignment.findIndex(sequence); int alignmentIndex = adjustForHiddenSeqs(absAlignmentIndex); - if (hiddenSequences[alignmentIndex] != null) + if (alignmentIndex < 0 || hiddenSequences[alignmentIndex] != null) { System.out.println("ERROR!!!!!!!!!!!"); + return; } hiddenSequences[alignmentIndex] = sequence; @@ -170,7 +171,13 @@ public class HiddenSequences public List showAll( Map hiddenRepSequences) { - List revealedSeqs = new ArrayList(); + List revealedSeqs = new ArrayList<>(); + + if (hiddenSequences == null) + { + return revealedSeqs; + } + for (int i = 0; i < hiddenSequences.length; i++) { if (hiddenSequences[i] != null) @@ -199,7 +206,7 @@ public class HiddenSequences public List showSequence(int alignmentIndex, Map hiddenRepSequences) { - List revealedSeqs = new ArrayList(); + List revealedSeqs = new ArrayList<>(); SequenceI repSequence = alignment.getSequenceAt(alignmentIndex); if (repSequence != null && hiddenRepSequences != null && hiddenRepSequences.containsKey(repSequence)) @@ -247,7 +254,8 @@ public class HiddenSequences } /** - * Convert absolute alignment index to visible alignment index + * Convert absolute alignment index to visible alignment index (or -1 if + * before the first visible sequence) * * @param alignmentIndex * @return @@ -260,8 +268,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; } @@ -274,7 +288,42 @@ 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 = Math.min(startRow, hiddenSequences.length - 1); + int count = 0; + while ((index > -1) && (count < visibleDistance)) + { + if (hiddenSequences[index] == null) + { + // count visible sequences + count++; + } + index--; + } + return index; } /** @@ -362,4 +411,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; + } }