JAL-1685 tests added for ambiguity codes (including failing test for R)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 11 Mar 2015 10:52:50 +0000 (10:52 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 11 Mar 2015 10:52:50 +0000 (10:52 +0000)
test/jalview/analysis/AlignmentUtilsTests.java
test/jalview/schemes/DnaCodonTests.java
test/jalview/schemes/ResiduePropertiesTest.java [new file with mode: 0644]

index f56dd5d..b612a04 100644 (file)
@@ -605,12 +605,4 @@ public class AlignmentUtilsTests
             0,
             "FPMG".toCharArray()));
   }
-
-  @Test
-  public void testTranslatesAs_withAmbiguityCodes()
-  {
-    // R means A or G
-    assertTrue(AlignmentUtils.translatesAs("car".toCharArray(), 0,
-            "Q".toCharArray()));
-  }
 }
index d8529f8..8288bf5 100644 (file)
  */
 package jalview.schemes;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
 
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.Sequence;
-import jalview.datamodel.SequenceI;
-
-import java.io.IOException;
 import java.util.Map;
-import java.util.Vector;
 
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class DnaCodonTests
@@ -71,13 +62,10 @@ public class DnaCodonTests
     // note - this test will be removed once the old codon table (including
     // Vectors) is removed
     String additional = "", failtrans = "", differentTr = "";
-    for (Object aa : ResidueProperties.codonHash.keySet())
+    for (String amacid : ResidueProperties.codonHash.keySet())
     {
-      String amacid = (String) aa;
-      for (Object codons : ((Vector) ResidueProperties.codonHash
-              .get(amacid)))
+      for (String codon : ResidueProperties.codonHash.get(amacid))
       {
-        String codon = (String) codons;
         String trans = ResidueProperties.codonTranslate(codon);
         String oldtrans = ResidueProperties._codonTranslate(codon);
         if (trans == null)
diff --git a/test/jalview/schemes/ResiduePropertiesTest.java b/test/jalview/schemes/ResiduePropertiesTest.java
new file mode 100644 (file)
index 0000000..d72d1e1
--- /dev/null
@@ -0,0 +1,135 @@
+package jalview.schemes;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class ResiduePropertiesTest
+{
+
+  /**
+   * Test 'standard' codon translations (no ambiguity codes)
+   */
+  @Test
+  public void testCodonTranslate()
+  {
+    // standard translation table order column 1/2/3/4
+    assertEquals("F", ResidueProperties.codonTranslate("TTT"));
+    assertEquals("F", ResidueProperties.codonTranslate("TTC"));
+    assertEquals("L", ResidueProperties.codonTranslate("TTA"));
+    assertEquals("L", ResidueProperties.codonTranslate("TTG"));
+    assertEquals("L", ResidueProperties.codonTranslate("CTT"));
+    assertEquals("L", ResidueProperties.codonTranslate("CTC"));
+    assertEquals("L", ResidueProperties.codonTranslate("CTA"));
+    assertEquals("L", ResidueProperties.codonTranslate("CTG"));
+    assertEquals("I", ResidueProperties.codonTranslate("ATT"));
+    assertEquals("I", ResidueProperties.codonTranslate("ATC"));
+    assertEquals("I", ResidueProperties.codonTranslate("ATA"));
+    assertEquals("M", ResidueProperties.codonTranslate("ATG"));
+    assertEquals("V", ResidueProperties.codonTranslate("GTT"));
+    assertEquals("V", ResidueProperties.codonTranslate("GTC"));
+    assertEquals("V", ResidueProperties.codonTranslate("GTA"));
+    assertEquals("V", ResidueProperties.codonTranslate("GTG"));
+    assertEquals("S", ResidueProperties.codonTranslate("TCT"));
+    assertEquals("S", ResidueProperties.codonTranslate("TCC"));
+    assertEquals("S", ResidueProperties.codonTranslate("TCA"));
+    assertEquals("S", ResidueProperties.codonTranslate("TCG"));
+    assertEquals("P", ResidueProperties.codonTranslate("CCT"));
+    assertEquals("P", ResidueProperties.codonTranslate("CCC"));
+    assertEquals("P", ResidueProperties.codonTranslate("CCA"));
+    assertEquals("P", ResidueProperties.codonTranslate("CCG"));
+    assertEquals("T", ResidueProperties.codonTranslate("ACT"));
+    assertEquals("T", ResidueProperties.codonTranslate("ACC"));
+    assertEquals("T", ResidueProperties.codonTranslate("ACA"));
+    assertEquals("T", ResidueProperties.codonTranslate("ACG"));
+    assertEquals("A", ResidueProperties.codonTranslate("GCT"));
+    assertEquals("A", ResidueProperties.codonTranslate("GCC"));
+    assertEquals("A", ResidueProperties.codonTranslate("GCA"));
+    assertEquals("A", ResidueProperties.codonTranslate("GCG"));
+    assertEquals("Y", ResidueProperties.codonTranslate("TAT"));
+    assertEquals("Y", ResidueProperties.codonTranslate("TAC"));
+    assertEquals("STOP", ResidueProperties.codonTranslate("TAA"));
+    assertEquals("STOP", ResidueProperties.codonTranslate("TAG"));
+    assertEquals("H", ResidueProperties.codonTranslate("CAT"));
+    assertEquals("H", ResidueProperties.codonTranslate("CAC"));
+    assertEquals("Q", ResidueProperties.codonTranslate("CAA"));
+    assertEquals("Q", ResidueProperties.codonTranslate("CAG"));
+    assertEquals("N", ResidueProperties.codonTranslate("AAT"));
+    assertEquals("N", ResidueProperties.codonTranslate("AAC"));
+    assertEquals("K", ResidueProperties.codonTranslate("AAA"));
+    assertEquals("K", ResidueProperties.codonTranslate("AAG"));
+    assertEquals("D", ResidueProperties.codonTranslate("GAT"));
+    assertEquals("D", ResidueProperties.codonTranslate("GAC"));
+    assertEquals("E", ResidueProperties.codonTranslate("GAA"));
+    assertEquals("E", ResidueProperties.codonTranslate("GAG"));
+    assertEquals("C", ResidueProperties.codonTranslate("TGT"));
+    assertEquals("C", ResidueProperties.codonTranslate("TGC"));
+    assertEquals("STOP", ResidueProperties.codonTranslate("TGA"));
+    assertEquals("W", ResidueProperties.codonTranslate("TGG"));
+    assertEquals("R", ResidueProperties.codonTranslate("CGT"));
+    assertEquals("R", ResidueProperties.codonTranslate("CGC"));
+    assertEquals("R", ResidueProperties.codonTranslate("CGA"));
+    assertEquals("R", ResidueProperties.codonTranslate("CGG"));
+    assertEquals("S", ResidueProperties.codonTranslate("AGT"));
+    assertEquals("S", ResidueProperties.codonTranslate("AGC"));
+    assertEquals("R", ResidueProperties.codonTranslate("AGA"));
+    assertEquals("R", ResidueProperties.codonTranslate("AGG"));
+    assertEquals("G", ResidueProperties.codonTranslate("GGT"));
+    assertEquals("G", ResidueProperties.codonTranslate("GGC"));
+    assertEquals("G", ResidueProperties.codonTranslate("GGA"));
+    assertEquals("G", ResidueProperties.codonTranslate("GGG"));
+  }
+
+  /**
+   * Test a sample of codon translations involving ambiguity codes. Should
+   * return a protein value where the ambiguity does not affect the translation.
+   */
+  @Test
+  public void testCodonTranslate_ambiguityCodes()
+  {
+    // Y is C or T
+    assertEquals("C", ResidueProperties.codonTranslate("TGY"));
+    assertEquals("L", ResidueProperties.codonTranslate("YTA"));
+
+    // W is A or T
+    assertEquals("L", ResidueProperties.codonTranslate("CTW"));
+    assertNull(ResidueProperties.codonTranslate("TTW"));
+
+    // S is G or C
+    assertEquals("G", ResidueProperties.codonTranslate("GGS"));
+    assertNull(ResidueProperties.codonTranslate("ATS"));
+
+    // K is T or G
+    assertEquals("S", ResidueProperties.codonTranslate("TCS"));
+    assertNull(ResidueProperties.codonTranslate("ATK"));
+
+    // M is C or A
+    assertEquals("T", ResidueProperties.codonTranslate("ACM"));
+    assertNull(ResidueProperties.codonTranslate("TAM"));
+
+    // D is A, G or T
+    assertEquals("P", ResidueProperties.codonTranslate("CCD"));
+    assertNull(ResidueProperties.codonTranslate("AAD"));
+
+    // V is A, C or G
+    assertEquals("V", ResidueProperties.codonTranslate("GTV"));
+    assertNull(ResidueProperties.codonTranslate("TTV"));
+
+    // H is A, C or T
+    assertEquals("A", ResidueProperties.codonTranslate("GCH"));
+    assertEquals("I", ResidueProperties.codonTranslate("ATH"));
+    assertNull(ResidueProperties.codonTranslate("AGH"));
+
+    // B is C, G or T
+    assertEquals("P", ResidueProperties.codonTranslate("CCB"));
+    assertNull(ResidueProperties.codonTranslate("TAB"));
+
+    // R is A or G
+    assertEquals("R", ResidueProperties.codonTranslate("AGR"));
+    assertEquals("STOP", ResidueProperties.codonTranslate("TAR"));
+    assertEquals("STOP", ResidueProperties.codonTranslate("TRA"));
+    assertNull(ResidueProperties.codonTranslate("ATR"));
+
+  }
+}