JAL-1517 fix copyright for 2.8.2
[jalview.git] / test / jalview / schemes / DnaCodonTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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   @Test
47   public void testAmbiguityCodon() {
48     for (String ac:ResidueProperties.ambiguityCodes.keySet())
49     {
50       assertTrue("Couldn't resolve GGN as glycine codon",ResidueProperties.codonHash2.get("GG"+ac).equals("G"));
51     }
52   }
53   @Test
54   public void regenerateCodonTable() {
55     for (Map.Entry<String, String> codon:ResidueProperties.codonHash2.entrySet())
56     {
57       System.out.println("ResidueProperties.codonHash2.set(\""+codon.getKey()+"\", \""+codon.getValue()+"\");");
58     }
59   }
60   @Test
61   public void checkOldCodonagainstNewCodonTable() {
62     // note - this test will be removed once the old codon table (including Vectors) is removed
63     String additional="",failtrans="",differentTr="";
64     for (Object aa:ResidueProperties.codonHash.keySet())
65     {
66       String amacid=(String) aa;
67       for (Object codons:((Vector)ResidueProperties.codonHash.get(amacid)))
68       {
69         String codon = (String) codons;
70         String trans = ResidueProperties.codonTranslate(codon);
71         String oldtrans = ResidueProperties._codonTranslate(codon);
72         if (trans==null) {
73           additional+="\nOld translation table includes additional codons for "+amacid+" : "+codon;
74         }
75         if (oldtrans==null) {
76           failtrans+=("\nold translation routine failed for old translation entry (aa was "+amacid+" codon was "+codon+")");
77         }
78         if (!oldtrans.equals(trans))
79         {
80           differentTr+=("\nDifferent translation for old and new routines: "+amacid+" "+codon+" => expected "+oldtrans+" and got "+trans);
81         }
82       }
83     }
84     assertTrue(""+additional+"\n"+failtrans+"\n"+differentTr,additional.length()==0 && failtrans.length()==0 && differentTr.length()==0);
85   }
86 }