From 4db713f772ee30861f368dcea9f306b987ad01d2 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 16 Dec 2014 10:47:48 +0000 Subject: [PATCH] JAL-845 first simple unit tests added --- test/jalview/analysis/DnaTest.java | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/jalview/analysis/DnaTest.java diff --git a/test/jalview/analysis/DnaTest.java b/test/jalview/analysis/DnaTest.java new file mode 100644 index 0000000..b1ce141 --- /dev/null +++ b/test/jalview/analysis/DnaTest.java @@ -0,0 +1,70 @@ +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); + } +} -- 1.7.10.2