1 package jalview.schemes;
3 import static org.testng.Assert.assertEquals;
5 import jalview.datamodel.SequenceI;
6 import jalview.gui.AlignFrame;
7 import jalview.gui.AlignViewport;
8 import jalview.io.DataSourceType;
9 import jalview.io.FileLoader;
11 import java.awt.Color;
13 import org.testng.annotations.Test;
15 public class PIDColourSchemeTest
17 static final Color white = Color.white;
19 static final Color over40 = new Color(204, 204, 255);
21 static final Color over60 = new Color(153, 153, 255);
23 static final Color over80 = new Color(100, 100, 255);
26 * Test findColour for cases:
29 * <li>no match to consensus: white</li>
30 * <li>match consensus with pid > 80%: 100,100,255</li>
31 * <li>match consensus with pid > 60%: 153, 153, 255</li>
32 * <li>match consensus with pid > 40%: 204, 204, 255</li>
33 * <li>match consensus with pid <= 40%: white</li>
34 * <li>joint consensus matching</li>
35 * <li>case insensitive matching</li>
38 @Test(groups = "Functional")
39 public void testFindColour()
41 ColourSchemeI scheme = new PIDColourScheme();
44 * doesn't use column or sequence
45 * we assume consensus residue is computed as upper case
47 assertEquals(scheme.findColour('A', 0, null, "A", 0f), white);
48 assertEquals(scheme.findColour('A', 0, null, "A", 40f), white);
49 assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
50 assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
51 assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
52 assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
53 assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
54 assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
55 assertEquals(scheme.findColour('A', 0, null, "KFV", 100f), white);
57 assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
58 assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
59 assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
63 * Test that changing the 'ignore gaps in consensus' in the viewport (an
64 * option on the annotation label popup menu) results in a change to the
67 @Test(groups = "Functional")
68 public void testFindColour_ignoreGaps()
76 * first column consensus is A
77 * first column PID is 50%, or 67% ignoring gaps
79 String seqs = ">seq1\nAAAAA\n>seq2\nAAAAA\n>seq3\n-CCCC\n>seq4\nFFFFF\n";
82 * load data and wait for consensus to be computed
84 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
85 DataSourceType.PASTE);
86 AlignViewport viewport = af.getViewport();
87 viewport.setIgnoreGapsConsensus(false, af.alignPanel);
88 while (viewport.getConsensusSeq() == null)
95 } catch (InterruptedException e)
100 af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
102 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
105 * including gaps, A should be coloured for 50% consensus
108 .getResidueShading().findColour('A', 0, seq);
109 assertEquals(c, over40);
112 * now choose to ignore gaps; colour should be for 67%
114 viewport.setIgnoreGapsConsensus(true, af.alignPanel);
116 .getResidueShading().findColour('A', 0, seq);
117 assertEquals(c, over60);