Computes per-neighbourhood somatic hypermutation (SHM) summary statistics
from B cell receptor (BCR) data stored in colData. For each
neighbourhood, the function aggregates SHM metrics across cells that carry
BCR information, and flags neighbourhoods with insufficient BCR coverage as
unreliable.
Usage
nhood_shm(
object,
nhood_col = NULL,
shm_cols = c("mu_count_VDJ", "mu_count_VJ", "mu_freq_VDJ", "mu_freq_VJ", "mu_count",
"mu_freq"),
min_n_shm = 20,
summary_metric = "mean",
result_name = "nhood_shm"
)Arguments
- object
A
MiloorSingleCellExperimentobject. Seurat objects must first be converted viaas.SingleCellExperiment.- nhood_col
Character string. For plain
SingleCellExperimentobjects (i.e. notMilo), the name of thecolDatacolumn containing neighbourhood assignments. Not required forMiloobjects.- shm_cols
Character vector of column names in
colData(object)containing per-cell SHM metrics to aggregate. Defaults toc("mu_count_VDJ", "mu_count_VJ", "mu_freq_VDJ", "mu_freq_VJ", "mu_count", "mu_freq"). All specified columns must be present incolData; missing columns will raise an error.- min_n_shm
Integer. Minimum number of cells with SHM annotation required for a neighbourhood's SHM statistics to be considered reliable. Neighbourhoods with fewer than
min_n_shmcontigs are retained in the output but haveshm_reliable = FALSEandNAvalues for all SHM columns. Default is10.- summary_metric
Character string specifying the central tendency statistic to compute for each SHM metric within each neighbourhood. One of
"mean"(default) or"median". The corresponding spread metric is computed automatically: standard deviation (sd) for"mean", interquartile range (IQR) for"median".- result_name
Character string. Name of the metadata slot in which to store the resulting SHM data frame, i.e. the results are accessible via
metadata(object)[[result_name]]. If the slot already exists it will be overwritten with a warning. Default is"nhood_shm".
Value
The input object with an additional (or updated) entry in
metadata(object)[[result_name]]. The stored value is a
data.frame with one row per neighbourhood and the following columns:
nhoodNeighbourhood identifier.
nhood_sizeTotal number of cells in the neighbourhood.
n_shmNumber of cells with at least one non-
NASHM value.shm_capture_rateProportion of neighbourhood cells with SHM data (
n_shm / nhood_size).shm_reliableLogical;
TRUEifn_shm >= min_n_shm.<shm_col>_<summary_metric>One column per entry in
shm_colscontaining the aggregated statistic (mean or median).<shm_col>_<spread_metric>One column per entry in
shm_colscontaining the spread statistic (sdorIQR).
The data frame also carries the following attributes:
min_n_shm, shm_cols, summary_metric, and
spread_metric.
Details
Object type handling
Milo objects: Neighbourhood membership is read directly from the sparse
nhoodsmatrix vianhoods. Row names of this matrix must matchcolnames(object); a mismatch raises an error to prevent silent misassignment.Plain SingleCellExperiment objects: A binary neighbourhood membership matrix is constructed internally from the column specified by
nhood_col. Cells withNAassignments are excluded with a warning.
Examples
if (FALSE) { # \dontrun{
# --- Milo object ---
milo_obj <- nhood_shm(
object = milo_obj,
shm_cols = c("mu_freq_VDJ", "mu_freq_VJ", "mu_freq"),
min_n_shm = 15,
summary_metric = "median",
result_name = "nhood_shm"
)
# Retrieve results
shm_df <- metadata(milo_obj)[["nhood_shm"]]
head(shm_df)
# --- Plain SingleCellExperiment object ---
sce_obj <- nhood_shm(
object = sce_obj,
nhood_col = "neighbourhood_id",
min_n_shm = 10,
summary_metric = "mean"
)
} # }