public void testGetMappedRegion()
{
// introns lower case, exons upper case
- final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
- seq1.createDatasetSequence();
- final Sequence seq2 = new Sequence("Seq2", "-TA-gG-Gg-CG-a");
- seq2.createDatasetSequence();
+ final Sequence dna1 = new Sequence("Seq1/10-18", "c-G-TA-gC-gT-T");
+ dna1.createDatasetSequence();
+ final Sequence dna2 = new Sequence("Seq2/20-28", "-TA-gG-Gg-CG-a");
+ dna2.createDatasetSequence();
- final Sequence aseq1 = new Sequence("Seq1", "-P-R");
- aseq1.createDatasetSequence();
- final Sequence aseq2 = new Sequence("Seq2", "-LY-Q");
- aseq2.createDatasetSequence();
+ final Sequence pep1 = new Sequence("Seq1/3-4", "-P-R");
+ pep1.createDatasetSequence();
+ final Sequence pep2 = new Sequence("Seq2/7-9", "-LY-Q");
+ pep2.createDatasetSequence();
/*
* First with no mappings
*/
AlignedCodonFrame acf = new AlignedCodonFrame();
- assertNull(acf.getMappedRegion(seq1, aseq1, 1));
+ assertNull(acf.getMappedRegion(dna1, pep1, 3));
/*
* Set up the mappings for the exons (upper-case bases)
* Note residue Q is unmapped
*/
- 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);
- map = new MapList(new int[] { 1, 2, 4, 5, 7, 8 }, new int[] { 1, 2 },
+ MapList map1 = new MapList(new int[] { 11, 13, 15, 15, 17, 18 }, new int[] {
+ 3, 4 }, 3, 1);
+ acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map1);
+ MapList map2 = new MapList(new int[] { 20, 21, 23, 24, 26, 27 }, new int[] { 7, 9 },
3, 1);
- acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map);
+ acf.addMap(dna2.getDatasetSequence(), pep2.getDatasetSequence(), map2);
- assertArrayEquals(new int[] { 2, 4 },
- acf.getMappedRegion(seq1, aseq1, 1));
- assertArrayEquals(new int[] { 6, 6, 8, 9 },
- acf.getMappedRegion(seq1, aseq1, 2));
- assertArrayEquals(new int[] { 1, 2, 4, 4 },
- acf.getMappedRegion(seq2, aseq2, 1));
- assertArrayEquals(new int[] { 5, 5, 7, 8 },
- acf.getMappedRegion(seq2, aseq2, 2));
+ /*
+ * get codon positions for peptide position
+ */
+ assertArrayEquals(new int[] { 11, 13 },
+ acf.getMappedRegion(dna1, pep1, 3));
+ assertArrayEquals(new int[] { 15, 15, 17, 18 },
+ acf.getMappedRegion(dna1, pep1, 4));
+ assertArrayEquals(new int[] { 20, 21, 23, 23 },
+ acf.getMappedRegion(dna2, pep2, 7));
+ assertArrayEquals(new int[] { 24, 24, 26, 27 },
+ acf.getMappedRegion(dna2, pep2, 8));
/*
- * No mapping from seq2 to Q
+ * No mapping from dna2 to Q
*/
- assertNull(acf.getMappedRegion(seq2, aseq2, 3));
+ assertNull(acf.getMappedRegion(dna2, pep2, 9));
/*
- * No mapping from sequence 1 to sequence 2
+ * No mapping from dna1 to pep2
+ */
+ assertNull(acf.getMappedRegion(dna1, pep2, 7));
+
+ /*
+ * get peptide position for codon position
*/
- assertNull(acf.getMappedRegion(seq1, aseq2, 1));
+ assertArrayEquals(new int[] { 3, 3 },
+ acf.getMappedRegion(pep1, dna1, 11));
+ assertArrayEquals(new int[] { 3, 3 },
+ acf.getMappedRegion(pep1, dna1, 12));
+ assertArrayEquals(new int[] { 3, 3 },
+ acf.getMappedRegion(pep1, dna1, 13));
+ assertNull(acf.getMappedRegion(pep1, dna1, 14)); // intron base, not mapped
+
}
@Test(groups = { "Functional" })
mapping = acf.getCoveringMapping(cds2, pep);
assertNotNull(mapping);
}
+
+ /**
+ * Test the method that adds mapped positions to SearchResults
+ */
+ @Test(groups = { "Functional" })
+ public void testMarkMappedRegion()
+ {
+ // introns lower case, exons upper case
+ final Sequence dna1 = new Sequence("Seq1/10-18", "c-G-TA-gC-gT-T");
+ dna1.createDatasetSequence();
+ final Sequence dna2 = new Sequence("Seq2/20-28", "-TA-gG-Gg-CG-a");
+ dna2.createDatasetSequence();
+
+ final Sequence pep1 = new Sequence("Seq1/3-4", "-P-R");
+ pep1.createDatasetSequence();
+ final Sequence pep2 = new Sequence("Seq2/7-9", "-LY-Q");
+ pep2.createDatasetSequence();
+
+ /*
+ * First with no mappings
+ */
+ AlignedCodonFrame acf = new AlignedCodonFrame();
+ SearchResults sr = new SearchResults();
+ acf.markMappedRegion(dna1, 12, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * Set up the mappings for the exons (upper-case bases)
+ * Note residue Q is unmapped
+ */
+ MapList map1 = new MapList(new int[] { 11, 13, 15, 15, 17, 18 }, new int[] {
+ 3, 4 }, 3, 1);
+ acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map1);
+ MapList map2 = new MapList(new int[] { 20, 21, 23, 24, 26, 27 }, new int[] { 7, 8 },
+ 3, 1);
+ acf.addMap(dna2.getDatasetSequence(), pep2.getDatasetSequence(), map2);
+
+ /*
+ * intron bases are not mapped
+ */
+ acf.markMappedRegion(dna1, 10, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * Q is not mapped
+ */
+ acf.markMappedRegion(pep2, 9, sr);
+ assertTrue(sr.isEmpty());
+
+ /*
+ * mark peptide position for exon position (of aligned sequence)
+ */
+ acf.markMappedRegion(dna1, 11, sr);
+ SearchResults expected = new SearchResults();
+ expected.addResult(pep1.getDatasetSequence(), 3, 3);
+ assertEquals(sr, expected);
+
+ /*
+ * mark peptide position for exon position of dataset sequence - same result
+ */
+ sr = new SearchResults();
+ acf.markMappedRegion(dna1.getDatasetSequence(), 11, sr);
+ assertEquals(sr, expected);
+
+ /*
+ * marking the same position a second time should not create a duplicate match
+ */
+ acf.markMappedRegion(dna1.getDatasetSequence(), 12, sr);
+ assertEquals(sr, expected);
+
+ /*
+ * mark exon positions for peptide position (of aligned sequence)
+ */
+ sr = new SearchResults();
+ acf.markMappedRegion(pep2, 7, sr); // codon positions 20, 21, 23
+ expected = new SearchResults();
+ expected.addResult(dna2.getDatasetSequence(), 20, 21);
+ expected.addResult(dna2.getDatasetSequence(), 23, 23);
+ assertEquals(sr, expected);
+
+ /*
+ * add another codon to the same SearchResults
+ */
+ acf.markMappedRegion(pep1.getDatasetSequence(), 4, sr); // codon positions 15, 17, 18
+ expected.addResult(dna1.getDatasetSequence(), 15, 15);
+ expected.addResult(dna1.getDatasetSequence(), 17, 18);
+ assertEquals(sr, expected);
+ }
}