Last data update: 2014.03.03

R: Manipulate BCF files.
BcfFileR 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", 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)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Rsamtools)
Loading required package: GenomeInfoDb
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomicRanges
Loading required package: Biostrings
Loading required package: XVector
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/Rsamtools/BcfFile-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: BcfFile
> ### Title: Manipulate BCF files.
> ### Aliases: BcfFile-class BcfFileList-class BcfFile BcfFileList
> ###   open.BcfFile 'close.BcfFile ' isOpen,BcfFile-method bcfMode
> ###   scanBcfHeader,BcfFile-method scanBcf,BcfFile-method
> ###   indexBcf,BcfFile-method
> ### Keywords: classes
> 
> ### ** Examples
> 
> 
> fl <- system.file("extdata", "ex1.bcf", package="Rsamtools",
+                   mustWork=TRUE)
> bf <- BcfFile(fl)        # implicit index
> bf
class: BcfFile 
path: /home/ddbj/local/lib64/R/library/Rsamtools/extdata/ex1.bcf
index: /home/ddbj/local/lib64/R/library/Rsamtools/extdata/ex1.bcf
isOpen: FALSE 
yieldSize: NA 
> identical(scanBcf(bf), scanBcf(fl))
[1] TRUE
> 
> 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)
[1] TRUE TRUE
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>