From: gmungoc Date: Tue, 20 Jan 2015 09:46:30 +0000 (+0000) Subject: JAL-1619 test that reordering cDNA does not change translation results X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e06580cb9fa7255844392883e96d5f9cbc680ec1;p=jalview.git JAL-1619 test that reordering cDNA does not change translation results --- diff --git a/test/jalview/analysis/DnaTest.java b/test/jalview/analysis/DnaTest.java index 43ee5f2..59938ae 100644 --- a/test/jalview/analysis/DnaTest.java +++ b/test/jalview/analysis/DnaTest.java @@ -5,8 +5,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import jalview.api.AlignViewportI; import jalview.datamodel.AlignedCodon; +import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; import jalview.io.FormatAdapter; @@ -252,6 +254,61 @@ public class DnaTest } /** + * This test generates a random cDNA alignment and its translation, then + * reorders the cDNA and retranslates, and verifies that the translations are + * the same (apart from ordering). + */ + @Test + public void testTranslateCdna_sequenceOrderIndependent() + { + /* + * Generate cDNA - 8 sequences of 12 bases each. + */ + AlignmentI cdna = new DnaAlignmentGenerator().generate(12, 8, 97); + ColumnSelection cs = new ColumnSelection(); + AlignViewportI av = new AlignViewport(cdna, cs); + Dna dna = new Dna(av, new int[] + { 0, cdna.getWidth() - 1 }); + AlignmentI translated = dna.translateCdna(); + + /* + * Jumble the cDNA sequences and translate. + */ + SequenceI[] sorted = new SequenceI[cdna.getHeight()]; + final int[] jumbler = new int[] + { 6, 7, 3, 4, 2, 0, 1, 5 }; + int seqNo = 0; + for (int i : jumbler) + { + sorted[seqNo++] = cdna.getSequenceAt(i); + } + AlignmentI cdnaReordered = new Alignment(sorted); + av = new AlignViewport(cdnaReordered, cs); + dna = new Dna(av, new int[] + { 0, cdna.getWidth() - 1 }); + AlignmentI translated2 = dna.translateCdna(); + + /* + * Check translated sequences are the same in both alignments. + */ + System.out.println("Original"); + System.out.println(translated.toString()); + System.out.println("Sorted"); + System.out.println(translated2.toString()); + + int sortedSequenceIndex = 0; + for (int originalSequenceIndex : jumbler) + { + final String translation1 = translated.getSequenceAt( + originalSequenceIndex).getSequenceAsString(); + final String translation2 = translated2.getSequenceAt(sortedSequenceIndex) + .getSequenceAsString(); + assertEquals(translation2, translation1); + sortedSequenceIndex++; + } + } + + /** * Test that all the cases in testCompareCodonPos have a 'symmetric' * comparison (without checking the actual comparison result). */