BiocFile-class: BiocFile objects

BiocFile-classR Documentation

BiocFile objects


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.

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.


as.character(x): Returns the path of the file as a character vector.

Related functions

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

See Also

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 <-
      .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")

  ## Create CSVFile
  csv <- CSVFile(temp)

  ## Display path of file

  ## Display resource of file

Bioconductor/BiocIO documentation built on May 15, 2022, 2:19 a.m.