From: Jim Procter Date: Fri, 29 Apr 2016 11:41:31 +0000 (+0100) Subject: JAL-192 fix bounds when no hidden regions, and when sequence contained in hidden... X-Git-Tag: Release_2_10_0~235^2~1^2^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a97249105994383dca7ea64259b17ba8ddce31be;p=jalview.git JAL-192 fix bounds when no hidden regions, and when sequence contained in hidden region --- diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index c232781..624e083 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1091,11 +1091,11 @@ public class ColumnSelection { int fpos=seq.getStart(),lpos= seq.getEnd(); int start = 0; - int end = seq.getLength(); if (hiddenColumns == null || hiddenColumns.size() == 0) { - return new int[] { seq.findIndex(fpos), seq.findIndex(lpos), fpos, + return new int[] { seq.findIndex(fpos) - 1, seq.findIndex(lpos) - 1, + fpos, lpos }; } @@ -1104,7 +1104,7 @@ public class ColumnSelection List regions = getHiddenColumns(); int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq .getLength(), hideEnd = -1; - int visPrev = 0, visNext = 0, base = 0; + int visPrev = 0, visNext = 0; boolean foundStart = false; for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd() && p < pLen; p++) @@ -1115,8 +1115,8 @@ public class ColumnSelection while (hideEnd < p && rcount < regions.size()) { int[] region = regions.get(rcount++); - visNext += region[1] + 1 - region[0]; - visPrev = visNext-1; + visPrev = visNext; + visNext += region[0] - visPrev; hideStart = region[0]; hideEnd = region[1]; } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index e595e65..f266d36 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -502,8 +502,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int[] refbounds = av.getColumnSelection() .locateVisibleBoundsOfSequence(refSeq); - refSp = refbounds[0] - 1; - refEp = refbounds[1] - 1; + refSp = refbounds[0]; + refEp = refbounds[1]; scalestartx = refSp + ((scalestartx - refSp) / 10) * 10; } diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index 0e7678b..36932d1 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -100,17 +100,50 @@ public class ColumnSelectionTest public void testLocateVisibleBoundsofSequence() { ColumnSelection cs = new ColumnSelection(); - SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E"); + SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---"); assertEquals(2, seq.findIndex(seq.getStart())); - assertEquals(Arrays.toString(new int[] { seq.findIndex(seq.getStart()), - seq.findIndex(seq.getEnd()), seq.getStart(), seq.getEnd() }), + + // no hidden columns + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1, seq.getStart(), + seq.getEnd() }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + // hidden column on gap after end of sequence - should not affect bounds + cs.hideColumns(13); + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1, seq.getStart(), + seq.getEnd() }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + cs.revealAllHiddenColumns(); + // hidden column on gap before beginning of sequence - should vis bounds by + // one + cs.hideColumns(0); + assertEquals( + Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, + seq.findIndex(seq.getEnd()) - 2, seq.getStart(), + seq.getEnd() }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + cs.revealAllHiddenColumns(); + // hide columns around most of sequence - leave one residue remaining cs.hideColumns(1, 3); cs.hideColumns(6, 11); assertEquals("-D", cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]); assertEquals(Arrays.toString(new int[] { 1, 1, 3, 3 }), 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 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + } @Test(groups = { "Functional" })