From b02cc7f6cd659b0c140f4c91a79f0f47e7878626 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 15 Nov 2017 15:47:41 +0000 Subject: [PATCH] JAL-2816 exclude filtered / thresholded out features when finding --- src/jalview/schemes/FeatureColour.java | 5 ++-- .../seqfeatures/FeatureRendererModel.java | 8 +++-- .../renderer/seqfeatures/FeatureRendererTest.java | 31 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 71a89b0..bad25f5 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -49,7 +49,7 @@ import java.util.StringTokenizer; */ public class FeatureColour implements FeatureColourI { - static final Color DEFAULT_NO_COLOUR = Color.LIGHT_GRAY; + static final Color DEFAULT_NO_COLOUR = null; private static final String BAR = "|"; @@ -607,8 +607,7 @@ public class FeatureColour implements FeatureColourI /* * graduated colour case, optionally with threshold * may be based on feature score on an attribute value - * Float.NaN is assigned minimum visible score colour - * no such attribute is assigned the 'no value' colour + * Float.NaN, or no value, is assigned the 'no value' colour */ float scr = feature.getScore(); if (attributeName != null) diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 28fceec..6afec67 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -297,9 +297,13 @@ public abstract class FeatureRendererModel List features = sequence.findFeatures(column, column, visibleTypes); + /* + * include features unless their feature group is not displayed, or + * they are hidden (have no colour) based on a filter or colour threshold + */ for (SequenceFeature sf : features) { - if (!featureGroupNotShown(sf)) + if (!featureGroupNotShown(sf) && getColour(sf) != null) { result.add(sf); } @@ -993,7 +997,7 @@ public abstract class FeatureRendererModel for (SequenceFeature sf : features) { - if (!featureGroupNotShown(sf)) + if (!featureGroupNotShown(sf) && getColour(sf) != null) { result.add(sf); } diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index 438feba..fb20dd4 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -252,6 +252,37 @@ public class FeatureRendererTest features = fr.findFeaturesAtColumn(seq, 5); assertEquals(features.size(), 1); assertTrue(features.contains(sf8)); + + /* + * give "Type3" features a graduated colour scheme + * - first with no threshold + */ + FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, null, 0f, + 10f); + fr.getFeatureColours().put("Type3", gc); + features = fr.findFeaturesAtColumn(seq, 8); + assertTrue(features.contains(sf4)); + // now with threshold > 2f - feature score of 1f is excluded + gc.setAboveThreshold(true); + gc.setThreshold(2f); + features = fr.findFeaturesAtColumn(seq, 8); + assertFalse(features.contains(sf4)); + + /* + * make "Type3" graduated colour by attribute "AF" + * - first with no attribute held - feature should be excluded + */ + gc.setAttributeName("AF"); + features = fr.findFeaturesAtColumn(seq, 8); + assertFalse(features.contains(sf4)); + // now with the attribute above threshold - should be included + sf4.setValue("AF", "2.4"); + features = fr.findFeaturesAtColumn(seq, 8); + assertTrue(features.contains(sf4)); + // now with the attribute below threshold - should be excluded + sf4.setValue("AF", "1.4"); + features = fr.findFeaturesAtColumn(seq, 8); + assertFalse(features.contains(sf4)); } @Test(groups = "Functional") -- 1.7.10.2