JAL-1705 ensure the right mapping is used to align CDS to cDNA
[jalview.git] / test / jalview / analysis / AlignmentUtilsTests.java
index 3d3736f..7ccbf97 100644 (file)
@@ -50,6 +50,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import org.testng.annotations.Test;
 
@@ -1953,7 +1954,65 @@ public class AlignmentUtilsTests
      */
     dna.addCodonFrame(acf);
     AlignmentUtils.alignAs(cds, dna);
-    assertEquals("---GGGTTT---", cds.getSequenceAt(0).getSequenceAsString());
+    assertEquals("---GGGTTT", cds.getSequenceAt(0).getSequenceAsString());
     assertEquals("CCC------AAA", cds.getSequenceAt(1).getSequenceAsString());
   }
+
+  @Test(groups = { "Functional" })
+  public void testAddMappedPositions()
+  {
+    SequenceI from = new Sequence("dna", "ggAA-ATcc-TT-g");
+    SequenceI seq1 = new Sequence("cds", "AAATTT");
+    from.createDatasetSequence();
+    seq1.createDatasetSequence();
+    Mapping mapping = new Mapping(seq1, new MapList(
+            new int[] { 3, 6, 9, 10 },
+            new int[] { 1, 6 }, 1, 1));
+    Map<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
+    AlignmentUtils.addMappedPositions(seq1, from, mapping, map);
+
+    /*
+     * verify map has seq1 residues in columns 3,4,6,7,11,12
+     */
+    assertEquals(6, map.size());
+    assertEquals('A', map.get(3).get(seq1).charValue());
+    assertEquals('A', map.get(4).get(seq1).charValue());
+    assertEquals('A', map.get(6).get(seq1).charValue());
+    assertEquals('T', map.get(7).get(seq1).charValue());
+    assertEquals('T', map.get(11).get(seq1).charValue());
+    assertEquals('T', map.get(12).get(seq1).charValue());
+
+    /*
+     * 
+     */
+  }
+
+  /**
+   * Test case where the mapping 'from' range includes a stop codon which is
+   * absent in the 'to' range
+   */
+  @Test(groups = { "Functional" })
+  public void testAddMappedPositions_withStopCodon()
+  {
+    SequenceI from = new Sequence("dna", "ggAA-ATcc-TT-g");
+    SequenceI seq1 = new Sequence("cds", "AAATTT");
+    from.createDatasetSequence();
+    seq1.createDatasetSequence();
+    Mapping mapping = new Mapping(seq1, new MapList(
+            new int[] { 3, 6, 9, 10 },
+            new int[] { 1, 6 }, 1, 1));
+    Map<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
+    AlignmentUtils.addMappedPositions(seq1, from, mapping, map);
+  
+    /*
+     * verify map has seq1 residues in columns 3,4,6,7,11,12
+     */
+    assertEquals(6, map.size());
+    assertEquals('A', map.get(3).get(seq1).charValue());
+    assertEquals('A', map.get(4).get(seq1).charValue());
+    assertEquals('A', map.get(6).get(seq1).charValue());
+    assertEquals('T', map.get(7).get(seq1).charValue());
+    assertEquals('T', map.get(11).get(seq1).charValue());
+    assertEquals('T', map.get(12).get(seq1).charValue());
+  }
 }