2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.renderer;
23 import static org.testng.AssertJUnit.assertEquals;
25 import jalview.bin.Cache;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.AlignViewport;
32 import jalview.gui.JvOptionPane;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.UserColourScheme;
35 import jalview.schemes.ZappoColourScheme;
37 import java.awt.Color;
38 import java.util.ArrayList;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 public class OverviewResColourFinderTest
46 @BeforeClass(alwaysRun = true)
47 public void setUpJvOptionPane()
49 JvOptionPane.setInteractiveMode(false);
50 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51 Cache.loadProperties("test/jalview/io/testProps.jvprops");
54 @Test(groups = { "Functional" })
55 public void testGetResidueBoxColour_none()
57 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
58 AlignmentI al = new Alignment(new SequenceI[] { seq });
59 final AlignViewport av = new AlignViewport(al);
60 ResidueColourFinder rcf = new OverviewResColourFinder();
62 // gaps are grey, residues white
63 assertEquals(Color.white, rcf.getResidueColour(true,
64 av.getResidueShading(),
66 assertEquals(Color.lightGray, rcf
67 .getResidueColour(true, av.getResidueShading(), null, seq, 2,
70 // unaffected by showBoxes setting
71 assertEquals(Color.white, rcf.getResidueColour(false,
72 av.getResidueShading(), null, seq, 0, null));
73 assertEquals(Color.lightGray, rcf.getResidueColour(false,
74 av.getResidueShading(), null, seq, 2, null));
77 @Test(groups = { "Functional" })
78 public void testGetResidueBoxColour_zappo()
80 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
82 AlignmentI al = new Alignment(new SequenceI[] { seq });
83 final AlignViewport av = new AlignViewport(al);
84 ResidueColourFinder rcf = new OverviewResColourFinder();
85 av.setGlobalColourScheme(new ZappoColourScheme());
87 // @see ResidueProperties.zappo
88 assertEquals(Color.pink,
89 rcf.getResidueColour(true, av.getResidueShading(),
90 null, seq, 0, null)); // M
91 assertEquals(Color.green,
92 rcf.getResidueColour(true, av.getResidueShading(),
93 null, seq, 2, null)); // T
94 assertEquals(Color.magenta,
95 rcf.getResidueColour(true, av.getResidueShading(),
96 null, seq, 5, null)); // G
97 assertEquals(Color.orange,
98 rcf.getResidueColour(true, av.getResidueShading(),
99 null, seq, 12, null)); // F
101 // gap colour not specified so gaps are lightGray
102 assertEquals(Color.lightGray, rcf
103 .getResidueColour(true, av.getResidueShading(), null, seq, 3,
106 // unaffected by showBoxes setting
107 assertEquals(Color.pink, rcf.getResidueColour(false,
108 av.getResidueShading(), null, seq, 0, null)); // M
109 assertEquals(Color.green, rcf.getResidueColour(false,
110 av.getResidueShading(), null, seq, 2, null)); // T
111 assertEquals(Color.magenta, rcf.getResidueColour(false,
112 av.getResidueShading(), null, seq, 5, null)); // G
113 assertEquals(Color.orange, rcf.getResidueColour(false,
114 av.getResidueShading(), null, seq, 12, null)); // F
116 // gap colour not specified so gaps are lightGray
117 assertEquals(Color.lightGray, rcf
118 .getResidueColour(false, av.getResidueShading(), null, seq, 3,
123 @Test(groups = { "Functional" })
124 public void testGetResidueBoxColour_userdef()
126 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
128 AlignmentI al = new Alignment(new SequenceI[] { seq });
129 final AlignViewport av = new AlignViewport(al);
130 ResidueColourFinder rcf = new OverviewResColourFinder();
132 Color[] newColours = new Color[24];
133 for (int i = 0; i < 24; i++)
135 newColours[i] = null;
138 av.setGlobalColourScheme(new UserColourScheme(newColours));
140 // gap colour not specified so gaps are lightGray
141 assertEquals(Color.lightGray, rcf
142 .getResidueColour(true, av.getResidueShading(), null, seq, 3,
145 newColours[23] = Color.pink;
146 av.setGlobalColourScheme(new UserColourScheme(newColours));
148 // gap colour specified as pink
149 assertEquals(Color.pink, rcf.getResidueColour(true,
150 av.getResidueShading(),
151 null, seq, 3, null));
153 // unaffected by showBoxes setting
154 // gap colour not specified so gaps are lightGray
155 newColours[23] = null;
156 assertEquals(Color.lightGray, rcf.getResidueColour(false,
157 av.getResidueShading(), null, seq, 3, null));
159 newColours[23] = Color.pink;
160 av.setGlobalColourScheme(new UserColourScheme(newColours));
162 // gap colour specified as pink
163 assertEquals(Color.pink, rcf.getResidueColour(false,
164 av.getResidueShading(), null, seq, 3, null));
168 public void testGetResidueBoxColour_group()
170 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
171 AlignmentI al = new Alignment(new SequenceI[] { seq });
173 ColourSchemeI cs = new ZappoColourScheme();
174 ArrayList<SequenceI> seqlist = new ArrayList<>();
176 SequenceGroup sg = new SequenceGroup(seqlist, "testgroup", cs, true,
179 SequenceGroup[] groups = new SequenceGroup[1];
182 final AlignViewport av = new AlignViewport(al);
183 ResidueColourFinder rcf = new OverviewResColourFinder();
185 // G in group specified as magenta in Zappo
186 assertEquals(Color.magenta, rcf.getResidueColour(false,
187 av.getResidueShading(), groups, seq, 7, null));
189 // Residue outside group coloured white
190 assertEquals(Color.white, rcf.getResidueColour(false,
191 av.getResidueShading(), groups, seq, 0, null));
193 // Gap outside group coloured lightgray
194 assertEquals(Color.lightGray, rcf.getResidueColour(false,
195 av.getResidueShading(), groups, seq, 2, null));
197 // use legacy colouring
198 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
200 // G in group specified as magenta in Zappo
201 assertEquals(Color.magenta, rcf.getResidueColour(false,
202 av.getResidueShading(), groups, seq, 7, null));
204 // Residue outside group coloured lightgray
205 assertEquals(Color.lightGray, rcf.getResidueColour(false,
206 av.getResidueShading(), groups, seq, 0, null));
208 // Gap outside group coloured white
209 assertEquals(Color.white, rcf.getResidueColour(false,
210 av.getResidueShading(), groups, seq, 2, null));
213 rcf = new OverviewResColourFinder(false, Color.blue, Color.red);
215 // G in group specified as magenta in Zappo
216 assertEquals(Color.magenta, rcf.getResidueColour(false,
217 av.getResidueShading(), groups, seq, 7, null));
219 // Residue outside group coloured white
220 assertEquals(Color.white, rcf.getResidueColour(false,
221 av.getResidueShading(), groups, seq, 0, null));
223 // Gap outside group coloured blue
224 assertEquals(Color.blue, rcf.getResidueColour(false,
225 av.getResidueShading(), groups, seq, 2, null));
229 public void testGetBoxColour()
231 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
233 AlignmentI al = new Alignment(new SequenceI[] { seq });
234 final AlignViewport av = new AlignViewport(al);
236 // non-legacy colouring
237 ResidueColourFinder rcf = new OverviewResColourFinder();
238 ResidueShaderI shader = new ResidueShader();
241 Color c = rcf.getBoxColour(shader, seq, 0);
242 assertEquals(Color.white, c);
245 c = rcf.getBoxColour(shader, seq, 3);
247 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP,
250 // legacy colouring set explicitly via constructor
251 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
252 shader = new ResidueShader();
254 // residues light gray
255 c = rcf.getBoxColour(shader, seq, 0);
256 assertEquals(Color.lightGray, c);
259 c = rcf.getBoxColour(shader, seq, 3);
260 assertEquals(Color.white, c);
262 // legacy colouring off
263 rcf = new OverviewResColourFinder();
264 shader = new ResidueShader();
267 c = rcf.getBoxColour(shader, seq, 0);
268 assertEquals(Color.white, c);
271 c = rcf.getBoxColour(shader, seq, 3);
273 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP,
276 // non legacy colouring with colour scheme
277 rcf = new OverviewResColourFinder(false, Color.blue, Color.red);
278 shader = new ResidueShader(new ZappoColourScheme());
281 c = rcf.getBoxColour(shader, seq, 0);
282 assertEquals(Color.pink, c);
285 c = rcf.getBoxColour(shader, seq, 3);
286 assertEquals(Color.blue, c);
288 // legacy colouring with colour scheme
289 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
292 c = rcf.getBoxColour(shader, seq, 0);
293 assertEquals(Color.pink, c);
296 c = rcf.getBoxColour(shader, seq, 3);
297 assertEquals(Color.white, c);