From: Jim Procter Date: Fri, 29 Apr 2016 13:52:59 +0000 (+0100) Subject: JAL-192 need visible and actual sequence limits for scale X-Git-Tag: Release_2_10_0~235^2~1^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cea44c7306e8f7b81a3338f28fb676cd6f0e8c64;p=jalview.git JAL-192 need visible and actual sequence limits for scale --- diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 624e083..e3a8472 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1082,10 +1082,12 @@ public class ColumnSelection /** * Locate the first and last position visible for this sequence. if seq isn't * visible then return the position of the left and right of the hidden - * boundary region + * boundary region, and the corresponding alignment column indices for the + * extent of the sequence * * @param seq - * @return int[] { visible start, visible end, first seqpos, last seqpos } + * @return int[] { visible start, visible end, first seqpos, last seqpos, + * alignment index for seq start, alignment index for seq end } */ public int[] locateVisibleBoundsOfSequence(SequenceI seq) { @@ -1094,9 +1096,8 @@ public class ColumnSelection if (hiddenColumns == null || hiddenColumns.size() == 0) { - return new int[] { seq.findIndex(fpos) - 1, seq.findIndex(lpos) - 1, - fpos, - lpos }; + int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1; + return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos }; } // Simply walk along the sequence whilst watching for hidden column @@ -1104,13 +1105,20 @@ public class ColumnSelection List regions = getHiddenColumns(); int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq .getLength(), hideEnd = -1; - int visPrev = 0, visNext = 0; + int visPrev = 0, visNext = 0, firstP = -1, lastP = -1; boolean foundStart = false; for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd() && p < pLen; p++) { if (!Comparison.isGap(seq.getCharAt(p))) { + // keep track of first/last column + // containing sequence data regardless of visibility + if (firstP == -1) + { + firstP = p; + } + lastP = p; // update hidden region start/end while (hideEnd < p && rcount < regions.size()) { @@ -1143,10 +1151,10 @@ public class ColumnSelection if (foundStart) { return new int[] { findColumnPosition(start), - findColumnPosition(lastvispos), fpos, lpos }; + findColumnPosition(lastvispos), fpos, lpos, firstP, lastP }; } // otherwise, sequence was completely hidden - return new int[] { visPrev, visNext, 0, 0 }; + return new int[] { visPrev, visNext, 0, 0, firstP, lastP }; } /** diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index f266d36..aedb157 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -494,7 +494,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int scalestartx = (startx / 10) * 10; SequenceI refSeq = av.getAlignment().getSeqrep(); - int refSp = 0, refEp = -1; + int refSp = 0, refEp = -1, refStart = 0, refEnd = -1, refStartI = 0, refEndI = -1; if (refSeq != null) { // find bounds and set origin appopriately @@ -504,6 +504,10 @@ public class ScalePanel extends JPanel implements MouseMotionListener, refSp = refbounds[0]; refEp = refbounds[1]; + refStart = refbounds[2]; + refEnd = refbounds[3]; + refStartI = refbounds[4]; + refEndI = refbounds[5]; scalestartx = refSp + ((scalestartx - refSp) / 10) * 10; } @@ -536,13 +540,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // TODO show bounds if position is a gap // - ie L--R -> "1L|2R" for // marker - if (iadj < refSp) + if (iadj < refStartI) { - string = String.valueOf(iadj - refSp); + string = String.valueOf(iadj - refStartI); } - else if (iadj > refEp) + else if (iadj > refEndI) { - string = "+" + String.valueOf(iadj - refEp); + string = "+" + String.valueOf(iadj - refEndI); } else { diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 36932d1..63f80b2 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -107,7 +107,8 @@ public class ColumnSelectionTest assertEquals( Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd() }), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); // hidden column on gap after end of sequence - should not affect bounds @@ -115,7 +116,8 @@ public class ColumnSelectionTest assertEquals( Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd() }), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(); @@ -125,7 +127,8 @@ public class ColumnSelectionTest assertEquals( Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getEnd()) - 2, seq.getStart(), - seq.getEnd() }), + seq.getEnd(), seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(); @@ -134,14 +137,20 @@ public class ColumnSelectionTest cs.hideColumns(6, 11); assertEquals("-D", cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]); - assertEquals(Arrays.toString(new int[] { 1, 1, 3, 3 }), + assertEquals( + Arrays.toString(new int[] { 1, 1, 3, 3, + seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(); // hide whole sequence - should just get location of hidden region // containing sequence cs.hideColumns(1, 11); - assertEquals(Arrays.toString(new int[] { 0, 1, 0, 0 }), + assertEquals( + Arrays.toString(new int[] { 0, 1, 0, 0, + seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); }