Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.datamodel

File SequenceGroupTest.java

 

Code metrics

0
180
7
1
358
246
10
0.06
25.71
7
1.43

Classes

Class Line # Actions
SequenceGroupTest 45 180 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertNotNull;
26    import static org.testng.Assert.assertNotSame;
27    import static org.testng.Assert.assertNull;
28    import static org.testng.Assert.assertSame;
29    import static org.testng.Assert.assertTrue;
30    import static org.testng.Assert.fail;
31   
32    import jalview.analysis.Conservation;
33    import jalview.schemes.NucleotideColourScheme;
34    import jalview.schemes.PIDColourScheme;
35   
36    import java.awt.Color;
37    import java.util.ArrayList;
38    import java.util.Collections;
39    import java.util.List;
40   
41    import org.testng.annotations.Test;
42   
43    import junit.extensions.PA;
44   
 
45    public class SequenceGroupTest
46    {
 
47  0 toggle @Test(groups = { "Functional" })
48    public void testAddSequence()
49    {
50  0 SequenceGroup sg = new SequenceGroup();
51  0 assertTrue(sg.getSequences().isEmpty());
52   
53  0 SequenceI seq1 = new Sequence("seq1", "abc");
54  0 SequenceI seq2 = new Sequence("seq2", "abc");
55  0 SequenceI seq3 = new Sequence(seq1);
56   
57  0 sg.addSequence(null, false);
58  0 assertTrue(sg.getSequences().isEmpty());
59  0 sg.addSequence(seq1, false);
60  0 assertEquals(sg.getSequences().size(), 1);
61  0 assertTrue(sg.getSequences().contains(seq1));
62    // adding the same sequence again does nothing
63  0 sg.addSequence(seq1, false);
64  0 assertEquals(sg.getSequences().size(), 1);
65  0 assertTrue(sg.getSequences().contains(seq1));
66  0 sg.addSequence(seq2, false);
67  0 sg.addSequence(seq2, false);
68  0 sg.addSequence(seq3, false);
69  0 assertEquals(sg.getSequences().size(), 3);
70  0 assertTrue(sg.getSequences().contains(seq1));
71  0 assertTrue(sg.getSequences().contains(seq2));
72  0 assertTrue(sg.getSequences().contains(seq3));
73    }
74   
 
75  0 toggle @Test(groups = { "Functional" })
76    public void testAddOrRemove()
77    {
78  0 SequenceGroup sg = new SequenceGroup();
79  0 assertTrue(sg.getSequences().isEmpty());
80   
81  0 SequenceI seq1 = new Sequence("seq1", "abc");
82  0 SequenceI seq2 = new Sequence("seq2", "abc");
83  0 SequenceI seq3 = new Sequence(seq1);
84   
85  0 sg.addOrRemove(seq1, false);
86  0 assertEquals(sg.getSequences().size(), 1);
87  0 sg.addOrRemove(seq2, false);
88  0 assertEquals(sg.getSequences().size(), 2);
89  0 sg.addOrRemove(seq3, false);
90  0 assertEquals(sg.getSequences().size(), 3);
91  0 assertTrue(sg.getSequences().contains(seq1));
92  0 assertTrue(sg.getSequences().contains(seq2));
93  0 assertTrue(sg.getSequences().contains(seq3));
94  0 sg.addOrRemove(seq1, false);
95  0 assertEquals(sg.getSequences().size(), 2);
96  0 assertFalse(sg.getSequences().contains(seq1));
97    }
98   
 
99  0 toggle @Test(groups = { "Functional" })
100    public void testGetColourScheme()
101    {
102  0 SequenceGroup sg = new SequenceGroup();
103  0 assertNotNull(sg.getGroupColourScheme());
104  0 assertNull(sg.getColourScheme());
105   
106  0 sg.setGroupColourScheme(null);
107  0 assertNull(sg.getColourScheme());
108   
109  0 NucleotideColourScheme scheme = new NucleotideColourScheme();
110  0 sg.setColourScheme(scheme);
111  0 assertSame(scheme, sg.getColourScheme());
112    }
113   
 
114  0 toggle @Test(groups = { "Functional" })
115    public void testSetContext()
116    {
117  0 SequenceGroup sg1 = new SequenceGroup();
118  0 SequenceGroup sg2 = new SequenceGroup();
119  0 SequenceGroup sg3 = new SequenceGroup();
120  0 assertNull(sg1.getContext());
121  0 sg1.setContext(null);
122  0 assertNull(sg1.getContext());
123  0 try
124    {
125  0 sg1.setContext(sg1); // self-reference :-O
126  0 fail("Expected exception");
127    } catch (IllegalArgumentException e)
128    {
129    // expected
130  0 assertNull(sg1.getContext());
131    }
132  0 sg1.setContext(sg2);
133  0 assertSame(sg2, sg1.getContext());
134  0 sg2.setContext(sg3);
135  0 try
136    {
137  0 sg3.setContext(sg1); // circular reference :-O
138  0 fail("Expected exception");
139    } catch (IllegalArgumentException e)
140    {
141    // expected
142  0 assertNull(sg3.getContext());
143    }
144   
145    /*
146    * use PrivilegedAccessor to 'force' a SequenceGroup with
147    * a circular context reference
148    */
149  0 PA.setValue(sg2, "context", sg2);
150  0 try
151    {
152  0 sg3.setContext(sg2, false); // circular reference in sg2
153  0 fail("Expected exception");
154    } catch (IllegalArgumentException e)
155    {
156    // expected
157  0 assertNull(sg3.getContext());
158    }
159   
160    // test isDefined setting behaviour
161  0 sg2 = new SequenceGroup();
162  0 sg1.setContext(null, false);
163  0 assertFalse(sg1.isDefined());
164   
165  0 sg1.setContext(sg2, false);
166  0 assertFalse(sg1.isDefined());
167   
168  0 sg1.setContext(sg2, true);
169  0 assertTrue(sg1.isDefined());
170   
171    // setContext without defined parameter does not change isDefined
172  0 sg1.setContext(null);
173  0 assertTrue(sg1.isDefined());
174   
175  0 sg1.setContext(null, false);
176  0 sg1.setContext(sg2);
177  0 assertFalse(sg1.isDefined());
178    }
179   
 
180  0 toggle @Test(groups = { "Functional" })
181    public void testContains()
182    {
183    /*
184    * essentially the same tests as AlignmentI.findGroup
185    * but from a particular group's perspective
186    */
187   
188  0 SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI");
189  0 SequenceI seq2 = new Sequence("seq2", "---JKLMNO---");
190  0 AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 });
191    /*
192    * add a group consisting of just "DEF"
193    */
194  0 SequenceGroup sg1 = new SequenceGroup();
195  0 sg1.addSequence(seq1, false);
196  0 sg1.setStartRes(3);
197  0 sg1.setEndRes(5);
198   
199    /*
200    * test sequence membership
201    */
202  0 assertTrue(sg1.contains(seq1));
203  0 assertFalse(sg1.contains(seq2));
204   
205    /*
206    * test sequence+position
207    */
208   
209  0 assertFalse(sg1.contains(seq1, 2)); // position not in group
210  0 assertFalse(sg1.contains(seq1, 6)); // position not in group
211  0 assertFalse(sg1.contains(seq2, 5)); // sequence not in group
212  0 assertTrue(sg1.contains(seq1, 3)); // yes
213  0 assertTrue(sg1.contains(seq1, 4));
214  0 assertTrue(sg1.contains(seq1, 5));
215   
216    /*
217    * add a group consisting of
218    * EF--
219    * KLMN
220    */
221  0 SequenceGroup sg2 = new SequenceGroup();
222  0 sg2.addSequence(seq1, false);
223  0 sg2.addSequence(seq2, false);
224  0 sg2.setStartRes(4);
225  0 sg2.setEndRes(7);
226  0 a.addGroup(sg2);
227   
228    /*
229    * if a residue is in more than one group, method returns
230    * the first found (in order groups were added)
231    */
232  0 assertTrue(sg2.contains(seq1, 4));
233  0 assertTrue(sg2.contains(seq1, 5));
234   
235    /*
236    * seq2 only belongs to the second group
237    */
238  0 assertTrue(sg2.contains(seq2, 4));
239  0 assertTrue(sg2.contains(seq2, 5));
240  0 assertTrue(sg2.contains(seq2, 6));
241  0 assertTrue(sg2.contains(seq2, 7));
242  0 assertFalse(sg2.contains(seq2, 3));
243  0 assertFalse(sg2.contains(seq2, 8));
244  0 sg2.setEndRes(8);
245  0 assertTrue(sg2.contains(seq2, 8));
246  0 sg2.deleteSequence(seq2, false);
247  0 assertFalse(sg2.contains(seq2));
248    }
249   
 
250  0 toggle @Test(groups = { "Functional" })
251    public void testCopyConstructor()
252    {
253  0 SequenceI seq = new Sequence("seq", "ABC");
254  0 SequenceGroup sg = new SequenceGroup();
255  0 sg.addSequence(seq, false);
256  0 sg.setName("g1");
257  0 sg.setDescription("desc");
258  0 sg.setColourScheme(new PIDColourScheme());
259  0 Conservation cons = new Conservation("Cons", 2,
260    Collections.<SequenceI> emptyList(), 3, 12);
261  0 PA.setValue(cons, "consSequence", new Sequence("s", "abc"));
262  0 sg.getGroupColourScheme().setConservation(cons);
263  0 sg.getGroupColourScheme().setConsensus(new Profiles(0,null));
264  0 sg.setDisplayBoxes(false);
265  0 sg.setDisplayText(false);
266  0 sg.setColourText(true);
267  0 sg.isDefined = true;
268  0 sg.setShowNonconserved(true);
269  0 sg.setOutlineColour(Color.red);
270  0 sg.setIdColour(Color.blue);
271  0 sg.thresholdTextColour = 1;
272  0 sg.textColour = Color.orange;
273  0 sg.textColour2 = Color.yellow;
274  0 sg.setIgnoreGapsConsensus(false);
275  0 sg.setshowSequenceLogo(true);
276  0 sg.setNormaliseSequenceLogo(true);
277  0 sg.setHidereps(true);
278  0 sg.setHideCols(true);
279  0 sg.setShowConsensusHistogram(true);
280  0 sg.setContext(new SequenceGroup());
281   
282  0 SequenceGroup sg2 = new SequenceGroup(sg);
283  0 assertEquals(sg2.getName(), sg.getName());
284  0 assertEquals(sg2.getDescription(), sg.getDescription());
285  0 assertNotSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme());
286  0 assertSame(sg2.getColourScheme(), sg.getColourScheme());
287  0 assertSame(PA.getValue(sg2.getGroupColourScheme(), "consensus"),
288    PA.getValue(sg.getGroupColourScheme(), "consensus"));
289  0 assertSame(PA.getValue(sg2.getGroupColourScheme(), "conservation"),
290    PA.getValue(sg.getGroupColourScheme(), "conservation"));
291  0 assertEquals(sg2.getDisplayBoxes(), sg.getDisplayBoxes());
292  0 assertEquals(sg2.getDisplayText(), sg.getDisplayText());
293  0 assertEquals(sg2.getColourText(), sg.getColourText());
294  0 assertEquals(sg2.getShowNonconserved(), sg.getShowNonconserved());
295  0 assertEquals(sg2.getOutlineColour(), sg.getOutlineColour());
296  0 assertEquals(sg2.getIdColour(), sg.getIdColour());
297  0 assertEquals(sg2.thresholdTextColour, sg.thresholdTextColour);
298  0 assertEquals(sg2.textColour, sg.textColour);
299  0 assertEquals(sg2.textColour2, sg.textColour2);
300  0 assertEquals(sg2.getIgnoreGapsConsensus(), sg.getIgnoreGapsConsensus());
301  0 assertEquals(sg2.isShowSequenceLogo(), sg.isShowSequenceLogo());
302  0 assertEquals(sg2.isNormaliseSequenceLogo(),
303    sg.isNormaliseSequenceLogo());
304  0 assertEquals(sg2.isHidereps(), sg.isHidereps());
305  0 assertEquals(sg2.isHideCols(), sg.isHideCols());
306  0 assertEquals(sg2.isShowConsensusHistogram(),
307    sg.isShowConsensusHistogram());
308   
309    /*
310    * copy of sequences
311    */
312  0 assertNotSame(sg2.getSequences(), sg.getSequences());
313  0 assertEquals(sg2.getSequences(), sg.getSequences());
314   
315    /*
316    * isDefined should only be set true when a new group is added to
317    * an alignment, not in the copy constructor
318    */
319  0 assertFalse(sg2.isDefined());
320   
321    /*
322    * context should be set explicitly, not by copy
323    */
324  0 assertNull(sg2.getContext());
325    }
326   
 
327  0 toggle @Test(groups = { "Functional" })
328    public void testConstructor_list()
329    {
330  0 SequenceI s1 = new Sequence("abcde", "fg");
331  0 SequenceI s2 = new Sequence("foo", "bar");
332  0 List<SequenceI> seqs = new ArrayList<SequenceI>();
333  0 seqs.add(s1);
334  0 seqs.add(s2);
335  0 SequenceGroup sg = new SequenceGroup(seqs);
336   
337    /*
338    * verify sg has a copy of the original list
339    */
340  0 List<SequenceI> sgList = sg.getSequences();
341  0 assertNotSame(sgList, seqs);
342  0 assertEquals(sgList, seqs);
343   
344    /*
345    * add to sgList, original is unchanged
346    */
347  0 sg.addSequence(new Sequence("bar", "foo"), false);
348  0 assertEquals(sgList.size(), 3);
349  0 assertEquals(seqs.size(), 2);
350   
351    /*
352    * delete from original, sgList is unchanged
353    */
354  0 seqs.remove(s1);
355  0 assertEquals(sgList.size(), 3);
356  0 assertEquals(seqs.size(), 1);
357    }
358    }