JAL-3706 handle virtual feature extending to unmapped stop codon
[jalview.git] / test / jalview / datamodel / MappedFeaturesTest.java
index e4caac3..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,9 +9,11 @@ import java.util.Map;
 
 import org.testng.annotations.Test;
 
+import jalview.util.MapList;
+
 public class MappedFeaturesTest
 {
-  @Test
+  @Test(groups = "Functional")
   public void testFindProteinVariants()
   {
     /*
@@ -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[]
@@ -68,13 +68,20 @@ public class MappedFeaturesTest
     assertEquals(variant, "c.13T>C(p.=)");
 
     /*
-     * CSQ:HGVSp value is used if present
+     * CSQ:HGVSp value is used if present 
+     * _and_ it contains "p." following a colon
      */
     Map<String, String> csq = new HashMap<>();
     csq.put("HGVSp", "hello:world");
     sf2.setValue("CSQ", csq);
     variant = mf.findProteinVariants(sf2);
-    assertEquals(variant, "world");
+    assertEquals(variant, "c.13T>C(p.=)");
+    csq.put("HGVSp", "p.HelloWorld");
+    variant = mf.findProteinVariants(sf2);
+    assertEquals(variant, "c.13T>C(p.=)");
+    csq.put("HGVSp", "try this:hellop.world");
+    variant = mf.findProteinVariants(sf2);
+    assertEquals(variant, "hellop.world");
 
     /*
      * missense and indel variants in second codon
@@ -110,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);
+  }
 }