Plotting DMRs (Differentially Methylated Regions) using Gviz package in R
1
1
Entering edit mode
sinha.puja ▴ 10
@sinhapuja-18708
Last seen 19 months ago

Hi All,

I have a file list consisting of Chromosome, Start , End & Methylation Difference in the following format in excel:

Chrom  Start                End          Meth. Diff
chr1    38565900    38566000    -0.20276818
chr1    38870400    38870500    -0.342342342
chr1    39469400    39469500    -0.250260552
chr1    52013600    52013700    -0.37797619
chr1    52751700    52751800    0.257575758
chr1    75505100    75505200    -0.262847308

I need help in plotting the DMRs using Gviz package in R. I tried a code below but it doesn't turn out correct.

library(Gviz)
library(GenomicRanges)
library(BSgenome)
library(Biostrings)
library(XVector)
library(readxl)
library(BSgenome.Rnorvegicus.UCSC.rn6)
genome <- getBSgenome("BSgenome.Rnorvegicus.UCSC.rn6") 
genome
data1 <- read_excel("DMRs_plots.xlsx")
library(rtracklayer)
track1 <- DataTrack(data = data1, from = "38565900" , to = "75505200", chromosome = Chrom$chr1, name = "DMRs")
plotTracks(track1)

If anyone know how to plot and correct my code including how to add methylation difference values, then that will be of great help.

Thanks.

Gviz • 227 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 4 hours ago
United States

This works for me

> z <- read.table("tmp.txt", TRUE)
> z
  Chrom    Start      End  Meth.diff
1  chr1 38565900 38566000 -0.2027682
2  chr1 38870400 38870500 -0.3423423
3  chr1 39469400 39469500 -0.2502606
4  chr1 52013600 52013700 -0.3779762
5  chr1 52751700 52751800  0.2575758
6  chr1 75505100 75505200 -0.2628473
> names(z) <- c("chromosome","start","end", "diff")
> track <- DataTrack(z, genome = "hg19")
> plotTracks(track)
> 

And I knew to change the names based on the help page, which is pretty clear?

A 'data.frame' object: the 'data.frame' needs to contain at least the
              two mandatory columns 'start' and 'end' with the range
              coordinates. It may also contain a 'chromosome' column
              with the chromosome information for each range. If
              missing it will be drawn from the separate 'chromosome'
              argument. All additional numeric columns will be
              interpreted as data columns, unless the 'data' argument
              is explicitely provided.

Well, except for the explicitey part ;-D

ADD COMMENT
0
Entering edit mode

Thanks James. I modified the code below as:

z <- read_excel("DMRs_temp.xlsx")
z
z <- c("Chrom","Start","End", "Meth. Diff.")
**track <- DataTrack(z, genome = "rn6")**

But the quoted last step gives me error as below: Error: 'range' must be an object of class 'character' of length 1

Thanks.

ADD REPLY
0
Entering edit mode

You should compare what I did with what you did. It's quite different.

ADD REPLY
0
Entering edit mode

Hi, This time I exactly followed your code but again the same step gives following error: Error in .fillWithDefaults(range, defaults[missing], args[missing], len = nrow(range)) : The mandatory argument 'NA' is missing with no default. I don't know how to troubleshoot this.

Thanks.

ADD REPLY
0
Entering edit mode

You couldn't have followed my code and got that error, because the code I show doesn't generate an error! This is a deterministic process - if you do what I have done, and it works for me, then by definition it will work for you. So you must have done something different.

If you plan to learn R, you need to pay better attention. For example, I said I did

> names(z) <- c("chromosome","start","end", "diff")

And then you did

z <- c("Chrom","Start","End", "Meth. Diff.")

Seeming to think that those were the same things. They aren't even remotely close to the same thing! Do you see why not? I also showed you the help page for how to create a data.frame that will work for DataTrack. It's quite clear, if you read and try to understand.

ADD REPLY

Login before adding your answer.

Traffic: 375 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