1 package jalview.renderer;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
7 import jalview.analysis.Conservation;
8 import jalview.datamodel.Profile;
9 import jalview.datamodel.ProfileI;
10 import jalview.datamodel.Profiles;
11 import jalview.datamodel.Sequence;
12 import jalview.datamodel.SequenceI;
13 import jalview.schemes.PIDColourScheme;
15 import java.awt.Color;
16 import java.util.Collections;
18 import org.testng.annotations.Test;
20 public class ResidueShaderTest
23 @Test(groups = "Functional")
24 public void testAboveThreshold()
27 * make up profiles for this alignment:
33 ProfileI[] profiles = new ProfileI[4];
34 profiles[0] = new Profile(4, 0, 2, "AS");
35 profiles[1] = new Profile(4, 0, 4, "R");
36 profiles[2] = new Profile(4, 4, 0, "");
37 profiles[3] = new Profile(4, 1, 2, "T");
38 ResidueShader ccs = new ResidueShader(new PIDColourScheme());
39 ccs.setConsensus(new Profiles(profiles));
44 ccs.setThreshold(0, true);
45 assertTrue(ccs.aboveThreshold('a', 0));
46 assertTrue(ccs.aboveThreshold('S', 0));
47 assertTrue(ccs.aboveThreshold('W', 0));
48 assertTrue(ccs.aboveThreshold('R', 1));
49 assertTrue(ccs.aboveThreshold('W', 2));
50 assertTrue(ccs.aboveThreshold('t', 3));
51 assertTrue(ccs.aboveThreshold('Q', 3));
54 * with threshold, include gaps
56 ccs.setThreshold(60, false);
57 assertFalse(ccs.aboveThreshold('a', 0));
58 assertFalse(ccs.aboveThreshold('S', 0));
59 assertTrue(ccs.aboveThreshold('R', 1));
60 assertFalse(ccs.aboveThreshold('W', 2));
61 assertFalse(ccs.aboveThreshold('t', 3)); // 50% < 60%
64 * with threshold, ignore gaps
66 ccs.setThreshold(60, true);
67 assertFalse(ccs.aboveThreshold('a', 0));
68 assertFalse(ccs.aboveThreshold('S', 0));
69 assertTrue(ccs.aboveThreshold('R', 1));
70 assertFalse(ccs.aboveThreshold('W', 2));
71 assertTrue(ccs.aboveThreshold('t', 3)); // 67% > 60%
75 * Test colour bleaching based on conservation score and conservation slider.
76 * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
78 @Test(groups = "Functional")
79 public void testApplyConservation()
81 ResidueShader ccs = new ResidueShader(new PIDColourScheme());
83 // no conservation present - no fading
84 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 12));
87 * stub Conservation to return a given consensus string
89 final String consSequence = "0123456789+*-";
90 Conservation cons = new Conservation(null,
91 Collections.<SequenceI> emptyList(), 0, 0)
94 public SequenceI getConsSequence()
96 return new Sequence("seq", consSequence);
99 ccs.setConservation(cons);
101 // column out of range:
102 assertEquals(Color.RED,
103 ccs.applyConservation(Color.RED, consSequence.length()));
106 * with 100% threshold, 'fade factor' is
107 * (11-score)/10 * 100/20 = (11-score)/2
108 * which is >= 1 for all scores i.e. all fade to white except +, *
110 ccs.setConservationInc(100);
111 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 0));
112 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 1));
113 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 2));
114 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 3));
115 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 4));
116 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 5));
117 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 6));
118 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 7));
119 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 8));
120 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 9));
121 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
122 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
123 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12));
126 * with 0% threshold, there should be no fading
128 ccs.setConservationInc(0);
129 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 0));
130 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 1));
131 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 2));
132 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 3));
133 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 4));
134 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 5));
135 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 6));
136 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 7));
137 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 8));
138 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 9));
139 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
140 assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
141 assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12)); // gap
144 * with 40% threshold, 'fade factor' is
145 * (11-score)/10 * 40/20 = (11-score)/5
146 * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
147 * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
149 ccs.setConservationInc(40);
150 Color colour = new Color(155, 105, 55);
151 assertEquals(Color.WHITE, ccs.applyConservation(colour, 0));
152 assertEquals(Color.WHITE, ccs.applyConservation(colour, 1));
153 assertEquals(Color.WHITE, ccs.applyConservation(colour, 2));
154 assertEquals(Color.WHITE, ccs.applyConservation(colour, 3));
155 assertEquals(Color.WHITE, ccs.applyConservation(colour, 4));
156 assertEquals(Color.WHITE, ccs.applyConservation(colour, 5));
157 assertEquals(Color.WHITE, ccs.applyConservation(colour, 6));
158 assertEquals(new Color(235, 225, 215), ccs.applyConservation(colour, 7));
159 assertEquals(new Color(215, 195, 175), ccs.applyConservation(colour, 8));
160 assertEquals(new Color(195, 165, 135), ccs.applyConservation(colour, 9));
161 assertEquals(colour, ccs.applyConservation(colour, 10));
162 assertEquals(colour, ccs.applyConservation(colour, 11));
163 assertEquals(Color.WHITE, ccs.applyConservation(colour, 12));