X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;h=42b898db0fd8bd8a57138cde4b519a6a63b616bf;hb=58827f5ad6ff27d76c20c1aba96cd3b4a200a691;hp=1a6a5f342e8ec9bb8b1fda575657e243ccd12f33;hpb=e42eed3a0089a8a064560df4cf17a5021fd1e16a;p=jalview.git diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 1a6a5f3..42b898d 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -173,6 +173,13 @@ public class FeatureColourTest assertEquals(Color.yellow, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); + + /* + * modify original attribute label and check that copy doesn't change + */ + fc.setAttributeName("MAF", "AF"); + assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); + } @Test(groups = { "Functional" }) @@ -274,8 +281,9 @@ public class FeatureColourTest fc = new FeatureColour(); fc.setColourByLabel(true); fc.setAttributeName("CLIN_SIG"); - assertEquals("domain\tattribute|CLIN_SIG", fc.toJalviewFormat("domain")); - + assertEquals("domain\tattribute|CLIN_SIG", + fc.toJalviewFormat("domain")); + /* * colour by label (autoscaled) (an odd state you can reach by selecting * 'above threshold', then deselecting 'threshold is min/max' then 'colour @@ -341,7 +349,7 @@ public class FeatureColourTest "domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex, redHex); assertEquals(expected, fc.toJalviewFormat("domain")); - + /* * colour ranges over the actual score ranges (not min/max) */ @@ -357,8 +365,8 @@ public class FeatureColourTest fc.setThreshold(12.5f); fc.setBelowThreshold(true); expected = String.format( - "domain\tscore|%s|%s|noValueMax|12.0|25.0|below|12.5", - greenHex, redHex); + "domain\tscore|%s|%s|noValueMax|12.0|25.0|below|12.5", greenHex, + redHex); assertEquals(expected, fc.toJalviewFormat("domain")); /* @@ -400,8 +408,8 @@ public class FeatureColourTest /* * simple colour by hex code */ - fc = FeatureColour.parseJalviewFeatureColour(Format - .getHexString(Color.RED)); + fc = FeatureColour + .parseJalviewFeatureColour(Format.getHexString(Color.RED)); assertTrue(fc.isSimpleColour()); assertEquals(Color.RED, fc.getColour()); @@ -469,11 +477,60 @@ public class FeatureColourTest assertFalse(fc.hasThreshold()); assertEquals(Color.RED, fc.getMinColour()); assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.RED, fc.getNoColour()); assertEquals(10f, fc.getMin()); assertEquals(20f, fc.getMax()); assertTrue(fc.isAutoScaled()); /* + * the same, with 'no value colour' specified as max + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novaluemax|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.GREEN, fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with 'no value colour' specified as min + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novalueMin|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.RED, fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with 'no value colour' specified as none + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novaluenone|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertNull(fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with invalid 'no value colour' + */ + try + { + fc = FeatureColour + .parseJalviewFeatureColour("red|green|blue|10.0|20.0"); + fail("expected exception"); + } catch (IllegalArgumentException e) + { + assertEquals( + "Couldn't parse the minimum value for graduated colour ('blue')", + e.getMessage()); + } + + /* * graduated colour (explicitly by 'score') (no threshold) */ fc = FeatureColour @@ -610,4 +667,136 @@ public class FeatureColourTest 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()); + } }