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 jalview.datamodel.AlignmentI;
26 import jalview.gui.AlignFrame;
27 import jalview.io.DataSourceType;
28 import jalview.io.FileLoader;
30 import java.awt.Color;
32 import org.testng.annotations.Test;
34 public class ClustalxColourSchemeTest
37 private static final String FASTA =
50 @Test(groups = "Functional")
51 public void testFindColour()
53 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
54 DataSourceType.PASTE);
55 AlignmentI al = af.getViewport().getAlignment();
56 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
59 * column 1 is 70% A which is above Clustalx threshold of 60%
61 Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
62 assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
65 * column 2 is 70% A or V which is above Clustalx threshold for group
67 assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
70 * column 3 is 60% A which is not above Clustalx threshold
71 * the Ks in the other rows are not in the same Clustalx group
73 assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
76 * column 4 is 60% N which is above Clustalx threshold of 50%
78 Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
79 assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
82 * column 5 is 40% N and 40% Y which fails to pass the threshold of
85 assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
88 * column 6 is 40% N and 50% Y which fails to pass the threshold of
91 assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
94 * column 7 is 40% R and 30% K which combine to make > 60%
96 Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
97 assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
98 assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
101 * column 8 is >85% Q which qualifies K and R to be red
103 assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
104 assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
106 // TODO more test cases; check if help documentation matches implementation
112 * Test for colour calculation when the consensus percentage ignores gapped
115 @Test(groups = "Functional")
116 public void testFindColour_ignoreGaps()
122 * first column is 66% C (blue) including gaps
123 * or 100% C ignoring gaps
125 String fasta = ">seq1\nCCC\n>seq2\nccc\n>seq3\n-CC\n";
126 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
127 DataSourceType.PASTE);
128 AlignmentI al = af.getViewport().getAlignment();
129 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
132 * column 1 is 66% C which is above Clustalx threshold of 60%
134 Color clustalBlue = ClustalxColourScheme.ClustalColour.BLUE.colour;
135 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
138 * set directly to ignore gaps
140 cs.setIncludeGaps(false);
141 Color clustalPink = ClustalxColourScheme.ClustalColour.PINK.colour;
142 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
145 * set ignore gaps on the viewport...
147 cs.setIncludeGaps(true);
148 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
149 af.getViewport().setIgnoreGapsConsensus(true, af.alignPanel);
150 // next test fails: colour scheme does not read ignore gaps flag from
152 // assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);