JAL-3706 handle virtual feature extending to unmapped stop codon
[jalview.git] / test / jalview / datamodel / MappedFeaturesTest.java
index de4ce6c..5d00089 100644 (file)
@@ -2,8 +2,6 @@ package jalview.datamodel;
 
 import static org.testng.Assert.assertEquals;
 
-import jalview.util.MapList;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -11,6 +9,8 @@ import java.util.Map;
 
 import org.testng.annotations.Test;
 
+import jalview.util.MapList;
+
 public class MappedFeaturesTest
 {
   @Test(groups = "Functional")
@@ -21,7 +21,7 @@ public class MappedFeaturesTest
      * dna/10-20 aCGTaGctGAa (codons CGT=R, GGA = G)
      * mapping: 3:1 from [11-13,15,18-19] to peptide/1-2 RG 
      */
-    SequenceI from = new Sequence("dna/10-20", "acgTAGCTGAA");
+    SequenceI from = new Sequence("dna/10-20", "aCGTaGctGAa");
     SequenceI to = new Sequence("peptide", "RG");
     MapList map = new MapList(new int[] { 11, 13, 15, 15, 18, 19 },
             new int[]
@@ -117,4 +117,45 @@ public class MappedFeaturesTest
     variant = mf.findProteinVariants(sf9);
     assertEquals(variant, "");
   }
+
+  @Test(groups = "Functional")
+  public void testGetMappedPositions()
+  {
+    // CDS including stop codon taa
+    SequenceI cds = new Sequence("cds/10-21", "ATGcgtGGAtaa");
+    SequenceI peptide = new Sequence("peptide", "MRG"); // ATG, CGT, GGA
+    
+    /*
+     * emulate 'map from' range based on CDS _including_ stop codon
+     */
+    MapList map = new MapList(new int[] { 10, 21 }, new int[] { 1, 3 }, 3,
+            1);
+    Mapping mapping = new Mapping(peptide, map);
+
+    MappedFeatures mf = new MappedFeatures(mapping, cds, 2, 'M', null);
+    
+    /*
+     * scenario: sequence_variant feature on CDS at position 14;
+     * find the corresponding position on peptide
+     */
+    int[] pepPos = mf.getMappedPositions(14,  14);
+    assertEquals(pepPos[0], 2);
+    assertEquals(pepPos[1], 2);
+    
+    /*
+     * scenario: exon feature on CDS including stop codon;
+     */
+    pepPos = mf.getMappedPositions(10, 21);
+    assertEquals(pepPos[0], 1);
+    assertEquals(pepPos[1], 3);
+    
+    /*
+     * now with the mapping from protein to CDS
+     */
+    mapping = new Mapping(cds, map.getInverse());
+    mf = new MappedFeatures(mapping, peptide, 15, 't', null);
+    int[] cdsPos = mf.getMappedPositions(2,  2);
+    assertEquals(cdsPos[0], 13);
+    assertEquals(cdsPos[1], 15);
+  }
 }