Question: How to center data points on coordinates (bases) in Gviz?
0
gravatar for Robert
3 months ago by
Robert10
Robert10 wrote:

I plot my NGS data using the Gviz library. When I use a .bedGraph file to construct a DataTrack the data points appear between genomic coordinates (bases). The same is true for a corresponding .bw file (not shown in code below). When I first read the .bedGraph file and then construct a DataTrack "manually" the data points appear centered on the genomic coordinates but shifted by -1. I can correct this by adding +1 to start and end when constructing the DataTrack.

library(Gviz)

bedGraph.data.track <- DataTrack("counts.bedGraph", genome = "sacCer3", chromosome = "chrII", name = "bedGraph")

tmp <- read.table(file = "counts.bedGraph", col.names = c("chr", "start", "end", "score"))
df.data.track <- DataTrack(start = tmp$start, end = tmp$end, data = tmp$score, genome = "sacCer3", chromosome = "chrII", name = "df")
shifted.df.data.track <- DataTrack(start = tmp$start + 1, end = tmp$end + 1, data = tmp$score, genome = "sacCer3", chromosome = "chrII", name = "shift.df")

axis.track <- GenomeAxisTrack()

library(BSgenome.Scerevisiae.UCSC.sacCer3)
sequence.track <- SequenceTrack(sequence = BSgenome.Scerevisiae.UCSC.sacCer3, chromosome = "chrII", genome = "sacCer3")

plotTracks(list(axis.track, sequence.track, bedGraph.data.track, df.data.track, shifted.df.data.track), chromosome = "chrII", from = 0, to = 5)

enter image description here

Is there an easy way to shift the coordinates by +0.5 for .bedGraph (and .bw)-based DataTracks, such that data points appear centered on the coordinates (bases)?

gviz • 97 views
ADD COMMENTlink modified 3 months ago • written 3 months ago by Robert10

Thanks for bringing that up. There was a bug in the Gviz and I pushed fix into both branches (release 1.28.1 and devel 1.29.1). Now the data points, ticks and tick-marks should be aligned. Let me know if that works for you.

BTW. When reading the bedGraph manually, keep in mind that start is "0-based" and end is "1-based" in the file itself. However in R/Bioc the both coordinates are "1-based". In this case, you should only add +1 to start positions. The built-in functions for import and export of UCSC file formats are doing that automatically. They are provided in rtracklayer package and Gviz simply uses them to read those files.

ADD REPLYlink written 3 months ago by Robert Ivanek650
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 213 users visited in the last hour