Reading BAM files
To get started, you'll read mapped reads from a BAM file into R. These files store information about the alignment between read sequences and the reference genome in a compressed binary format. Loading data from BAM files is a common task when analyzing genomic data.
In this exercise, you'll first load all reads from a bam file. This is straightforward but can require a lot of memory, so in the second part, you'll learn how to load only the reads from a region of interest.
This is a part of the course
“ChIP-seq with Bioconductor in R”
Exercise instructions
- Load reads from chr20_bam file using the
readGAlignments()
function. - Create a
BamViews
object for chr20_bam that covers the region 29805000 - 29820000 on chromosome 20. - Use
readGAlignments()
again to load only the reads in that view. - Inspect the
reads_sub
object usingstr()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load reads form chr20_bam file
reads <- ___(chr20_bam)
# Create a `BamViews` object for the range 29805000 - 29820000 on chromosome 20
bam_views <- ___(___, bamRanges=GRanges("chr20", IRanges(start=29805000, end=29820000)))
# Load only the reads in that view
reads_sub <- ___(___)
# Inspect the `reads_sub` object
___(reads_sub)