1 package jalview.schemes;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertSame;
6 import static org.testng.Assert.assertTrue;
8 import jalview.bin.Cache;
9 import jalview.bin.Jalview;
10 import jalview.datamodel.AnnotatedCollectionI;
11 import jalview.datamodel.SequenceCollectionI;
12 import jalview.datamodel.SequenceI;
13 import jalview.gui.AlignFrame;
14 import jalview.gui.Desktop;
15 import jalview.gui.SequenceRenderer;
16 import jalview.io.DataSourceType;
17 import jalview.io.FileLoader;
18 import jalview.schemes.ClustalxColourScheme.ClustalColour;
20 import java.awt.Color;
21 import java.util.Iterator;
24 import org.testng.annotations.AfterClass;
25 import org.testng.annotations.BeforeClass;
26 import org.testng.annotations.Test;
28 public class ColourSchemesTest
31 * a colour scheme that alternates Taylor and Zappo
34 class Stripy extends ResidueColourScheme
36 private ResidueColourScheme odd;
38 private ResidueColourScheme even;
45 * constructor given colours for odd and even columns
50 private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)
52 odd = (ResidueColourScheme) cs1;
53 even = (ResidueColourScheme) cs2;
57 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
58 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
60 final ColourSchemeI cs1 = ColourSchemes.getInstance()
61 .getColourScheme(JalviewColourScheme.Taylor.toString(),
62 (AnnotatedCollectionI) null);
63 final ColourSchemeI cs2 = ColourSchemes.getInstance()
64 .getColourScheme(JalviewColourScheme.Zappo.toString(),
65 (AnnotatedCollectionI) null);
66 return new Stripy(cs1, cs2);
70 public Color findColour(char c, int j, SequenceI seq)
74 return odd.findColour(c, j, seq);
78 return even.findColour(c, j, seq);
83 public String getSchemeName()
90 * a colour scheme that is Clustal but using AWT colour equivalents
92 class MyClustal extends ResidueColourScheme
94 ClustalxColourScheme delegate;
100 private MyClustal(AnnotatedCollectionI sg,
101 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
103 delegate = new ClustalxColourScheme(sg, hiddenRepSequences);
107 public Color findColour(char c, int j, SequenceI seq)
109 Color col = delegate.findColour(c, j, seq);
111 if (col.equals(ClustalColour.BLUE.colour))
115 else if (col.equals(ClustalColour.CYAN.colour))
119 else if (col.equals(ClustalColour.GREEN.colour))
121 result = Color.green;
123 else if (col.equals(ClustalColour.MAGENTA.colour))
125 result = Color.magenta;
127 else if (col.equals(ClustalColour.ORANGE.colour))
129 result = Color.orange;
131 else if (col.equals(ClustalColour.PINK.colour))
135 else if (col.equals(ClustalColour.RED.colour))
139 else if (col.equals(ClustalColour.YELLOW.colour))
141 result = Color.yellow;
147 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
148 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
150 return new MyClustal(sg, hiddenRepSequences);
154 public String getSchemeName()
161 @BeforeClass(alwaysRun = true)
162 public static void setUpBeforeClass() throws Exception
165 * use read-only test properties file
167 Cache.loadProperties("test/jalview/io/testProps.jvprops");
168 Jalview.main(new String[] { "-nonews" });
171 @AfterClass(alwaysRun = true)
172 public static void tearDownAfterClass() throws Exception
174 Desktop.instance.closeAll_actionPerformed(null);
177 @Test(groups = "Functional")
178 public void testGetColourSchemes()
181 * this just verifies that built-in colour schemes are loaded into ColourSchemes
182 * in the order in which they are declared in the JalviewColourScheme enum
183 * (this also determines their order in Colour menus)
185 Iterator<ColourSchemeI> schemes = ColourSchemes.getInstance().getColourSchemes().iterator();
186 JalviewColourScheme[] jalviewSchemes = JalviewColourScheme.values();
188 while (schemes.hasNext() && i < jalviewSchemes.length)
190 assertTrue(schemes.next().getSchemeName()
191 .equals(jalviewSchemes[i].toString()));
196 @Test(groups = "Functional")
197 public void testGetColourScheme()
199 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
200 ">seq1\nAGLRTWQU", DataSourceType.PASTE);
201 ColourSchemes schemes = ColourSchemes.getInstance();
203 AnnotatedCollectionI al = af.getViewport().getAlignment();
205 for (JalviewColourScheme cs : JalviewColourScheme.values())
207 ColourSchemeI registered = schemes.getColourScheme(cs.toString(), al);
208 assertSame(registered.getClass(), cs.getSchemeClass());
210 af.closeMenuItem_actionPerformed(true);
213 @Test(groups = "Functional")
214 public void testRegisterColourScheme()
216 ColourSchemes.getInstance().registerColourScheme(new Stripy());
217 ColourSchemes.getInstance().registerColourScheme(new MyClustal());
218 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
219 "examples/uniref50.fa", DataSourceType.FILE);
221 * set a breakpoint here to see and play with the newly registered
222 * colour schemes in the AlignFrame colour menu
224 SequenceRenderer sr = new SequenceRenderer(af.getViewport());
225 SequenceI seq = af.getViewport().getAlignment().findName("FER_CAPAA");
228 * set and check Taylor colours
230 af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString());
231 Color taylor1 = sr.getResidueColour(seq, 88, null); // E 255,0,102
232 Color taylor2 = sr.getResidueColour(seq, 89, null); // A 204,255,0
233 Color taylor3 = sr.getResidueColour(seq, 90, null); // G 255,153,0
234 assertEquals(taylor1, new Color(255, 0, 102));
235 assertEquals(taylor2, new Color(204, 255, 0));
236 assertEquals(taylor3, new Color(255, 153, 0));
239 * set and check Zappo colours
241 af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString());
242 Color zappo1 = sr.getResidueColour(seq, 88, null); // E red
243 Color zappo2 = sr.getResidueColour(seq, 89, null); // A pink
244 Color zappo3 = sr.getResidueColour(seq, 90, null); // G magenta
245 assertEquals(zappo1, Color.red);
246 assertEquals(zappo2, Color.pink);
247 assertEquals(zappo3, Color.magenta);
250 * set 'stripy' colours - odd columns are Taylor and even are Zappo
252 af.changeColour_actionPerformed("stripy");
253 Color stripy1 = sr.getResidueColour(seq, 88, null);
254 Color stripy2 = sr.getResidueColour(seq, 89, null);
255 Color stripy3 = sr.getResidueColour(seq, 90, null);
256 assertEquals(stripy1, zappo1);
257 assertEquals(stripy2, taylor2);
258 assertEquals(stripy3, zappo3);
261 * set and check Clustal colours
263 af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString());
264 Color clustal1 = sr.getResidueColour(seq, 88, null);
265 Color clustal2 = sr.getResidueColour(seq, 89, null);
266 Color clustal3 = sr.getResidueColour(seq, 90, null);
267 assertEquals(clustal1, ClustalColour.MAGENTA.colour);
268 assertEquals(clustal2, ClustalColour.BLUE.colour);
269 assertEquals(clustal3, ClustalColour.ORANGE.colour);
272 * set 'MyClustal' colours - uses AWT colour equivalents
274 af.changeColour_actionPerformed("MyClustal");
275 Color myclustal1 = sr.getResidueColour(seq, 88, null);
276 Color myclustal2 = sr.getResidueColour(seq, 89, null);
277 Color myclustal3 = sr.getResidueColour(seq, 90, null);
278 assertEquals(myclustal1, Color.MAGENTA);
279 assertEquals(myclustal2, Color.BLUE);
280 assertEquals(myclustal3, Color.ORANGE);
284 * Tests for check if scheme name exists. Built-in scheme names are the
285 * toString() values of enum JalviewColourScheme.
287 @Test(groups = "Functional")
288 public void testNameExists()
290 ColourSchemes cs = ColourSchemes.getInstance();
291 assertFalse(cs.nameExists(null));
292 assertFalse(cs.nameExists(""));
293 assertTrue(cs.nameExists("Clustal"));
294 assertTrue(cs.nameExists("CLUSTAL"));
295 assertFalse(cs.nameExists("CLUSTAL "));
296 assertTrue(cs.nameExists("% Identity"));
297 assertFalse(cs.nameExists("PID"));