Can GViz show multiple HighlightTrack with multiple colors in the same track?
1
0
Entering edit mode
@ibarraignacio-15136
Last seen 6.4 years ago

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

gviz • 2.1k views
ADD COMMENT
1
Entering edit mode
Robert Ivanek ▴ 750
@robert-ivanek-5892
Last seen 12 months ago
Switzerland

Dear Ignacio,

If I understood you correctly, you want to use different colours for highlighted region in  HighlightTrack object. But that works already now. 

Let me know if that is sufficient for you.

Best, Robert

 

library(Gviz)
data(cpgIslands)
chr <- as.character(unique(seqnames(cpgIslands)))
gen <- genome(cpgIslands)
atrack <- AnnotationTrack(cpgIslands, name="CpG")
itrack <- IdeogramTrack(genome=gen, chromosome=chr)
set.seed(255)
lim <- c(26700000, 26750000)
coords <- sort(c(lim[1], sample(seq(from=lim[1], to=lim[2]), 99), lim[2]))
dat <- runif(100, min=-10, max=10)
dtrack <- DataTrack(data=dat, start=coords[-length(coords)], end=coords[-1], chromosome=chr, genome=gen, name="Uniform")
data(geneModels)
grtrack <- GeneRegionTrack(geneModels, genome=gen, chromosome=chr, name="foo")
gtrack <- GenomeAxisTrack()
## two highlight tracks with two/three highlighted regions
ht1 <- HighlightTrack(trackList=list(itrack, gtrack, atrack), start=c(26705000, 26720000), width=7000, chromosome=7, col=c("#E41A1C", "#377EB8"), fill=c("#FBB4AE", "#B3CDE3"))
ht2 <- HighlightTrack(trackList=dtrack, start=c(26705000, 26720000, 26735000), width=7000, chromosome=7, col=c("#E41A1C", "#377EB8", "#4DAF4A"), fill=c("#FBB4AE", "#B3CDE3", "#CCEBC5"))
## 
plotTracks(list(ht1, grtrack, ht2), from=lim[1], to=lim[2])
ADD COMMENT
0
Entering edit mode

Thanks Robert! That's precisely the scheme I was trying to get to work!

ADD REPLY
0
Entering edit mode

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:

col Integer or character scalar. The boder color for the highlighting regions. *(spelling mistake is in the original document)

ADD REPLY
0
Entering edit mode

Thanks. I fixed it in the documentation it will be available with next minor version bump.

ADD REPLY

Login before adding your answer.

Traffic: 884 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6