+package jalview.schemes;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.Profile;
+import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.util.Collections;
+
+import org.testng.annotations.Test;
+
+public class CollectionColourSchemeTest
+{
+
+ @Test(groups = "Functional")
+ public void testAboveThreshold()
+ {
+ /*
+ * make up profiles for this alignment:
+ * AR-Q
+ * AR--
+ * SR-T
+ * SR-T
+ */
+ ProfileI[] profiles = new ProfileI[4];
+ profiles[0] = new Profile(4, 0, 2, "AS");
+ profiles[1] = new Profile(4, 0, 4, "R");
+ profiles[2] = new Profile(4, 4, 0, "");
+ profiles[3] = new Profile(4, 1, 2, "T");
+ CollectionColourScheme ccs = new CollectionColourScheme(
+ new PIDColourScheme());
+ ccs.setConsensus(new Profiles(profiles));
+
+ /*
+ * no threshold
+ */
+ ccs.setThreshold(0, true);
+ assertTrue(ccs.aboveThreshold('a', 0));
+ assertTrue(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('W', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertTrue(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3));
+ assertTrue(ccs.aboveThreshold('Q', 3));
+
+ /*
+ * with threshold, include gaps
+ */
+ ccs.setThreshold(60, false);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertFalse(ccs.aboveThreshold('t', 3)); // 50% < 60%
+
+ /*
+ * with threshold, ignore gaps
+ */
+ ccs.setThreshold(60, true);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3)); // 67% > 60%
+ }
+
+ /**
+ * Test colour bleaching based on conservation score and conservation slider.
+ * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
+ */
+ @Test(groups = "Functional")
+ public void testApplyConservation()
+ {
+ CollectionColourScheme ccs = new CollectionColourScheme(
+ new PIDColourScheme());
+
+ // no conservation present - no fading
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * stub Conservation to return a given consensus string
+ */
+ final String consSequence = "0123456789+*-";
+ Conservation cons = new Conservation(null,
+ Collections.<SequenceI> emptyList(), 0, 0)
+ {
+ @Override
+ public SequenceI getConsSequence() {
+ return new Sequence("seq", consSequence);
+ }
+ };
+ ccs.setConservation(cons);
+
+ // column out of range:
+ assertEquals(Color.RED,
+ ccs.applyConservation(Color.RED, consSequence.length()));
+
+ /*
+ * with 100% threshold, 'fade factor' is
+ * (11-score)/10 * 100/20 = (11-score)/2
+ * which is >= 1 for all scores i.e. all fade to white except +, *
+ */
+ ccs.setConservationInc(100);
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * with 0% threshold, there should be no fading
+ */
+ ccs.setConservationInc(0);
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12)); // gap
+
+ /*
+ * with 40% threshold, 'fade factor' is
+ * (11-score)/10 * 40/20 = (11-score)/5
+ * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
+ * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
+ */
+ ccs.setConservationInc(40);
+ Color colour = new Color(155, 105, 55);
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 6));
+ assertEquals(new Color(235, 225, 215), ccs.applyConservation(colour, 7));
+ assertEquals(new Color(215, 195, 175), ccs.applyConservation(colour, 8));
+ assertEquals(new Color(195, 165, 135), ccs.applyConservation(colour, 9));
+ assertEquals(colour, ccs.applyConservation(colour, 10));
+ assertEquals(colour, ccs.applyConservation(colour, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 12));
+ }
+
+}