JAL-2371 rename global/viewportColourScheme to residueShading
[jalview.git] / test / jalview / schemes / PIDColourSchemeTest.java
1 package jalview.schemes;
2
3 import static org.testng.Assert.assertEquals;
4
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;
10
11 import java.awt.Color;
12
13 import org.testng.annotations.Test;
14
15 public class PIDColourSchemeTest
16 {
17   static final Color white = Color.white;
18
19   static final Color over40 = new Color(204, 204, 255);
20
21   static final Color over60 = new Color(153, 153, 255);
22
23   static final Color over80 = new Color(100, 100, 255);
24
25   /**
26    * Test findColour for cases:
27    * <ul>
28    * <li>gap: white</li>
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>
36    * <ul>
37    */
38   @Test(groups = "Functional")
39   public void testFindColour()
40   {
41     ColourSchemeI scheme = new PIDColourScheme();
42
43     /*
44      * doesn't use column or sequence
45      */
46     assertEquals(scheme.findColour('A', 0, null, "A", 0f), white);
47     assertEquals(scheme.findColour('A', 0, null, "A", 40f), white);
48     assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
49     assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
50     assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
51     assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
52     assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
53     assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
54     assertEquals(scheme.findColour('A', 0, null, "KFV", 100f), white);
55
56     assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
57     assertEquals(scheme.findColour('A', 0, null, "a", 80f), over60);
58     assertEquals(scheme.findColour('a', 0, null, "a", 80f), over60);
59     assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
60     assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
61   }
62
63   /**
64    * Test that changing the 'ignore gaps in consensus' in the viewport (an
65    * option on the annotation label popup menu) results in a change to the
66    * colouring
67    */
68   @Test(groups = "Functional")
69   public void testFindColour_ignoreGaps()
70   {
71     /*
72      * AAAAA
73      * AAAAA
74      * -CCCC
75      * FFFFF
76      * 
77      * first column consensus is A
78      * first column PID is 50%, or 67% ignoring gaps
79      */
80     String seqs = ">seq1\nAAAAA\n>seq2\nAAAAA\n>seq3\n-CCCC\n>seq4\nFFFFF\n";
81     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
82             DataSourceType.PASTE);
83     AlignViewport viewport = af.getViewport();
84     viewport.setIgnoreGapsConsensus(false, af.alignPanel);
85     af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
86
87     SequenceI seq = viewport.getAlignment().getSequenceAt(0);
88
89     /*
90      * including gaps, A should be coloured for 50% consensus
91      */
92     Color c = viewport
93             .getResidueShading().findColour('A', 0, seq);
94     assertEquals(c, over40);
95
96     /*
97      * now choose to ignore gaps; colour should be for 67%
98      */
99     viewport.setIgnoreGapsConsensus(true, af.alignPanel);
100     c = viewport
101             .getResidueShading().findColour('A', 0, seq);
102     assertEquals(c, over60);
103   }
104 }