From 121c82f4beaff8cee80159d93ac794c5bfd7506d Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 26 Sep 2019 16:23:15 +0100 Subject: [PATCH] JAL-3070 allow SequenceI.findPositions(0,column+1) to return range between 1 and column+1 --- src/jalview/datamodel/Sequence.java | 3 ++- src/jalview/datamodel/SequenceI.java | 4 ++-- test/jalview/datamodel/SequenceTest.java | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 9ba768d..5008a3e 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1052,7 +1052,8 @@ public class Sequence extends ASequence implements SequenceI @Override public ContiguousI findPositions(int fromColumn, int toColumn) { - if (toColumn < fromColumn || fromColumn < 1) + fromColumn = Math.max(fromColumn, 1); + if (toColumn < fromColumn) { return null; } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index d06adcb..5cddade 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -217,10 +217,10 @@ public interface SequenceI extends ASequenceI * from 1), or null if no residues are included in the range * * @param fromColum - * - first column base 1 + * - first column base 1. (0 and negative positions are rounded up) * @param toColumn * - last column, base 1 - * @return + * @return null if fromColum>toColumn */ public ContiguousI findPositions(int fromColum, int toColumn); diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index c344645..b607321 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -298,8 +298,6 @@ public class SequenceTest * invalid inputs */ assertNull(sq.findPositions(6, 5)); - assertNull(sq.findPositions(0, 5)); - assertNull(sq.findPositions(-1, 5)); /* * all gapped ranges @@ -342,6 +340,16 @@ public class SequenceTest assertEquals(new Range(11, 12), sq.findPositions(5, 10)); // DE assertEquals(new Range(8, 13), sq.findPositions(1, 13)); // the lot assertEquals(new Range(8, 13), sq.findPositions(1, 99)); + + /** + * now try on a sequence with no gaps + */ + sq.createDatasetSequence(); + assertEquals(new Range(8, 13), + sq.getDatasetSequence().findPositions(1, 99)); + assertEquals(new Range(8, 13), + sq.getDatasetSequence().findPositions(0, 99)); + } /** -- 1.7.10.2