diff_methylsig: Calculates differential methylation statistics using a...

View source: R/diff_methylsig.R

diff_methylsigR Documentation

Calculates differential methylation statistics using a Beta-binomial approach

Description

The function calculates differential methylation statistics between two groups of samples using a beta-binomial approach to calculate differential methylation statistics, accounting for variation among samples within each group. The function can be applied to a BSseq object subjected to filter_loci_by_coverage(), filter_loci_by_snps(), filter_loci_by_group_coverage() or any combination thereof. Moreover, the function can be applied to a BSseq object which has been tiled with tile_by_regions() or tile_by_windows().

Usage

diff_methylsig(
  bs,
  group_column,
  comparison_groups,
  disp_groups,
  local_window_size = 0,
  local_weight_function,
  t_approx = TRUE,
  n_cores = 1
)

Arguments

bs

a BSseq object.

group_column

a character string indicating the column of pData(bs) to use for determining group membership.

comparison_groups

a named character vector indicating the case and control factors of group_column for the comparison.

disp_groups

a named logical vector indicating the whether to use case, control, or both to estimate the dispersion.

local_window_size

an integer indicating the size of the window for use in determining local information to improve mean and dispersion parameter estimations. In addition to a the distance constraint, a maximum of 5 loci upstream and downstream of the locus are used. The default is 0, indicating no local information is used.

local_weight_function

a weight kernel function. The default is the tri-weight kernel function defined as function(u) = (1-u^2)^3. The domain of any given weight function should be [-1,1], and the range should be [0,1].

t_approx

a logical value indicating whether to use squared t approximation for the likelihood ratio statistics. Chi-square approximation (t_approx = FALSE) is recommended when the sample size is large. Default is TRUE.

n_cores

an integer denoting how many cores should be used for differential methylation calculations.

Value

A GRanges object containing the following mcols:

meth_case:

Methylation estimate for case.

meth_control:

Methylation estimate for control.

meth_diff:

The difference meth_case - meth_control.

direction:

The group for which the locus is hyper-methylated. Note, this is not subject to significance thresholds.

pvalue:

The p-value from the t-test (t_approx = TRUE) or the Chi-Square test (t_approx = FALSE).

fdr:

The Benjamini-Hochberg adjusted p-values using p.adjust(method = 'BH').

disp_est:

The dispersion estimate.

log_lik_ratio:

The log likelihood ratio.

df:

Degrees of freedom used when t_approx = TRUE.

Examples

data(BS.cancer.ex, package = 'bsseqData')

bs = filter_loci_by_group_coverage(
    bs = BS.cancer.ex,
    group_column = 'Type',
    c('cancer' = 2, 'normal' = 2))

small_test = bs[seq(50)]

diff_gr = diff_methylsig(
    bs = small_test,
    group_column = 'Type',
    comparison_groups = c('case' = 'cancer', 'control' = 'normal'),
    disp_groups = c('case' = TRUE, 'control' = TRUE),
    local_window_size = 0,
    t_approx = TRUE,
    n_cores = 1)


sartorlab/methylSig documentation built on Aug. 22, 2024, 5:58 p.m.