From e584930ae4941e8508c9073c6f08eb484a914bdf Mon Sep 17 00:00:00 2001 From: gmungoc Date: Sat, 22 Jul 2017 16:38:54 +0100 Subject: [PATCH] JAL-2624 check feature colour threshold when colouring structure --- .../renderer/seqfeatures/FeatureRenderer.java | 8 ++- .../seqfeatures/FeatureRendererModel.java | 10 ++- .../seqfeatures/FeatureColourFinderTest.java | 65 ++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index 98f5bff..759101d 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -335,6 +335,12 @@ public class FeatureRenderer extends FeatureRendererModel } Color featureColour = getColour(sequenceFeature); + if (featureColour == null) + { + // score feature outwith threshold for colouring + continue; + } + boolean isContactFeature = sequenceFeature.isContactFeature(); if (isContactFeature) @@ -352,7 +358,7 @@ public class FeatureRenderer extends FeatureRendererModel drawnColour = featureColour; } } - else if (showFeature(sequenceFeature)) + else { if (av.isShowSequenceFeaturesHeight() && !Float.isNaN(sequenceFeature.score)) diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index f6addb8..40f38b6 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -575,9 +575,17 @@ public abstract class FeatureRendererModel implements public Color getColour(SequenceFeature feature) { FeatureColourI fc = getFeatureStyle(feature.getType()); - return fc.getColor(feature); + return fc.isColored(feature) ? fc.getColor(feature) : null; } + /** + * Answers true unless the feature has a score value which lies outside a + * minimum or maximum threshold configured for colouring. This method does not + * check feature type or group visibility. + * + * @param sequenceFeature + * @return + */ protected boolean showFeature(SequenceFeature sequenceFeature) { FeatureColourI fc = getFeatureStyle(sequenceFeature.type); diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index 9b68b43..4fc079e 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -450,4 +450,69 @@ public class FeatureColourFinderTest FeatureColourFinder finder2 = new FeatureColourFinder(null); assertTrue(finder2.noFeaturesDisplayed()); } + + @Test(groups = "Functional") + public void testFindFeatureColour_graduatedWithThreshold() + { + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 2, + 2, 0f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 4, + 4, 5f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 7, + 7, 10f, "KdGroup")); + + /* + * graduated colour from 0 to 10 + * above threshold value of 5 + */ + Color min = new Color(100, 50, 150); + Color max = new Color(200, 0, 100); + FeatureColourI fc = new FeatureColour(min, max, 0, 10); + fc.setAboveThreshold(true); + fc.setThreshold(5f); + fr.setColour("kd", fc); + fr.featuresAdded(); + av.setShowSequenceFeatures(true); + + /* + * position 2, column 1, score 0 - below threshold - default colour + */ + Color c = finder.findFeatureColour(Color.blue, seq, 1); + assertEquals(c, Color.blue); + + /* + * position 4, column 3, score 5 - at threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.blue); + + /* + * position 7, column 9, score 10 - maximum colour in range + */ + c = finder.findFeatureColour(Color.blue, seq, 9); + assertEquals(c, max); + + /* + * now colour below threshold of 5 + */ + fc.setBelowThreshold(true); + + /* + * position 2, column 1, score 0 - min colour + */ + c = finder.findFeatureColour(Color.blue, seq, 1); + assertEquals(c, min); + + /* + * position 4, column 3, score 5 - at threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.blue); + + /* + * position 7, column 9, score 10 - above threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 9); + assertEquals(c, Color.blue); + } } -- 1.7.10.2