Clover icon

jalviewX

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

File AAFrequencyTest.java

 

Code metrics

2
120
6
1
235
167
7
0.06
20
6
1.17

Classes

Class Line # Actions
AAFrequencyTest 37 120 7 15
0.882812588.3%
 

Contributing tests

This file is covered by 4 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.analysis;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNull;
25   
26    import jalview.datamodel.AlignmentAnnotation;
27    import jalview.datamodel.Annotation;
28    import jalview.datamodel.ProfileI;
29    import jalview.datamodel.ProfilesI;
30    import jalview.datamodel.Sequence;
31    import jalview.datamodel.SequenceI;
32    import jalview.gui.JvOptionPane;
33   
34    import org.testng.annotations.BeforeClass;
35    import org.testng.annotations.Test;
36   
 
37    public class AAFrequencyTest
38    {
39   
 
40  1 toggle @BeforeClass(alwaysRun = true)
41    public void setUpJvOptionPane()
42    {
43  1 JvOptionPane.setInteractiveMode(false);
44  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45    }
46   
 
47  1 toggle @Test(groups = { "Functional" })
48    public void testCalculate_noProfile()
49    {
50  1 SequenceI seq1 = new Sequence("Seq1", "CAG-T");
51  1 SequenceI seq2 = new Sequence("Seq2", "CAC-T");
52  1 SequenceI seq3 = new Sequence("Seq3", "C---G");
53  1 SequenceI seq4 = new Sequence("Seq4", "CA--t");
54  1 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
55  1 int width = seq1.getLength();
56  1 ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
57    false);
58   
59    // col 0 is 100% C
60  1 ProfileI col = result.get(0);
61  1 assertEquals(100f, col.getPercentageIdentity(false));
62  1 assertEquals(100f, col.getPercentageIdentity(true));
63  1 assertEquals(4, col.getMaxCount());
64  1 assertEquals("C", col.getModalResidue());
65  1 assertNull(col.getCounts());
66   
67    // col 1 is 75% A
68  1 col = result.get(1);
69  1 assertEquals(75f, col.getPercentageIdentity(false));
70  1 assertEquals(100f, col.getPercentageIdentity(true));
71  1 assertEquals(3, col.getMaxCount());
72  1 assertEquals("A", col.getModalResidue());
73   
74    // col 2 is 50% G 50% C or 25/25 counting gaps
75  1 col = result.get(2);
76  1 assertEquals(25f, col.getPercentageIdentity(false));
77  1 assertEquals(50f, col.getPercentageIdentity(true));
78  1 assertEquals(1, col.getMaxCount());
79  1 assertEquals("CG", col.getModalResidue());
80   
81    // col 3 is all gaps
82  1 col = result.get(3);
83  1 assertEquals(0f, col.getPercentageIdentity(false));
84  1 assertEquals(0f, col.getPercentageIdentity(true));
85  1 assertEquals(0, col.getMaxCount());
86  1 assertEquals("", col.getModalResidue());
87   
88    // col 4 is 75% T 25% G
89  1 col = result.get(4);
90  1 assertEquals(75f, col.getPercentageIdentity(false));
91  1 assertEquals(75f, col.getPercentageIdentity(true));
92  1 assertEquals(3, col.getMaxCount());
93  1 assertEquals("T", col.getModalResidue());
94    }
95   
 
96  1 toggle @Test(groups = { "Functional" })
97    public void testCalculate_withProfile()
98    {
99  1 SequenceI seq1 = new Sequence("Seq1", "CAGT");
100  1 SequenceI seq2 = new Sequence("Seq2", "CACT");
101  1 SequenceI seq3 = new Sequence("Seq3", "C--G");
102  1 SequenceI seq4 = new Sequence("Seq4", "CA-t");
103  1 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
104  1 int width = seq1.getLength();
105  1 ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
106    true);
107   
108  1 ProfileI profile = result.get(0);
109  1 assertEquals(4, profile.getCounts().getCount('C'));
110  1 assertEquals(4, profile.getHeight());
111  1 assertEquals(4, profile.getNonGapped());
112   
113  1 profile = result.get(1);
114  1 assertEquals(3, profile.getCounts().getCount('A'));
115  1 assertEquals(4, profile.getHeight());
116  1 assertEquals(3, profile.getNonGapped());
117   
118  1 profile = result.get(2);
119  1 assertEquals(1, profile.getCounts().getCount('C'));
120  1 assertEquals(1, profile.getCounts().getCount('G'));
121  1 assertEquals(4, profile.getHeight());
122  1 assertEquals(2, profile.getNonGapped());
123   
124  1 profile = result.get(3);
125  1 assertEquals(3, profile.getCounts().getCount('T'));
126  1 assertEquals(1, profile.getCounts().getCount('G'));
127  1 assertEquals(4, profile.getHeight());
128  1 assertEquals(4, profile.getNonGapped());
129    }
130   
 
131  0 toggle @Test(groups = { "Functional" }, enabled = false)
132    public void testCalculate_withProfileTiming()
133    {
134  0 SequenceI seq1 = new Sequence("Seq1", "CAGT");
135  0 SequenceI seq2 = new Sequence("Seq2", "CACT");
136  0 SequenceI seq3 = new Sequence("Seq3", "C--G");
137  0 SequenceI seq4 = new Sequence("Seq4", "CA-t");
138  0 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
139   
140    // ensure class loaded and initialised
141  0 int width = seq1.getLength();
142  0 AAFrequency.calculate(seqs, width, 0, width, true);
143   
144  0 int reps = 100000;
145  0 long start = System.currentTimeMillis();
146  0 for (int i = 0; i < reps; i++)
147    {
148  0 AAFrequency.calculate(seqs, width, 0, width, true);
149    }
150  0 System.out.println(System.currentTimeMillis() - start);
151    }
152   
153    /**
154    * Test generation of consensus annotation with options 'include gaps'
155    * (profile percentages are of all sequences, whether gapped or not), and
156    * 'show logo' (the full profile with all residue percentages is reported in
157    * the description for the tooltip)
158    */
 
159  1 toggle @Test(groups = { "Functional" })
160    public void testCompleteConsensus_includeGaps_showLogo()
161    {
162    /*
163    * first compute the profiles
164    */
165  1 SequenceI seq1 = new Sequence("Seq1", "CAG-T");
166  1 SequenceI seq2 = new Sequence("Seq2", "CAC-T");
167  1 SequenceI seq3 = new Sequence("Seq3", "C---G");
168  1 SequenceI seq4 = new Sequence("Seq4", "CA--t");
169  1 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
170  1 int width = seq1.getLength();
171  1 ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
172   
173  1 AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
174    "PID", new Annotation[width]);
175  1 AAFrequency
176    .completeConsensus(consensus, profiles, 0, 5, false, true, 4);
177   
178  1 Annotation ann = consensus.annotations[0];
179  1 assertEquals("C 100%", ann.description);
180  1 assertEquals("C", ann.displayCharacter);
181  1 ann = consensus.annotations[1];
182  1 assertEquals("A 75%", ann.description);
183  1 assertEquals("A", ann.displayCharacter);
184  1 ann = consensus.annotations[2];
185  1 assertEquals("C 25%; G 25%", ann.description);
186  1 assertEquals("+", ann.displayCharacter);
187  1 ann = consensus.annotations[3];
188  1 assertEquals("", ann.description);
189  1 assertEquals("-", ann.displayCharacter);
190  1 ann = consensus.annotations[4];
191  1 assertEquals("T 75%; G 25%", ann.description);
192  1 assertEquals("T", ann.displayCharacter);
193    }
194   
195    /**
196    * Test generation of consensus annotation with options 'ignore gaps' (profile
197    * percentages are of the non-gapped sequences) and 'no logo' (only the modal
198    * residue[s] percentage is reported in the description for the tooltip)
199    */
 
200  1 toggle @Test(groups = { "Functional" })
201    public void testCompleteConsensus_ignoreGaps_noLogo()
202    {
203    /*
204    * first compute the profiles
205    */
206  1 SequenceI seq1 = new Sequence("Seq1", "CAG-T");
207  1 SequenceI seq2 = new Sequence("Seq2", "CAC-T");
208  1 SequenceI seq3 = new Sequence("Seq3", "C---G");
209  1 SequenceI seq4 = new Sequence("Seq4", "CA--t");
210  1 SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
211  1 int width = seq1.getLength();
212  1 ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
213   
214  1 AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
215    "PID", new Annotation[width]);
216  1 AAFrequency
217    .completeConsensus(consensus, profiles, 0, 5, true, false, 4);
218   
219  1 Annotation ann = consensus.annotations[0];
220  1 assertEquals("C 100%", ann.description);
221  1 assertEquals("C", ann.displayCharacter);
222  1 ann = consensus.annotations[1];
223  1 assertEquals("A 100%", ann.description);
224  1 assertEquals("A", ann.displayCharacter);
225  1 ann = consensus.annotations[2];
226  1 assertEquals("[CG] 50%", ann.description);
227  1 assertEquals("+", ann.displayCharacter);
228  1 ann = consensus.annotations[3];
229  1 assertEquals("", ann.description);
230  1 assertEquals("-", ann.displayCharacter);
231  1 ann = consensus.annotations[4];
232  1 assertEquals("T 75%", ann.description);
233  1 assertEquals("T", ann.displayCharacter);
234    }
235    }