JAL-1432 updated copyright notices
[jalview.git] / test / jalview / schemes / DnaCodonTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.schemes;
20
21 import static org.junit.Assert.*;
22
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.ColumnSelection;
25 import jalview.datamodel.Sequence;
26 import jalview.datamodel.SequenceI;
27
28 import java.io.IOException;
29 import java.util.Map;
30 import java.util.Vector;
31
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 public class DnaCodonTests
37 {
38
39   @Test
40   public void testAmbiguityCodeGeneration()
41   {
42     assertTrue(ResidueProperties.ambiguityCodes.size()>0);
43   }
44   @Test
45   public void testAmbiguityCodon() {
46     for (String ac:ResidueProperties.ambiguityCodes.keySet())
47     {
48       assertTrue("Couldn't resolve GGN as glycine codon",ResidueProperties.codonHash2.get("GG"+ac).equals("G"));
49     }
50   }
51   @Test
52   public void regenerateCodonTable() {
53     for (Map.Entry<String, String> codon:ResidueProperties.codonHash2.entrySet())
54     {
55       System.out.println("ResidueProperties.codonHash2.set(\""+codon.getKey()+"\", \""+codon.getValue()+"\");");
56     }
57   }
58   @Test
59   public void checkOldCodonagainstNewCodonTable() {
60     // note - this test will be removed once the old codon table (including Vectors) is removed
61     String additional="",failtrans="",differentTr="";
62     for (Object aa:ResidueProperties.codonHash.keySet())
63     {
64       String amacid=(String) aa;
65       for (Object codons:((Vector)ResidueProperties.codonHash.get(amacid)))
66       {
67         String codon = (String) codons;
68         String trans = ResidueProperties.codonTranslate(codon);
69         String oldtrans = ResidueProperties._codonTranslate(codon);
70         if (trans==null) {
71           additional+="\nOld translation table includes additional codons for "+amacid+" : "+codon;
72         }
73         if (oldtrans==null) {
74           failtrans+=("\nold translation routine failed for old translation entry (aa was "+amacid+" codon was "+codon+")");
75         }
76         if (!oldtrans.equals(trans))
77         {
78           differentTr+=("\nDifferent translation for old and new routines: "+amacid+" "+codon+" => expected "+oldtrans+" and got "+trans);
79         }
80       }
81     }
82     assertTrue(""+additional+"\n"+failtrans+"\n"+differentTr,additional.length()==0 && failtrans.length()==0 && differentTr.length()==0);
83   }
84 }