BcfFile {Rsamtools} | R Documentation

## Manipulate BCF files.

### Description

Use `BcfFile()` to create a reference to a BCF (and optionally its index). The reference remains open across calls to methods, avoiding costly index re-loading.

`BcfFileList()` provides a convenient way of managing a list of `BcfFile` instances.

### Usage

    ## Constructors

    BcfFile(file, index = file,
            mode=ifelse(grepl("\\.bcf$", file), "rb", "r"))
    BcfFileList(...)

    ## Opening / closing

    ## S3 method for class 'BcfFile'
    open(con, ...)
    ## S3 method for class 'BcfFile'
    close(con, ...)

    ## accessors; also path(), index()

    ## S4 method for signature 'BcfFile'
    isOpen(con, rw="")
    bcfMode(object)

    ## actions

    ## S4 method for signature 'BcfFile'
    scanBcfHeader(file, ...)
    ## S4 method for signature 'BcfFile'
    scanBcf(file, ..., param=ScanBcfParam())
    ## S4 method for signature 'BcfFile'
    indexBcf(file, ...)

### Arguments

`con, object` | An instance of `BcfFile`.
`file` | A character(1) vector of the BCF file path or, (for indexBcf) an instance of `BcfFile` point to a BCF file.
`index` | A character(1) vector of the BCF index.
`mode` | A character(1) vector; `mode="rb"` indicates a binary (BCF) file, `mode="r"` a text (VCF) file.
`param` | An optional `ScanBcfParam` instance to further influence scanning.
`...` | Additional arguments. For `BcfFileList`, this can either be a single character vector of paths to BCF files, or several instances of `BcfFile` objects.
`rw` | Mode of file; ignored.

### Objects from the Class

Objects are created by calls of the form `BcfFile()`.

### Fields

The `BcfFile` class inherits fields from the `RsamtoolsFile` class.

### Functions and methods

`BcfFileList` inherits methods from `RsamtoolsFileList` and `SimpleList`.

Opening / closing:

open.BcfFile

  Opens the (local or remote) `path` and `index` (if `bamIndex` is not `character(0)`), files. Returns a `BcfFile` instance.

close.BcfFile

  Closes the `BcfFile` `con`; returning (invisibly) the updated `BcfFile`. The instance may be re-opened with `open.BcfFile`.

Accessors:

path

  Returns a character(1) vector of the BCF path name.

index

  Returns a character(1) vector of BCF index name.

bcfMode

  Returns a character(1) vector BCF mode.

Methods:

scanBcf

  Visit the path in `path(file)`, returning the result of `scanBcf` applied to the specified path.

show

  Compactly display the object.

### Author(s)

Martin Morgan

### Examples

    fl <- system.file("extdata", "ex1.bcf.gz", package="Rsamtools",
                      mustWork=TRUE)
    bf <- BcfFile(fl)        # implicit index
    bf
    identical(scanBcf(bf), scanBcf(fl))

    rng <- GRanges(c("seq1", "seq2"), IRanges(1, c(1575, 1584)))
    param <- ScanBcfParam(which=rng)
    bcf <- scanBcf(bf, param=param)  ## all ranges

    ## ranges one at a time 'bf'
    open(bf)
    sapply(seq_len(length(rng)), function(i, bcfFile, rng) {
        param <- ScanBcfParam(which=rng)
        bcf <- scanBcf(bcfFile, param=param)[[1]]
        ## do extensive work with bcf
        isOpen(bf)  ## file remains open
    }, bf, rng)

[Package Rsamtools version 2.8.0 Index]