I have a >30GB BAM file. How do I load into an R console?
I tried using Rsamtools, but getting following error message.
Error in value[[3L]](cond) :
'Realloc' could not re-allocate memory (62914560 bytes)
file: test.sorted.bam
index:
In addition: Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
Reached total allocation of 3991Mb: see help(memory.size)
2: In doTryCatch(return(expr), name, parentenv, handler) :
Reached total allocation of 3991Mb: see help(memory.size)
How much memory do you have on your machine? If you really want to be able to load the entire file in R you will need to have a lot of memory. However, most of the times you don't need to do that. Depending on what you want to do with your alignments, you might be able to do it by processing the file by chunk, which will reduce memory usage a lot and also improve performance. Please check the man page for BamFile in the Rsamtools package and at its yieldSize argument for more information about this. Also the man page for readGAlignments() in the GenomicAlignments package has some examples of how to load and process a BAM file by chunk.