ivanek / Gviz

This is the Gviz development repository. Gviz plots data and annotation information along genomic coordinates.
https://bioconductor.org/packages/Gviz/
Artistic License 2.0
75 stars 10 forks source link

H3K4Me3 not working: Error fetching data from UCSC #48

Closed sebastian-li closed 3 years ago

sebastian-li commented 3 years ago

Hi I was trying to plot H3K4Me3 with Gviz and I ran into the following problem:

H3K4Me3 <- UcscTrack(genome=gen, chromosome=chr, from=from, to=to, track="Layered H3K4Me3", trackType = "DataTrack", start="start", end="end", data="score", type = "hist", window = "auto", col.histogram = "darkred", fill.histogram = "darkred", background.title = "#E4BBB0", name="H3K4me3")

It gave me the following error message: Error in UcscTrack(genome = gen, chromosome = chr, from = from, to = to, : Error fetching data from UCSC In addition: Warning messages: 1: In .local(x, ...) : 'track' parameter is deprecated now you go by the 'table' instead Use ucscTables(genome, track) to retrieve the list of tables for a track 2: In UcscTrack(genome = gen, chromosome = chr, from = from, to = to, : Error in stop_if_wrong_length("'seqnames'", ans_len) : 'seqnames' must have the length of the object to construct (31) or length 1

However, if I remove trackType = "DataTrack" it will work fine but the plot is not acceptable because of wrong trackType I suppose. just wondering how can I solve this issue?

thank you!

ivanek commented 3 years ago

Hi @nerdybo,

There is very little information in your post. Missing genome version, chromosome and position and also there is no sessionInfo.

I assume you used hg38 genome. The issue is that the H3K4me3 data are available as bigWig files on UCSC and cannot be directly queried by Gviz. You need to fetch the corresponding data by rtracklayer function import.bw.

I had to search for the track content on the Genome Browser website and also for the urls pointing to the files.

Something along the lines can work:

library(Gviz)

gen <- "hg38"
chr <- "chr1"
from <- 27001
to <- 32000

bigwigs <- c(
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneGm12878H3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneH1hescH3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneHsmmH3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneHuvecH3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneNhekH3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneNhlfH3k4me3StdSig.bigWig",
    "/gbdb/hg38/bbi/wgEncodeReg/wgEncodeRegMarkH3k4me3/wgEncodeBroadHistoneGm12878H3k4me3StdSig.bigWig"
)

bigwigs <- bigwigs <- paste0("http://hgdownload.soe.ucsc.edu/goldenPath/hg38/encodeDCC/wgEncodeRegMarkH3k4me3/", basename(bigwigs))

tracks <- lapply(bigwigs, function(bw) {
    dt <- import.bw(bw, which=GRanges(chr, IRanges(from-500, to+500))) # not sure if one really needs to enlarge the region for fetching the data
    dt <- DataTrack(dt, 
                     genome=gen,
                     chromosome=chr,
                     from=from,
                     to=to,
                     type = "hist", window = "auto",
                     col.histogram = rgb(140/256,0,0,7/10),
                     fill.histogram = rgb(140/256,0,0,4/10),
                     background.title = "#E4BBB0",
                     name="H3K4me3")
    dt
})

plotTracks(OverlayTrack(tracks), chromosome = chr, from = from, to=to)

issue_48