JAL-3070 allow SequenceI.findPositions(0,column+1) to return range between 1 and...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 26 Sep 2019 15:23:15 +0000 (16:23 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 26 Sep 2019 15:23:15 +0000 (16:23 +0100)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceI.java
test/jalview/datamodel/SequenceTest.java

index 9ba768d..5008a3e 100755 (executable)
@@ -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;
     }
index d06adcb..5cddade 100755 (executable)
@@ -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);
 
index c344645..b607321 100644 (file)
@@ -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));
+
   }
 
   /**