Learn R Programming

rtracklayer (version 1.32.0)

io: Import and export

Description

The functions import and export load and save objects from and to particular file formats. The rtracklayer package implements support for a number of annotation and sequence formats.

Usage

export(object, con, format, ...)
import(con, format, text, ...)

Arguments

object
The object to export.
con
The connection from which data is loaded or to which data is saved. If this is a character vector, it is assumed to be a filename and a corresponding file connection is created and then closed after exporting the object. If a RTLFile derivative, the data is loaded from or saved to the underlying resource. If missing, the function will return the output as a character vector, rather than writing to a connection.
format
The format of the output. If missing and con is a filename, the format is derived from the file extension. This argument is unnecessary when con is a derivative of RTLFile.
text
If con is missing, this can be a character vector directly providing the string data to import.
...
Parameters to pass to the format-specific method.

Value

  • If con is missing, a character vector containing the string output. Otherwise, nothing is returned.

Details

The rtracklayer package supports a number of file formats for representing annotated genomic intervals. These are each represented as a subclass of RTLFile. Below, we list the major supported formats, with some advice for when a particular file format is appropriate: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] In summary, for the typical use case of combining gene models with experimental data, GFF is preferred for gene models and BigWig is preferred for quantitative score vectors. Note that the Rsamtools package provides support for the BAM file format (for representing read alignments), among others. Based on this, the rtracklayer package provides an export method for writing GAlignments and GappedReads objects as BAM. For variants, consider VCF, supported by the VariantAnnotation package.

There is also support for reading and writing biological sequences, including the UCSC TwoBit format for compactly storing a genome sequence along with a mask. The files are binary, so they are efficiently queried for particular ranges. A similar format is FA, supported by Rsamtools.

See Also

Format-specific options for the popular formats: GFF, BED, Bed15, bedGraph, WIG, BigWig

Examples

Run this code
track <- import(system.file("tests", "v1.gff", package = "rtracklayer"))
  export(track, "my.gff", version = "3")
  ## equivalently,
  export(track, "my.gff3")
  ## or
  con <- file("my.gff3")
  export(track, con, "gff3")
  close(con)
  ## or as a string
  export(track, format = "gff3")

Run the code above in your browser using DataLab