Dear BioC community,
My question is related to the addition multiple highlights with multiple colors in the same track using GViz (e.g. red/blue, according to additional input parameters).
This is an image showing multiple highlights in multiple places, which could be red/blue independently https://tinyurl.com/y8mp7uyq
The following version works and it appends the HighlightTrack to a DataTrack. However, it just highlights peaks in the track as a single color (red)
# All highlights together (one color)
# This version works, but it uses only one color
highlights.list <- NULL
if(nrow(sig_peaks_sel) > 0){
print(sig_peaks_sel)
# print(nrow(sig_peaks_sel))
highlight_color <- 'red'
highlights.list <- HighlightTrack(trackList = track.list, # track.list is a DataTrack
start = sig_peaks_sel$pos - (500 / 2),
width=500,
chromosome=chr, fill=highlight_color,
inBackground=F, alpha=0.6)
}
tracks <- c(tracks, highlights.list)
plotTracks(tracks)
For highlighting using specific colors, I tried a for-loop to add them one by one. Here, I am getting an error if I have more than one highlight added to the same DataTrack (i.e. two or more).
# Separate highlights with two possible colors, added iteratively to the track
for(j in 1:nrow(sig_peaks_sel)){
highlight_color <- ifelse(sig_peaks_sel$log2FoldChange[j] > 0, 'red', 'blue')
highlights.list <- HighlightTrack(trackList = track.list, # track.list is a DataTrack
start = c(sig_peaks_sel$pos[j] - (500 / 2)),
width=500, # col='gray',
chromosome=chr, fill=highlight_color,
inBackground=F, alpha=0.6)
}
tracks <- c(tracks, highlights.list)
plotTracks(tracks)
The error message is
# Error in (function (classes, fdef, mtable) :
# Unable to find an inherited method for function 'drawGD' for signature '"HighlightTrack"'
Can the implementation of multiple highlights with multiple colors in the same track be accomplished by modifying this function?
Could there be an additional, simpler way in might the required functionality is generated (multiple highlights/ multiple colors, same track)?
Thanks, Ignacio
Thanks Robert! That's precisely the scheme I was trying to get to work!
Thanks for the example. This solution does work (and is the logical thing to do), but the documentation isn't leading to that... According to the manual, the optional settings for HighlightTrack (col and fill) are expected to be scalars, rather than vectors:
Thanks. I fixed it in the documentation it will be available with next minor version bump.