From b7cb4c78d9d787e918c9d88f917a41642dd90a7a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 18 Apr 2018 12:28:37 +0100 Subject: [PATCH] JAL-2593 render 'duplicate' features if transparency is applied --- .../seqfeatures/FeatureRendererModel.java | 37 +++++++++++--------- .../renderer/seqfeatures/FeatureRendererTest.java | 14 +++++--- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 2f30e94..43b0550 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -54,9 +54,9 @@ public abstract class FeatureRendererModel */ protected float transparency = 1.0f; - protected Map featureColours = new ConcurrentHashMap(); + protected Map featureColours = new ConcurrentHashMap<>(); - protected Map featureGroups = new ConcurrentHashMap(); + protected Map featureGroups = new ConcurrentHashMap<>(); protected String[] renderOrder; @@ -156,7 +156,7 @@ public abstract class FeatureRendererModel { av.setFeaturesDisplayed(fdi = new FeaturesDisplayed()); } - List nft = new ArrayList(); + List nft = new ArrayList<>(); for (String featureType : featureTypes) { if (!fdi.isRegistered(featureType)) @@ -192,7 +192,7 @@ public abstract class FeatureRendererModel renderOrder = neworder; } - protected Map minmax = new Hashtable(); + protected Map minmax = new Hashtable<>(); public Map getMinMax() { @@ -271,7 +271,7 @@ public abstract class FeatureRendererModel * include features at the position provided their feature type is * displayed, and feature group is null or marked for display */ - List result = new ArrayList(); + List result = new ArrayList<>(); if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null) { return result; @@ -320,7 +320,7 @@ public abstract class FeatureRendererModel } FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed(); - Set oldfeatures = new HashSet(); + Set oldfeatures = new HashSet<>(); if (renderOrder != null) { for (int i = 0; i < renderOrder.length; i++) @@ -333,7 +333,7 @@ public abstract class FeatureRendererModel } AlignmentI alignment = av.getAlignment(); - List allfeatures = new ArrayList(); + List allfeatures = new ArrayList<>(); for (int i = 0; i < alignment.getHeight(); i++) { @@ -413,7 +413,7 @@ public abstract class FeatureRendererModel */ if (minmax == null) { - minmax = new Hashtable(); + minmax = new Hashtable<>(); } synchronized (minmax) { @@ -450,7 +450,7 @@ public abstract class FeatureRendererModel */ private void updateRenderOrder(List allFeatures) { - List allfeatures = new ArrayList(allFeatures); + List allfeatures = new ArrayList<>(allFeatures); String[] oldRender = renderOrder; renderOrder = new String[allfeatures.size()]; boolean initOrders = (featureOrder == null); @@ -617,7 +617,7 @@ public abstract class FeatureRendererModel { if (featureOrder == null) { - featureOrder = new Hashtable(); + featureOrder = new Hashtable<>(); } featureOrder.put(type, new Float(position)); return position; @@ -676,7 +676,7 @@ public abstract class FeatureRendererModel * note visible feature ordering and colours before update */ List visibleFeatures = getDisplayedFeatureTypes(); - Map visibleColours = new HashMap( + Map visibleColours = new HashMap<>( getFeatureColours()); FeaturesDisplayedI av_featuresdisplayed = null; @@ -836,7 +836,7 @@ public abstract class FeatureRendererModel { if (featureGroups != null) { - List gp = new ArrayList(); + List gp = new ArrayList<>(); for (String grp : featureGroups.keySet()) { @@ -882,7 +882,7 @@ public abstract class FeatureRendererModel @Override public Map getDisplayedFeatureCols() { - Map fcols = new Hashtable(); + Map fcols = new Hashtable<>(); if (getViewport().getFeaturesDisplayed() == null) { return fcols; @@ -910,7 +910,7 @@ public abstract class FeatureRendererModel public List getDisplayedFeatureTypes() { List typ = getRenderOrder(); - List displayed = new ArrayList(); + List displayed = new ArrayList<>(); FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed(); if (feature_disp != null) { @@ -931,7 +931,7 @@ public abstract class FeatureRendererModel @Override public List getDisplayedFeatureGroups() { - List _gps = new ArrayList(); + List _gps = new ArrayList<>(); for (String gp : getFeatureGroups()) { if (checkGroupVisibility(gp, false)) @@ -966,7 +966,7 @@ public abstract class FeatureRendererModel public List findFeaturesAtResidue(SequenceI sequence, int resNo) { - List result = new ArrayList(); + List result = new ArrayList<>(); if (!av.areFeaturesDisplayed() || getFeaturesDisplayed() == null) { return result; @@ -1011,6 +1011,7 @@ public abstract class FeatureRendererModel { return; } + SequenceFeatures.sortFeatures(features, true); boolean simpleColour = fc == null || fc.isSimpleColour(); SequenceFeature lastFeature = null; @@ -1030,8 +1031,10 @@ public abstract class FeatureRendererModel * same extent as another (so would just redraw the same colour); * (checking type and isContactFeature as a fail-safe here, although * currently they are guaranteed to match in this context) + * don't remove 'redundant' features if transparency is applied + * (as feature count affects depth of feature colour) */ - if (simpleColour) + if (simpleColour && transparency == 1f) { if (lastFeature != null && sf.getBegin() == lastFeature.getBegin() && sf.getEnd() == lastFeature.getEnd() diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index d3cddf9..3d48097 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -341,10 +341,7 @@ public class FeatureRendererTest fr.filterFeaturesForDisplay(features, new FeatureColour(Color.black, Color.white, 0f, 1f)); assertEquals(features.size(), 4); - assertTrue(features.contains(sf1)); - assertTrue(features.contains(sf3)); - assertTrue(features.contains(sf4)); - assertTrue(features.contains(sf5)); + assertFalse(features.contains(sf2)); /* * co-located features with colour by label @@ -359,5 +356,14 @@ public class FeatureRendererTest assertTrue(features.contains(sf3)); assertTrue(features.contains(sf4)); assertTrue(features.contains(sf5)); + + /* + * no filtering if transparency is applied + */ + fr.setTransparency(0.5f); + features = seq.getSequenceFeatures(); + fr.setGroupVisibility("group2", true); + fr.filterFeaturesForDisplay(features, new FeatureColour(Color.RED)); + assertEquals(features.size(), 5); } } -- 1.7.10.2