Work with GRanges objects in DiffBind
5
0
Entering edit mode
@xulongwang-8641
Last seen 9.3 years ago
United States

It seems DiffBind run everything on top of dba objects. But all peak data are stored as GRanges objects in my workflow. How to make the DBA object from GRanges easily, so I do not have to read in the peaks again as DBA? 

XuLong

diffbind • 2.9k views
ADD COMMENT
3
Entering edit mode
Rory Stark ★ 5.2k
@rory-stark-5741
Last seen 5 weeks ago
Cambridge, UK

Hi XuLong-

If you don't want to write the GRanges objects out as peak files, you can use the dba.peakset() function instead of dba(). 

You have to call dba.peakset() once for each peakset you want to add. The first call should set DBA=NULL, and subsequent calls should set DBA to the DBA object returned from the previous call. You can set all the metadata for each peakset as well.

For example, if you have a samplesheet named samples,  and your peaks in a GRangesList named peaklist, you could call dba.peakset() in a loop, supplying your peaks as a GRanges object:

myDBA <- NULL
samples <- read.csv("samplesheet.csv",as.is=TRUE)
for(i in 1:nrow(samples)) {
   myDBA <- dba.peakset(DBA=myDBA,peaks=peaklist[[i]],
                        sampID=samples$SampleName[i], 
                        tissue=samples$Tissue[i],
                        factor=samples$Factor[i],
                        condition=samples$Condition[i],
                        treatment=samples$Treatment[i],
                        replicate=samples$Replicate[i],
                        peak.caller = "mycaller", 
                        bamReads=samples$bamReads[i],
                        control=samples$ControlID[i],
                        bamControl=samples$bamControl[i])
}

Cheers-

Rory

ADD COMMENT
0
Entering edit mode
@xulongwang-8641
Last seen 9.3 years ago
United States

Thanks much Rory, this solves my needs well.

ADD COMMENT
0
Entering edit mode
termanini ▴ 10
@termanini-8493
Last seen 8.3 years ago

AHello, I am trying to do that, but I got an error:

g = GRanges(seqnames = "chr1", ranges = c(1, 1000));

dba.peakset(NULL, peaks=g);

Error in `[.data.frame`(peaks[[i]], , 1:4) : undefined columns selected

This happen with different GRanges (with or without strand specified etc).

Can anyone help me?

Thanks very much,
Albert

 

 

 

ADD COMMENT
0
Entering edit mode
Rory Stark ★ 5.2k
@rory-stark-5741
Last seen 5 weeks ago
Cambridge, UK

This is a bug caused by the lack of a "score" metadata column. I'll check in a fix to deal with a missing score. In the meantime, here is a workaround:

> g <- GRanges(seqnames = "chr1", ranges = c(1, 1000), score = rep(1,length(c(1,1000))))

Cheers-

Rory

ADD COMMENT
0
Entering edit mode
termanini ▴ 10
@termanini-8493
Last seen 8.3 years ago

Thanks Rory, it works!

Best,

Albert

 

ADD COMMENT

Login before adding your answer.

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