Title: | Standard Input and Output for Bioconductor Packages |
---|---|
Description: | The `BiocIO` package contains high-level abstract classes and generics used by developers to build IO funcionality within the Bioconductor suite of packages. Implements `import()` and `export()` standard generics for importing and exporting biological data formats. `import()` supports whole-file as well as chunk-wise iterative import. The `import()` interface optionally provides a standard mechanism for 'lazy' access via `filter()` (on row or element-like components of the file resource), `select()` (on column-like components of the file resource) and `collect()`. The `import()` interface optionally provides transparent access to remote (e.g. via https) as well as local access. Developers can register a file extension, e.g., `.loom` for dispatch from character-based URIs to specific `import()` / `export()` methods based on classes representing file types, e.g., `LoomFile()`. |
Authors: | Martin Morgan [aut], Michael Lawrence [aut], Daniel Van Twisk [aut], Marcel Ramos [cre] |
Maintainer: | Marcel Ramos <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.17.0 |
Built: | 2024-10-30 04:20:42 UTC |
Source: | https://github.com/bioc/BiocIO |
BiocFile
is the base virtual class for high-level file
abstractions where subclasses are associated with a particular file format
or type. It wraps a low-level representation of a file, currently either a
path, URL, or connection object. We can represent a list of BiocFile
objects with a BiocFileList
.
BiocFileList(files) resource(x) resource(x) <- value ## S4 method for signature 'BiocFile' resource(x) ## S4 replacement method for signature 'BiocFile,character_OR_connection' resource(x) <- value fileFormat(x) ## S4 method for signature 'character' fileFormat(x) ## S4 method for signature 'BiocFile' fileFormat(x) ## S4 method for signature 'BiocFile' path(object, ...) ## S4 method for signature 'BiocFile' show(object) FileForFormat(path, format = file_ext(path), prefix = NULL, suffix = "File") ## S4 method for signature 'BiocFile' as.character(x)
BiocFileList(files) resource(x) resource(x) <- value ## S4 method for signature 'BiocFile' resource(x) ## S4 replacement method for signature 'BiocFile,character_OR_connection' resource(x) <- value fileFormat(x) ## S4 method for signature 'character' fileFormat(x) ## S4 method for signature 'BiocFile' fileFormat(x) ## S4 method for signature 'BiocFile' path(object, ...) ## S4 method for signature 'BiocFile' show(object) FileForFormat(path, format = file_ext(path), prefix = NULL, suffix = "File") ## S4 method for signature 'BiocFile' as.character(x)
files |
|
x |
A |
object |
A |
... |
additional arguments to lower-level functions, not used. |
path , value
|
Either a |
format |
|
prefix |
|
suffix |
|
For constructors, an instance of that class. For extractors such as
resource
and path
, typically a character
vector of the file path.
For FileForFormat
, a convenient instance of the class for which the
input file corresponds to.
In the code snippets below, x
represents a BiocFile
object.
path(x)
Gets the path, as a character
vector, to the resource
represented by the BiocFile
object, if possible.
resource(x)
Gets the low-level resource, either a character vector (a path or URL) or a connection.
fileFormat(x)
Gets a string identifying the file format. Can also be called directly on a character file path, in which case it uses a heuristic based on the file extension.
The prefix
and suffix
arguments are used to filter the class names to
those that match the pattern paste0(prefix, format, suffix)
. If either
prefix
or suffix
are NULL
, they are ignored. Note that the search is
case insensitive and does require the format
to be in the name of the
class.
Michael Lawrence
Implementing classes include: BigWigFile, TwoBitFile, BEDFile, GFFFile, WIGFile
## For our examples, we create a class called CSVFILE that extends BiocFile .CSVFile <- setClass("CSVFile", contains = "BiocFile") ## Constructor CSVFile <- function(resource) { .CSVFile(resource = resource) } setMethod("import", "CSVFile", function(con, format, text, ...) { read.csv(resource(con), ...) }) ## Define export setMethod("export", c("data.frame", "CSVFile"), function(object, con, format, ...) { write.csv(object, resource(con), ...) } ) ## Recommend CSVFile class for .csv files temp <- tempfile(fileext = ".csv") FileForFormat(temp) ## Create CSVFile csv <- CSVFile(temp) ## Display path of file path(csv) ## Display resource of file resource(csv)
## For our examples, we create a class called CSVFILE that extends BiocFile .CSVFile <- setClass("CSVFile", contains = "BiocFile") ## Constructor CSVFile <- function(resource) { .CSVFile(resource = resource) } setMethod("import", "CSVFile", function(con, format, text, ...) { read.csv(resource(con), ...) }) ## Define export setMethod("export", c("data.frame", "CSVFile"), function(object, con, format, ...) { write.csv(object, resource(con), ...) } ) ## Recommend CSVFile class for .csv files temp <- tempfile(fileext = ".csv") FileForFormat(temp) ## Create CSVFile csv <- CSVFile(temp) ## Display path of file path(csv) ## Display resource of file resource(csv)
Methods and generics for file compression strategies.
decompress(manager, con, ...) ## S4 method for signature 'ANY' decompress(manager, con, ...) ## S4 method for signature 'CompressedFile' decompress(manager, con, ...) ## S4 method for signature 'character' decompress(manager, con, ...) ## S4 method for signature 'CompressedFile' fileFormat(x)
decompress(manager, con, ...) ## S4 method for signature 'ANY' decompress(manager, con, ...) ## S4 method for signature 'CompressedFile' decompress(manager, con, ...) ## S4 method for signature 'character' decompress(manager, con, ...) ## S4 method for signature 'CompressedFile' fileFormat(x)
manager |
The connection manager, defaults to the internal |
con |
The connection from which data is loaded or to which data is
saved. If this is a |
... |
Parameters to pass to the format-specific method. |
x |
A |
A decompressed representation of a CompressedFile
or character
object
FileForFormat(path, format = file_ext(path))
Determines the file type of path
and returns a high-level file object
such as BamFile, BEDFile, BigWigFile, etc.
file <- tempfile(fileext = ".gzip") decompress(con = file)
file <- tempfile(fileext = ".gzip") decompress(con = file)
The functions import
and export
load and save objects from
and to particular file formats.
import(con, format, text, ...) ## S4 method for signature 'connection,character,ANY' import(con, format, text, ...) ## S4 method for signature 'connection,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'character,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'character,character,ANY' import(con, format, text, ...) ## S4 method for signature 'missing,ANY,character' import(con, format, text, ...) export(object, con, format, ...) ## S4 method for signature 'ANY,connection,character' export(object, con, format, ...) ## S4 method for signature 'ANY,connection,missing' export(object, con, format, ...) ## S4 method for signature 'ANY,missing,character' export(object, con, format, ...) ## S4 method for signature 'ANY,character,missing' export(object, con, format, ...) ## S4 method for signature 'ANY,character,character' export(object, con, format, ...) ## S4 method for signature 'CompressedFile,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'ANY,CompressedFile,missing' export(object, con, format, ...)
import(con, format, text, ...) ## S4 method for signature 'connection,character,ANY' import(con, format, text, ...) ## S4 method for signature 'connection,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'character,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'character,character,ANY' import(con, format, text, ...) ## S4 method for signature 'missing,ANY,character' import(con, format, text, ...) export(object, con, format, ...) ## S4 method for signature 'ANY,connection,character' export(object, con, format, ...) ## S4 method for signature 'ANY,connection,missing' export(object, con, format, ...) ## S4 method for signature 'ANY,missing,character' export(object, con, format, ...) ## S4 method for signature 'ANY,character,missing' export(object, con, format, ...) ## S4 method for signature 'ANY,character,character' export(object, con, format, ...) ## S4 method for signature 'CompressedFile,missing,ANY' import(con, format, text, ...) ## S4 method for signature 'ANY,CompressedFile,missing' export(object, con, format, ...)
con |
The connection from which data is loaded or to which data is
saved. If this is a |
format |
The format of the output. If missing and |
text |
If |
... |
Parameters to pass to the format-specific method. |
object |
The object to export. |
If con
is missing, a character vector containing the string output.
Otherwise, nothing is returned.
Michael Lawrence
Format-specific options for the popular formats: GFF, BED, Bed15, bedGraph, WIG, BigWig
## To illustrate export(), import(), and yeild(), we create a class, CSVFILE .CSVFile <- setClass("CSVFile", contains = "BiocFile") ## Constructor CSVFile <- function(resource) { .CSVFile(resource = resource) } ## Define import setMethod("import", "CSVFile", function(con, format, text, ...) { read.csv(resource(con), ...) } ) ## Define export setMethod("export", c("data.frame", "CSVFile"), function(object, con, format, ...) { write.csv(object, resource(con), ...) } ) ## Usage temp <- tempfile(fileext = ".csv") csv <- CSVFile(temp) export(mtcars, csv) df <- import(csv)
## To illustrate export(), import(), and yeild(), we create a class, CSVFILE .CSVFile <- setClass("CSVFile", contains = "BiocFile") ## Constructor CSVFile <- function(resource) { .CSVFile(resource = resource) } ## Define import setMethod("import", "CSVFile", function(con, format, text, ...) { read.csv(resource(con), ...) } ) ## Define export setMethod("export", c("data.frame", "CSVFile"), function(object, con, format, ...) { write.csv(object, resource(con), ...) } ) ## Usage temp <- tempfile(fileext = ".csv") csv <- CSVFile(temp) export(mtcars, csv) df <- import(csv)