Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.datamodel

File AlignedCodonIteratorTest.java

 

Code metrics

0
86
6
1
190
132
7
0.08
14.33
6
1.17

Classes

Class Line # Actions
AlignedCodonIteratorTest 41 86 7 1
0.9891304498.9%
 

Contributing tests

This file is covered by 5 tests. .

Source view

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.datamodel;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25   
26    import jalview.gui.JvOptionPane;
27    import jalview.util.MapList;
28   
29    import java.util.Iterator;
30   
31    import org.testng.Assert;
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.Test;
34   
35    /**
36    * Unit tests for Mapping$AlignedCodonIterator
37    *
38    * @author gmcarstairs
39    *
40    */
 
41    public class AlignedCodonIteratorTest
42    {
43   
 
44  1 toggle @BeforeClass(alwaysRun = true)
45    public void setUpJvOptionPane()
46    {
47  1 JvOptionPane.setInteractiveMode(false);
48  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49    }
50   
51    /**
52    * Test normal case for iterating over aligned codons.
53    */
 
54  1 toggle @Test(groups = { "Functional" })
55    public void testNext()
56    {
57  1 SequenceI from = new Sequence("Seq1", "-CgC-C-cCtAG-AtG-Gc");
58  1 from.createDatasetSequence();
59  1 SequenceI to = new Sequence("Seq1", "-PQ-R-");
60  1 to.createDatasetSequence();
61  1 MapList map = new MapList(
62    new int[] { 1, 1, 3, 4, 6, 6, 8, 10, 12, 13 },
63    new int[] { 1, 3 }, 3, 1);
64  1 Mapping m = new Mapping(to.getDatasetSequence(), map);
65   
66  1 Iterator<AlignedCodon> codons = m.getCodonIterator(from, '-');
67  1 AlignedCodon codon = codons.next();
68  1 assertEquals("[1, 3, 5]", codon.toString());
69  1 assertEquals("P", codon.product);
70  1 codon = codons.next();
71  1 assertEquals("[8, 10, 11]", codon.toString());
72  1 assertEquals("Q", codon.product);
73  1 codon = codons.next();
74  1 assertEquals("[13, 15, 17]", codon.toString());
75  1 assertEquals("R", codon.product);
76  1 assertFalse(codons.hasNext());
77    }
78   
79    /**
80    * Test weird case where the mapping skips over a peptide.
81    */
 
82  1 toggle @Test(groups = { "Functional" })
83    public void testNext_unmappedPeptide()
84    {
85  1 SequenceI from = new Sequence("Seq1", "-CgC-C-cCtAG-AtG-Gc");
86  1 from.createDatasetSequence();
87  1 SequenceI to = new Sequence("Seq1", "-PQ-TR-");
88  1 to.createDatasetSequence();
89  1 MapList map = new MapList(
90    new int[] { 1, 1, 3, 4, 6, 6, 8, 10, 12, 13 }, new int[] { 1,
91    2, 4, 4 }, 3, 1);
92  1 Mapping m = new Mapping(to.getDatasetSequence(), map);
93   
94  1 Iterator<AlignedCodon> codons = m.getCodonIterator(from, '-');
95  1 AlignedCodon codon = codons.next();
96  1 assertEquals("[1, 3, 5]", codon.toString());
97  1 assertEquals("P", codon.product);
98  1 codon = codons.next();
99  1 assertEquals("[8, 10, 11]", codon.toString());
100  1 assertEquals("Q", codon.product);
101  1 codon = codons.next();
102  1 assertEquals("[13, 15, 17]", codon.toString());
103  1 assertEquals("R", codon.product);
104  1 assertFalse(codons.hasNext());
105    }
106   
107    /**
108    * Test for exception thrown for an incomplete codon.
109    */
 
110  1 toggle @Test(groups = { "Functional" })
111    public void testNext_incompleteCodon()
112    {
113  1 SequenceI from = new Sequence("Seq1", "-CgC-C-cCgTt");
114  1 from.createDatasetSequence();
115  1 SequenceI to = new Sequence("Seq1", "-PQ-R-");
116  1 to.createDatasetSequence();
117  1 MapList map = new MapList(new int[] { 1, 1, 3, 4, 6, 6, 8, 8 },
118    new int[] { 1, 3 }, 3, 1);
119  1 Mapping m = new Mapping(to.getDatasetSequence(), map);
120   
121  1 Iterator<AlignedCodon> codons = m.getCodonIterator(from, '-');
122  1 AlignedCodon codon = codons.next();
123  1 assertEquals("[1, 3, 5]", codon.toString());
124  1 assertEquals("P", codon.product);
125  1 try
126    {
127  1 codon = codons.next();
128  0 Assert.fail("expected exception");
129    } catch (IncompleteCodonException e)
130    {
131    // expected
132    }
133    }
134   
135    /**
136    * Test normal case for iterating over aligned codons.
137    */
 
138  1 toggle @Test(groups = { "Functional" })
139    public void testAnother()
140    {
141  1 SequenceI from = new Sequence("Seq1", "TGCCATTACCAG-");
142  1 from.createDatasetSequence();
143  1 SequenceI to = new Sequence("Seq1", "CHYQ");
144  1 to.createDatasetSequence();
145  1 MapList map = new MapList(new int[] { 1, 12 }, new int[] { 1, 4 }, 3, 1);
146  1 Mapping m = new Mapping(to.getDatasetSequence(), map);
147   
148  1 Iterator<AlignedCodon> codons = m.getCodonIterator(from, '-');
149  1 AlignedCodon codon = codons.next();
150  1 assertEquals("[0, 1, 2]", codon.toString());
151  1 assertEquals("C", codon.product);
152  1 codon = codons.next();
153  1 assertEquals("[3, 4, 5]", codon.toString());
154  1 assertEquals("H", codon.product);
155  1 codon = codons.next();
156  1 assertEquals("[6, 7, 8]", codon.toString());
157  1 assertEquals("Y", codon.product);
158  1 codon = codons.next();
159  1 assertEquals("[9, 10, 11]", codon.toString());
160  1 assertEquals("Q", codon.product);
161  1 assertFalse(codons.hasNext());
162    }
163   
164    /**
165    * Test for a case with sequence (and mappings) not starting at 1
166    */
 
167  1 toggle @Test(groups = { "Functional" })
168    public void testNext_withOffset()
169    {
170  1 SequenceI from = new Sequence("Seq1", "-CgC-C-cCtAG-AtG-Gc", 7, 20);
171  1 from.createDatasetSequence();
172  1 SequenceI to = new Sequence("Seq1/10-12", "-PQ-R-");
173  1 to.createDatasetSequence();
174  1 MapList map = new MapList(new int[] { 7, 7, 9, 10, 12, 12, 14, 16, 18,
175    19 }, new int[] { 10, 12 }, 3, 1);
176  1 Mapping m = new Mapping(to.getDatasetSequence(), map);
177   
178  1 Iterator<AlignedCodon> codons = m.getCodonIterator(from, '-');
179  1 AlignedCodon codon = codons.next();
180  1 assertEquals("[1, 3, 5]", codon.toString());
181  1 assertEquals("P", codon.product);
182  1 codon = codons.next();
183  1 assertEquals("[8, 10, 11]", codon.toString());
184  1 assertEquals("Q", codon.product);
185  1 codon = codons.next();
186  1 assertEquals("[13, 15, 17]", codon.toString());
187  1 assertEquals("R", codon.product);
188  1 assertFalse(codons.hasNext());
189    }
190    }