JAL-3706 handle virtual feature extending to unmapped stop codon
[jalview.git] / src / jalview / datamodel / MappedFeatures.java
index d652a97..1f672be 100644 (file)
@@ -276,7 +276,8 @@ public class MappedFeatures
 
   /**
    * Answers the mapped ranges (as one or more [start, end] positions) which
-   * correspond to the given [begin, end] range of the linked sequence.
+   * correspond to the given [begin, end] range of (some feature on) the linked
+   * sequence.
    * 
    * <pre>
    * Example: MappedFeatures with CDS features mapped to peptide 
@@ -293,9 +294,27 @@ public class MappedFeatures
    */
   public int[] getMappedPositions(int begin, int end)
   {
+    int[] result = null;
     MapList map = mapping.getMap();
-    return mapping.to == featureSequence ? map.locateInFrom(begin, end)
-            : map.locateInTo(begin, end);
+    if (mapping.to == featureSequence)
+    {
+      result = map.locateInFrom(begin, end);
+      if (result == null)
+      {
+        // fudge for feature (e.g. CDS) extending to a mapped stop codon
+        result = map.locateInFrom(begin, end-3);
+      }
+    }
+    else
+    {
+      result = map.locateInTo(begin, end);
+      if (result == null)
+      {
+        // fudge for feature (e.g. CDS) extending to a mapped stop codon
+        result = map.locateInTo(begin, end-3);
+      }
+    }
+    return result;
   }
 
   /**