applySpline: applies a spline smoothing to a tidy data.table containing x...

Description Usage Arguments Details Value See Also Examples

View source: R/functions_signal_operations.R

Description

applySpline Is intended for two-dimensional tidy data.tables, as retured by ssvFetchBigwig

Usage

1
applySpline(dt, n, x_ = "x", y_ = "y", by_ = "", splineFun = stats::spline)

Arguments

dt

a tidy data.table containing two-dimensional data

n

the number of interpolation points to use per input point, see ?spline. n must be > 1.

x_

the variable name of the x-values

y_

the variable name of the y-values

by_

optionally, any variables that provide grouping to the data. default is none. see details.

splineFun

a function that accepts x, y, and n as arguments and returns a list of length 2 with named elements x and y. stats::spline by default. see stats::spline for details.

Details

by_ is quite powerful. If by_ = c('gene_id', 'sample_id'), splines will be calculated individually for each gene in each sample. alternatively if by_ = c('gene_id')

Value

a newly derived data.table that is n times longer than original.

See Also

ssvFetchBigwig

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#data may be blockier than we'd like
ggplot(CTCF_in_10a_profiles_dt[, list(y = mean(y)), by = list(sample, x)]) +
    geom_line(aes(x = x, y = y, color = sample))

#can be smoothed by applying a spline  (think twice about doing so,
#it may look prettier but may also be deceptive or misleading)

splined_smooth = applySpline(CTCF_in_10a_profiles_dt, n = 10,
    y_ = 'y', by_ = c('id', 'sample'))
ggplot(splined_smooth[, list(y = mean(y)), by = list(sample, x)]) +
    geom_line(aes(x = x, y = y, color = sample))

seqsetvis documentation built on Nov. 8, 2020, 5:57 p.m.