JAL-2624 additional tests for FeatureColour.getColour(),
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 24 Jul 2017 08:24:48 +0000 (09:24 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 24 Jul 2017 08:24:48 +0000 (09:24 +0100)
filterFeaturesForDisplay

src/jalview/schemes/FeatureColour.java
test/jalview/renderer/seqfeatures/FeatureRendererTest.java
test/jalview/schemes/FeatureColourTest.java

index ed3e02d..b748d9e 100644 (file)
@@ -553,9 +553,13 @@ public class FeatureColour implements FeatureColourI
 
     /*
      * graduated colour case, optionally with threshold
-     * (treating Float.NaN as within visible range here)
+     * Float.NaN is assigned minimum visible score colour
      */
     float scr = feature.getScore();
+    if (Float.isNaN(scr))
+    {
+      return getMinColour();
+    }
     if (isAboveThreshold() && scr <= threshold)
     {
       return null;
@@ -568,10 +572,6 @@ public class FeatureColour implements FeatureColourI
     {
       return getMaxColour();
     }
-    if (Float.isNaN(scr))
-    {
-      return getMinColour();
-    }
     float scl = (scr - base) / range;
     if (isHighToLow)
     {
index 3e27aba..dc86605 100644 (file)
@@ -267,15 +267,20 @@ public class FeatureRendererTest
     fr.filterFeaturesForDisplay(features, null); // empty list, does nothing
 
     SequenceI seq = av.getAlignment().getSequenceAt(0);
-    SequenceFeature sf1 = new SequenceFeature("Cath", "", 6, 8, "group1");
+    SequenceFeature sf1 = new SequenceFeature("Cath", "", 6, 8, Float.NaN,
+            "group1");
     seq.addSequenceFeature(sf1);
-    SequenceFeature sf2 = new SequenceFeature("Cath", "", 5, 11, "group2");
+    SequenceFeature sf2 = new SequenceFeature("Cath", "", 5, 11, 2f,
+            "group2");
     seq.addSequenceFeature(sf2);
-    SequenceFeature sf3 = new SequenceFeature("Cath", "", 5, 11, "group3");
+    SequenceFeature sf3 = new SequenceFeature("Cath", "", 5, 11, 3f,
+            "group3");
     seq.addSequenceFeature(sf3);
-    SequenceFeature sf4 = new SequenceFeature("Cath", "", 6, 8, "group4");
+    SequenceFeature sf4 = new SequenceFeature("Cath", "", 6, 8, 4f,
+            "group4");
     seq.addSequenceFeature(sf4);
-    SequenceFeature sf5 = new SequenceFeature("Cath", "", 6, 9, "group4");
+    SequenceFeature sf5 = new SequenceFeature("Cath", "", 6, 9, 5f,
+            "group4");
     seq.addSequenceFeature(sf5);
 
     fr.findAllFeatures(true);
@@ -329,6 +334,7 @@ public class FeatureRendererTest
 
     /*
      * no filtering of co-located features with graduated colour scheme
+     * filterFeaturesForDisplay does _not_ check colour threshold
      * sf2 is removed as its group is hidden
      */
     features = seq.getSequenceFeatures();
index 03f7efa..7a72c15 100644 (file)
@@ -128,17 +128,28 @@ public class FeatureColourTest
             150f);
     SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f,
             null);
+
+    /*
+     * feature with score of Float.NaN is always assigned minimum colour
+     */
+    SequenceFeature sf2 = new SequenceFeature("type", "desc", 0, 20,
+            Float.NaN, null);
+
     fc.setThreshold(100f); // ignore for now
     assertEquals(new Color(204, 204, 204), fc.getColor(sf));
+    assertEquals(Color.white, fc.getColor(sf2));
 
     fc.setAboveThreshold(true); // feature lies below threshold
     assertNull(fc.getColor(sf));
+    assertEquals(Color.white, fc.getColor(sf2));
 
     fc.setBelowThreshold(true);
     fc.setThreshold(70f);
     assertNull(fc.getColor(sf)); // feature score == threshold - hidden
+    assertEquals(Color.white, fc.getColor(sf2));
     fc.setThreshold(69f);
     assertNull(fc.getColor(sf)); // feature score > threshold - hidden
+    assertEquals(Color.white, fc.getColor(sf2));
   }
 
   /**