From: kiramt Date: Wed, 12 Jul 2017 08:43:10 +0000 (+0100) Subject: JAL-2588 Check/fix show boxes settings + unit test updates. X-Git-Tag: Release_2_10_3b1~142^2~2^2~9^2~3^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=aebfd3e1071a70f850b5ef051f9c70bd5e027706;p=jalview.git JAL-2588 Check/fix show boxes settings + unit test updates. --- diff --git a/src/jalview/appletgui/SequenceRenderer.java b/src/jalview/appletgui/SequenceRenderer.java index 516dcc1..684701e 100755 --- a/src/jalview/appletgui/SequenceRenderer.java +++ b/src/jalview/appletgui/SequenceRenderer.java @@ -84,7 +84,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer { // TODO replace 8 or so code duplications with calls to this method // (refactored as needed) - return resColourFinder.getResidueColour(av.getResidueShading(), + return resColourFinder.getResidueColour(av.getShowBoxes(), + av.getResidueShading(), allGroups, seq, position, finder); } diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 5bb0de7..c27c16b 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -95,7 +95,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer public Color getResidueColour(final SequenceI seq, int position, FeatureColourFinder finder) { - return resColourFinder.getResidueColour(av.getResidueShading(), + return resColourFinder.getResidueColour(av.getShowBoxes(), + av.getResidueShading(), allGroups, seq, position, finder); } diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index 8d9f036..607988f 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -161,7 +161,8 @@ public class OverviewRenderer if ((seq != null) && (seq.getLength() > lastcol)) { - color = resColFinder.getResidueColour(shader, allGroups, seq, lastcol, + color = resColFinder.getResidueColour(true, shader, allGroups, seq, + lastcol, fcfinder); } diff --git a/src/jalview/renderer/OverviewResColourFinder.java b/src/jalview/renderer/OverviewResColourFinder.java index 793d349..5ed218b 100644 --- a/src/jalview/renderer/OverviewResColourFinder.java +++ b/src/jalview/renderer/OverviewResColourFinder.java @@ -20,6 +20,7 @@ */ package jalview.renderer; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.Comparison; @@ -33,6 +34,9 @@ public class OverviewResColourFinder extends ResidueColourFinder Color resBoxColour = Color.white; char currentChar = seq.getCharAt(i); + // In the overview window, gaps are coloured grey, unless the colour scheme + // specifies a gap colour, in which case gaps honour the colour scheme + // settings if (shader.getColourScheme() != null) { if (Comparison.isGap(currentChar) @@ -52,4 +56,28 @@ public class OverviewResColourFinder extends ResidueColourFinder return resBoxColour; } + + /** + * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the + * overview displays the colours regardless. + */ + @Override + protected Color getResidueBoxColour(boolean showBoxes, + ResidueShaderI shader, + SequenceGroup[] allGroups, SequenceI seq, int i) + { + ResidueShaderI currentShader; + SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups, + i); + if (currentSequenceGroup != null) + { + currentShader = currentSequenceGroup.getGroupColourScheme(); + } + else + { + currentShader = shader; + } + + return getBoxColour(currentShader, seq, i); + } } diff --git a/src/jalview/renderer/ResidueColourFinder.java b/src/jalview/renderer/ResidueColourFinder.java index 99f5107..2da7233 100644 --- a/src/jalview/renderer/ResidueColourFinder.java +++ b/src/jalview/renderer/ResidueColourFinder.java @@ -32,12 +32,32 @@ public class ResidueColourFinder { } - public Color getResidueColour(ResidueShaderI shader, + /** + * Get the colour of a residue in a sequence + * + * @param showBoxes + * true if the viewport's Show Boxes setting is true + * @param shader + * the viewport's colour scheme + * @param allGroups + * all the groups which seq participates in + * @param seq + * the sequence containing the residue + * @param position + * the position of the residue in the sequence + * @param finder + * FeatureColourFinder for the viewport + * @return colour of the residue + */ + public Color getResidueColour(boolean showBoxes, ResidueShaderI shader, SequenceGroup[] allGroups, final SequenceI seq, int position, FeatureColourFinder finder) { - Color col = getResidueBoxColour(shader, allGroups, seq, position); + Color col = getResidueBoxColour(showBoxes, shader, allGroups, seq, + position); + // if there's a FeatureColourFinder we might override the residue colour + // here with feature colouring if (finder != null) { col = finder.findFeatureColour(col, seq, position); @@ -45,27 +65,54 @@ public class ResidueColourFinder return col; } - private Color getResidueBoxColour(ResidueShaderI shader, + /** + * Get the residue colour without accounting for any features + * + * @param showBoxes + * true if the viewport's Show Boxes setting is true + * @param shader + * the viewport's colour scheme + * @param allGroups + * all the groups which seq participates in + * @param seq + * the sequence containing the residue + * @param i + * the position of the residue in the sequence + * @return + */ + protected Color getResidueBoxColour(boolean showBoxes, + ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq, int i) { - - ResidueShaderI currentShader; - SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups, i); if (currentSequenceGroup != null) { - currentShader = currentSequenceGroup.getGroupColourScheme(); + if (currentSequenceGroup.getDisplayBoxes()) + { + return getBoxColour(currentSequenceGroup.getGroupColourScheme(), + seq, i); + } } - else + else if (showBoxes) { - currentShader = shader; + return getBoxColour(shader, seq, i); } - - return getBoxColour(currentShader, seq, i); + + return Color.white; } + /** + * Search all the groups for a sequence to find the one which a given res + * falls into + * + * @param allGroups + * all the groups a sequence participates in + * @param res + * the residue to search for + * @return a sequence group for res, or null if no sequence group applies + */ public SequenceGroup getCurrentSequenceGroup(SequenceGroup[] allGroups, int res) { @@ -90,11 +137,11 @@ public class ResidueColourFinder * DOCUMENT ME! * * @param shader - * DOCUMENT ME! + * the viewport's colour scheme * @param seq - * DOCUMENT ME! + * the sequence containing the residue * @param i - * DOCUMENT ME! + * the position of the residue in the sequence */ public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i) { diff --git a/test/jalview/renderer/OverviewResColourFinderTest.java b/test/jalview/renderer/OverviewResColourFinderTest.java index 900994e..649a0bf 100644 --- a/test/jalview/renderer/OverviewResColourFinderTest.java +++ b/test/jalview/renderer/OverviewResColourFinderTest.java @@ -55,10 +55,18 @@ public class OverviewResColourFinderTest ResidueColourFinder rcf = new OverviewResColourFinder(); // gaps are grey, residues white - assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.white, rcf.getResidueColour(true, + av.getResidueShading(), null, seq, 0, null)); assertEquals(Color.lightGray, rcf - .getResidueColour(av.getResidueShading(), null, seq, 2, null)); + .getResidueColour(true, av.getResidueShading(), null, seq, 2, + null)); + + // unaffected by showBoxes setting + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 0, null)); + assertEquals(Color.lightGray, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 2, null)); } @Test(groups = { "Functional" }) @@ -72,22 +80,38 @@ public class OverviewResColourFinderTest av.setGlobalColourScheme(new ZappoColourScheme()); // @see ResidueProperties.zappo - assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.pink, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 0, null)); // M - assertEquals(Color.green, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.green, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 2, null)); // T - assertEquals(Color.magenta, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.magenta, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 5, null)); // G - assertEquals(Color.orange, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.orange, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 12, null)); // F // gap colour not specified so gaps are lightGray assertEquals(Color.lightGray, rcf - .getResidueColour(av.getResidueShading(), null, seq, 3, null)); + .getResidueColour(true, av.getResidueShading(), null, seq, 3, + null)); + + // unaffected by showBoxes setting + assertEquals(Color.pink, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 0, null)); // M + assertEquals(Color.green, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 2, null)); // T + assertEquals(Color.magenta, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 5, null)); // G + assertEquals(Color.orange, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 12, null)); // F // gap colour not specified so gaps are lightGray assertEquals(Color.lightGray, rcf - .getResidueColour(av.getResidueShading(), null, seq, 3, null)); + .getResidueColour(false, av.getResidueShading(), null, seq, 3, + null)); } @@ -110,13 +134,28 @@ public class OverviewResColourFinderTest // gap colour not specified so gaps are lightGray assertEquals(Color.lightGray, rcf - .getResidueColour(av.getResidueShading(), null, seq, 3, null)); + .getResidueColour(true, av.getResidueShading(), null, seq, 3, + null)); newColours[23] = Color.pink; av.setGlobalColourScheme(new UserColourScheme(newColours)); // gap colour specified as pink - assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.pink, rcf.getResidueColour(true, + av.getResidueShading(), null, seq, 3, null)); + + // unaffected by showBoxes setting + // gap colour not specified so gaps are lightGray + newColours[23] = null; + assertEquals(Color.lightGray, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 3, null)); + + newColours[23] = Color.pink; + av.setGlobalColourScheme(new UserColourScheme(newColours)); + + // gap colour specified as pink + assertEquals(Color.pink, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 3, null)); } } diff --git a/test/jalview/renderer/ResidueColourFinderTest.java b/test/jalview/renderer/ResidueColourFinderTest.java index 175c68e..81fb2c0 100644 --- a/test/jalview/renderer/ResidueColourFinderTest.java +++ b/test/jalview/renderer/ResidueColourFinderTest.java @@ -57,17 +57,28 @@ public class ResidueColourFinderTest // @see ResidueProperties.zappo assertEquals(Color.pink, - rcf.getResidueColour(av.getResidueShading(), null, seq, 0, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 0, null)); // M assertEquals(Color.green, - rcf.getResidueColour(av.getResidueShading(), null, seq, 2, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 2, null)); // T assertEquals(Color.magenta, - rcf.getResidueColour(av.getResidueShading(), null, seq, 5, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 5, null)); // G assertEquals(Color.orange, - rcf.getResidueColour(av.getResidueShading(), null, seq, 12, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, + 12, null)); // F + + // everything is white if showBoxes is false + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 0, null)); // M + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 2, null)); // T + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 5, null)); // G + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 12, null)); // F } @Test(groups = { "Functional" }) @@ -78,10 +89,18 @@ public class ResidueColourFinderTest final AlignViewport av = new AlignViewport(al); ResidueColourFinder rcf = new ResidueColourFinder(); - assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.white, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 0, null)); - assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.white, + rcf.getResidueColour(true, av.getResidueShading(), null, seq, 2, null)); + + // no change if showBoxes is false + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 0, null)); + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 2, null)); } @Test(groups = { "Functional" }) @@ -103,18 +122,30 @@ public class ResidueColourFinderTest // gap colour not specified so gap colour is null // this is consistent with previous behaviour, but may not be correct? - assertEquals(null, rcf.getResidueColour(av.getResidueShading(), + assertEquals(null, rcf.getResidueColour(true, av.getResidueShading(), null, seq, 3, null)); newColours[23] = Color.pink; av.setGlobalColourScheme(new UserColourScheme(newColours)); // gap colour specified as pink - assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(), + assertEquals(Color.pink, rcf.getResidueColour(true, + av.getResidueShading(), + null, seq, 3, null)); + + // everything is white if showBoxes is false + newColours[23] = null; + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 3, null)); - } - // TODO more tests for getResidueColour covering groups, feature rendering, - // gaps, overview... + newColours[23] = Color.pink; + av.setGlobalColourScheme(new UserColourScheme(newColours)); + + // gap colour specified as pink + assertEquals(Color.white, rcf.getResidueColour(false, + av.getResidueShading(), null, seq, 3, null)); + } + // TODO more tests for getResidueColour covering groups, feature rendering... }