--- /dev/null
+package jalview.analysis;
+
+import static org.junit.Assert.assertEquals;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.io.FormatAdapter;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class DnaTest
+{
+ // AA encoding codons as ordered on the Jalview help page Amino Acid Table
+ private static String fasta = ">B\n" + "GCT" + "GCC" + "GCA" + "GCG"
+ + "TGT" + "TGC" + "GAT" + "GAC" + "GAA" + "GAG" + "TTT" + "TTC"
+ + "GGT" + "GGC" + "GGA" + "GGG" + "CAT" + "CAC" + "ATT" + "ATC"
+ + "ATA" + "AAA" + "AAG" + "TTG" + "TTA" + "CTT" + "CTC" + "CTA"
+ + "CTG" + "ATG" + "AAT" + "AAC" + "CCT" + "CCC" + "CCA" + "CCG"
+ + "CAA" + "CAG" + "CGT" + "CGC" + "CGA" + "CGG" + "AGA" + "AGG"
+ + "TCT" + "TCC" + "TCA" + "TCG" + "AGT" + "AGC" + "ACT" + "ACC"
+ + "ACA" + "ACG" + "GTT" + "GTC" + "GTA" + "GTG" + "TGG" + "TAT"
+ + "TAC" + "TAA" + "TAG" + "TGA";
+
+ /**
+ * Test simple translation to Amino Acids (with STOP codons translated to X).
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCdnaTranslate_simple() throws IOException
+ {
+ AlignmentI alf = new FormatAdapter().readFile(fasta,
+ FormatAdapter.PASTE, "FASTA");
+ final String sequenceAsString = alf
+ .getSequenceAt(0).getSequenceAsString();
+ AlignmentI translated = Dna.CdnaTranslate(alf.getSequencesArray(),
+ new String[]
+ { sequenceAsString }, new int[]
+ { 0, alf.getWidth() - 1 }, alf.getGapCharacter(), null,
+ alf.getWidth(), null);
+ String aa = translated.getSequenceAt(0).getSequenceAsString();
+ assertEquals(
+ "AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYYXXX",
+ aa);
+ }
+
+ /**
+ * Test translation excluding hidden columns.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCdnaTranslate_hiddenColumns() throws IOException
+ {
+ AlignmentI alf = new FormatAdapter().readFile(fasta,
+ FormatAdapter.PASTE, "FASTA");
+ ColumnSelection cs = new jalview.datamodel.ColumnSelection();
+ cs.hideColumns(6, 14); // hide codons 3/4/5
+ cs.hideColumns(24, 35); // hide codons 9-12
+ cs.hideColumns(177, 191); // hide codons 60-64
+ AlignmentI translated = Dna.CdnaTranslate(alf.getSequencesArray(),
+ cs.getVisibleSequenceStrings(0, alf.getWidth(),
+ alf.getSequencesArray()), new int[]
+ { 0, alf.getWidth() - 1 }, alf.getGapCharacter(), null,
+ alf.getWidth(), null);
+ String aa = translated.getSequenceAt(0).getSequenceAsString();
+ assertEquals("AACDDGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVW", aa);
+ }
+}