1 package jalview.datamodel;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNull;
5 import org.testng.annotations.Test;
6 import jalview.util.MapList;
8 import java.util.Arrays;
10 public class AlignedCodonFrameTest
14 * Test the method that locates the first aligned sequence that has a mapping.
17 public void testFindAlignedSequence()
19 AlignmentI cdna = new Alignment(new SequenceI[]
21 final Sequence seq1 = new Sequence("Seq1", "C-G-TA-GC");
22 seq1.createDatasetSequence();
23 cdna.addSequence(seq1);
24 final Sequence seq2 = new Sequence("Seq2", "-TA-GG-GG");
25 seq2.createDatasetSequence();
26 cdna.addSequence(seq2);
28 AlignmentI aa = new Alignment(new SequenceI[]
30 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
31 aseq1.createDatasetSequence();
32 aa.addSequence(aseq1);
33 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
34 aseq2.createDatasetSequence();
35 aa.addSequence(aseq2);
38 * Mapping from first DNA sequence to second AA sequence.
40 AlignedCodonFrame acf = new AlignedCodonFrame();
42 assertNull(acf.findAlignedSequence(seq1, aa));
44 MapList map = new MapList(new int[]
47 acf.addMap(seq1.getDatasetSequence(), aseq2.getDatasetSequence(), map);
50 * DNA seq1 maps to AA seq2
52 assertEquals(aa.getSequenceAt(1),
53 acf.findAlignedSequence(cdna
54 .getSequenceAt(0).getDatasetSequence(), aa));
56 assertEquals(cdna.getSequenceAt(0),
57 acf.findAlignedSequence(aa
58 .getSequenceAt(1).getDatasetSequence(), cdna));
62 * Test the method that locates the mapped codon for a protein position.
65 public void testGetMappedRegion()
67 // introns lower case, exons upper case
68 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
69 seq1.createDatasetSequence();
70 final Sequence seq2 = new Sequence("Seq2", "-TA-gG-Gg-CG-a");
71 seq2.createDatasetSequence();
73 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
74 aseq1.createDatasetSequence();
75 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
76 aseq2.createDatasetSequence();
79 * First with no mappings
81 AlignedCodonFrame acf = new AlignedCodonFrame();
83 assertNull(acf.getMappedRegion(seq1, aseq1, 1));
86 * Set up the mappings for the exons (upper-case bases)
88 MapList map = new MapList(new int[]
89 { 2, 4, 6, 6, 8, 9 }, new int[]
91 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
92 map = new MapList(new int[]
93 { 1, 2, 4, 5, 7, 8 }, new int[]
95 acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map);
97 assertEquals("[2, 4]",
98 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 1)));
99 assertEquals("[6, 6, 8, 9]",
100 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 2)));
101 assertEquals("[1, 2, 4, 4]",
102 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 1)));
103 assertEquals("[5, 5, 7, 8]",
104 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 2)));
107 * No mapping from sequence 1 to sequence 2
109 assertNull(acf.getMappedRegion(seq1, aseq2, 1));
113 public void testGetMappedCodon()
115 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
116 seq1.createDatasetSequence();
117 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
118 aseq1.createDatasetSequence();
121 * First with no mappings
123 AlignedCodonFrame acf = new AlignedCodonFrame();
125 assertNull(acf.getMappedCodon(seq1.getDatasetSequence(), 0));
128 * Set up the mappings for the exons (upper-case bases)
130 MapList map = new MapList(new int[]
131 { 2, 4, 6, 6, 8, 9 }, new int[]
133 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
135 assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
136 aseq1.getDatasetSequence(), 1)));
137 assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
138 aseq1.getDatasetSequence(), 2)));