8f878f0e25228856ccacb84f3adbabca435f69ba
[jalview.git] / test / jalview / analysis / DnaTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.analysis;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignedCodon;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.AlignViewport;
34 import jalview.io.FormatAdapter;
35
36 import java.io.IOException;
37
38 import org.testng.annotations.Test;
39
40 public class DnaTest
41 {
42   // @formatter:off
43   // AA encoding codons as ordered on the Jalview help page Amino Acid Table
44   private static String fasta = ">B\n" + "GCT" + "GCC" + "GCA" + "GCG"
45           + "TGT" + "TGC" + "GAT" + "GAC" + "GAA" + "GAG" + "TTT" + "TTC"
46           + "GGT" + "GGC" + "GGA" + "GGG" + "CAT" + "CAC" + "ATT" + "ATC"
47           + "ATA" + "AAA" + "AAG" + "TTG" + "TTA" + "CTT" + "CTC" + "CTA"
48           + "CTG" + "ATG" + "AAT" + "AAC" + "CCT" + "CCC" + "CCA" + "CCG"
49           + "CAA" + "CAG" + "CGT" + "CGC" + "CGA" + "CGG" + "AGA" + "AGG"
50           + "TCT" + "TCC" + "TCA" + "TCG" + "AGT" + "AGC" + "ACT" + "ACC"
51           + "ACA" + "ACG" + "GTT" + "GTC" + "GTA" + "GTG" + "TGG" + "TAT"
52           + "TAC" + "TAA" + "TAG" + "TGA";
53
54   private static String JAL_1312_example_align_fasta = ">B.FR.83.HXB2_LAI_IIIB_BRU_K03455/45-306\n"
55           + "ATGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
56           + "GGAGCTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATACTGGGACA\n"
57           + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAGATCATTATATAATACAGTAGCAACCCTCTATTG\n"
58           + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAC\n"
59           + ">gi|27804621|gb|AY178912.1|/1-259\n"
60           + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
61           + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGGACA\n"
62           + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
63           + "TGTTCATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAT\n"
64           + ">gi|27804623|gb|AY178913.1|/1-259\n"
65           + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
66           + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGAACA\n"
67           + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
68           + "TGTTCATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
69           + ">gi|27804627|gb|AY178915.1|/1-260\n"
70           + "-TGGGAAAA-ATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
71           + "GGAGCTAGAACGATTCGCAGTTAACCCTGGCCTGTTAGAAACATCAGAAGGTTGTAGACAAATATTGGGACA\n"
72           + "GCTACAACCATCCCTTGAGACAGGATCAGAAGAACTTAAATCATTATWTAATACCATAGCAGTCCTCTATTG\n"
73           + "TGTACATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAG\n"
74           + ">gi|27804631|gb|AY178917.1|/1-261\n"
75           + "-TGGGAAAAAATTCGGTTGAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
76           + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACACCAGAAGGCTGTAGACAAATACTGGGACA\n"
77           + "GCTACAACCGTCCCTTCAGACAGGATCGGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
78           + "TGTGCATCAAAGGATAGATGTAAAAGACACCAAGGAGGCTTTAGAC\n"
79           + ">gi|27804635|gb|AY178919.1|/1-261\n"
80           + "-TGGGAGAGAATTCGGTTACGGCCAGGAGGAAAGAAAAAATATAAATTGAAACATATAGTATGGGCAGGCAG\n"
81           + "AGAGCTAGATCGATTCGCAGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAGATATTGGGACA\n"
82           + "GCTACAACCGTCCCTTAAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
83           + "TGTACATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
84           + ">gi|27804641|gb|AY178922.1|/1-261\n"
85           + "-TGGGAGAAAATTCGGTTACGGCCAGGGGGAAAGAAAAGATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
86           + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAAATACTGGGACA\n"
87           + "GTTACACCCATCCCTTCATACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
88           + "TGTGCATCAAAGGATAGAAGTAAAAGACACCAAGGAAGCTTTAGAC\n"
89           + ">gi|27804647|gb|AY178925.1|/1-261\n"
90           + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATCAATTAAAACATGTAGTATGGGCAAGCAG\n"
91           + "GGAACTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
92           + "GCTACAACCATCCCTTCAGACAGGATCAGAGGAACTTAAATCATTATTTAATACAGTAGCAGTCCTCTATTG\n"
93           + "TGTACATCAAAGAATAGATGTAAAAGACACCAAGGAAGCTCTAGAA\n"
94           + ">gi|27804649|gb|AY178926.1|/1-261\n"
95           + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
96           + "GGAGCTAGAACGATTCGCGGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAACTACTGGGACA\n"
97           + "GTTACAACCATCCCTTCAGACAGGATCAGAAGAACTCAAATCATTATATAATACAATAGCAACCCTCTATTG\n"
98           + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCCTTAGAT\n"
99           + ">gi|27804653|gb|AY178928.1|/1-261\n"
100           + "-TGGGAAAGAATTCGGTTAAGGCCAGGGGGAAAGAAACAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
101           + "GGAGCTAGACCGATTCGCACTTAACCCCGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
102           + "GCTACAATCGTCCCTTCAGACAGGATCAGAAGAACTTAGATCACTATATAATACAGTAGCAGTCCTCTATTG\n"
103           + "TGTGCATCAAAAGATAGATGTAAAAGACACCAAGGAAGCCTTAGAC\n"
104           + ">gi|27804659|gb|AY178931.1|/1-261\n"
105           + "-TGGGAAAAAATTCGGTTACGGCCAGGAGGAAAGAAAAGATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
106           + "GGAGCTAGAACGATTYGCAGTTAATCCTGGCCTTTTAGAAACAGCAGAAGGCTGTAGACAAATACTGGGACA\n"
107           + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
108           + "TGTACATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAA\n";
109   // @formatter:on
110
111   /**
112    * Corner case for this test is the presence of codons after codons that were
113    * not translated.
114    * 
115    * @throws IOException
116    */
117   @Test(groups = { "Functional" })
118   public void testTranslateCdna_withUntranslatableCodons()
119           throws IOException
120   {
121     AlignmentI alf = new FormatAdapter().readFile(
122             JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
123             "FASTA");
124     ColumnSelection cs = new ColumnSelection();
125     AlignViewportI av = new AlignViewport(alf, cs);
126     Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 });
127     AlignmentI translated = dna.translateCdna();
128     assertNotNull("Couldn't do a full width translation of test data.",
129             translated);
130   }
131
132   /**
133    * Test variant in which 15 column blocks at a time are translated (the rest
134    * hidden).
135    * 
136    * @throws IOException
137    */
138   @Test(groups = { "Functional" })
139   public void testTranslateCdna_withUntranslatableCodonsAndHiddenColumns()
140           throws IOException
141   {
142     AlignmentI alf = new FormatAdapter().readFile(
143             JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
144             "FASTA");
145     int vwidth = 15;
146     for (int ipos = 0; ipos + vwidth < alf.getWidth(); ipos += vwidth)
147     {
148       ColumnSelection cs = new ColumnSelection();
149       if (ipos > 0)
150       {
151         cs.hideColumns(0, ipos - 1);
152       }
153       cs.hideColumns(ipos + vwidth, alf.getWidth());
154       int[] vcontigs = cs.getVisibleContigs(0, alf.getWidth());
155       AlignViewportI av = new AlignViewport(alf, cs);
156       Dna dna = new Dna(av, vcontigs);
157       AlignmentI transAlf = dna.translateCdna();
158
159       assertTrue("Translation failed (ipos=" + ipos
160               + ") No alignment data.", transAlf != null);
161       assertTrue("Translation failed (ipos=" + ipos + ") Empty alignment.",
162               transAlf.getHeight() > 0);
163       assertTrue("Translation failed (ipos=" + ipos + ") Translated "
164               + transAlf.getHeight() + " sequences from " + alf.getHeight()
165               + " sequences", alf.getHeight() == transAlf.getHeight());
166     }
167   }
168
169   /**
170    * Test simple translation to Amino Acids (with STOP codons translated to *).
171    * 
172    * @throws IOException
173    */
174   @Test(groups = { "Functional" })
175   public void testTranslateCdna_simple() throws IOException
176   {
177     AlignmentI alf = new FormatAdapter().readFile(fasta,
178             FormatAdapter.PASTE, "FASTA");
179     ColumnSelection cs = new ColumnSelection();
180     AlignViewportI av = new AlignViewport(alf, cs);
181     Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 });
182     AlignmentI translated = dna.translateCdna();
183     String aa = translated.getSequenceAt(0).getSequenceAsString();
184     assertEquals(
185             "AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYY***",
186             aa);
187   }
188
189   /**
190    * Test translation excluding hidden columns.
191    * 
192    * @throws IOException
193    */
194   @Test(groups = { "Functional" })
195   public void testTranslateCdna_hiddenColumns() throws IOException
196   {
197     AlignmentI alf = new FormatAdapter().readFile(fasta,
198             FormatAdapter.PASTE, "FASTA");
199     ColumnSelection cs = new jalview.datamodel.ColumnSelection();
200     cs.hideColumns(6, 14); // hide codons 3/4/5
201     cs.hideColumns(24, 35); // hide codons 9-12
202     cs.hideColumns(177, 191); // hide codons 60-64
203     AlignViewportI av = new AlignViewport(alf, cs);
204     Dna dna = new Dna(av, new int[] { 0, alf.getWidth() - 1 });
205     AlignmentI translated = dna.translateCdna();
206     String aa = translated.getSequenceAt(0).getSequenceAsString();
207     assertEquals("AACDDGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVW", aa);
208   }
209
210   /**
211    * Use this test to help debug into any cases of interest.
212    */
213   @Test(groups = { "Functional" })
214   public void testCompareCodonPos_oneOnly()
215   {
216     assertFollows("-AA--A", "G--GG"); // 2 shifted seq2, 3 shifted seq1
217   }
218
219   /**
220    * Tests for method that compares 'alignment' of two codon position triplets.
221    */
222   @Test(groups = { "Functional" })
223   public void testCompareCodonPos()
224   {
225     /*
226      * Returns 0 for any null argument
227      */
228     assertEquals(0, Dna.compareCodonPos(new AlignedCodon(1, 2, 3), null));
229     assertEquals(0, Dna.compareCodonPos(null, new AlignedCodon(1, 2, 3)));
230
231     /*
232      * Work through 27 combinations. First 9 cases where first position matches.
233      */
234     assertMatches("AAA", "GGG"); // 2 and 3 match
235     assertFollows("AA-A", "GGG"); // 2 matches, 3 shifted seq1
236     assertPrecedes("AAA", "GG-G"); // 2 matches, 3 shifted seq2
237     assertFollows("A-AA", "GG-G"); // 2 shifted seq1, 3 matches
238     assertFollows("A-A-A", "GG-G"); // 2 shifted seq1, 3 shifted seq1
239     assertPrecedes("A-AA", "GG--G"); // 2 shifted seq1, 3 shifted seq2
240     assertPrecedes("AA-A", "G-GG"); // 2 shifted seq2, 3 matches
241     assertFollows("AA--A", "G-GG"); // 2 shifted seq2, 3 shifted seq1
242     assertPrecedes("AAA", "G-GG"); // 2 shifted seq2, 3 shifted seq2
243
244     /*
245      * 9 cases where first position is shifted in first sequence.
246      */
247     assertFollows("-AAA", "G-GG"); // 2 and 3 match
248     assertFollows("-AA-A", "G-GG"); // 2 matches, 3 shifted seq1
249     // 'enclosing' case: pick first to start precedes
250     assertFollows("-AAA", "G-G-G"); // 2 matches, 3 shifted seq2
251     assertFollows("-A-AA", "G-G-G"); // 2 shifted seq1, 3 matches
252     assertFollows("-A-A-A", "G-G-G"); // 2 shifted seq1, 3 shifted seq1
253     // 'enclosing' case: pick first to start precedes
254     assertFollows("-A-AA", "G-G--G"); // 2 shifted seq1, 3 shifted seq2
255     assertFollows("-AA-A", "G--GG"); // 2 shifted seq2, 3 matches
256     assertFollows("-AA--A", "G--GG"); // 2 shifted seq2, 3 shifted seq1
257     assertPrecedes("-AAA", "G--GG"); // 2 shifted seq2, 3 shifted seq2
258
259     /*
260      * 9 cases where first position is shifted in second sequence.
261      */
262     assertPrecedes("A-AA", "-GGG"); // 2 and 3 match
263     assertPrecedes("A-A-A", "-GGG"); // 2 matches, 3 shifted seq1
264     assertPrecedes("A-AA", "-GG-G"); // 2 matches, 3 shifted seq2
265     assertPrecedes("A--AA", "-GG-G"); // 2 shifted seq1, 3 matches
266     // 'enclosing' case with middle base deciding:
267     assertFollows("A--AA", "-GGG"); // 2 shifted seq1, 3 shifted seq1
268     assertPrecedes("A--AA", "-GG--G"); // 2 shifted seq1, 3 shifted seq2
269     assertPrecedes("AA-A", "-GGG"); // 2 shifted seq2, 3 matches
270     assertPrecedes("AA--A", "-GGG"); // 2 shifted seq2, 3 shifted seq1
271     assertPrecedes("AAA", "-GGG"); // 2 shifted seq2, 3 shifted seq2
272   }
273
274   /**
275    * This test generates a random cDNA alignment and its translation, then
276    * reorders the cDNA and retranslates, and verifies that the translations are
277    * the same (apart from ordering).
278    */
279   @Test(groups = { "Functional" })
280   public void testTranslateCdna_sequenceOrderIndependent()
281   {
282     /*
283      * Generate cDNA - 8 sequences of 12 bases each.
284      */
285     AlignmentI cdna = new DnaAlignmentGenerator().generate(12, 8, 97, 5, 5);
286     ColumnSelection cs = new ColumnSelection();
287     AlignViewportI av = new AlignViewport(cdna, cs);
288     Dna dna = new Dna(av, new int[] { 0, cdna.getWidth() - 1 });
289     AlignmentI translated = dna.translateCdna();
290
291     /*
292      * Jumble the cDNA sequences and translate.
293      */
294     SequenceI[] sorted = new SequenceI[cdna.getHeight()];
295     final int[] jumbler = new int[] { 6, 7, 3, 4, 2, 0, 1, 5 };
296     int seqNo = 0;
297     for (int i : jumbler)
298     {
299       sorted[seqNo++] = cdna.getSequenceAt(i);
300     }
301     AlignmentI cdnaReordered = new Alignment(sorted);
302     av = new AlignViewport(cdnaReordered, cs);
303     dna = new Dna(av, new int[] { 0, cdna.getWidth() - 1 });
304     AlignmentI translated2 = dna.translateCdna();
305
306     /*
307      * Check translated sequences are the same in both alignments.
308      */
309     System.out.println("Original");
310     System.out.println(translated.toString());
311     System.out.println("Sorted");
312     System.out.println(translated2.toString());
313
314     int sortedSequenceIndex = 0;
315     for (int originalSequenceIndex : jumbler)
316     {
317       final String translation1 = translated.getSequenceAt(
318               originalSequenceIndex).getSequenceAsString();
319       final String translation2 = translated2.getSequenceAt(
320               sortedSequenceIndex).getSequenceAsString();
321       assertEquals(translation2, translation1);
322       sortedSequenceIndex++;
323     }
324   }
325
326   /**
327    * Test that all the cases in testCompareCodonPos have a 'symmetric'
328    * comparison (without checking the actual comparison result).
329    */
330   @Test(groups = { "Functional" })
331   public void testCompareCodonPos_isSymmetric()
332   {
333     assertSymmetric("AAA", "GGG");
334     assertSymmetric("AA-A", "GGG");
335     assertSymmetric("AAA", "GG-G");
336     assertSymmetric("A-AA", "GG-G");
337     assertSymmetric("A-A-A", "GG-G");
338     assertSymmetric("A-AA", "GG--G");
339     assertSymmetric("AA-A", "G-GG");
340     assertSymmetric("AA--A", "G-GG");
341     assertSymmetric("AAA", "G-GG");
342     assertSymmetric("-AAA", "G-GG");
343     assertSymmetric("-AA-A", "G-GG");
344     assertSymmetric("-AAA", "G-G-G");
345     assertSymmetric("-A-AA", "G-G-G");
346     assertSymmetric("-A-A-A", "G-G-G");
347     assertSymmetric("-A-AA", "G-G--G");
348     assertSymmetric("-AA-A", "G--GG");
349     assertSymmetric("-AA--A", "G--GG");
350     assertSymmetric("-AAA", "G--GG");
351     assertSymmetric("A-AA", "-GGG");
352     assertSymmetric("A-A-A", "-GGG");
353     assertSymmetric("A-AA", "-GG-G");
354     assertSymmetric("A--AA", "-GG-G");
355     assertSymmetric("A--AA", "-GGG");
356     assertSymmetric("A--AA", "-GG--G");
357     assertSymmetric("AA-A", "-GGG");
358     assertSymmetric("AA--A", "-GGG");
359     assertSymmetric("AAA", "-GGG");
360   }
361
362   private void assertSymmetric(String codon1, String codon2)
363   {
364     assertEquals("Comparison of '" + codon1 + "' and '" + codon2
365             + " not symmetric", Integer.signum(compare(codon1, codon2)),
366             -Integer.signum(compare(codon2, codon1)));
367   }
368
369   /**
370    * Assert that the first sequence should map to the same position as the
371    * second in a translated alignment. Also checks that this is true if the
372    * order of the codons is reversed.
373    * 
374    * @param codon1
375    * @param codon2
376    */
377   private void assertMatches(String codon1, String codon2)
378   {
379     assertEquals("Expected '" + codon1 + "' matches '" + codon2 + "'", 0,
380             compare(codon1, codon2));
381     assertEquals("Expected '" + codon2 + "' matches '" + codon1 + "'", 0,
382             compare(codon2, codon1));
383   }
384
385   /**
386    * Assert that the first sequence should precede the second in a translated
387    * alignment
388    * 
389    * @param codon1
390    * @param codon2
391    */
392   private void assertPrecedes(String codon1, String codon2)
393   {
394     assertEquals("Expected '" + codon1 + "'  precedes '" + codon2 + "'",
395             -1, compare(codon1, codon2));
396   }
397
398   /**
399    * Assert that the first sequence should follow the second in a translated
400    * alignment
401    * 
402    * @param codon1
403    * @param codon2
404    */
405   private void assertFollows(String codon1, String codon2)
406   {
407     assertEquals("Expected '" + codon1 + "'  follows '" + codon2 + "'", 1,
408             compare(codon1, codon2));
409   }
410
411   /**
412    * Convert two nucleotide strings to base positions and pass to
413    * Dna.compareCodonPos, return the result.
414    * 
415    * @param s1
416    * @param s2
417    * @return
418    */
419   private int compare(String s1, String s2)
420   {
421     final AlignedCodon cd1 = convertCodon(s1);
422     final AlignedCodon cd2 = convertCodon(s2);
423     System.out.println("K: " + s1 + "  " + cd1.toString());
424     System.out.println("G: " + s2 + "  " + cd2.toString());
425     System.out.println();
426     return Dna.compareCodonPos(cd1, cd2);
427   }
428
429   /**
430    * Convert a string e.g. "-GC-T" to base positions e.g. [1, 2, 4]. The string
431    * should have exactly 3 non-gap characters, and use '-' for gaps.
432    * 
433    * @param s
434    * @return
435    */
436   private AlignedCodon convertCodon(String s)
437   {
438     int[] codon = new int[3];
439     int i = 0;
440     for (int j = 0; j < s.length(); j++)
441     {
442       if (s.charAt(j) != '-')
443       {
444         codon[i++] = j;
445       }
446     }
447     return new AlignedCodon(codon[0], codon[1], codon[2]);
448   }
449
450   /**
451    * Weirdly, maybe worth a test to prove the helper method of this test class.
452    */
453   @Test(groups = { "Functional" })
454   public void testConvertCodon()
455   {
456     assertEquals("[0, 1, 2]", convertCodon("AAA").toString());
457     assertEquals("[0, 2, 5]", convertCodon("A-A--A").toString());
458     assertEquals("[1, 3, 4]", convertCodon("-A-AA-").toString());
459   }
460 }