Skip to contents

Computes cell-level epigenomic erosion scores from a chromatin state count matrix. The function performs fraction normalization, centered log-ratio (CLR) transformation, z-scoring, and applies a state-specific sign vector (+1 for repressive states, -1 for active states). Optionally, it can regress out covariates (e.g., TSS enrichment, nCount_ATAC) from the resulting erosion scores.

Usage

ErosionScore(mat, meta, state_signs, covariates = NULL)

Arguments

mat

A numeric matrix of chromatin states as columns an cells as rows and states as columns. Typically produced by CalculateStateMatrix().

meta

A data frame (such as seurat_obj@meta.data) containing cell-level metadata. Required if covariate regression is to be performed.

state_signs

A named numeric vector indicating the sign (+1 or -1) for each chromatin state. Names must match the column names of input.

covariates

A character vector of column names in meta specifying which covariates to regress out of the erosion score. Default is NULL.

Value

A data frame with:

  • erosion_score: the raw erosion score per cell.

  • erosion_score_corrected (if covariates given): residual erosion score with covariates regressed out.

.

Details

The erosion score is calculated as:

  1. Normalize counts per cell to fractions.

  2. Apply log transform and center across states.

  3. Z-score each state across all cells.

  4. Multiply z-scored states by the sign vector (+1 for repressive, -1 for active).

  5. Sum across states to obtain one erosion score per cell.

If covariates is supplied, a linear model is fit using the specified covariates as predictors of the erosion score. The residuals from this model are returned as a covariate-corrected erosion score.