JAL-2816 JAL-2835 additional tests to include colour/filter by attribute
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 16 Nov 2017 09:13:00 +0000 (09:13 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 16 Nov 2017 09:13:00 +0000 (09:13 +0000)
test/jalview/renderer/seqfeatures/FeatureRendererTest.java

index 821c3b7..745eec3 100644 (file)
@@ -21,6 +21,7 @@ import jalview.util.matcher.KeyedMatcherSetI;
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -407,14 +408,15 @@ public class FeatureRendererTest
     SequenceFeature sf2 = new SequenceFeature("Cath", "", 6, 8, 6f,
             "group1");
     // score 6 is half way from yellow(255, 255, 0) to red(255, 0, 0)
-    assertEquals(fr.getColour(sf2), new Color(255, 128, 0));
+    Color expected = new Color(255, 128, 0);
+    assertEquals(fr.getColour(sf2), expected);
     
     /*
      * above threshold, score is above threshold - no change
      */
     gc.setAboveThreshold(true);
     gc.setThreshold(5f);
-    assertEquals(fr.getColour(sf2), new Color(255, 128, 0));
+    assertEquals(fr.getColour(sf2), expected);
 
     /*
      * threshold is min-max; now score 6 is 1/6 of the way from 5 to 11
@@ -454,7 +456,7 @@ public class FeatureRendererTest
 
     // with numeric attribute value
     sf2.setValue("AF", "6");
-    assertEquals(fr.getColour(sf2), new Color(255, 128, 0));
+    assertEquals(fr.getColour(sf2), expected);
 
     // with numeric value outwith threshold
     gc.setAboveThreshold(true);
@@ -463,7 +465,7 @@ public class FeatureRendererTest
 
     // with filter on AF < 4
     gc.setAboveThreshold(false);
-    assertEquals(fr.getColour(sf2), new Color(255, 128, 0));
+    assertEquals(fr.getColour(sf2), expected);
     KeyedMatcherSetI filter = new KeyedMatcherSet();
     filter.and(new KeyedMatcher(Condition.LT, 4f, "AF"));
     fr.setFeatureFilter("Cath", filter);
@@ -481,6 +483,25 @@ public class FeatureRendererTest
     assertNull(fr.getColour(sf2));
     // attribute matches filter
     sf2.setValue("Consequence", "Missense variant");
-    assertEquals(fr.getColour(sf2), new Color(255, 128, 0));
+    assertEquals(fr.getColour(sf2), expected);
+
+    // with filter on CSQ.Feature contains "ENST01234"
+    filter = new KeyedMatcherSet();
+    filter.and(new KeyedMatcher(Condition.Matches, "ENST01234", "CSQ",
+            "Feature"));
+    fr.setFeatureFilter("Cath", filter);
+    // if feature has no CSQ data, no colour
+    assertNull(fr.getColour(sf2));
+    // if CSQ data does not include Feature, no colour
+    Map<String, String> csqData = new HashMap<>();
+    csqData.put("BIOTYPE", "Transcript");
+    sf2.setValue("CSQ", csqData);
+    assertNull(fr.getColour(sf2));
+    // if attribute does not match filter, no colour
+    csqData.put("Feature", "ENST9876");
+    assertNull(fr.getColour(sf2));
+    // attribute matches filter
+    csqData.put("Feature", "ENST01234");
+    assertEquals(fr.getColour(sf2), expected);
   }
 }