What about chunking the roi's, so that there is less iteration but the data
size is still manageable? See BBmisc::chunk.

Michael


On Mon, May 26, 2014 at 2:23 AM, Julian Gehring <julian.gehring@embl.de>wrote:

> 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
>

	[[alternative HTML version deleted]]

