Compute and store marker features
add_marker_features.RdPerforms differential testing to identify features enriched in each cell
group. Supports bias-matched background selection (matching ArchR's
getMarkerFeatures()) and pre-test normalization. Works on any
matrix assay (GeneScoreMatrix, TileMatrix, PeakMatrix, RNA, etc.).
Usage
# Default S3 method
add_marker_features(
proj,
group_by,
cell_metadata = NULL,
method = "wilcoxon",
p_adjust_method = "BH",
bias = c("TSSEnrichment", "log10(nFrags)"),
k = 100L,
max_cells = 500L,
buffer_ratio = 0.8,
norm_by = NULL,
scale_to = 10000,
knn_method = knn_hnsw(),
seed = 1L,
verbose = getOption("MarchR.verbose", FALSE),
...
)
# S3 method for class 'MarchRProject'
add_marker_features(
proj,
group_by,
assay_name = character(0),
dataset_names = character(0),
method = "wilcoxon",
p_adjust_method = "BH",
bias = c("TSSEnrichment", "log10(nFrags)"),
k = 100L,
max_cells = 500L,
buffer_ratio = 0.8,
norm_by = NULL,
scale_to = 10000,
knn_method = knn_hnsw(),
seed = 1L,
verbose = getOption("MarchR.verbose", FALSE),
overwrite = FALSE,
...
)Arguments
- proj
(MarchRProject or IterableMatrix) Object containing the matrix to test. For the default method, pass a matrix directly.
- group_by
(character or named vector) How to define cell groups. Can be a column name in cell metadata or a named character/factor vector. For the default method, must be a named character vector.
- cell_metadata
(data.frame or NULL) Cell metadata for bias matching. Required when
biasis not NULL. Rownames must be cell names.- method
(character) Statistical test:
"wilcoxon". Default"wilcoxon".- p_adjust_method
(character) p-value adjustment method passed to
p.adjust(). Default"BH".- bias
(character or NULL) Bias variable expressions evaluated against cell metadata. Default
c("TSSEnrichment", "log10(nFrags)"). Set toNULLfor one-vs-all (no bias matching).- k
(integer) KNN neighbors for bias matching. Default 100L.
- max_cells
(integer) Max foreground cells per group. Default 500L.
- buffer_ratio
(numeric) Min fraction of foreground with matched backgrounds. Default 0.8.
- norm_by
(character or NULL) Per-cell normalization:
NULL(colSums), a metadata column, or"none". Default NULL.- scale_to
(numeric) Column-sum normalization target. Default 1e4.
- knn_method
(function) BPCells KNN method. Default
knn_hnsw().- seed
(integer) Random seed. Default 1L.
- verbose
(logical) Print progress messages. Default
getOption("MarchR.verbose", FALSE).- ...
Additional arguments passed to methods.
- assay_name
(character) Name of the matrix assay to use. Uses smart selection if not specified. Also used as the storage key in
proj$marker_results.- dataset_names
(character) Datasets to include. Default all. (MarchRProject method only.)
- overwrite
(logical) If TRUE, overwrite existing marker result for this assay. Default FALSE. (MarchRProject method only.)
Value
For the default method: a MarkerResult object.
For MarchRProject: the project with the result stored in
proj$marker_results[[assay_name]].
Details
This function wraps BPCells::marker_features() and adds bias-matched
background selection, normalization, p-value adjustment, and log2 fold change.
ArchR correspondence: Replaces ArchR's getMarkerFeatures().
See also
get_marker_features for retrieving stored results
plot_marker_heatmap for plotting
MarkerResult for the result class