2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNull;
26 import jalview.util.MapList;
28 import java.util.Arrays;
30 import org.testng.annotations.Test;
32 public class AlignedCodonFrameTest
36 * Test the method that locates the first aligned sequence that has a mapping.
38 @Test(groups = { "Functional" })
39 public void testFindAlignedSequence()
41 AlignmentI cdna = new Alignment(new SequenceI[] {});
42 final Sequence seq1 = new Sequence("Seq1", "C-G-TA-GC");
43 seq1.createDatasetSequence();
44 cdna.addSequence(seq1);
45 final Sequence seq2 = new Sequence("Seq2", "-TA-GG-GG");
46 seq2.createDatasetSequence();
47 cdna.addSequence(seq2);
49 AlignmentI aa = new Alignment(new SequenceI[] {});
50 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
51 aseq1.createDatasetSequence();
52 aa.addSequence(aseq1);
53 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
54 aseq2.createDatasetSequence();
55 aa.addSequence(aseq2);
58 * Mapping from first DNA sequence to second AA sequence.
60 AlignedCodonFrame acf = new AlignedCodonFrame();
62 assertNull(acf.findAlignedSequence(seq1, aa));
64 MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1);
65 acf.addMap(seq1.getDatasetSequence(), aseq2.getDatasetSequence(), map);
68 * DNA seq1 maps to AA seq2
70 assertEquals(aa.getSequenceAt(1), acf.findAlignedSequence(cdna
71 .getSequenceAt(0).getDatasetSequence(), aa));
73 assertEquals(cdna.getSequenceAt(0), acf.findAlignedSequence(aa
74 .getSequenceAt(1).getDatasetSequence(), cdna));
78 * Test the method that locates the mapped codon for a protein position.
80 @Test(groups = { "Functional" })
81 public void testGetMappedRegion()
83 // introns lower case, exons upper case
84 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
85 seq1.createDatasetSequence();
86 final Sequence seq2 = new Sequence("Seq2", "-TA-gG-Gg-CG-a");
87 seq2.createDatasetSequence();
89 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
90 aseq1.createDatasetSequence();
91 final Sequence aseq2 = new Sequence("Seq2", "-LY-");
92 aseq2.createDatasetSequence();
95 * First with no mappings
97 AlignedCodonFrame acf = new AlignedCodonFrame();
99 assertNull(acf.getMappedRegion(seq1, aseq1, 1));
102 * Set up the mappings for the exons (upper-case bases)
104 MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] {
106 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
107 map = new MapList(new int[] { 1, 2, 4, 5, 7, 8 }, new int[] { 1, 2 },
109 acf.addMap(seq2.getDatasetSequence(), aseq2.getDatasetSequence(), map);
111 assertEquals("[2, 4]",
112 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 1)));
113 assertEquals("[6, 6, 8, 9]",
114 Arrays.toString(acf.getMappedRegion(seq1, aseq1, 2)));
115 assertEquals("[1, 2, 4, 4]",
116 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 1)));
117 assertEquals("[5, 5, 7, 8]",
118 Arrays.toString(acf.getMappedRegion(seq2, aseq2, 2)));
121 * No mapping from sequence 1 to sequence 2
123 assertNull(acf.getMappedRegion(seq1, aseq2, 1));
126 @Test(groups = { "Functional" })
127 public void testGetMappedCodon()
129 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T");
130 seq1.createDatasetSequence();
131 final Sequence aseq1 = new Sequence("Seq1", "-P-R");
132 aseq1.createDatasetSequence();
135 * First with no mappings
137 AlignedCodonFrame acf = new AlignedCodonFrame();
139 assertNull(acf.getMappedCodon(seq1.getDatasetSequence(), 0));
142 * Set up the mappings for the exons (upper-case bases)
144 MapList map = new MapList(new int[] { 2, 4, 6, 6, 8, 9 }, new int[] {
146 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
148 assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
149 aseq1.getDatasetSequence(), 1)));
150 assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
151 aseq1.getDatasetSequence(), 2)));
155 * Test for the case where sequences have start > 1
157 @Test(groups = { "Functional" })
158 public void testGetMappedCodon_forSubSequences()
160 final Sequence seq1 = new Sequence("Seq1", "c-G-TA-gC-gT-T", 27, 35);
161 seq1.createDatasetSequence();
163 final Sequence aseq1 = new Sequence("Seq1", "-P-R", 12, 13);
164 aseq1.createDatasetSequence();
167 * Set up the mappings for the exons (upper-case bases)
169 AlignedCodonFrame acf = new AlignedCodonFrame();
170 MapList map = new MapList(new int[] { 28, 30, 32, 32, 34, 35 },
171 new int[] { 12, 13 }, 3, 1);
172 acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
174 assertEquals("[G, T, A]", Arrays.toString(acf.getMappedCodon(
175 aseq1.getDatasetSequence(), 12)));
176 assertEquals("[C, T, T]", Arrays.toString(acf.getMappedCodon(
177 aseq1.getDatasetSequence(), 13)));