Splicing large bam file with Rsamtools
1
0
Entering edit mode
Diana ▴ 10
@diana-19465
Last seen 5.2 years ago

Dear all,

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

library(Rsamtools)
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)),
4
+ 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 • 867 views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 5 days ago
United States

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 COMMENT

Login before adding your answer.

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