Hi everybody,
I was wondering if it was possible to group different DataTrack
objects in a Gviz plot? In the user guide, the example for grouping data is done using a GRanges
objects that contains two metadata columns for the different scores that belong to a group. Creating this is difficult because I would like to group scores/coverages from different bigWig files that have different intervals and therefore can't simply be merged together into a single GRanges
object. I already started exploring possible strategies to do that, but it seems quite complicated, especially since I'm planning to plot around 100 profiles, which is quite easy if they don't need to be grouped, but with grouping the plot would be a lot nicer. You can find the corresponding question on Biostars here: https://www.biostars.org/p/448502/
My current way to plot the tracks follows the user guide, reading the bigWig files into separate DataTrack
objects, then creating a list from them and handing that list over to plotTrack
(see below).
library(Gviz)
gtrack <- GenomeAxisTrack()
itrack <- IdeogramTrack(genome = 'mm10', chromosome = 'chr5')
txdb <- GenomicFeatures::makeTxDbFromGFF('annotation.gtf.gz')
grtrack <- GeneRegionTrack(
txdb,
genome = 'mm10',
chromosome = 'chr5',
name = 'RefSeq'
)
bigwig_files <- paste0(
'<input_dir>/',
rep(c('H3K4me3','H3K27me3','H3K27ac','H3K4me1'), each = 4),
'_',
c('SD_3m','SD_6m','SD_12m','CR_12m'),
'.bw'
)
track_names <- gsub(bigwig_files, pattern = '.bw', replacement = '')
counter <- 0
for ( file in bigwig_files ) {
counter <- counter + 1
if ( grepl(bigwig_files[counter], pattern = 'H3K4me3') ) {
gradient <- RColorBrewer::brewer.pal(9, 'Blues')
} else if ( grepl(bigwig_files[counter], pattern = 'H3K27me3') ) {
gradient <- RColorBrewer::brewer.pal(9, 'Reds')
} else if ( grepl(bigwig_files[counter], pattern = 'H3K27ac') ) {
gradient <- RColorBrewer::brewer.pal(9, 'Greens')
} else if ( grepl(bigwig_files[counter], pattern = 'H3K4me1') ) {
gradient <- RColorBrewer::brewer.pal(9, 'Oranges')
}
assign(
x = track_names[counter],
value = DataTrack(
range = bigwig_files[counter],
genome = 'mm10',
type = 'heatmap',
name = track_names[counter],
size = 2,
gradient = gradient,
window = -1,
chromosome = 'chr5'
)
)
}
my_list <- list(itrack, gtrack, grtrack)
for ( i in 1:length(bigwig_files) ) {
my_list[[i+3]] <- get(track_names[i])
}
plotTracks(
my_list,
from = 142903115-10000,
to = 142906754+10000
)
And this is the resulting plot.
I know that those are heatmaps, but if I can manage to group them together I would like to use lines, similar to this example from the user guide (chapter 4.3.1, first figure, https://bioconductor.org/packages/release/bioc/vignettes/Gviz/inst/doc/Gviz.html#43_datatrack).
I also wasn't able to make the track names fit into the little boxes, which could've been a possible, yet not idea, workaround.
I would greatly appreciate if somebody could give me some advise if what I have in mind is even possible, and if so, how to achieve it. Or, if it's not possible, what some possible workarounds could be.
Best, Roman
Ok, that would still be a workaround however, right? Since I won't be able to combine the data into mean + confidence interval as shown in the figure from the user guide that I was referring to. And even if it's just the separate lines, it doesn't really help that much. The problem is that the track labels are not shown. I can't manually add them later, that's too much work. If the tracks in the plot I showed would be grouped, I could have a group label "H3K4me3" and then the individual track names as sample names.
For the exact reason you mentioned I was doubtful about the solution proposed on Biostars (actually, that's why I came here). But I don't understand your comment. Would you have noticed my question there? Should I have deleted my question on Biostars? They are not even identical questions. Here I specifically ask about Gviz, whereas on Biostars it's about merging GRanges objects.
Best, Roman
But in that case the best would be to pre-calculated manually, to obtain
GRanges
object with individual score columns. If the bigWig files do not have fixed with it might be necessary to have 1bp tiles to avoid above mentioned case that one tile overlaps with multiple ranges in one bigWig file.