From 2ea8e563632139227131ad744ce9000704dc9264 Mon Sep 17 00:00:00 2001 From: Louis Bergelson Date: Fri, 16 Aug 2024 12:12:29 -0400 Subject: [PATCH] SpliceJunction tracks now honor manual color setttings * Fixes https://github.com/igvteam/igv/issues/1504 --- .../igv/renderer/SpliceJunctionRenderer.java | 48 ++++++++++++------- .../broad/igv/sam/SpliceJunctionTrack.java | 2 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/broad/igv/renderer/SpliceJunctionRenderer.java b/src/main/java/org/broad/igv/renderer/SpliceJunctionRenderer.java index dec058e58..5d9cb6daa 100644 --- a/src/main/java/org/broad/igv/renderer/SpliceJunctionRenderer.java +++ b/src/main/java/org/broad/igv/renderer/SpliceJunctionRenderer.java @@ -35,7 +35,6 @@ import org.broad.igv.feature.SpliceJunctionFeature; import org.broad.igv.feature.Strand; import org.broad.igv.prefs.Constants; - import org.broad.igv.prefs.IGVPreferences; import org.broad.igv.prefs.PreferencesManager; import org.broad.igv.track.FeatureTrack; import org.broad.igv.track.RenderContext; @@ -101,7 +100,7 @@ public void render(List featureList, // If any part of the feature fits in the track rectangle draw it if (junctionFeature.getEnd() > origin && junctionFeature.getStart() < end) { boolean shouldHighlight = junctionFeature.isSameJunction(selectedFeature); - drawFeature(junctionFeature, shouldShowFlankingRegions, shouldHighlight, origin, locScale, trackRectangle, g2D); + drawFeature(junctionFeature, shouldShowFlankingRegions, shouldHighlight, origin, locScale, trackRectangle, track, g2D); } } @@ -126,7 +125,7 @@ public void render(List featureList, * @param g2D */ protected void drawFeature(SpliceJunctionFeature junctionFeature, boolean shouldShowFlankingRegions, - boolean highlight, double origin, double locScale, Rectangle trackRectangle, Graphics2D g2D) { + boolean highlight, double origin, double locScale, Rectangle trackRectangle, Track track, Graphics2D g2D) { int flankingStart = junctionFeature.getStart(); int flankingEnd = junctionFeature.getEnd(); @@ -150,20 +149,25 @@ protected void drawFeature(SpliceJunctionFeature junctionFeature, boolean should if (strand != null && strand.equals(Strand.NEGATIVE)) isPositiveStrand = false; - //If the feature color is specified, use it, except that we set our own alpha depending on whether - //the feature is highlighted. Otherwise default based on strand and highlight. - Color color; - if (featureColor != null) { - int r = featureColor.getRed(); - int g = featureColor.getGreen(); - int b = featureColor.getBlue(); - int alpha = highlight ? 255 : 140; - color = new Color(r, g, b, alpha); - } else { - if (isPositiveStrand) + /* + Choose the feature color: + 1. Check if the user specified a positive / negative track color + 2. Check if the feature has its own color + 3. Use the default + We modify the alpha value of the chosen color to indicate if it is highlighted + */ + final Color color; + final Color trackColor = isPositiveStrand ? track.getExplicitColor() : track.getExplicitAltColor(); + if( trackColor != null ) { + color = adjustAlpha(trackColor, highlight); + } else if (featureColor != null) { + color = adjustAlpha(featureColor, highlight); + } else { + if (isPositiveStrand) { color = highlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS; - else - color = highlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; + } else { + color = highlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; + } } g2D.setColor(color); @@ -247,6 +251,18 @@ protected void drawFeature(SpliceJunctionFeature junctionFeature, boolean should } + /** + * @return a variant of the input color with a different alpha depending on if it is a highlight color or not + */ + private static Color adjustAlpha(final Color featureColor, final boolean highlight) { + Color color; + int r = featureColor.getRed(); + int g = featureColor.getGreen(); + int b = featureColor.getBlue(); + int alpha = highlight ? 255 : 140; + color = new Color(r, g, b, alpha); + return color; + } /** diff --git a/src/main/java/org/broad/igv/sam/SpliceJunctionTrack.java b/src/main/java/org/broad/igv/sam/SpliceJunctionTrack.java index a65989ff6..2e3d5af97 100644 --- a/src/main/java/org/broad/igv/sam/SpliceJunctionTrack.java +++ b/src/main/java/org/broad/igv/sam/SpliceJunctionTrack.java @@ -94,7 +94,7 @@ public SpliceJunctionTrack(ResourceLocator locator, String name, this.dataManager = dataManager; this.dataManager.subscribe(this); this.alignmentTrack = alignmentTrack; - this.strandOption = ignoreStrand; + SpliceJunctionTrack.strandOption = ignoreStrand; } public SpliceJunctionTrack() {