Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 11:45:30 GMT
  2. Package jalview.analysis

File GeneticCodesTest.java

 

Code metrics

2
175
7
1
318
221
8
0.05
25
7
1.14

Classes

Class Line # Actions
GeneticCodesTest 32 175 8
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.analysis;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertNull;
26    import static org.testng.Assert.assertSame;
27   
28    import java.util.Iterator;
29   
30    import org.testng.annotations.Test;
31   
 
32    public class GeneticCodesTest
33    {
 
34  1 toggle @Test(groups = "Functional")
35    public void testGetCodeTable()
36    {
37  1 GeneticCodes codes = GeneticCodes.getInstance();
38  1 assertEquals(codes.getStandardCodeTable().getName(), "Standard");
39  1 assertEquals(codes.getStandardCodeTable().getId(), "1");
40  1 assertSame(codes.getStandardCodeTable(), codes.getCodeTable("1"));
41  1 assertEquals(codes.getCodeTable("2").getName(),
42    "Vertebrate Mitochondrial");
43  1 assertEquals(codes.getCodeTable("11").getName(),
44    "Bacterial, Archaeal and Plant Plastid");
45  1 assertEquals(codes.getCodeTable("31").getName(),
46    "Blastocrithidia Nuclear");
47    }
48   
 
49  1 toggle @Test(groups = "Functional")
50    public void testGetCodeTables()
51    {
52  1 GeneticCodes codes = GeneticCodes.getInstance();
53  1 Iterator<GeneticCodeI> tableIterator = codes.getCodeTables().iterator();
54  1 String[] ids = new String[] { "1", "2", "3", "4", "5", "6", "9", "10",
55    "11", "12", "13", "14", "15", "16", "21", "22", "23", "24", "25",
56    "26", "27", "28", "29", "30", "31" };
57  26 for (int i = 0; i < ids.length; i++)
58    {
59  25 assertEquals(tableIterator.next().getId(), ids[i]);
60    }
61  1 assertFalse(tableIterator.hasNext());
62    }
63   
 
64  1 toggle @Test(groups = "Functional")
65    public void testTranslate()
66    {
67  1 GeneticCodes codes = GeneticCodes.getInstance();
68   
69  1 GeneticCodeI gc = codes.getCodeTable("1");
70  1 assertNull(gc.translate("XYZ"));
71  1 assertEquals(gc.translate("AGA"), "R");
72   
73  1 gc = codes.getCodeTable("2");
74  1 assertEquals(gc.translate("AGA"), "*"); // variant
75  1 assertEquals(gc.translate("ttc"), "F"); // non-variant
76   
77    // table 11 has no variant translations - should serve the standard values
78  1 gc = codes.getCodeTable("11");
79  1 assertEquals(gc.translate("ttc"), "F");
80   
81  1 gc = codes.getCodeTable("31");
82  1 assertEquals(gc.translate("TGA"), "W"); // variant
83  1 assertEquals(gc.translate("tag"), "E"); // variant
84  1 assertEquals(gc.translate("AGC"), "S"); // non-variant
85    }
86   
87    /**
88    * Test 'standard' codon translations (no ambiguity codes)
89    */
 
90  1 toggle @Test(groups = { "Functional" })
91    public void testTranslate_standardTable()
92    {
93  1 GeneticCodeI st = GeneticCodes.getInstance().getStandardCodeTable();
94  1 assertEquals("F", st.translate("TTT"));
95  1 assertEquals("F", st.translate("TTC"));
96  1 assertEquals("L", st.translate("TTA"));
97  1 assertEquals("L", st.translate("TTG"));
98  1 assertEquals("L", st.translate("CTT"));
99  1 assertEquals("L", st.translate("CTC"));
100  1 assertEquals("L", st.translate("CTA"));
101  1 assertEquals("L", st.translate("CTG"));
102  1 assertEquals("I", st.translate("ATT"));
103  1 assertEquals("I", st.translate("ATC"));
104  1 assertEquals("I", st.translate("ATA"));
105  1 assertEquals("M", st.translate("ATG"));
106  1 assertEquals("V", st.translate("GTT"));
107  1 assertEquals("V", st.translate("GTC"));
108  1 assertEquals("V", st.translate("GTA"));
109  1 assertEquals("V", st.translate("GTG"));
110  1 assertEquals("S", st.translate("TCT"));
111  1 assertEquals("S", st.translate("TCC"));
112  1 assertEquals("S", st.translate("TCA"));
113  1 assertEquals("S", st.translate("TCG"));
114  1 assertEquals("P", st.translate("CCT"));
115  1 assertEquals("P", st.translate("CCC"));
116  1 assertEquals("P", st.translate("CCA"));
117  1 assertEquals("P", st.translate("CCG"));
118  1 assertEquals("T", st.translate("ACT"));
119  1 assertEquals("T", st.translate("ACC"));
120  1 assertEquals("T", st.translate("ACA"));
121  1 assertEquals("T", st.translate("ACG"));
122  1 assertEquals("A", st.translate("GCT"));
123  1 assertEquals("A", st.translate("GCC"));
124  1 assertEquals("A", st.translate("GCA"));
125  1 assertEquals("A", st.translate("GCG"));
126  1 assertEquals("Y", st.translate("TAT"));
127  1 assertEquals("Y", st.translate("TAC"));
128  1 assertEquals("*", st.translate("TAA"));
129  1 assertEquals("*", st.translate("TAG"));
130  1 assertEquals("H", st.translate("CAT"));
131  1 assertEquals("H", st.translate("CAC"));
132  1 assertEquals("Q", st.translate("CAA"));
133  1 assertEquals("Q", st.translate("CAG"));
134  1 assertEquals("N", st.translate("AAT"));
135  1 assertEquals("N", st.translate("AAC"));
136  1 assertEquals("K", st.translate("AAA"));
137  1 assertEquals("K", st.translate("AAG"));
138  1 assertEquals("D", st.translate("GAT"));
139  1 assertEquals("D", st.translate("GAC"));
140  1 assertEquals("E", st.translate("GAA"));
141  1 assertEquals("E", st.translate("GAG"));
142  1 assertEquals("C", st.translate("TGT"));
143  1 assertEquals("C", st.translate("TGC"));
144  1 assertEquals("*", st.translate("TGA"));
145  1 assertEquals("W", st.translate("TGG"));
146  1 assertEquals("R", st.translate("CGT"));
147  1 assertEquals("R", st.translate("CGC"));
148  1 assertEquals("R", st.translate("CGA"));
149  1 assertEquals("R", st.translate("CGG"));
150  1 assertEquals("S", st.translate("AGT"));
151  1 assertEquals("S", st.translate("AGC"));
152  1 assertEquals("R", st.translate("AGA"));
153  1 assertEquals("R", st.translate("AGG"));
154  1 assertEquals("G", st.translate("GGT"));
155  1 assertEquals("G", st.translate("GGC"));
156  1 assertEquals("G", st.translate("GGA"));
157  1 assertEquals("G", st.translate("GGG"));
158    }
159   
160    /**
161    * Test a sample of codon translations involving ambiguity codes. Should
162    * return a protein value where the ambiguity does not affect the translation.
163    */
 
164  1 toggle @Test(groups = { "Functional" })
165    public void testTranslate_standardTableAmbiguityCodes()
166    {
167  1 GeneticCodeI st = GeneticCodes.getInstance().getStandardCodeTable();
168    // Y is C or T
169  1 assertEquals("C", st.translate("TGY"));
170    // Phenylalanine first base variation
171  1 assertEquals("L", st.translate("YTA"));
172   
173    // W is A or T
174  1 assertEquals("L", st.translate("CTW"));
175  1 assertNull(st.translate("TTW"));
176   
177    // S is G or C
178  1 assertEquals("G", st.translate("GGS"));
179  1 assertNull(st.translate("ATS"));
180   
181    // K is T or G
182  1 assertEquals("S", st.translate("TCK"));
183  1 assertNull(st.translate("ATK"));
184   
185    // M is C or A
186  1 assertEquals("T", st.translate("ACM"));
187    // Arginine first base variation
188  1 assertEquals("R", st.translate("MGA"));
189  1 assertEquals("R", st.translate("MGG"));
190  1 assertNull(st.translate("TAM"));
191   
192    // D is A, G or T
193  1 assertEquals("P", st.translate("CCD"));
194  1 assertNull(st.translate("AAD"));
195   
196    // V is A, C or G
197  1 assertEquals("V", st.translate("GTV"));
198  1 assertNull(st.translate("TTV"));
199   
200    // H is A, C or T
201  1 assertEquals("A", st.translate("GCH"));
202  1 assertEquals("I", st.translate("ATH"));
203  1 assertNull(st.translate("AGH"));
204   
205    // B is C, G or T
206  1 assertEquals("P", st.translate("CCB"));
207  1 assertNull(st.translate("TAB"));
208   
209    // R is A or G
210    // additional tests for JAL-1685 (resolved)
211  1 assertEquals("L", st.translate("CTR"));
212  1 assertEquals("V", st.translate("GTR"));
213  1 assertEquals("S", st.translate("TCR"));
214  1 assertEquals("P", st.translate("CCR"));
215  1 assertEquals("T", st.translate("ACR"));
216  1 assertEquals("A", st.translate("GCR"));
217  1 assertEquals("R", st.translate("CGR"));
218  1 assertEquals("G", st.translate("GGR"));
219  1 assertEquals("R", st.translate("AGR"));
220  1 assertEquals("E", st.translate("GAR"));
221  1 assertEquals("K", st.translate("AAR"));
222  1 assertEquals("L", st.translate("TTR"));
223  1 assertEquals("Q", st.translate("CAR"));
224  1 assertEquals("*", st.translate("TAR"));
225  1 assertEquals("*", st.translate("TRA"));
226    // Arginine first and third base ambiguity
227  1 assertEquals("R", st.translate("MGR"));
228  1 assertNull(st.translate("ATR"));
229   
230    // N is any base; 8 proteins accept any base in 3rd position
231  1 assertEquals("L", st.translate("CTN"));
232  1 assertEquals("V", st.translate("GTN"));
233  1 assertEquals("S", st.translate("TCN"));
234  1 assertEquals("P", st.translate("CCN"));
235  1 assertEquals("T", st.translate("ACN"));
236  1 assertEquals("A", st.translate("GCN"));
237  1 assertEquals("R", st.translate("CGN"));
238  1 assertEquals("G", st.translate("GGN"));
239  1 assertNull(st.translate("ATN"));
240  1 assertNull(st.translate("ANT"));
241  1 assertNull(st.translate("NAT"));
242  1 assertNull(st.translate("ANN"));
243  1 assertNull(st.translate("NNA"));
244  1 assertNull(st.translate("NNN"));
245   
246    // some random stuff
247  1 assertNull(st.translate("YWB"));
248  1 assertNull(st.translate("VHD"));
249  1 assertNull(st.translate("WSK"));
250    }
251   
252    /**
253    * Test a sample of codon translations involving ambiguity codes. Should
254    * return a protein value where the ambiguity does not affect the translation.
255    */
 
256  1 toggle @Test(groups = { "Functional" })
257    public void testTranslate_nonStandardTableAmbiguityCodes()
258    {
259  1 GeneticCodeI standard = GeneticCodes.getInstance()
260    .getStandardCodeTable();
261   
262    /*
263    * Vertebrate Mitochondrial (Table 2)
264    */
265  1 GeneticCodeI gc = GeneticCodes.getInstance().getCodeTable("2");
266    // AGR is AGA or AGG - R in standard code, * in table 2
267  1 assertEquals(gc.translate("AGR"), "*");
268  1 assertEquals(standard.translate("AGR"), "R");
269    // TGR is TGA or TGG - ambiguous in standard code, W in table 2
270  1 assertEquals(gc.translate("TGR"), "W");
271  1 assertNull(standard.translate("TGR"));
272   
273    /*
274    * Yeast Mitochondrial (Table 3)
275    */
276  1 gc = GeneticCodes.getInstance().getCodeTable("3");
277    // CTN is L in standard code, T in table 3
278  1 assertEquals(gc.translate("ctn"), "T");
279  1 assertEquals(standard.translate("CTN"), "L");
280   
281    /*
282    * Alternative Yeast Nuclear (Table 12)
283    */
284  1 gc = GeneticCodes.getInstance().getCodeTable("12");
285    // CTG is S; in the standard code CTN is L
286  1 assertEquals(gc.translate("CTG"), "S");
287  1 assertNull(gc.translate("CTK")); // K is G or T -> S or L
288  1 assertEquals(standard.translate("CTK"), "L");
289  1 assertEquals(gc.translate("CTH"), "L"); // H is anything other than G
290  1 assertEquals(standard.translate("CTH"), "L");
291  1 assertEquals(standard.translate("CTN"), "L");
292   
293    /*
294    * Trematode Mitochondrial (Table 21)
295    */
296  1 gc = GeneticCodes.getInstance().getCodeTable("21");
297    // AAR is K in standard code, ambiguous in table 21 as AAA=N not K
298  1 assertNull(gc.translate("AAR"));
299  1 assertEquals(standard.translate("AAR"), "K");
300    }
301   
 
302  1 toggle @Test(groups = "Functional")
303    public void testTranslateCanonical()
304    {
305  1 GeneticCodes codes = GeneticCodes.getInstance();
306   
307  1 GeneticCodeI gc = codes.getCodeTable("1");
308  1 assertNull(gc.translateCanonical("XYZ"));
309  1 assertEquals(gc.translateCanonical("AGA"), "R");
310    // translateCanonical should not resolve ambiguity codes
311  1 assertNull(gc.translateCanonical("TGY"));
312   
313  1 gc = codes.getCodeTable("2");
314  1 assertNull(gc.translateCanonical("AGR"));
315  1 assertEquals(gc.translateCanonical("AGA"), "*"); // variant
316  1 assertEquals(gc.translateCanonical("ttc"), "F"); // non-variant
317    }
318    }