JAL-1620 version bump and release notes
[jalview.git] / test / jalview / schemes / DnaCodonTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
3  * Copyright (C) 2014 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.schemes;
22
23 import static org.junit.Assert.*;
24
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
29
30 import java.io.IOException;
31 import java.util.Map;
32 import java.util.Vector;
33
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37
38 public class DnaCodonTests
39 {
40
41   @Test
42   public void testAmbiguityCodeGeneration()
43   {
44     assertTrue(ResidueProperties.ambiguityCodes.size() > 0);
45   }
46
47   @Test
48   public void testAmbiguityCodon()
49   {
50     for (String ac : ResidueProperties.ambiguityCodes.keySet())
51     {
52       assertTrue("Couldn't resolve GGN as glycine codon",
53               ResidueProperties.codonHash2.get("GG" + ac).equals("G"));
54     }
55   }
56
57   @Test
58   public void regenerateCodonTable()
59   {
60     for (Map.Entry<String, String> codon : ResidueProperties.codonHash2
61             .entrySet())
62     {
63       System.out.println("ResidueProperties.codonHash2.set(\""
64               + codon.getKey() + "\", \"" + codon.getValue() + "\");");
65     }
66   }
67
68   @Test
69   public void checkOldCodonagainstNewCodonTable()
70   {
71     // note - this test will be removed once the old codon table (including
72     // Vectors) is removed
73     String additional = "", failtrans = "", differentTr = "";
74     for (Object aa : ResidueProperties.codonHash.keySet())
75     {
76       String amacid = (String) aa;
77       for (Object codons : ((Vector) ResidueProperties.codonHash
78               .get(amacid)))
79       {
80         String codon = (String) codons;
81         String trans = ResidueProperties.codonTranslate(codon);
82         String oldtrans = ResidueProperties._codonTranslate(codon);
83         if (trans == null)
84         {
85           additional += "\nOld translation table includes additional codons for "
86                   + amacid + " : " + codon;
87         }
88         if (oldtrans == null)
89         {
90           failtrans += ("\nold translation routine failed for old translation entry (aa was "
91                   + amacid + " codon was " + codon + ")");
92         }
93         if (!oldtrans.equals(trans))
94         {
95           differentTr += ("\nDifferent translation for old and new routines: "
96                   + amacid
97                   + " "
98                   + codon
99                   + " => expected "
100                   + oldtrans
101                   + " and got " + trans);
102         }
103       }
104     }
105     assertTrue("" + additional + "\n" + failtrans + "\n" + differentTr,
106             additional.length() == 0 && failtrans.length() == 0
107                     && differentTr.length() == 0);
108   }
109 }