BiocFile-class: BiocFile class objects

BiocFile-classR Documentation

BiocFile class objects

Description

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.

Usage

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)

Arguments

files

character() A vector of file paths for the BiocFileList constructor

x

A BiocFile instance

object

A BiocFile instance

...

additional arguments to lower-level functions, not used.

path, value

Either a character or connection object to replace the original resource

format

character(1) The file extension conducive to a file class name, e.g., CSVFile

prefix

character(1) The prefix to prepend to the format class name, e.g., Spatial for a class SpatialCSV.

suffix

character(1) The suffix to append to the format class name, e.g., File for a class CSVFile.

Value

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.

Accessor Methods

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.

FileForFormat

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.

Author(s)

Michael Lawrence

See Also

Implementing classes include: BigWigFile, TwoBitFile, BEDFile, GFFFile, WIGFile

Examples

## 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)


Bioconductor/BiocIO documentation built on Nov. 25, 2024, 6:14 p.m.