+
+ @Test(groups = { "Functional" })
+ public void testGetColor_colourByAttributeText()
+ {
+ FeatureColour fc = new FeatureColour();
+ fc.setColourByLabel(true);
+ fc.setAttributeName("consequence");
+ SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
+ null);
+
+ /*
+ * if feature has no such attribute, use 'no value' colour
+ */
+ assertEquals(FeatureColour.DEFAULT_NO_COLOUR, fc.getColor(sf));
+
+ /*
+ * if feature has attribute, generate colour from value
+ */
+ sf.setValue("consequence", "benign");
+ Color expected = ColorUtils.createColourFromName("benign");
+ assertEquals(expected, fc.getColor(sf));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetColor_GraduatedByAttributeValue()
+ {
+ /*
+ * graduated colour based on attribute value for AF
+ * given a min-max range of 0-100
+ */
+ FeatureColour fc = new FeatureColour(Color.white,
+ new Color(50, 100, 150), new Color(150, 200, 250), Color.yellow,
+ 0f, 100f);
+ String attName = "AF";
+ fc.setAttributeName(attName);
+
+ /*
+ * first case: feature lacks the attribute - use 'no value' colour
+ */
+ SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f,
+ null);
+ assertEquals(Color.yellow, fc.getColor(sf));
+
+ /*
+ * second case: attribute present but not numeric - treat as if absent
+ */
+ sf.setValue(attName, "twelve");
+ assertEquals(Color.yellow, fc.getColor(sf));
+
+ /*
+ * third case: valid attribute value
+ */
+ sf.setValue(attName, "20.0");
+ Color expected = new Color(70, 120, 170);
+ assertEquals(expected, fc.getColor(sf));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testIsOutwithThreshold()
+ {
+ FeatureColourI fc = new FeatureColour(Color.red);
+ SequenceFeature sf = new SequenceFeature("METAL", "desc", 10, 12, 1.2f, "grp");
+ assertFalse(fc.isOutwithThreshold(null));
+ assertFalse(fc.isOutwithThreshold(sf));
+
+ fc = new FeatureColour(null, Color.white, Color.black, Color.green, 0f,
+ 10f);
+ assertFalse(fc.isOutwithThreshold(sf)); // no threshold
+
+ fc.setAboveThreshold(true);
+ fc.setThreshold(1f);
+ assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is above 1
+
+ fc.setThreshold(2f);
+ assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not above 2
+
+ fc.setBelowThreshold(true);
+ assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is below 2
+
+ fc.setThreshold(1f);
+ assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not below 1
+
+ /*
+ * with attribute value threshold
+ */
+ fc.setAttributeName("AC");
+ assertFalse(fc.isOutwithThreshold(sf)); // missing attribute AC is ignored
+
+ sf.setValue("AC", "-1");
+ assertFalse(fc.isOutwithThreshold(sf)); // value -1 is below 1
+
+ sf.setValue("AC", "1");
+ assertTrue(fc.isOutwithThreshold(sf)); // value 1 is not below 1
+
+ sf.setValue("AC", "junk");
+ assertFalse(fc.isOutwithThreshold(sf)); // bad value is ignored
+ }
+
+ /**
+ * Test description of feature colour suitable for a tooltip
+ */
+ @Test(groups = { "Functional" })
+ public void testGetDescription()
+ {
+ /*
+ * plain colour
+ */
+ FeatureColour fc = new FeatureColour(Color.RED);
+ assertEquals(
+ String.format("r=%d,g=%d,b=%d", Color.RED.getRed(),
+ Color.red.getGreen(), Color.red.getBlue()),
+ fc.getDescription());
+
+ /*
+ * colour by label (no threshold)
+ */
+ fc = new FeatureColour();
+ fc.setColourByLabel(true);
+ assertEquals("By Label", fc.getDescription());
+
+ /*
+ * colour by attribute text (no threshold)
+ */
+ fc = new FeatureColour();
+ fc.setColourByLabel(true);
+ fc.setAttributeName("CLIN_SIG");
+ assertEquals("By CLIN_SIG", fc.getDescription());
+
+ /*
+ * colour by label (above score threshold)
+ */
+ fc = new FeatureColour();
+ fc.setColourByLabel(true);
+ fc.setAutoScaled(false);
+ fc.setThreshold(12.5f);
+ fc.setAboveThreshold(true);
+ assertEquals("By Label (Score > 12.5)",
+ fc.getDescription());
+
+ /*
+ * colour by label (below score threshold)
+ */
+ fc.setBelowThreshold(true);
+ assertEquals("By Label (Score < 12.5)",
+ fc.getDescription());
+
+ /*
+ * colour by attributes text (below score threshold)
+ */
+ fc.setBelowThreshold(true);
+ fc.setAttributeName("CSQ", "Consequence");
+ assertEquals(
+ "By CSQ:Consequence (Score < 12.5)",
+ fc.getDescription());
+
+ /*
+ * graduated colour by score, no threshold
+ */
+ fc = new FeatureColour(null, Color.GREEN, Color.RED, null, 12f, 25f);
+ assertEquals("By Score", fc.getDescription());
+
+ /*
+ * graduated colour by score, below threshold
+ */
+ fc.setThreshold(12.5f);
+ fc.setBelowThreshold(true);
+ assertEquals("By Score (< 12.5)",
+ fc.getDescription());
+
+ /*
+ * graduated colour by score, above threshold
+ */
+ fc.setThreshold(12.5f);
+ fc.setAboveThreshold(true);
+ fc.setAutoScaled(false);
+ assertEquals("By Score (> 12.5)",
+ fc.getDescription());
+
+ /*
+ * graduated colour by attribute, no threshold
+ */
+ fc.setAttributeName("CSQ", "AF");
+ fc.setAboveThreshold(false);
+ fc.setAutoScaled(false);
+ assertEquals("By CSQ:AF", fc.getDescription());
+
+ /*
+ * graduated colour by attribute, above threshold
+ */
+ fc.setAboveThreshold(true);
+ fc.setAutoScaled(false);
+ assertEquals("By CSQ:AF (> 12.5)",
+ fc.getDescription());
+ }