From: Jim Procter Date: Fri, 23 Sep 2022 12:04:24 +0000 (+0100) Subject: JAL-4071 colour rows according to simple/graduated feature colour, beginning of suppo... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeatures%2FJAL-4071_visibleFeaturesCounter;p=jalview.git JAL-4071 colour rows according to simple/graduated feature colour, beginning of support for complement features --- diff --git a/examples/groovy/featuresCounter.groovy b/examples/groovy/featuresCounter.groovy index dc4c97c..990800e 100644 --- a/examples/groovy/featuresCounter.groovy +++ b/examples/groovy/featuresCounter.groovy @@ -40,8 +40,8 @@ def annotator = [ getNames: { ['Phosphorylation', 'Turn'] as String[] }, getDescriptions: { ['Count of Phosphorylation features', 'Count of Turn features'] as String[] }, - getMinColour: { [0, 255, 255] as int[] }, // cyan - getMaxColour: { [0, 0, 255] as int[] }, // blue + getMinColour: { i -> [0, 255, 255] as int[] }, // cyan + getMaxColour: { i -> [0, 0, 255] as int[] }, // blue count: { res, feats -> int phos diff --git a/examples/groovy/visibleFeaturesCounter.groovy b/examples/groovy/visibleFeaturesCounter.groovy index b3180f8..56b3912 100644 --- a/examples/groovy/visibleFeaturesCounter.groovy +++ b/examples/groovy/visibleFeaturesCounter.groovy @@ -75,8 +75,8 @@ def columnSetCounter = [ getNames: { visibleFeatures as String[] }, getDescriptions: { visibleFeatures as String[] }, - getMinColour: { [0, 255, 255] as int[] }, // cyan - getMaxColour: { [0, 0, 255] as int[] }, // blue + getMinColour: { i-> [0, 255, 255] as int[] }, // cyan + getMaxColour: { i-> [0, 0, 255] as int[] }, // blue count: { res, feats -> getCounts.call(feats) diff --git a/src/jalview/workers/ColumnCounterSetWorker.java b/src/jalview/workers/ColumnCounterSetWorker.java index 3a4bcc4..0858527 100644 --- a/src/jalview/workers/ColumnCounterSetWorker.java +++ b/src/jalview/workers/ColumnCounterSetWorker.java @@ -29,6 +29,7 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.MappedFeatures; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureRenderer; @@ -147,11 +148,6 @@ class ColumnCounterSetWorker extends AlignCalcWorker max[crow] = 0; } - int[] minC = counter.getMinColour(); - int[] maxC = counter.getMaxColour(); - Color minColour = new Color(minC[0], minC[1], minC[2]); - Color maxColour = new Color(maxC[0], maxC[1], maxC[2]); - for (int col = 0; col < width; col++) { int[] count = counts[col]; @@ -181,6 +177,11 @@ class ColumnCounterSetWorker extends AlignCalcWorker for (int anrow = 0; anrow < rows; anrow++) { + int[] minC = counter.getMinColour(anrow); + int[] maxC = counter.getMaxColour(anrow); + Color minColour = new Color(minC[0], minC[1], minC[2]); + Color maxColour = new Color(maxC[0], maxC[1], maxC[2]); + Annotation[] anns = new Annotation[width]; long rmax = 0; /* @@ -276,6 +277,12 @@ class ColumnCounterSetWorker extends AlignCalcWorker */ // see JAL-2075 List features = fr.findFeaturesAtColumn(seq, col + 1); + if (fr.hasRenderOrder()) + { + MappedFeatures mappedFeatres = fr.findComplementFeaturesAtResidue(seq, + seq.findPosition(col)); + features.addAll(mappedFeatres.features); + } int[] count = this.counter.count(String.valueOf(res), features); return count; } diff --git a/src/jalview/workers/FeatureSetCounterI.java b/src/jalview/workers/FeatureSetCounterI.java index e14952f..fec8afd 100644 --- a/src/jalview/workers/FeatureSetCounterI.java +++ b/src/jalview/workers/FeatureSetCounterI.java @@ -21,10 +21,10 @@ package jalview.workers; -import jalview.datamodel.SequenceFeature; - import java.util.List; +import jalview.datamodel.SequenceFeature; + /** * An interface for a type that returns counts (per computed annotation type) of * any value of interest at a sequence position that can be determined from the @@ -66,20 +66,22 @@ public interface FeatureSetCounterI String[] getDescriptions(); /** - * Returns the colour (as [red, green, blue] values in the range 0-255) to use - * for the minimum value on histogram bars. If this is different to - * getMaxColour(), then bars will have a graduated colour. + * for each property returned from getNames Returns the colour (as [red, + * green, blue] values in the range 0-255) to use for the minimum value on + * histogram bars. If this is different to getMaxColour(), then bars will have + * a graduated colour. * * @return */ - int[] getMinColour(); + int[] getMinColour(int anrow); /** - * Returns the colour (as [red, green, blue] values in the range 0-255) to use - * for the maximum value on histogram bars. If this is the same as - * getMinColour(), then bars will have a single colour (not graduated). + * for each property returned from getNames Returns the colour (as [red, + * green, blue] values in the range 0-255) to use for the maximum value on + * histogram bars. If this is the same as getMinColour(), then bars will have + * a single colour (not graduated). * * @return */ - int[] getMaxColour(); + int[] getMaxColour(int anrow); } diff --git a/src/jalview/workers/VisibleFeaturesAnnotationTracks.java b/src/jalview/workers/VisibleFeaturesAnnotationTracks.java index baa8038..6e54628 100644 --- a/src/jalview/workers/VisibleFeaturesAnnotationTracks.java +++ b/src/jalview/workers/VisibleFeaturesAnnotationTracks.java @@ -20,14 +20,17 @@ */ package jalview.workers; +import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import jalview.api.AlignViewportI; +import jalview.api.FeatureColourI; import jalview.api.FeaturesDisplayedI; import jalview.datamodel.SequenceFeature; import jalview.gui.FeatureRenderer; @@ -44,7 +47,10 @@ public class VisibleFeaturesAnnotationTracks implements FeatureSetCounterI @Override public void propertyChange(PropertyChangeEvent evt) { - if (ourViewport != null) // could check source is + if (ourViewport != null) // could + // check + // source + // is // ourFr.getChangeSupport... { updateFeatureAnnotationTracks(); @@ -91,6 +97,9 @@ public class VisibleFeaturesAnnotationTracks implements FeatureSetCounterI .isShowSequenceFeatureCounts() ? ourViewport.getFeaturesDisplayed() : null; + // get latest FeatureRenderer, just in case it's different. + ourFr = ourFr.getAlignPanel().getFeatureRenderer(); + Set visibleFeatures = new HashSet(); if (featuresDisp != null) { @@ -103,13 +112,35 @@ public class VisibleFeaturesAnnotationTracks implements FeatureSetCounterI } // otherwise set up tracks accordingly + int[][] minC = new int[visibleFeatures.size()][3], + maxC = new int[visibleFeatures.size()][3]; + Map fcs = ourFr.getDisplayedFeatureCols(); + int p = 0; + for (String s : visibleFeatures) + { + FeatureColourI color = fcs.get(s); + if (color.isSimpleColour()) + { + minC[p] = new int[] { 133, 133, 133 }; + maxC[p] = new int[] { color.getColour().getRed(), + color.getColour().getGreen(), color.getColour().getBlue() }; + } + else + { + Color min = color.getMinColour(), max = color.getMaxColour(); + minC[p] = new int[] { min.getRed(), min.getGreen(), min.getBlue() }; + maxC[p] = new int[] { max.getRed(), max.getGreen(), max.getBlue() }; + } + p++; + } + minColours = minC; + maxColours = maxC; /* * and register the counter */ if (ourWorker != null) { - Set toRemove = new HashSet(), - toAdd = new HashSet(); + Set toRemove = new HashSet(); toRemove.addAll(dispFeatures); toRemove.removeAll(visibleFeatures); dispFeatures = visibleFeatures; @@ -169,15 +200,25 @@ public class VisibleFeaturesAnnotationTracks implements FeatureSetCounterI return dispFeatures.toArray(new String[0]); } + int[][] minColours = null, maxColours = null; + @Override - public int[] getMaxColour() + public int[] getMaxColour(int row) { + if (maxColours != null && row >= 0 && row < maxColours.length) + { + return maxColours[row]; + } return new int[] { 0, 0, 255 }; } @Override - public int[] getMinColour() + public int[] getMinColour(int row) { - return new int[] { 0, 255, 255 }; + if (minColours != null && row >= 0 && row < minColours.length) + { + return minColours[row]; + } + return new int[] { 133, 133, 133 }; } } \ No newline at end of file