DataTrack-class | R Documentation |
A class to store numeric data values along genomic coordinates. Multiple samples as well as sample groupings are supported, with the restriction of equal genomic coordinates for a single observation across samples.
## S4 method for signature 'DataTrack'
initialize(.Object, data = matrix(), strand, ...)
## S4 method for signature 'ReferenceDataTrack'
initialize(
.Object,
stream,
reference,
mapping = list(),
args = list(),
defaults = list(),
...
)
DataTrack(
range = NULL,
start = NULL,
end = NULL,
width = NULL,
data,
chromosome,
strand,
genome,
name = "DataTrack",
importFunction,
stream = FALSE,
...
)
## S4 method for signature 'DataTrack'
values(x, all = FALSE)
## S4 replacement method for signature 'DataTrack'
values(x) <- value
## S4 method for signature 'DataTrack'
strand(x)
## S4 replacement method for signature 'DataTrack,ANY'
strand(x) <- value
## S4 method for signature 'DataTrack,ANY'
split(x, f, drop = FALSE, ...)
## S4 method for signature 'DataTrack'
feature(GdObject)
## S4 replacement method for signature 'DataTrack,character'
feature(GdObject) <- value
## S4 method for signature 'DataTrack'
collapseTrack(GdObject, diff = .pxResolution(coord = "x"), xrange)
## S4 method for signature 'DataTrack,ANY,ANY,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'DataTrack'
subset(
x,
from = NULL,
to = NULL,
sort = FALSE,
drop = TRUE,
use.defaults = TRUE,
...
)
## S4 method for signature 'ReferenceDataTrack'
subset(x, from, to, chromosome, ...)
## S4 method for signature 'DataTrack'
drawAxis(GdObject, ...)
## S4 method for signature 'DataTrack'
drawGD(GdObject, minBase, maxBase, prepare = FALSE, subset = TRUE, ...)
## S4 method for signature 'DataTrack'
show(object)
## S4 method for signature 'ReferenceDataTrack'
show(object)
.Object |
.Object |
data |
A numeric matrix of data points with the number of columns equal
to the number of coordinates in |
strand |
Character vector, the strand information for the individual
track items. Currently this has to be unique for the whole track and doesn't
really have any visible consequences, but we might decide to make
|
... |
Additional items which will all be interpreted as further display parameters. |
stream |
A logical flag indicating that the user-provided import
function can deal with indexed files and knows how to process the additional
|
range |
An optional meta argument to handle the different input types.
If the The different input options for
|
start, end, width |
Integer vectors, giving the start and the end end coordinates for the individual track items, or their width. Two of the three need to be specified, and have to be of equal length or of length one, in which case the single value will be recycled accordingly. Otherwise, the usual R recycling rules for vectors do not apply and the function will cast an error. |
chromosome |
The chromosome on which the track's genomic ranges are
defined. A valid UCSC chromosome identifier if
|
genome |
The genome on which the track's ranges are defined. Usually
this is a valid UCSC genome identifier, however this is not being formally
checked at this point. If not provided here the constructor will try to
extract this information from the provided input, and eventually will fall
back to the default value of |
name |
Character scalar of the track's name used in the title panel when plotting. |
importFunction |
A user-defined function to be used to import the data
from a file. This only applies when the Some file types support indexing by genomic coordinates (e.g., |
value |
Value to be set. |
GdObject |
Object of |
Depending on the setting of the type
display parameter, the data can
be plotted in various different forms as well as combinations thereof.
Supported plotting types are:
p
:simple xy-plot.
l
: lines plot. In the case of multiple samples this plotting
type is not overly usefull since the points in the data matrix are connected
in column-wise order. Type a
might be more appropriate in these
situations.
b
:combination of xy-plot and lines plot.
a
:lines plot of the column-wise average values.
s
:sort and connect data points along the x-axis
S
:sort and connect data points along the y-axis
g
: add grid lines. To ensure a consitant look and feel across
multiple tracks, grid lines should preferentially be added by using the
grid
display parameter.
r
:add a regression line to the plot.
h
:histogram-like vertical lines centered in the middle of the coordinate ranges.
smooth
: add a loess fit to the plot. The following display
parameters can be used to control the loess calculation: span, degree,
family, evaluation
. See panel.loess
for details.
histogram
: plot data as a histogram, where the width of the
histogram bars reflects the width of the genomic ranges in the range
slot.
mountain
: plot a smoothed version of the data relative to a
baseline, as defined by the baseline
display parameter. The following
display parameters can be used to control the smoothing: span, degree,
family, evaluation
. See panel.loess
for details. The layout
of the plot can be further customized via the following display parameters:
col.mountain, lwd.mountain, lty.mountain, fill.mountain
.
polygon
: plot data as a polygon (similar to
mountain
-type but without smoothing). Data are plotted relative to a
baseline, as defined by the baseline
display parameter. The layout of
the plot can be further customized via the following display parameters:
col.mountain, lwd.mountain, lty.mountain, fill.mountain
.
boxplot
: plot the data as box-and-whisker plots. The layout
of the plot can be further customized via the following display parameters:
box.ratio, box.width, varwidt, notch, notch.frac, levels.fos, stats,
coef, do.out
. See panel.bwplot
for details.
gradient
: collapse the data across samples and plot this
average value as a color-coded gradient. Essenitally this is similar to the
heatmap-type plot of a single sample. The layout of the plot can be further
customized via the display parameters ncolor
and gradient
which control the number of gradient colors as well as the gradient base
colors, respectively.
heatmap
: plot the color-coded values for all samples in the
form of a heatmap. The data for individual samples can be visually separated
by setting the separator
display parameter. It's value is taken as
the amount of spacing in pixels in between two heatmap rows. The layout of
the plot can be further customized via the display parameters ncolor
and gradient
which control the number of gradient colors as well as
the gradient base colors, respectively.
horizon
: plot continuous data by cutting the y range into
segments and overplotting them with color representing the magnitude and
direction of deviation. This is particularly useful when comparing multiple
samples, in which case the horizon strips are stacked. See
horizonplot
for details. Please note that the origin
and horizonscale
arguments of the Lattice horizonplot
function
are available as display parameters horizon.origin
and
horizon.scale
.
For some of the above plotting-types the groups
display parameter can
be used to indicate sample sub-groupings. Its value is supposed to be a
factor vector of similar length as the number of samples. In most cases, the
groups are shown in different plotting colors and data aggregation
operations are done in a stratified fashion.
The window
display parameter can be used to aggregate the data prior
to plotting. Its value is taken as the number of equal-sized windows along
the genomic coordinates of the track for which to compute average values.
The special value auto
can be used to automatically determine a
reasonable number of windows which can be particularly useful when plotting
very large genomic regions with many data points.
The aggregation
parameter can be set to define the aggregation
function to be used when averaging in windows or across collapsed items. It
takes the form of either a function which should condense a numeric vector
into a single number, or one of the predefined options as character scalars
"mean"
, "median"
or "sum"
for mean, median or
summation, respectively. Defaults to computing mean values for each sample.
Note that the predefined options can be much faster because they are
optimized to work on large numeric tables.
The return value of the constructor function is a new object of class
DataTrack
or ReferenceDataTrack
.
initialize(DataTrack)
: Initialize.
ReferenceDataTrack-class
: The file-based version of the DataTrack-class
.
initialize(ReferenceDataTrack)
: Initialize.
DataTrack()
: Constructor function for DataTrack-class
values(DataTrack)
: return the raw data values of the object, i.e.,
the data matrix in the data
slot.
values(DataTrack) <- value
: Replace the data matrix in the data
slot.
strand(DataTrack)
: return a vector of strand specifiers for all
track items, in the form '+' for the Watson strand, '-' for the Crick
strand or '*' for either of the two.
strand(x = DataTrack) <- value
: replace the strand information for the track items.
The replacement value needs to be an appropriate scalar or vector of strand values.
split(x = DataTrack, f = ANY)
: Split a DataTrack
object by an appropriate
factor vector (or another vector that can be coerced into one).
The output of this operation is a list of DataTrack
objects.
feature(DataTrack)
: returns NULL since there is no grouping
information for the ranges in a DataTrack
.
feature(GdObject = DataTrack) <- value
: this return the unaltered input object since
there is no grouping information for the ranges in a DataTrack
.
collapseTrack(DataTrack)
: preprocess the track before plotting.
This will collapse overlapping track items based on the available resolution
and increase the width and height of all track objects to a minimum value
to avoid rendering issues. See collapsing for details.
x[i
: subset the items in the DataTrack
object.
This is essentially similar to subsetting of the GRanges
object in the
range
slot. For most applications, the subset method may be more appropriate.
subset(DataTrack)
: Subset a DataTrack
by coordinates
and sort if necessary.
subset(ReferenceDataTrack)
: Subset a ReferenceDataTrack
by coordinates
and sort if necessary.
drawAxis(DataTrack)
: add a y-axis to the title panel of a track.
drawGD(DataTrack)
: plot the object to a graphics device.
The return value of this method is the input object, potentially updated
during the plotting operation. Internally, there are two modes in which the
method can be called. Either in 'prepare' mode, in which case no plotting is
done but the object is preprocessed based on the available space, or in
'plotting' mode, in which case the actual graphical output is created.
Since subsetting of the object can be potentially costly, this can be
switched off in case subsetting has already been performed before or
is not necessary.
show(DataTrack)
: Show method.
show(ReferenceDataTrack)
: Show method.
Objects can be created using the constructor function DataTrack
.
Florian Hahne
DisplayPars
GdObject
GRanges
HighlightTrack
ImageMap
IRanges
RangeTrack
DataTrack
collapsing
grouping
panel.grid
plotTracks
settings
## Object construction:
## An empty object
DataTrack()
## from individual arguments
dat <- matrix(runif(400), nrow = 4)
dtTrack <- DataTrack(
start = seq(1, 1000, len = 100), width = 10, data = dat,
chromosome = 1, genome = "mm9", name = "random data"
)
## from GRanges
library(GenomicRanges)
gr <- GRanges(seqnames = "chr1", ranges = IRanges(seq(1, 1000, len = 100),
width = 10
))
values(gr) <- t(dat)
dtTrack <- DataTrack(range = gr, genome = "mm9", name = "random data")
## from IRanges
dtTrack <- DataTrack(
range = ranges(gr), data = dat, genome = "mm9",
name = "random data", chromosome = 1
)
## from a data.frame
df <- as.data.frame(gr)
colnames(df)[1] <- "chromosome"
dtTrack <- DataTrack(range = df, genome = "mm9", name = "random data")
## Plotting
plotTracks(dtTrack)
## Track names
names(dtTrack)
names(dtTrack) <- "foo"
plotTracks(dtTrack)
## Subsetting and splitting
subTrack <- subset(dtTrack, from = 100, to = 300)
length(subTrack)
subTrack[1:2, ]
subTrack[, 1:2]
split(dtTrack, rep(1:2, each = 50))
## Accessors
start(dtTrack)
end(dtTrack)
width(dtTrack)
position(dtTrack)
width(subTrack) <- width(subTrack) - 5
strand(dtTrack)
strand(subTrack) <- "-"
chromosome(dtTrack)
chromosome(subTrack) <- "chrX"
genome(dtTrack)
genome(subTrack) <- "mm9"
range(dtTrack)
ranges(dtTrack)
## Data
values(dtTrack)
score(dtTrack)
## coercion
as(dtTrack, "data.frame")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.