import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
-import jalview.util.MapList;
-
import java.util.Arrays;
import java.util.List;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
+import jalview.gui.JvOptionPane;
+import jalview.util.MapList;
+
public class AlignedCodonFrameTest
{
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
/**
* Test the method that locates the first aligned sequence that has a mapping.
*/
assertArrayEquals(new int[] { 2, 2 },
acf.getMappedRegion(seq2, seq1, 6));
}
+
+ /**
+ * Tests for addMap. See also tests for MapList.addMapList
+ */
+ @Test(groups = { "Functional" })
+ public void testAddMap()
+ {
+ final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
+ seq1.createDatasetSequence();
+ final Sequence aseq1 = new Sequence("Seq1", "-V-L");
+ aseq1.createDatasetSequence();
+
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] {
+ 1, 2 }, 3, 1);
+ acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
+ assertEquals(1, acf.getMappingsFromSequence(seq1).size());
+ Mapping before = acf.getMappingsFromSequence(seq1).get(0);
+
+ /*
+ * add the same map again, verify it doesn't get duplicated
+ */
+ acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
+ assertEquals(1, acf.getMappingsFromSequence(seq1).size());
+ assertSame(before, acf.getMappingsFromSequence(seq1).get(0));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetCoveringMapping()
+ {
+ SequenceI dna = new Sequence("dna", "acttcaATGGCGGACtaattt");
+ SequenceI cds = new Sequence("cds/7-15", "ATGGCGGAC");
+ cds.setDatasetSequence(dna);
+ SequenceI pep = new Sequence("pep", "MAD");
+
+ /*
+ * with null argument or no mappings
+ */
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ assertNull(acf.getCoveringMapping(null, null));
+ assertNull(acf.getCoveringMapping(dna, null));
+ assertNull(acf.getCoveringMapping(null, pep));
+ assertNull(acf.getCoveringMapping(dna, pep));
+
+ /*
+ * with a non-covering mapping e.g. overlapping exon
+ */
+ MapList map = new MapList(new int[] { 7, 9 }, new int[] {
+ 1, 1 }, 3, 1);
+ acf.addMap(dna, pep, map);
+ assertNull(acf.getCoveringMapping(dna, pep));
+
+ acf = new AlignedCodonFrame();
+ MapList map2 = new MapList(new int[] { 13, 18 }, new int[] {
+ 2, 2 }, 3, 1);
+ acf.addMap(dna, pep, map2);
+ assertNull(acf.getCoveringMapping(dna, pep));
+
+ /*
+ * with a covering mapping from CDS (dataset) to protein
+ */
+ acf = new AlignedCodonFrame();
+ MapList map3 = new MapList(new int[] { 7, 15 }, new int[] {
+ 1, 3 }, 3, 1);
+ acf.addMap(dna, pep, map3);
+ assertNull(acf.getCoveringMapping(dna, pep));
+ SequenceToSequenceMapping mapping = acf.getCoveringMapping(cds, pep);
+ assertNotNull(mapping);
+
+ /*
+ * with a mapping that extends to stop codon
+ */
+ acf = new AlignedCodonFrame();
+ MapList map4 = new MapList(new int[] { 7, 18 }, new int[] {
+ 1, 3 }, 3, 1);
+ acf.addMap(dna, pep, map4);
+ assertNull(acf.getCoveringMapping(dna, pep));
+ assertNull(acf.getCoveringMapping(cds, pep));
+ SequenceI cds2 = new Sequence("cds/7-18", "ATGGCGGACtaa");
+ cds2.setDatasetSequence(dna);
+ mapping = acf.getCoveringMapping(cds2, pep);
+ assertNotNull(mapping);
+ }
}