1 package jalview.schemes;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
7 import jalview.datamodel.Profile;
8 import jalview.datamodel.ProfileI;
9 import jalview.datamodel.Profiles;
11 import java.awt.Color;
13 import org.testng.annotations.Test;
15 public class ResidueColourSchemeTest
17 @Test(groups = "Functional")
18 public void testAboveThreshold()
21 * make up profiles for this alignment:
27 ProfileI[] profiles = new ProfileI[4];
28 profiles[0] = new Profile(4, 0, 2, "AS");
29 profiles[1] = new Profile(4, 0, 4, "R");
30 profiles[2] = new Profile(4, 4, 0, "");
31 profiles[3] = new Profile(4, 1, 2, "T");
32 ResidueColourScheme rcs = new ResidueColourScheme();
33 rcs.setConsensus(new Profiles(profiles));
38 rcs.setThreshold(0, true);
39 assertTrue(rcs.aboveThreshold('a', 0));
40 assertTrue(rcs.aboveThreshold('S', 0));
41 assertFalse(rcs.aboveThreshold('W', 0));
42 assertTrue(rcs.aboveThreshold('R', 1));
43 assertFalse(rcs.aboveThreshold('W', 2));
44 assertTrue(rcs.aboveThreshold('t', 3));
45 assertFalse(rcs.aboveThreshold('Q', 3));
48 * with threshold, include gaps
50 rcs.setThreshold(60, false);
51 assertFalse(rcs.aboveThreshold('a', 0));
52 assertFalse(rcs.aboveThreshold('S', 0));
53 assertTrue(rcs.aboveThreshold('R', 1));
54 assertFalse(rcs.aboveThreshold('W', 2));
55 assertFalse(rcs.aboveThreshold('t', 3)); // 50% < 60%
58 * with threshold, ignore gaps
60 rcs.setThreshold(60, true);
61 assertFalse(rcs.aboveThreshold('a', 0));
62 assertFalse(rcs.aboveThreshold('S', 0));
63 assertTrue(rcs.aboveThreshold('R', 1));
64 assertFalse(rcs.aboveThreshold('W', 2));
65 assertTrue(rcs.aboveThreshold('t', 3)); // 67% > 60%
69 * Test colour bleaching based on conservation score and conservation slider.
70 * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
72 @Test(groups = "Functional")
73 public void testApplyConservation()
75 ResidueColourScheme rcs = new ResidueColourScheme();
77 // no conservation present - no fading
78 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 12));
80 // cheat by setting conservation sequence directly
81 // rather than calculating it - good enough for this test
82 String consensus = "0123456789+*-";
83 rcs.conservation = consensus.toCharArray();
85 // column out of range:
86 assertEquals(Color.RED,
87 rcs.applyConservation(Color.RED, consensus.length()));
90 * with 100% threshold, 'fade factor' is
91 * (11-score)/10 * 100/20 = (11-score)/2
92 * which is >= 1 for all scores i.e. all fade to white except +, *
94 rcs.setConservationInc(100);
95 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 0));
96 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 1));
97 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 2));
98 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 3));
99 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 4));
100 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 5));
101 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 6));
102 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 7));
103 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 8));
104 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 9));
105 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
106 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
107 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12));
110 * with 0% threshold, there should be no fading
112 rcs.setConservationInc(0);
113 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 0));
114 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 1));
115 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 2));
116 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 3));
117 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 4));
118 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 5));
119 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 6));
120 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 7));
121 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 8));
122 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 9));
123 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
124 assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
125 assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12)); // gap
128 * with 40% threshold, 'fade factor' is
129 * (11-score)/10 * 40/20 = (11-score)/5
130 * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
131 * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
133 rcs.setConservationInc(40);
134 Color colour = new Color(155, 105, 55);
135 assertEquals(Color.WHITE, rcs.applyConservation(colour, 0));
136 assertEquals(Color.WHITE, rcs.applyConservation(colour, 1));
137 assertEquals(Color.WHITE, rcs.applyConservation(colour, 2));
138 assertEquals(Color.WHITE, rcs.applyConservation(colour, 3));
139 assertEquals(Color.WHITE, rcs.applyConservation(colour, 4));
140 assertEquals(Color.WHITE, rcs.applyConservation(colour, 5));
141 assertEquals(Color.WHITE, rcs.applyConservation(colour, 6));
142 assertEquals(new Color(235, 225, 215), rcs.applyConservation(colour, 7));
143 assertEquals(new Color(215, 195, 175), rcs.applyConservation(colour, 8));
144 assertEquals(new Color(195, 165, 135), rcs.applyConservation(colour, 9));
145 assertEquals(colour, rcs.applyConservation(colour, 10));
146 assertEquals(colour, rcs.applyConservation(colour, 11));
147 assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));