Merge branch 'bug/JAL-2791exportFilteredFeature' into merge/JAL-2791
[jalview.git] / test / jalview / renderer / seqfeatures / FeatureRendererTest.java
index a9e3754..a0fb498 100644 (file)
@@ -535,4 +535,71 @@ public class FeatureRendererTest
     csqData.put("Feature", "ENST01234");
     assertEquals(fr.getColour(sf2), expected);
   }
+
+  @Test(groups = "Functional")
+  public void testIsVisible()
+  {
+    String seqData = ">s1\nMLQGIFPRS\n";
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqData,
+            DataSourceType.PASTE);
+    AlignViewportI av = af.getViewport();
+    FeatureRenderer fr = new FeatureRenderer(av);
+    SequenceI seq = av.getAlignment().getSequenceAt(0);
+    SequenceFeature sf = new SequenceFeature("METAL", "Desc", 10, 10, 1f,
+            "Group");
+    sf.setValue("AC", "11");
+    sf.setValue("CLIN_SIG", "Likely Pathogenic");
+    seq.addSequenceFeature(sf);
+
+    assertFalse(fr.isVisible(null));
+
+    /*
+     * initial state FeatureRenderer hasn't 'found' feature
+     * and so its feature type has not yet been set visible
+     */
+    assertFalse(fr.getDisplayedFeatureCols().containsKey("METAL"));
+    assertFalse(fr.isVisible(sf));
+
+    fr.findAllFeatures(true);
+    assertTrue(fr.isVisible(sf));
+
+    /*
+     * feature group not visible
+     */
+    fr.setGroupVisibility("Group", false);
+    assertFalse(fr.isVisible(sf));
+    fr.setGroupVisibility("Group", true);
+    assertTrue(fr.isVisible(sf));
+
+    /*
+     * feature score outwith colour threshold (score > 2)
+     */
+    FeatureColourI fc = new FeatureColour(Color.white, Color.black,
+            Color.white, 0, 10);
+    fc.setAboveThreshold(true);
+    fc.setThreshold(2f);
+    fr.setColour("METAL", fc);
+    assertFalse(fr.isVisible(sf)); // score 1 is not above threshold 2
+    fc.setBelowThreshold(true);
+    assertTrue(fr.isVisible(sf)); // score 1 is below threshold 2
+
+    /*
+     * colour with threshold on attribute AC (value is 11)
+     */
+    fc.setAttributeName("AC");
+    assertFalse(fr.isVisible(sf)); // value 11 is not below threshold 2
+    fc.setAboveThreshold(true);
+    assertTrue(fr.isVisible(sf)); // value 11 is above threshold 2
+
+    fc.setAttributeName("AF"); // attribute AF is absent in sf
+    assertTrue(fr.isVisible(sf)); // feature is not excluded by threshold
+
+    FeatureMatcherSetI filter = new FeatureMatcherSet();
+    filter.and(FeatureMatcher.byAttribute(Condition.Contains, "pathogenic",
+            "CLIN_SIG"));
+    fr.setFeatureFilter("METAL", filter);
+    assertTrue(fr.isVisible(sf)); // feature matches filter
+    filter.and(FeatureMatcher.byScore(Condition.LE, "0.4"));
+    assertFalse(fr.isVisible(sf)); // feature doesn't match filter
+  }
 }