1 package jalview.datamodel;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNull;
6 import jalview.util.MapList;
8 import java.util.Arrays;
10 import org.testng.annotations.Test;
12 public class AlignedCodonFrameTest
16 * Test the method that locates the first aligned sequence that has a mapping.
18 @Test(groups ={ "Functional" })
19 public void testFindAlignedSequence()
21 AlignmentI cdna = new Alignment(new SequenceI[]
23 final Sequence seq1 = new Sequence("Seq1", "C-G-TA-GC");
24 seq1.createDatasetSequence();
25 cdna.addSequence(seq1);
26 final Sequence seq2 = new Sequence("Seq2", "-TA-GG-GG");
27 seq2.createDatasetSequence();
28 cdna.addSequence(seq2);
30 AlignmentI aa = new Alignment(new SequenceI[]
32 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
33 aseq1.createDatasetSequence();
34 aa.addSequence(aseq1);
35 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
36 aseq2.createDatasetSequence();
37 aa.addSequence(aseq2);
40 * Mapping from first DNA sequence to second AA sequence.
42 AlignedCodonFrame acf = new AlignedCodonFrame();
44 assertNull(acf.findAlignedSequence(seq1, aa));
46 MapList map = new MapList(new int[]
49 acf.addMap(seq1.getDatasetSequence(), aseq2.getDatasetSequence(), map);
52 * DNA seq1 maps to AA seq2
54 assertEquals(aa.getSequenceAt(1),
55 acf.findAlignedSequence(cdna
56 .getSequenceAt(0).getDatasetSequence(), aa));
58 assertEquals(cdna.getSequenceAt(0),
59 acf.findAlignedSequence(aa
60 .getSequenceAt(1).getDatasetSequence(), cdna));
64 * Test the method that locates the mapped codon for a protein position.
66 @Test(groups ={ "Functional" })
67 public void testGetMappedRegion()
69 // introns lower case, exons upper case
70 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
71 seq1.createDatasetSequence();
72 final Sequence seq2 = new Sequence("Seq2", "-TA-gG-Gg-CG-a");
73 seq2.createDatasetSequence();
75 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
76 aseq1.createDatasetSequence();
77 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
78 aseq2.createDatasetSequence();
81 * First with no mappings
83 AlignedCodonFrame acf = new AlignedCodonFrame();
85 assertNull(acf.getMappedRegion(seq1, aseq1, 1));
88 * Set up the mappings for the exons (upper-case bases)
90 MapList map = new MapList(new int[]
91 { 2, 4, 6, 6, 8, 9 }, new int[]
93 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
94 map = new MapList(new int[]
95 { 1, 2, 4, 5, 7, 8 }, new int[]
97 acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map);
99 assertEquals("[2, 4]",
100 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 1)));
101 assertEquals("[6, 6, 8, 9]",
102 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 2)));
103 assertEquals("[1, 2, 4, 4]",
104 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 1)));
105 assertEquals("[5, 5, 7, 8]",
106 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 2)));
109 * No mapping from sequence 1 to sequence 2
111 assertNull(acf.getMappedRegion(seq1, aseq2, 1));
114 @Test(groups ={ "Functional" })
115 public void testGetMappedCodon()
117 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
118 seq1.createDatasetSequence();
119 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
120 aseq1.createDatasetSequence();
123 * First with no mappings
125 AlignedCodonFrame acf = new AlignedCodonFrame();
127 assertNull(acf.getMappedCodon(seq1.getDatasetSequence(), 0));
130 * Set up the mappings for the exons (upper-case bases)
132 MapList map = new MapList(new int[]
133 { 2, 4, 6, 6, 8, 9 }, new int[]
135 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
137 assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
138 aseq1.getDatasetSequence(), 1)));
139 assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
140 aseq1.getDatasetSequence(), 2)));