ScanBamParam() to create a parameter object influencing
what fields and which records are imported from a (binary) BAM file.
which requires that a BAM index file
# Constructor ScanBamParam(flag = scanBamFlag(), simpleCigar = FALSE, reverseComplement = FALSE, tag = character(0), tagFilter = list(), what = character(0), which, mapqFilter=NA_integer_)# Constructor helpers scanBamFlag(isPaired = NA, isProperPair = NA, isUnmappedQuery = NA, hasUnmappedMate = NA, isMinusStrand = NA, isMateMinusStrand = NA, isFirstMateRead = NA, isSecondMateRead = NA, isNotPrimaryRead = NA, isSecondaryAlignment = NA, isNotPassingQualityControls = NA, isDuplicate = NA)scanBamWhat()# Accessors bamFlag(object, asInteger=FALSE) bamFlag(object) <- value bamReverseComplement(object) bamReverseComplement(object) <- value bamSimpleCigar(object) bamSimpleCigar(object) <- value bamTag(object) bamTag(object) <- value bamTagFilter(object) bamTagFilter(object) <- value bamWhat(object) bamWhat(object) <- value bamWhich(object) bamWhich(object) <- value bamMapqFilter(object) bamMapqFilter(object) <- value"show"(object)# Flag utils bamFlagAsBitMatrix(flag, bitnames=FLAG_BITNAMES) bamFlagAND(flag1, flag2) bamFlagTest(flag, value)
ScanBamParam, an integer(2) vector used to filter reads based on their 'flag' entry. This is most easily created with the
bamFlagTest an integer vector
where each element represents a 'flag' entry.
reverseComplement=FALSE), but when this value is set to TRUE returns the sequence and quality scores of reads mapped to the minus strand in the reverse complement (sequence) and reverse (quality) of the read as stored in the BAM file. This might be useful if wishing to recover read and quality scores as represented in fastq files, but is NOT appropriate for variant calling or other alignment-based operations.
tagmust have exactly 2 characters.
listof atomic vectors. The name of each
listelement is the tag name (two-letter code), and the corresponding atomic vector is the set of acceptable values for the tag. Only reads with specified tags are included.
NAs, and empty strings are not allowed in the atomic vectors.
scanBamWhat()returns a vector of available fields. Fields are described on the
RangesList, or any object that can be coerced to a
RangesList, or missing object, from which a
IRangesListinstance will be constructed. Names of the
IRangesListcorrespond to reference sequences, and ranges to the regions on that reference sequence for which matches are desired. Because data types are coerced to
whichdoes not include strand information (use the
flagargument instead). Only records with a read overlapping the specified ranges are returned. All ranges must have ends less than or equal to 536870912.
character(1)name of the flag to test, e.g., isUnmappedQuery, from the arguments to
TRUE) or human-readable form (
integerencoding flags to be kept when they have their '0' (
keep0) or '1' (
keep1) bit set.
logicalindicating, when TRUE, that only 'simple' cigars (empty or 'M') are returned.
logicalindicating, when TRUE, that reads on the minus strand are to be reverse complemented (sequence) and reversed (quality).
characterindicating what tags are to be returned.
list(named) indicating tags to filter by, and the set of acceptable values for each tag.
characterindicating what fields are to be returned.
RangesListindicating which reference sequence and coordinate reads must overlap.
integerindicating the minimum mapping quality required for input, or NA to indicate no filtering.
whichargument to the constructor can be one of several different types, as documented above.
charactervector of tags to be extracted.
listof tags to filter by, and the set of their acceptable values.
charactervector of fields to be extracted.
RangesListof bounds on reads to be extracted. A length 0
RangesListrepresents all reads.
integer(2)representation of reads flagged to be kept or excluded.
logical(1)vector indicating whether reads without indels or clipping be kept.
logical(1)vector indicating whether reads on the minus strand will be returned with sequence reverse complemented and quality reversed.
## defaults p0 <- ScanBamParam() ## subset of reads based on genomic coordinates which <- RangesList(seq1=IRanges(1000, 2000), seq2=IRanges(c(100, 1000), c(1000, 2000))) p1 <- ScanBamParam(what=scanBamWhat(), which=which) ## subset of reads based on 'flag' value p2 <- ScanBamParam(what=scanBamWhat(), flag=scanBamFlag(isMinusStrand=FALSE)) ## subset of fields p3 <- ScanBamParam(what=c("rname", "strand", "pos", "qwidth")) ## use fl <- system.file("extdata", "ex1.bam", package="Rsamtools", mustWork=TRUE) res <- scanBam(fl, param=p2)[] lapply(res, head) ## tags; NM: edit distance; H1: 1-difference hits p4 <- ScanBamParam(tag=c("NM", "H1"), what="flag") bam4 <- scanBam(fl, param=p4) str(bam4[][["tag"]]) ## tagFilter p5 <- ScanBamParam(tag=c("NM", "H1"), tagFilter=list(NM=c(2, 3, 4))) bam5 <- scanBam(fl, param=p5) table(bam5[][["tag"]][["NM"]]) ## flag utils flag <- scanBamFlag(isUnmappedQuery=FALSE, isMinusStrand=TRUE) p6 <- ScanBamParam(what="flag") bam6 <- scanBam(fl, param=p6) flag6 <- bam6[][["flag"]] head(bamFlagAsBitMatrix(flag6[1:9])) colSums(bamFlagAsBitMatrix(flag6)) flag bamFlagAsBitMatrix(flag)