BiocFile-class | R Documentation |
A BiocFile
object is the base class for classes representing
files accessible with rtracklayer. It wraps a resource (either a path,
URL or connection). We can represent a list of BiocFile
objects
with a BiocFileList
.
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.
as.character(x)
:
Returns the path of the file as a character vector.
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..
bestFileFormat(x)
: Returns the best possible file format for a
given file. This function searches through loaded packages for "File"
classes that contain S4 methods for 'export' and 'import' for that class.
decompress(x)
: Returns a decompressed representation of a
CompressedFile
or character
object.
Michael Lawrence
Implementing classes include: BigWigFile
,
TwoBitFile
, BEDFile
,
GFFFile
, and 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.