6.2 BAM/SAM and reading HTS data

SAMtools RSamtools

# Primary method with Rsamtools
library(Rsamtools)
bamfilePath=system.file("extdata",
            "wgEncodeHaibTfbsGm12878Sp1Pcr1xAlnRep1.chr21.bam",
                      package="compGenomRData")

# get reads for regions of interest from the bam file
param <- ScanBamParam(which=promoter.gr)
counts <- countBam(bamfilePath, param=param)

# alternative method with GenomicAlignments
library(GenomicAlignments)
alns <- readGAlignments(bamfilePath, param=param)