From: gmungoc Date: Wed, 30 Aug 2017 16:31:29 +0000 (+0100) Subject: JAL-2704 don't shade gap colour for PID/conservation X-Git-Tag: Release_2_10_2b1~11^2~7^2~1^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=991d2210e8e086bde29a90bdf21979261442d889;p=jalview.git JAL-2704 don't shade gap colour for PID/conservation --- diff --git a/src/jalview/renderer/ResidueShader.java b/src/jalview/renderer/ResidueShader.java index 7e4f211..aa84816 100644 --- a/src/jalview/renderer/ResidueShader.java +++ b/src/jalview/renderer/ResidueShader.java @@ -250,7 +250,10 @@ public class ResidueShader implements ResidueShaderI /* * apply PID threshold and consensus fading if in force */ - colour = adjustColour(symbol, position, colour); + if (!Comparison.isGap(symbol)) + { + colour = adjustColour(symbol, position, colour); + } return colour; } diff --git a/test/jalview/renderer/ResidueShaderTest.java b/test/jalview/renderer/ResidueShaderTest.java index 76fd9b4..26d4b15 100644 --- a/test/jalview/renderer/ResidueShaderTest.java +++ b/test/jalview/renderer/ResidueShaderTest.java @@ -10,7 +10,10 @@ import jalview.datamodel.ProfileI; import jalview.datamodel.Profiles; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; +import jalview.schemes.ColourSchemeI; import jalview.schemes.PIDColourScheme; +import jalview.schemes.ResidueProperties; +import jalview.schemes.UserColourScheme; import java.awt.Color; import java.util.Collections; @@ -163,4 +166,60 @@ public class ResidueShaderTest assertEquals(Color.WHITE, ccs.applyConservation(colour, 12)); } + /** + * A custom gap colour should not be affected by Colour by Conservation + */ + @Test(groups = "Functional") + public void testFindColour_gapColour() + { + Color[] colours = new Color[ResidueProperties.maxProteinIndex + 1]; + colours[5] = Color.blue; // Q colour + colours[23] = Color.red; // gap colour + ColourSchemeI cs = new UserColourScheme(colours); + ResidueShader ccs = new ResidueShader(cs); + + assertEquals(Color.red, ccs.findColour(' ', 7, null)); + + /* + * stub Conservation to return a given consensus string + */ + final String consSequence = "0123456789+*-"; + Conservation cons = new Conservation(null, + Collections. emptyList(), 0, 0) + { + @Override + public SequenceI getConsSequence() + { + return new Sequence("seq", consSequence); + } + }; + ccs.setConservation(cons); + + /* + * with 0% threshold, there should be no fading + */ + ccs.setConservationInc(0); + assertEquals(Color.red, ccs.findColour(' ', 7, null)); + assertEquals(Color.blue, ccs.findColour('Q', 7, null)); + + /* + * with 40% threshold, 'fade factor' is + * (11-score)/10 * 40/20 = (11-score)/5 + * so position 7, score 7 fades 80% of the way to white (255, 255, 255) + */ + ccs.setConservationInc(40); + + /* + * gap colour is unchanged for Conservation + */ + assertEquals(Color.red, ccs.findColour(' ', 7, null)); + + /* + * residue colour is faded 80% of the way from + * blue(0, 0, 255) to white(255, 255, 255) + * making (204, 204, 255) + */ + assertEquals(new Color(204, 204, 255), ccs.findColour('Q', 7, null)); + } + }