JAL-2480 clarify that findOverlaps excludes spanning contact features
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 21 Jun 2017 10:59:28 +0000 (11:59 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 21 Jun 2017 10:59:28 +0000 (11:59 +0100)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/features/SequenceFeaturesI.java
test/jalview/datamodel/SequenceTest.java

index 5915d7e..cdfde5c 100755 (executable)
@@ -1826,7 +1826,7 @@ public class Sequence extends ASequence implements SequenceI
     /*
      * if the start or end column is gapped, startPos or endPos may be to the 
      * left or right, and we may have included adjacent or enclosing features;
-     * remove any that are not enclosing, non-contact features
+     * remove any that are not enclosing features
      */
     if (endPos > this.end || Comparison.isGap(sequence[fromColumn - 1])
             || Comparison.isGap(sequence[toColumn - 1]))
@@ -1837,18 +1837,8 @@ public class Sequence extends ASequence implements SequenceI
         SequenceFeature sf = it.next();
         int featureStartColumn = findIndex(sf.getBegin());
         int featureEndColumn = findIndex(sf.getEnd());
-        boolean noOverlap = featureStartColumn > toColumn
-                        || featureEndColumn < fromColumn;
-
-        /*
-         * reject an 'enclosing' feature if it is actually a contact feature
-         */
-        if (sf.isContactFeature() && featureStartColumn < fromColumn
-                && featureEndColumn > toColumn)
-        {
-          noOverlap = true;
-        }
-        if (noOverlap)
+        if (featureStartColumn > toColumn
+                        || featureEndColumn < fromColumn)
         {
           it.remove();
         }
index 40beae3..803ef0c 100644 (file)
@@ -22,7 +22,9 @@ public interface SequenceFeaturesI
   /**
    * Returns a (possibly empty) list of features, optionally restricted to
    * specified types, which overlap the given (inclusive) sequence position
-   * range
+   * range. Contact features are included if either start or end (or both) lie
+   * within the range. Non-contact features which span the range are also
+   * included.
    * 
    * @param from
    * @param to
index 71999e8..094bb24 100644 (file)
@@ -1458,6 +1458,16 @@ public class SequenceTest
     assertTrue(found.contains(sf1));
     assertTrue(found.contains(sf2));
     assertTrue(found.contains(sf4));
+
+    // columns 9-12 (F--G) includes F/G (once only) but not B/H feature
+    found = sq.findFeatures(9, 12);
+    assertEquals(1, found.size());
+    assertTrue(found.contains(sf4));
+
+    // column 4 (C) includes enclosing BCD but not B/H feature
+    found = sq.findFeatures(4, 4);
+    assertEquals(1, found.size());
+    assertTrue(found.contains(sf1));
   }
 
   @Test(groups = { "Functional" })