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