Question: Splicing large bam file with Rsamtools
gravatar for Diana
8 months ago by
Diana10 wrote:

Dear all,

I tried to open a bam file with the following script:

bam<-scanBam("~/Bamfiles Ivy/W9.1.1.bam")

As a result, a memory error occured:

Error in value[[3L]](cond) : 
  'Realloc' could not re-allocate memory (209715200 bytes)
  file: C:/Users/Diana/Documents/Bamfiles Ivy/W9.1.1.bam
  index: NA

Hence, I am trying to split the file into chunks (chromosomes). The official RSamtools introduction states this code:

> summaryFunction <- function(seqname, bamFile,
+ ...) {
+ param <- ScanBamParam(what = c("pos", "qwidth"),
+ which = GRanges(seqname, IRanges(1, 1e+07)),
+ flag = scanBamFlag(isUnmappedQuery = FALSE))
+ x <- scanBam(bamFile, ..., param = param)[[1]]
+ coverage(IRanges(x[["pos"]], width = x[["qwidth"]]))
+ }

However, I don't understand how to fill in the position and qwidth, as I can't read the Bamfile. I tried other things as well, including Seqtools, but it won't work.

I would be VERY grateful if someone could help me out!

rsamtools • 191 views
ADD COMMENTlink modified 8 months ago by Martin Morgan ♦♦ 23k • written 8 months ago by Diana10
Answer: Splicing large bam file with Rsamtools
gravatar for Martin Morgan
8 months ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

I'm not exactly sure what you mean by 'fill in the position and qwidth'. It's possible to find the widths of each chromosome with Rsamtools::scanBamHeader(), and use these to create GRanges corresponding to each seqname (chromosome).

Instead of using scanBam(), use the GenomicAlignments package, readGAlignments() or readGAlignmentPairs() and a ScanBamParam().

ADD COMMENTlink written 8 months ago by Martin Morgan ♦♦ 23k
Please log in to add an answer.


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