flatten_features: Flatten features

Description Usage Arguments Value See Also Examples

View source: R/shape_tornado.R

Description

Summarise a TornadoExperiment at every bin position for every sample by calculating a statistic over all features in a set. The defaults measure the mean, standard deviation and number of features.

Usage

1
2
3
4
5
flatten_features(
  tornado,
  assay_name = assayNames(tornado),
  measure = list(mean = colMeans2, sd = colSds, n = nrow)
)

Arguments

tornado

A TornadoExperiment object.

assay_name

A character(1): one of the assay names.

measure

A named list wherein each element is a function. Every function is expected to take a nrow(x) by nbin(x) matrix and return one of these results:

  • An atomic vector of length 1. An example of this is nrow().

  • An atomic vector of length nbin(x). An example of this is colMeans().

  • An atomic matrix of dimension nbin(x) by m with columnames. An example of this is the colQuantiles function.

As one might infer from the mentioned example functions, the col*-patterned functions are generally appropriate. Alternatively, the list elements can be formula with right-hand side. This follows the rlang lambda syntax.

Value

A long format data.frame with columns named after the measure argument, as well as position, feature_set and elements from colData(x).

See Also

Other tornado utilities: melt_tornado(), norm_tornado(), sort_tornado()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Summarise features
tor <- dummy_tornado()
df  <- flatten_features(tor)

# Estimate standard error of the mean
df$se <- sqrt(df$sd^2 / df$n)

# Plotting the result
require(ggplot2)
ggplot(df, aes(position, fill = feature_set)) +
  geom_ribbon(aes(ymin = mean - se, ymax = mean + se), alpha = 0.3) +
  geom_line(aes(y = mean, colour = feature_set)) +
  facet_wrap(~ sample_name)

# Calculating alternative metrics
require(matrixStats)
measure <- list(median = matrixStats::colMedians,
                mad = matrixStats::colMads,
                n = nrow)
df <- flatten_features(tor, measure = measure)

teunbrand/tornadoplot documentation built on Dec. 23, 2021, 8:48 a.m.