Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpliceJunction tracks now honor manual color setttings #1546

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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;
}


/**
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
Loading