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(), null, seq, 0, null));
65 assertEquals(Color.lightGray, rcf.getResidueColour(true,
66 av.getResidueShading(), null, seq, 2, null));
68 // unaffected by showBoxes setting
69 assertEquals(Color.white, rcf.getResidueColour(false,
70 av.getResidueShading(), null, seq, 0, null));
71 assertEquals(Color.lightGray, rcf.getResidueColour(false,
72 av.getResidueShading(), null, seq, 2, null));
75 @Test(groups = { "Functional" })
76 public void testGetResidueBoxColour_zappo()
78 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
80 AlignmentI al = new Alignment(new SequenceI[] { seq });
81 final AlignViewport av = new AlignViewport(al);
82 ResidueColourFinder rcf = new OverviewResColourFinder();
83 av.setGlobalColourScheme(new ZappoColourScheme());
85 // @see ResidueProperties.zappo
86 assertEquals(Color.pink, rcf.getResidueColour(true,
87 av.getResidueShading(), null, seq, 0, null)); // M
88 assertEquals(Color.green, rcf.getResidueColour(true,
89 av.getResidueShading(), null, seq, 2, null)); // T
90 assertEquals(Color.magenta, rcf.getResidueColour(true,
91 av.getResidueShading(), null, seq, 5, null)); // G
92 assertEquals(Color.orange, rcf.getResidueColour(true,
93 av.getResidueShading(), null, seq, 12, null)); // F
95 // gap colour not specified so gaps are lightGray
96 assertEquals(Color.lightGray, rcf.getResidueColour(true,
97 av.getResidueShading(), null, seq, 3, null));
99 // unaffected by showBoxes setting
100 assertEquals(Color.pink, rcf.getResidueColour(false,
101 av.getResidueShading(), null, seq, 0, null)); // M
102 assertEquals(Color.green, rcf.getResidueColour(false,
103 av.getResidueShading(), null, seq, 2, null)); // T
104 assertEquals(Color.magenta, rcf.getResidueColour(false,
105 av.getResidueShading(), null, seq, 5, null)); // G
106 assertEquals(Color.orange, rcf.getResidueColour(false,
107 av.getResidueShading(), null, seq, 12, null)); // F
109 // gap colour not specified so gaps are lightGray
110 assertEquals(Color.lightGray, rcf.getResidueColour(false,
111 av.getResidueShading(), null, seq, 3, null));
115 @Test(groups = { "Functional" })
116 public void testGetResidueBoxColour_userdef()
118 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
120 AlignmentI al = new Alignment(new SequenceI[] { seq });
121 final AlignViewport av = new AlignViewport(al);
122 ResidueColourFinder rcf = new OverviewResColourFinder();
124 Color[] newColours = new Color[24];
125 for (int i = 0; i < 24; i++)
127 newColours[i] = null;
130 av.setGlobalColourScheme(new UserColourScheme(newColours));
132 // gap colour not specified so gaps are lightGray
133 assertEquals(Color.lightGray, rcf.getResidueColour(true,
134 av.getResidueShading(), null, seq, 3, null));
136 newColours[23] = Color.pink;
137 av.setGlobalColourScheme(new UserColourScheme(newColours));
139 // gap colour specified as pink
140 assertEquals(Color.pink, rcf.getResidueColour(true,
141 av.getResidueShading(), null, seq, 3, null));
143 // unaffected by showBoxes setting
144 // gap colour not specified so gaps are lightGray
145 newColours[23] = null;
146 assertEquals(Color.lightGray, rcf.getResidueColour(false,
147 av.getResidueShading(), null, seq, 3, null));
149 newColours[23] = Color.pink;
150 av.setGlobalColourScheme(new UserColourScheme(newColours));
152 // gap colour specified as pink
153 assertEquals(Color.pink, rcf.getResidueColour(false,
154 av.getResidueShading(), null, seq, 3, null));
158 public void testGetResidueBoxColour_group()
160 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
161 AlignmentI al = new Alignment(new SequenceI[] { seq });
163 ColourSchemeI cs = new ZappoColourScheme();
164 ArrayList<SequenceI> seqlist = new ArrayList<>();
166 SequenceGroup sg = new SequenceGroup(seqlist, "testgroup", cs, true,
169 SequenceGroup[] groups = new SequenceGroup[1];
172 final AlignViewport av = new AlignViewport(al);
173 ResidueColourFinder rcf = new OverviewResColourFinder();
175 // G in group specified as magenta in Zappo
176 assertEquals(Color.magenta, rcf.getResidueColour(false,
177 av.getResidueShading(), groups, seq, 7, null));
179 // Residue outside group coloured white
180 assertEquals(Color.white, rcf.getResidueColour(false,
181 av.getResidueShading(), groups, seq, 0, null));
183 // Gap outside group coloured lightgray
184 assertEquals(Color.lightGray, rcf.getResidueColour(false,
185 av.getResidueShading(), groups, seq, 2, null));
187 // use legacy colouring
188 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
190 // G in group specified as magenta in Zappo
191 assertEquals(Color.magenta, rcf.getResidueColour(false,
192 av.getResidueShading(), groups, seq, 7, null));
194 // Residue outside group coloured lightgray
195 assertEquals(Color.lightGray, rcf.getResidueColour(false,
196 av.getResidueShading(), groups, seq, 0, null));
198 // Gap outside group coloured white
199 assertEquals(Color.white, rcf.getResidueColour(false,
200 av.getResidueShading(), groups, seq, 2, null));
203 rcf = new OverviewResColourFinder(false, Color.blue, Color.red);
205 // G in group specified as magenta in Zappo
206 assertEquals(Color.magenta, rcf.getResidueColour(false,
207 av.getResidueShading(), groups, seq, 7, null));
209 // Residue outside group coloured white
210 assertEquals(Color.white, rcf.getResidueColour(false,
211 av.getResidueShading(), groups, seq, 0, null));
213 // Gap outside group coloured blue
214 assertEquals(Color.blue, rcf.getResidueColour(false,
215 av.getResidueShading(), groups, seq, 2, null));
219 public void testGetBoxColour()
221 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
223 AlignmentI al = new Alignment(new SequenceI[] { seq });
224 final AlignViewport av = new AlignViewport(al);
226 // non-legacy colouring
227 ResidueColourFinder rcf = new OverviewResColourFinder();
228 ResidueShaderI shader = new ResidueShader();
231 Color c = rcf.getBoxColour(shader, seq, 0);
232 assertEquals(Color.white, c);
235 c = rcf.getBoxColour(shader, seq, 3);
237 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP,
240 // legacy colouring set explicitly via constructor
241 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
242 shader = new ResidueShader();
244 // residues light gray
245 c = rcf.getBoxColour(shader, seq, 0);
246 assertEquals(Color.lightGray, c);
249 c = rcf.getBoxColour(shader, seq, 3);
250 assertEquals(Color.white, c);
252 // legacy colouring off
253 rcf = new OverviewResColourFinder();
254 shader = new ResidueShader();
257 c = rcf.getBoxColour(shader, seq, 0);
258 assertEquals(Color.white, c);
261 c = rcf.getBoxColour(shader, seq, 3);
263 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP,
266 // non legacy colouring with colour scheme
267 rcf = new OverviewResColourFinder(false, Color.blue, Color.red);
268 shader = new ResidueShader(new ZappoColourScheme());
271 c = rcf.getBoxColour(shader, seq, 0);
272 assertEquals(Color.pink, c);
275 c = rcf.getBoxColour(shader, seq, 3);
276 assertEquals(Color.blue, c);
278 // legacy colouring with colour scheme
279 rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
282 c = rcf.getBoxColour(shader, seq, 0);
283 assertEquals(Color.pink, c);
286 c = rcf.getBoxColour(shader, seq, 3);
287 assertEquals(Color.white, c);