Sequence-class {IRanges} | R Documentation |
The Sequence virtual class is a general container for storing a sequence i.e. an ordered set of elements. These containers come in two types: XSequence and XRle.
The XSequence virtual class is a general container for storing an "external sequence". The following classes derive directly from the XSequence class.
The XRaw class is a container for storing an external sequence of bytes (stored as char values at the C level).
The XInteger class is a container for storing an external sequence of integer values (stored as int values at the C level).
The XNumeric class is a container for storing an external sequence of numeric values (stored as double values at the C level).
Also the XString class from the Biostrings package
The XRle virtual class is a general container for storing an "external sequence" that is stored in a run-time encoding format. The following classes derive directly from the XRle class.
The XRleInteger class is a container for storing an external run-length encoding of integers (stored as char values at the C level).
The purpose of these containers is to provide a "pass by address" semantic and also to avoid the overhead of copying the sequence data when a linear subsequence needs to be extracted.
In the code snippets below, x
is a Sequence object.
subseq(x, start=NA, end=NA, width=NA)
:
Extract the subsequence from x
specified by start
,
end
and width
.
The supplied start/end/width values are solved by a call to
solveUserSEW(length(x), start=start, end=end, width=width)
and therefore must be compliant with the rules of the SEW
(Start/End/Width) interface (see ?solveUserSEW
for the
details).
A note about performance: subseq
does NOT copy the sequence data
of an XSequence object. Hence it's very efficient and is therefore the
recommended way to extract a linear subsequence (i.e. a set of consecutive
elements) from an XSequence object. For example, extracting a 100Mb
subsequence from Human chromosome 1 (a 250Mb DNAString
object) with subseq
is (almost) instantaneous and has (almost) no
memory footprint (the cost in time and memory does not depend on the
length of the original sequence or on the length of the subsequence to
extract).
x[i, drop=TRUE]
:
Return a new Sequence object made of the selected elements (subscript
i
must be an NA-free numeric vector specifying the positions of
the elements to select). The drop
argument specifies whether or
not to coerce the returned sequence to a standard vector.
rep(x, times)
:
Return a new Sequence object made of the repeated elements.
Views-class,
solveUserSEW
,
DNAString-class
x1 <- XInteger(12, c(-1:10)) x1 length(x1) ## Subsetting x2 <- XInteger(99999, sample(99, 99999, replace=TRUE) - 50) x2 subseq(x2, start=10) subseq(x2, start=-10) subseq(x2, start=-20, end=-10) subseq(x2, start=10, width=5) subseq(x2, end=10, width=5) subseq(x2, end=10, width=0) x1[length(x1):1] x1[length(x1):1, drop=FALSE]