1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
\name{XVector-class}
\docType{class}
% XVector class, functions and methods:
\alias{class:XVector}
\alias{XVector-class}
\alias{XVector}
\alias{length,XVector-method}
\alias{bindROWS,XVector-method}
\alias{subseq}
\alias{subseq<-}
\alias{subseq,XVector-method}
\alias{subseq<-,XVector-method}
\alias{as.numeric,XVector-method}
\alias{show,XVector-method}
\alias{==,XVector,XVector-method}
% XRaw class, functions and methods:
\alias{class:XRaw}
\alias{XRaw-class}
\alias{XRaw}
\alias{coerce,raw,XRaw-method}
\alias{coerce,raw,XVector-method}
\alias{coerce,numeric,XRaw-method}
\alias{as.raw,XRaw-method}
\alias{as.integer,XRaw-method}
\alias{as.vector,XRaw-method}
% XInteger class, functions and methods:
\alias{class:XInteger}
\alias{XInteger-class}
\alias{XInteger}
\alias{coerce,numeric,XInteger-method}
\alias{coerce,integer,XVector-method}
\alias{as.integer,XInteger-method}
\alias{as.vector,XInteger-method}
% XDouble class, functions and methods:
\alias{class:XDouble}
\alias{XDouble-class}
\alias{XDouble}
\alias{XNumeric}
\alias{coerce,numeric,XDouble-method}
\alias{coerce,numeric,XVector-method}
\alias{as.numeric,XDouble-method}
\alias{as.vector,XDouble-method}
\alias{show,XDouble-method}
\title{XVector objects}
\description{
The XVector virtual class is a general container for storing
an "external vector". It inherits from the \link[S4Vectors]{Vector}
class, which has a rich interface.
The following classes derive directly from the XVector class:
The XRaw class is a container for storing an "external raw vector"
i.e. an external sequence of bytes (stored as char values at the
C level).
The XInteger class is a container for storing an "external integer
vector" i.e. an external sequence of integer values (stored as
int values at the C level).
The XDouble class is a container for storing an "external double
vector" i.e. an external sequence of numeric values (stored as
double values at the C level).
Also the \link[Biostrings]{XString} class defined in the Biostrings
package.
The purpose of the X* 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.
}
\section{Additional Subsetting operations on XVector objects}{
In the code snippets below, \code{x} is an XVector object.
\describe{
\item{\code{subseq(x, start=NA, end=NA, width=NA)}:}{
Extract the subsequence from \code{x} specified by \code{start},
\code{end} and \code{width}.
The supplied start/end/width values are solved by a call to
\code{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 \code{?solveUserSEW} for the
details).
A note about performance: \code{subseq} does NOT copy the sequence data
of an XVector 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 XVector object. For example, extracting a 100Mb
subsequence from Human chromosome 1 (a 250Mb
\link[Biostrings:DNAString-class]{DNAString} object) with \code{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).
}
\item{\code{subseq(x, start=NA, end=NA, width=NA) <- value}:}{
Replace the subsequence specified on the left (i.e. the subsequence
in \code{x} specified by \code{start}, \code{end} and \code{width})
by \code{value}.
\code{value} must belong to the same class as \code{x}, or to one of
its subclasses, or must be \code{NULL}.
This replacement method can modify the length of \code{x}, depending
on how the length of the left subsequence compares to the length of
\code{value}.
It can be used for inserting elements in \code{x} (specify an empty
left subsequence for this) or deleting elements from \code{x} (use
a \code{NULL} right value for this).
Unlike the extraction method above, this replacement method always
copies the sequence data of \code{x} (even for XVector objects).
NOTE: Only works for XRaw (and derived) objects for now.
}
}
}
\author{H. Pagès}
\seealso{
\link[S4Vectors]{Vector-class},
\link[Biostrings]{DNAString-class},
\link{XVectorList-class},
\link[IRanges]{Views-class},
\code{\link[IRanges]{solveUserSEW}},
\code{\link{compact}}
}
\examples{
## ---------------------------------------------------------------------
## A. XRaw OBJECTS
## ---------------------------------------------------------------------
x1 <- XRaw(4) # values are not initialized
x1
x2 <- as(c(255, 255, 199), "XRaw")
x2
y <- c(x1, x2, NULL, x1) # NULLs are ignored
y
subseq(y, start=-4)
subseq(y, start=-4) <- x2
y
## ---------------------------------------------------------------------
## B. XInteger OBJECTS
## ---------------------------------------------------------------------
x3 <- XInteger(12, val=c(-1:10))
x3
length(x3)
## Subsetting
x4 <- XInteger(99999, val=sample(99, 99999, replace=TRUE) - 50)
x4
subseq(x4, start=10)
subseq(x4, start=-10)
subseq(x4, start=-20, end=-10)
subseq(x4, start=10, width=5)
subseq(x4, end=10, width=5)
subseq(x4, end=10, width=0)
x3[length(x3):1]
x3[length(x3):1, drop=FALSE]
}
\keyword{methods}
\keyword{classes}
|