Skip to content

Commit

Permalink
SpliceJunction tracks now honor manual color setttings
Browse files Browse the repository at this point in the history
* Fixes #1504
  • Loading branch information
lbergelson committed Aug 16, 2024
1 parent b611dbc commit 4453bb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
48 changes: 32 additions & 16 deletions src/main/java/org/broad/igv/renderer/SpliceJunctionRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +100,7 @@ public void render(List<IGVFeature> 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);
}
}

Expand All @@ -126,7 +125,7 @@ public void render(List<IGVFeature> 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();
Expand All @@ -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);
Expand Down Expand Up @@ -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 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;
}


/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/sam/SpliceJunctionTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4453bb6

Please sign in to comment.