File: methods-PileupFiles.R

package info (click to toggle)
r-bioc-rsamtools 2.22.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,488 kB
  • sloc: ansic: 4,904; cpp: 1,586; sh: 40; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 2,096 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
PileupFiles <-
    function(files, ..., param=ApplyPileupsParam())
{
    bfl <- BamFileList(files, ...)
    new("PileupFiles", bfl, param=param)
}

plpFiles <- function(object) as(object, "BamFileList")

plpParam <- function(object) object@param

setMethod(applyPileups, c("PileupFiles", "ApplyPileupsParam"),
    function(files, FUN, ..., param)
{
    FUN <- match.fun(FUN)
    ok <- isOpen(files)
    if (!all(ok))
        if (any(ok))
            stop("all(isOpen(<PileupFiles>))' is not 'TRUE'")
        else {
            open(files)
            on.exit(close(files))
        }
    lvls <- lapply(files, seqlevels)
    for (i in seq_along(files)[-1])
        if (!identical(lvls[[i]], lvls[[1]])) {
            msg <- sprintf("applyPileups 'seqlevels' must be identical();
                failed when comparing %s with %s",
                sQuote(basename(path(files)[1])),
                sQuote(basename(path(files)[i])))
            stop(paste(strwrap(msg, exdent=4), collapse="\n"))
        }
    tryCatch({
        param <- as(param, "list")
        extptr <- lapply(files, .extptr)
        regions <-
            if (0L != length(param[["which"]])) .asRegions(param[["which"]])
            else NULL
        param[["what"]] <- c("seq", "qual") %in% param[["what"]]
        .Call(.apply_pileups, extptr, names(files), regions, param, FUN)
    }, error=function(err) {
        stop("applyPileups: ", conditionMessage(err), call.=FALSE)
    })
})

setMethod(applyPileups, c("PileupFiles", "missing"),
    function(files, FUN, ..., param)
{
    applyPileups(files, FUN, ..., param=plpParam(files))
})

setMethod(show, "PileupFiles", function(object) {
    cat("class:", class(object), "\n")
    nms <- names(object)
    txt <- paste(S4Vectors:::selectSome(nms, 3L), collapse=", ")
    cat(sprintf("names: %s (%d total)\n", txt, length(nms)))
    fls <- sapply(object, function(x) basename(path(x)))
    txt <- paste(S4Vectors:::selectSome(fls, 3L), collapse=", ")
    cat(sprintf("plpFiles: %s (%d total)\n", txt, length(fls)))
    cat("plpParam: class", class(plpParam(object)), "\n")
})