JAL-2816 exclude filtered / thresholded out features when finding
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 15 Nov 2017 15:47:41 +0000 (15:47 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 15 Nov 2017 15:47:41 +0000 (15:47 +0000)
src/jalview/schemes/FeatureColour.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
test/jalview/renderer/seqfeatures/FeatureRendererTest.java

index 71a89b0..bad25f5 100644 (file)
@@ -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)
index 28fceec..6afec67 100644 (file)
@@ -297,9 +297,13 @@ public abstract class FeatureRendererModel
     List<SequenceFeature> 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);
       }
index 438feba..fb20dd4 100644 (file)
@@ -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")