1 package jalview.schemes;
3 import static org.testng.Assert.assertEquals;
5 import jalview.datamodel.AlignmentI;
6 import jalview.gui.AlignFrame;
7 import jalview.io.DataSourceType;
8 import jalview.io.FileLoader;
10 import java.awt.Color;
12 import org.testng.annotations.Test;
14 public class ClustalxColourSchemeTest
17 private static final String FASTA =
30 @Test(groups = "Functional")
31 public void testFindColour()
33 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
34 DataSourceType.PASTE);
35 AlignmentI al = af.getViewport().getAlignment();
36 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
39 * column 1 is 70% A which is above Clustalx threshold of 60%
41 Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
42 assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
45 * column 2 is 70% A or V which is above Clustalx threshold for group
47 assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
50 * column 3 is 60% A which is not above Clustalx threshold
51 * the Ks in the other rows are not in the same Clustalx group
53 assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
56 * column 4 is 60% N which is above Clustalx threshold of 50%
58 Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
59 assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
62 * column 5 is 40% N and 40% Y which fails to pass the threshold of
65 assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
68 * column 6 is 40% N and 50% Y which fails to pass the threshold of
71 assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
74 * column 7 is 40% R and 30% K which combine to make > 60%
76 Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
77 assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
78 assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
81 * column 8 is >85% Q which qualifies K and R to be red
83 assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
84 assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
86 // TODO more test cases; check if help documentation matches implementation
92 * Test for colour calculation when the consensus percentage ignores gapped
95 @Test(groups = "Functional")
96 public void testFindColour_ignoreGaps()
102 * first column is 66% C (blue) including gaps
103 * or 100% C ignoring gaps
105 String fasta = ">seq1\nCCC\n>seq2\nccc\n>seq3\n-CC\n";
106 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
107 DataSourceType.PASTE);
108 AlignmentI al = af.getViewport().getAlignment();
109 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
112 * column 1 is 66% C which is above Clustalx threshold of 60%
114 Color clustalBlue = ClustalxColourScheme.ClustalColour.BLUE.colour;
115 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
118 * set directly to ignore gaps
120 cs.setIncludeGaps(false);
121 Color clustalPink = ClustalxColourScheme.ClustalColour.PINK.colour;
122 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
125 * set ignore gaps on the viewport...
127 cs.setIncludeGaps(true);
128 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
129 af.getViewport().setIgnoreGapsConsensus(true, af.alignPanel);
130 // next test fails: colour scheme does not read ignore gaps flag from
132 // assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);