| applyPileups {Rsamtools} | R Documentation |
applyPileups scans one or more BAM files, returning
position-specific sequence and quality summaries.
applyPileups(files, FUN, ..., param)
files |
A |
FUN |
A function of 1 argument,
|
... |
Additional arguments, passed to methods. |
param |
An instance of the object returned by
|
Regardless of param values, the algorithm follows samtools by
excluding reads flagged as unmapped, secondary, duplicate, or failing
quality control.
applyPileups returns a list equal in length to the
number of times FUN has been called, with each element
containing the result of FUN.
ApplyPileupsParam returns an object describing the parameters.
Martin Morgan
http://samtools.sourceforge.net/
## The examples below are currently broken and have been disabled for now
## Not run:
fl <- system.file("extdata", "ex1.bam", package="Rsamtools",
mustWork=TRUE)
fls <- PileupFiles(c(fl, fl))
calcInfo <-
function(x)
{
## information at each pile-up position
info <- apply(x[["seq"]], 2, function(y) {
y <- y[c("A", "C", "G", "T"),,drop=FALSE]
y <- y + 1L # continuity
cvg <- colSums(y)
p <- y / cvg[col(y)]
h <- -colSums(p * log(p))
ifelse(cvg == 4L, NA, h)
})
list(seqnames=x[["seqnames"]], pos=x[["pos"]], info=info)
}
which <- GRanges(c("seq1", "seq2"), IRanges(c(1000, 1000), 2000))
param <- ApplyPileupsParam(which=which, what="seq")
res <- applyPileups(fls, calcInfo, param=param)
str(res)
head(res[[1]][["pos"]]) # positions matching param
head(res[[1]][["info"]]) # inforamtion in each file
## 'param' as part of 'files'
fls1 <- PileupFiles(c(fl, fl), param=param)
res1 <- applyPileups(fls1, calcInfo)
identical(res, res1)
## yield by position, across ranges
param <- ApplyPileupsParam(which=which, yieldSize=500L,
yieldBy="position", what="seq")
res <- applyPileups(fls, calcInfo, param=param)
sapply(res, "[[", "seqnames")
## End(Not run)