[BioC] Looping over entries of a GRanges object

Julian Gehring julian.gehring at embl.de
Mon May 26 11:23:31 CEST 2014


Hi Michael and Brian,

Thanks for the suggestions.  The use case I have in mind: Extracting 
base counts from a BAM file for a set of regions of interest.  The code 
below should outline the idea for looping over all exons (just an 
example).  While 'applyPileups' and other functions can handle a GRanges 
input with multiple entries, the result of all regions would exceed the 
available memory.  This is why I considered looping over the regions of 
interest.

Best wishes
Julian


#+BEGIN_SRC R

library(GenomicRanges)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(Rsamtools)

ex = exons(TxDb.Hsapiens.UCSC.hg19.knownGene)
rois = reduce(unstrand(ex))

bam_file = ""

pu_files = PileupFiles(bam_file)
for(i in seq_along(rois)) {
     r = rois[i]
     param = PileupParam(which = r)
     pu = applyPileups(pu_files, function(x) x[["seq"]], param)
     ## more analysis on pileup 'pu' ##
}

#+END_SRC



More information about the Bioconductor mailing list