JAL-1312 formatting and more comprehensive test
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 17 Jun 2013 14:10:22 +0000 (15:10 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 17 Jun 2013 14:10:22 +0000 (15:10 +0100)
test/jalview/analysis/DnaTranslation.java

index a58131c..d29ee15 100644 (file)
@@ -13,86 +13,114 @@ 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";
+  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());
-      }
+  public void translationWithUntranslatableCodonsTest()
+  {
+    // Corner case for this test is the presence of codons after codons that
+    // were not translated.
+    jalview.datamodel.AlignmentI alf = null;
+    try
+    {
+      alf = new jalview.io.FormatAdapter().readFile(JAL_1312_example_align_fasta,
+              jalview.io.FormatAdapter.PASTE, "FASTA");
     } catch (IOException x)
     {
       x.printStackTrace();
-      fail("Unexpected IOException ("+x.getMessage()+") - check test environment");
+      fail("Unexpected IOException (" + x.getMessage()
+              + ") - check test environment");
     }
-  }
+    {
+      // full translation
+      ColumnSelection cs = new jalview.datamodel.ColumnSelection();
+      assertNotNull("Couldn't do a full width translation of test data.",
+              jalview.analysis.Dna.CdnaTranslate(
+                      alf.getSequencesArray(),
+                      cs.getVisibleSequenceStrings(0, alf.getWidth(),
+                              alf.getSequencesArray()), new int[]
+                      { 0, alf.getWidth() - 1 }, alf.getGapCharacter(),
+                      null, alf.getWidth(), null));
+    }
+    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());
+    }
+
+  }
 }