readBamFileAsGRanges: Import BAM file into GRanges

Description Usage Arguments Value Examples

View source: R/importReads.R

Description

Import aligned reads from a BAM file into a GRanges-class object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
readBamFileAsGRanges(
  bamfile,
  bamindex = bamfile,
  chromosomes = NULL,
  pairedEndReads = FALSE,
  remove.duplicate.reads = FALSE,
  min.mapq = 10,
  max.fragment.width = 1000,
  blacklist = NULL,
  what = "mapq"
)

Arguments

bamfile

A sorted BAM file.

bamindex

BAM index file. Can be specified without the .bai ending. If the index file does not exist it will be created and a warning is issued.

chromosomes

If only a subset of the chromosomes should be imported, specify them here.

pairedEndReads

Set to TRUE if you have paired-end reads in your BAM files (not implemented for BED files).

remove.duplicate.reads

A logical indicating whether or not duplicate reads should be removed.

min.mapq

Minimum mapping quality when importing from BAM files. Set min.mapq=0 to keep all reads.

max.fragment.width

Maximum allowed fragment length. This is to filter out erroneously wrong fragments due to mapping errors of paired end reads.

blacklist

A GRanges-class or a bed(.gz) file with blacklisted regions. Reads falling into those regions will be discarded.

what

A character vector of fields that are returned. Uses the Rsamtools::scanBamWhat function. See Rsamtools::ScanBamParam to see what is available.

Value

A GRanges-class object containing the reads.

Examples

1
2
3
4
5
6
7
## Get an example BAM file with ChIP-seq reads
bamfile <- system.file("extdata", "euratrans", "lv-H3K4me3-BN-female-bio1-tech1.bam",
                      package="chromstaRData")
## Read the file into a GRanges object
reads <- readBamFileAsGRanges(bamfile, chromosomes='chr12', pairedEndReads=FALSE,
                    min.mapq=10, remove.duplicate.reads=TRUE)
print(reads)

chromstaR documentation built on Nov. 8, 2020, 8:29 p.m.