test for JAL-1312
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 17 Jun 2013 09:21:32 +0000 (10:21 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 17 Jun 2013 09:21:32 +0000 (10:21 +0100)
test/jalview/analysis/DnaTranslation.java [new file with mode: 0644]

diff --git a/test/jalview/analysis/DnaTranslation.java b/test/jalview/analysis/DnaTranslation.java
new file mode 100644 (file)
index 0000000..a58131c
--- /dev/null
@@ -0,0 +1,98 @@
+package jalview.analysis;
+
+import static org.junit.Assert.*;
+import jalview.datamodel.ColumnSelection;
+
+import java.io.IOException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+public class DnaTranslation
+{
+
+  private static String JAL_1312_example_align_fasta =
+          ">B.FR.83.HXB2_LAI_IIIB_BRU_K03455/45-306\n"
+                  +"ATGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATACTGGGACA\n"
+                  +"GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAGATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAC\n"
+                  +">gi|27804621|gb|AY178912.1|/1-259\n"
+                  +"-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGGACA\n"
+                  +"GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTTCATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAT\n"
+                  +">gi|27804623|gb|AY178913.1|/1-259\n"
+                  +"-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGAACA\n"
+                  +"GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTTCATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
+                  +">gi|27804627|gb|AY178915.1|/1-260\n"
+                  +"-TGGGAAAA-ATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTCGCAGTTAACCCTGGCCTGTTAGAAACATCAGAAGGTTGTAGACAAATATTGGGACA\n"
+                  +"GCTACAACCATCCCTTGAGACAGGATCAGAAGAACTTAAATCATTATWTAATACCATAGCAGTCCTCTATTG\n"
+                  +"TGTACATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAG\n"
+                  +">gi|27804631|gb|AY178917.1|/1-261\n"
+                  +"-TGGGAAAAAATTCGGTTGAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACACCAGAAGGCTGTAGACAAATACTGGGACA\n"
+                  +"GCTACAACCGTCCCTTCAGACAGGATCGGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTGCATCAAAGGATAGATGTAAAAGACACCAAGGAGGCTTTAGAC\n"
+                  +">gi|27804635|gb|AY178919.1|/1-261\n"
+                  +"-TGGGAGAGAATTCGGTTACGGCCAGGAGGAAAGAAAAAATATAAATTGAAACATATAGTATGGGCAGGCAG\n"
+                  +"AGAGCTAGATCGATTCGCAGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAGATATTGGGACA\n"
+                  +"GCTACAACCGTCCCTTAAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTACATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
+                  +">gi|27804641|gb|AY178922.1|/1-261\n"
+                  +"-TGGGAGAAAATTCGGTTACGGCCAGGGGGAAAGAAAAGATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAAATACTGGGACA\n"
+                  +"GTTACACCCATCCCTTCATACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTGCATCAAAGGATAGAAGTAAAAGACACCAAGGAAGCTTTAGAC\n"
+                  +">gi|27804647|gb|AY178925.1|/1-261\n"
+                  +"-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATCAATTAAAACATGTAGTATGGGCAAGCAG\n"
+                  +"GGAACTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
+                  +"GCTACAACCATCCCTTCAGACAGGATCAGAGGAACTTAAATCATTATTTAATACAGTAGCAGTCCTCTATTG\n"
+                  +"TGTACATCAAAGAATAGATGTAAAAGACACCAAGGAAGCTCTAGAA\n"
+                  +">gi|27804649|gb|AY178926.1|/1-261\n"
+                  +"-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTCGCGGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAACTACTGGGACA\n"
+                  +"GTTACAACCATCCCTTCAGACAGGATCAGAAGAACTCAAATCATTATATAATACAATAGCAACCCTCTATTG\n"
+                  +"TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCCTTAGAT\n"
+                  +">gi|27804653|gb|AY178928.1|/1-261\n"
+                  +"-TGGGAAAGAATTCGGTTAAGGCCAGGGGGAAAGAAACAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGACCGATTCGCACTTAACCCCGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
+                  +"GCTACAATCGTCCCTTCAGACAGGATCAGAAGAACTTAGATCACTATATAATACAGTAGCAGTCCTCTATTG\n"
+                  +"TGTGCATCAAAAGATAGATGTAAAAGACACCAAGGAAGCCTTAGAC\n"
+                  +">gi|27804659|gb|AY178931.1|/1-261\n"
+                  +"-TGGGAAAAAATTCGGTTACGGCCAGGAGGAAAGAAAAGATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+                  +"GGAGCTAGAACGATTYGCAGTTAATCCTGGCCTTTTAGAAACAGCAGAAGGCTGTAGACAAATACTGGGACA\n"
+                  +"GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+                  +"TGTACATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAA\n";
+  @Test
+  public void translationWithUntranslatableCodonsTest() {
+    // Corner case for this test is the presence of codons after codons that were not translated.
+    try {
+      jalview.datamodel.AlignmentI alf = new jalview.io.FormatAdapter().readFile(JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE, "FASTA");
+      int vwidth=15; // translate in 15 base stretches
+      for (int ipos=0;ipos+vwidth<alf.getWidth();ipos+=vwidth) {
+        ColumnSelection cs = new jalview.datamodel.ColumnSelection();
+        if (ipos>0) { cs.hideColumns(0,ipos-1); }
+        cs.hideColumns(ipos+vwidth,alf.getWidth());
+        int[] vcontigs = cs.getVisibleContigs(0, alf.getWidth());
+        String[] sel = cs.getVisibleSequenceStrings(0, alf.getWidth(), alf.getSequencesArray());
+      jalview.datamodel.AlignmentI transAlf = jalview.analysis.Dna.CdnaTranslate(alf.getSequencesArray(), sel,
+              vcontigs, alf.getGapCharacter(),null, alf.getWidth(), null);
+              
+      assertTrue("Translation failed (ipos="+ipos+") No alignment data.",transAlf!=null);
+      assertTrue("Translation failed (ipos="+ipos+") Empty algnment.",transAlf.getHeight()>0);
+      assertTrue("Translation failed (ipos="+ipos+") Translated "+transAlf.getHeight()+" sequences from "+alf.getHeight()+" sequences",alf.getHeight()==transAlf.getHeight());
+      }
+    } catch (IOException x)
+    {
+      x.printStackTrace();
+      fail("Unexpected IOException ("+x.getMessage()+") - check test environment");
+    }
+  }
+
+}