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.schemes;
23 import static org.testng.Assert.assertEquals;
25 import java.awt.Color;
27 import org.testng.annotations.Test;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.AlignFrame;
31 import jalview.gui.AlignViewport;
32 import jalview.io.DataSourceType;
33 import jalview.io.FileLoader;
35 public class PIDColourSchemeTest
37 static final Color white = Color.white;
39 static final Color over40 = new Color(204, 204, 255);
41 static final Color over60 = new Color(153, 153, 255);
43 static final Color over80 = new Color(100, 100, 255);
46 * Test findColour for cases:
49 * <li>no match to consensus: white</li>
50 * <li>match consensus with pid > 80%: 100,100,255</li>
51 * <li>match consensus with pid > 60%: 153, 153, 255</li>
52 * <li>match consensus with pid > 40%: 204, 204, 255</li>
53 * <li>match consensus with pid <= 40%: white</li>
54 * <li>joint consensus matching</li>
55 * <li>case insensitive matching</li>
58 @Test(groups = "Functional")
59 public void testFindColour()
61 ColourSchemeI scheme = new PIDColourScheme();
64 * doesn't use column or sequence
65 * we assume consensus residue is computed as upper case
67 assertEquals(scheme.findColour('A', 0, null, "A", 0f), white);
68 assertEquals(scheme.findColour('A', 0, null, "A", 40f), white);
69 assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
70 assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
71 assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
72 assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
73 assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
74 assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
75 assertEquals(scheme.findColour('A', 0, null, "KFV", 100f), white);
77 assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
78 assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
79 assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
83 * Test that changing the 'ignore gaps in consensus' in the viewport (an
84 * option on the annotation label popup menu) results in a change to the
87 @Test(groups = "Functional")
88 public void testFindColour_ignoreGaps()
96 * first column consensus is A
97 * first column PID is 50%, or 67% ignoring gaps
99 String seqs = ">seq1\nAAAAA\n>seq2\nAAAAA\n>seq3\n-CCCC\n>seq4\nFFFFF\n";
102 * load data and wait for consensus to be computed
104 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
105 DataSourceType.PASTE);
106 AlignViewport viewport = af.getViewport();
107 viewport.setIgnoreGapsConsensus(false, af.alignPanel);
113 } catch (InterruptedException x)
116 } while (af.getViewport().getCalcManager().isWorking());
117 af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
119 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
122 * including gaps, A should be coloured for 50% consensus
124 Color c = viewport.getResidueShading().findColour('A', 0, seq);
125 assertEquals(c, over40);
128 * now choose to ignore gaps; colour should be for 67%
130 viewport.setIgnoreGapsConsensus(true, af.alignPanel);
131 c = viewport.getResidueShading().findColour('A', 0, seq);
132 assertEquals(c, over60);