Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.renderer

File OverviewResColourFinderTest.java

 

Code metrics

2
97
6
1
289
175
7
0.07
16.17
6
1.17

Classes

Class Line # Actions
OverviewResColourFinderTest 44 97 7
0.4666666746.7%
 

Contributing tests

This file is covered by 3 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.renderer;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24   
25    import java.awt.Color;
26    import java.util.ArrayList;
27   
28    import org.testng.annotations.BeforeClass;
29    import org.testng.annotations.Test;
30   
31    import jalview.bin.Cache;
32    import jalview.datamodel.Alignment;
33    import jalview.datamodel.AlignmentI;
34    import jalview.datamodel.Sequence;
35    import jalview.datamodel.SequenceGroup;
36    import jalview.datamodel.SequenceI;
37    import jalview.gui.AlignViewport;
38    import jalview.gui.JvOptionPane;
39    import jalview.gui.OverviewCanvas;
40    import jalview.schemes.ColourSchemeI;
41    import jalview.schemes.UserColourScheme;
42    import jalview.schemes.ZappoColourScheme;
43   
 
44    public class OverviewResColourFinderTest
45    {
46   
 
47  1 toggle @BeforeClass(alwaysRun = true)
48    public void setUpJvOptionPane()
49    {
50  1 JvOptionPane.setInteractiveMode(false);
51  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52  1 Cache.loadProperties("test/jalview/io/testProps.jvprops");
53    }
54   
 
55  1 toggle @Test(groups = { "Functional" })
56    public void testGetResidueBoxColour_none()
57    {
58  1 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
59  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
60  1 final AlignViewport av = new AlignViewport(al);
61  1 ResidueColourFinder rcf = new OverviewResColourFinder();
62   
63    // gaps are grey, residues white
64  1 assertEquals(Color.white, rcf.getResidueColour(true,
65    av.getResidueShading(), null, seq, 0, null));
66  1 assertEquals(Color.lightGray, rcf.getResidueColour(true,
67    av.getResidueShading(), null, seq, 2, null));
68   
69    // unaffected by showBoxes setting
70  1 assertEquals(Color.white, rcf.getResidueColour(false,
71    av.getResidueShading(), null, seq, 0, null));
72  1 assertEquals(Color.lightGray, rcf.getResidueColour(false,
73    av.getResidueShading(), null, seq, 2, null));
74    }
75   
 
76  1 toggle @Test(groups = { "Functional" })
77    public void testGetResidueBoxColour_zappo()
78    {
79  1 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
80    // gap
81  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
82  1 final AlignViewport av = new AlignViewport(al);
83  1 ResidueColourFinder rcf = new OverviewResColourFinder();
84  1 av.setGlobalColourScheme(new ZappoColourScheme());
85   
86    // @see ResidueProperties.zappo
87  1 assertEquals(Color.pink, rcf.getResidueColour(true,
88    av.getResidueShading(), null, seq, 0, null)); // M
89  1 assertEquals(Color.green, rcf.getResidueColour(true,
90    av.getResidueShading(), null, seq, 2, null)); // T
91  1 assertEquals(Color.magenta, rcf.getResidueColour(true,
92    av.getResidueShading(), null, seq, 5, null)); // G
93  1 assertEquals(Color.orange, rcf.getResidueColour(true,
94    av.getResidueShading(), null, seq, 12, null)); // F
95   
96    // gap colour not specified so gaps are lightGray
97  1 assertEquals(Color.lightGray, rcf.getResidueColour(true,
98    av.getResidueShading(), null, seq, 3, null));
99   
100    // unaffected by showBoxes setting
101  1 assertEquals(Color.pink, rcf.getResidueColour(false,
102    av.getResidueShading(), null, seq, 0, null)); // M
103  1 assertEquals(Color.green, rcf.getResidueColour(false,
104    av.getResidueShading(), null, seq, 2, null)); // T
105  1 assertEquals(Color.magenta, rcf.getResidueColour(false,
106    av.getResidueShading(), null, seq, 5, null)); // G
107  1 assertEquals(Color.orange, rcf.getResidueColour(false,
108    av.getResidueShading(), null, seq, 12, null)); // F
109   
110    // gap colour not specified so gaps are lightGray
111  1 assertEquals(Color.lightGray, rcf.getResidueColour(false,
112    av.getResidueShading(), null, seq, 3, null));
113   
114    }
115   
 
116  1 toggle @Test(groups = { "Functional" })
117    public void testGetResidueBoxColour_userdef()
118    {
119  1 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
120    // gap
121  1 AlignmentI al = new Alignment(new SequenceI[] { seq });
122  1 final AlignViewport av = new AlignViewport(al);
123  1 ResidueColourFinder rcf = new OverviewResColourFinder();
124   
125  1 Color[] newColours = new Color[24];
126  25 for (int i = 0; i < 24; i++)
127    {
128  24 newColours[i] = null;
129    }
130   
131  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
132   
133    // gap colour not specified so gaps are lightGray
134  1 assertEquals(Color.lightGray, rcf.getResidueColour(true,
135    av.getResidueShading(), null, seq, 3, null));
136   
137  1 newColours[23] = Color.pink;
138  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
139   
140    // gap colour specified as pink
141  1 assertEquals(Color.pink, rcf.getResidueColour(true,
142    av.getResidueShading(), null, seq, 3, null));
143   
144    // unaffected by showBoxes setting
145    // gap colour not specified so gaps are lightGray
146  1 newColours[23] = null;
147  1 assertEquals(Color.lightGray, rcf.getResidueColour(false,
148    av.getResidueShading(), null, seq, 3, null));
149   
150  1 newColours[23] = Color.pink;
151  1 av.setGlobalColourScheme(new UserColourScheme(newColours));
152   
153    // gap colour specified as pink
154  1 assertEquals(Color.pink, rcf.getResidueColour(false,
155    av.getResidueShading(), null, seq, 3, null));
156    }
157   
 
158  0 toggle @Test
159    public void testGetResidueBoxColour_group()
160    {
161  0 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
162  0 AlignmentI al = new Alignment(new SequenceI[] { seq });
163   
164  0 ColourSchemeI cs = new ZappoColourScheme();
165  0 ArrayList<SequenceI> seqlist = new ArrayList<>();
166  0 seqlist.add(seq);
167  0 SequenceGroup sg = new SequenceGroup(seqlist, "testgroup", cs, true,
168    true, true, 5, 9);
169  0 al.addGroup(sg);
170  0 SequenceGroup[] groups = new SequenceGroup[1];
171  0 groups[0] = sg;
172   
173  0 final AlignViewport av = new AlignViewport(al);
174  0 ResidueColourFinder rcf = new OverviewResColourFinder();
175   
176    // G in group specified as magenta in Zappo
177  0 assertEquals(Color.magenta, rcf.getResidueColour(false,
178    av.getResidueShading(), groups, seq, 7, null));
179   
180    // Residue outside group coloured white
181  0 assertEquals(Color.white, rcf.getResidueColour(false,
182    av.getResidueShading(), groups, seq, 0, null));
183   
184    // Gap outside group coloured lightgray
185  0 assertEquals(Color.lightGray, rcf.getResidueColour(false,
186    av.getResidueShading(), groups, seq, 2, null));
187   
188    // use legacy colouring
189  0 rcf = new OverviewResColourFinder(Color.white, Color.lightGray,
190    Color.red);
191   
192    // G in group specified as magenta in Zappo
193  0 assertEquals(Color.magenta, rcf.getResidueColour(false,
194    av.getResidueShading(), groups, seq, 7, null));
195   
196    // Residue outside group coloured lightgray
197  0 assertEquals(Color.lightGray, rcf.getResidueColour(false,
198    av.getResidueShading(), groups, seq, 0, null));
199   
200    // Gap outside group coloured white
201  0 assertEquals(Color.white, rcf.getResidueColour(false,
202    av.getResidueShading(), groups, seq, 2, null));
203   
204    // use new colouring
205  0 rcf = new OverviewResColourFinder(Color.blue, Color.white, Color.red);
206   
207    // G in group specified as magenta in Zappo
208  0 assertEquals(Color.magenta, rcf.getResidueColour(false,
209    av.getResidueShading(), groups, seq, 7, null));
210   
211    // Residue outside group coloured white
212  0 assertEquals(Color.white, rcf.getResidueColour(false,
213    av.getResidueShading(), groups, seq, 0, null));
214   
215    // Gap outside group coloured blue
216  0 assertEquals(Color.blue, rcf.getResidueColour(false,
217    av.getResidueShading(), groups, seq, 2, null));
218    }
219   
 
220  0 toggle @Test
221    public void testGetBoxColour()
222    {
223  0 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
224    // gap
225  0 AlignmentI al = new Alignment(new SequenceI[] { seq });
226  0 final AlignViewport av = new AlignViewport(al);
227   
228    // non-legacy colouring
229  0 ResidueColourFinder rcf = new OverviewResColourFinder();
230  0 ResidueShaderI shader = new ResidueShader();
231   
232    // residues white
233  0 Color c = rcf.getBoxColour(shader, seq, 0);
234  0 assertEquals(Color.white, c);
235   
236    // gaps gap colour
237  0 c = rcf.getBoxColour(shader, seq, 3);
238  0 assertEquals(OverviewCanvas.OVERVIEW_DEFAULT_GAP, c);
239   
240    // legacy colouring set explicitly via constructor
241  0 rcf = new OverviewResColourFinder(Color.white, Color.lightGray,
242    Color.red);
243  0 shader = new ResidueShader();
244   
245    // residues light gray
246  0 c = rcf.getBoxColour(shader, seq, 0);
247  0 assertEquals(Color.lightGray, c);
248   
249    // gaps white
250  0 c = rcf.getBoxColour(shader, seq, 3);
251  0 assertEquals(Color.white, c);
252   
253    // legacy colouring off
254  0 rcf = new OverviewResColourFinder();
255  0 shader = new ResidueShader();
256   
257    // residues white
258  0 c = rcf.getBoxColour(shader, seq, 0);
259  0 assertEquals(Color.white, c);
260   
261    // gaps gap colour
262  0 c = rcf.getBoxColour(shader, seq, 3);
263  0 assertEquals(OverviewCanvas.OVERVIEW_DEFAULT_GAP, c);
264   
265    // non legacy colouring with colour scheme
266  0 rcf = new OverviewResColourFinder(Color.blue, Color.white, Color.red);
267  0 shader = new ResidueShader(new ZappoColourScheme());
268   
269    // M residue pink
270  0 c = rcf.getBoxColour(shader, seq, 0);
271  0 assertEquals(Color.pink, c);
272   
273    // gaps blue
274  0 c = rcf.getBoxColour(shader, seq, 3);
275  0 assertEquals(Color.blue, c);
276   
277    // legacy colouring with colour scheme
278  0 rcf = new OverviewResColourFinder(Color.white, Color.lightGray,
279    Color.red);
280   
281    // M residue pink
282  0 c = rcf.getBoxColour(shader, seq, 0);
283  0 assertEquals(Color.pink, c);
284   
285    // gaps white
286  0 c = rcf.getBoxColour(shader, seq, 3);
287  0 assertEquals(Color.white, c);
288    }
289    }