"import"(con, format, text, trackLine = TRUE, genome = NA, colnames = NULL, which = NULL, seqinfo = NULL, extraCols = character())
import.bed(con, ...)
import.bed15(con, ...)
import.bedGraph(con, ...)
"export"(object, con, format, ...)
"export"(object, con, format, append = FALSE, index = FALSE, ignore.strand = FALSE, trackLine = NULL)
"export"(object, con, format, trackLine = TRUE, ...)
export.bed(object, con, ...)
export.bed15(object, con, ...)
"export"(object, con, format, expNames = NULL, trackLine = NULL, ...)
export.bedGraph(object, con, ...)
BEDFile
object. For the
functions ending in .bed
, .bedGraph
and .bed15
,
the file format is indicated by the function name. For the base
export
and import
functions, the format must be
indicated another way. If con
is a path, URL or connection,
either the file extension or the format
argument needs to be
one of bed, bed15, bedGraph or
bedpe. Compressed files (gz, bz2 and
xz) are handled transparently.
GRanges
or
something coercible to a GRanges
. If the object has a method
for asBED
(like GRangesList
), it is called prior to
coercion. This makes it possible to export a GRangesList
or
TxDb
in a way that preserves the hierarchical
structure. For exporting multiple tracks, in the UCSC track line
metaformat, pass a GenomicRangesList
, or something coercible to
one.
con
is
missing, a character vector to use as the inputTrackLine
object, as part of the returned
UCSCData
. For the UCSCData method on export,
whether to output the UCSC track line stored on the object, for the
other export methods, the actual TrackLine object to export.
NA
if
unknown. Typically, this is a UCSC identifier like hg19. An
attempt will be made to derive the seqinfo
on the return
value using either an installed BSgenome package or UCSC, if network
access is available.
GRanges
or other range-based object supported
by findOverlaps
. Only the intervals in the file
overlapping the given ranges are returned. This is much more efficient
when the file is indexed with the tabix utility.
TRUE
, automatically compress and index the
output file with bgzf and tabix. Note that tabix indexing will
sort the data by chromosome and start. Tabix supports a
single track in a file.
NULL
, the Seqinfo
object to set on
the result. If the genome
argument is not NA
, it must
agree with genome(seqinfo)
.
colClasses
from read.table
. It should indicate
the name and class of each extra/special column to read from the BED
file. As BED does not encode column names, these are assumed to be
the last columns in the file. This enables parsing of the various
BEDX+Y formats.
TRUE
, and con
points to a file path,
the data is appended to the file. Obviously, if con
is a
connection, the data is always appended.
object
to
export as sample columns in the BED15 file.BEDFile
method on
import
. When trackLine
is
TRUE
or the target format is BED15, the arguments are passed
through export.ucsc
, so track line parameters are supported.
Pairs
object combining two
GRanges
. The name
and score
are carried over to
the metadata columns.Otherwise, a GRanges
with the metadata columns described in the
details.
extraCols
argument to indicate the expected names and
classes of the special columns. We assume that the
last length(extraCols)
columns are special, and that the
preceding columns adhere to the BED format.BEDFile
class extends RTLFile
and is a
formal represention of a resource in the BED format.
To cast a path, URL or connection to a BEDFile
, pass it to
the BEDFile
constructor. Classes and constructors also exist
for the subclasses BED15File
, BEDGraphFile
and
BEDPEFile
. The following is the mapping of BED elements to a GRanges
object.
NA values are allowed only where indicated.
These appear as a . in the file. Only the first three columns
(chrom, start and strand) are required. The other columns can only be
included if all previous columns (to the left) are included. Upon export,
default values are used to automatically pad the table, if necessary.
ranges
component.
name
column; defaults to NA on export.
score
column, accessible via the score
accessor. Defaults to 0
on export. This is the only column present in BEDGraph (besides
chrom, start and end), and it is required.
strand
column, accessible via the strand
accessor; defaults to NA
on export.
Ranges
object in a
column named thick
; defaults to the ranges of the feature
on export.
col2rgb
, or any valid input to
col2rgb
, in the itemRgb
column; default is NA
on export, which translates to black.
RangesList
object
in a column named blocks
; defaults to empty upon BED15 export.
These columns are present only in BED15:
expIds
, containing the corresponding values from
expScores
. When a value is not present for a feature, NA is
substituted. NA values become -10000 in the file.
test_path <- system.file("tests", package = "rtracklayer")
test_bed <- file.path(test_path, "test.bed")
test <- import(test_bed)
test
test_bed_file <- BEDFile(test_bed)
import(test_bed_file)
test_bed_con <- file(test_bed)
import(test_bed_con, format = "bed")
close(test_bed_con)
import(test_bed, trackLine = FALSE)
import(test_bed, genome = "hg19")
import(test_bed, colnames = c("name", "strand", "thick"))
which <- GRanges("chr7:1-127473000")
import(test_bed, which = which)
## Not run:
# test_bed_out <- file.path(tempdir(), "test.bed")
# export(test, test_bed_out)
#
# test_bed_out_file <- BEDFile(test_bed_out)
# export(test, test_bed_out_file)
#
# export(test, test_bed_out, name = "Alternative name")
#
# test_bed_gz <- paste(test_bed_out, ".gz", sep = "")
# export(test, test_bed_gz)
#
# export(test, test_bed_out, index = TRUE)
# export(test, test_bed_out, index = TRUE, trackLine = FALSE)
#
# bed_text <- export(test, format = "bed")
# test <- import(format = "bed", text = bed_text)
# ## End(Not run)
Run the code above in your browser using DataLab