From: gmungoc Date: Thu, 27 Sep 2018 15:23:16 +0000 (+0100) Subject: JAL-2791 method that tests all conditions for feature visibility X-Git-Tag: Release_2_11_0~17^2~81^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=356260e6aa37640091849355ed97cd4103cc4c6c;p=jalview.git JAL-2791 method that tests all conditions for feature visibility --- diff --git a/src/jalview/api/FeatureRenderer.java b/src/jalview/api/FeatureRenderer.java index cf3c8da..28fe550 100644 --- a/src/jalview/api/FeatureRenderer.java +++ b/src/jalview/api/FeatureRenderer.java @@ -265,4 +265,19 @@ public interface FeatureRenderer * @return */ Color getColour(SequenceFeature feature); + + /** + * Answers true if feature would be shown, else false. A feature is shown if + * + * + * @param feature + * @return + */ + boolean isVisible(SequenceFeature feature); } diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 553f813..2aadee4 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -1150,4 +1150,32 @@ public abstract class FeatureRendererModel return filter == null ? true : filter.matches(sf); } + @Override + public boolean isVisible(SequenceFeature feature) + { + if (feature == null) + { + return false; + } + if (getFeaturesDisplayed() == null + || !getFeaturesDisplayed().isVisible(feature.getType())) + { + return false; + } + if (featureGroupNotShown(feature)) + { + return false; + } + FeatureColourI fc = featureColours.get(feature.getType()); + if (fc != null && fc.isOutwithThreshold(feature)) + { + return false; + } + if (!featureMatchesFilters(feature)) + { + return false; + } + return true; + } + } diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index 11b129e..7c9927f 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -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 + } }