Add doublet scores to a MarchR object
add_doublet_scores.RdFor a TileMatrix or other count assay in a MarchRDataset or MarchRProject,
simulate synthetic doublets and score each observed cell by its proximity to
synthetic doublets. These scores can then be used by filter_doublets().
Usage
add_doublet_scores(
x,
n_doublets = 1000,
n_trials = NULL,
sample_ratio = 0.5,
n_dimensions = 30L,
n_iterations = 2,
lsi_method = 1,
binarize = TRUE,
corr_cutoff = 0.75,
scale_dims = FALSE,
umap_params = list(),
lsi_params = list(),
scoring_method = c("UMAP", "LSI"),
knn_method = knn_hnsw(k = 10L, metric = "euclidean", ef = 200L),
force = FALSE,
seed = 1,
batch = TRUE,
threads = NULL,
verbose = getOption("MarchR.verbose", FALSE),
...
)
# S3 method for class 'MarchRDataset'
add_doublet_scores(
x,
assay_name = character(0),
n_doublets = 1000,
n_trials = NULL,
sample_ratio = 0.5,
n_dimensions = 30L,
n_iterations = 2,
lsi_method = 1,
binarize = TRUE,
corr_cutoff = 0.75,
scale_dims = FALSE,
umap_params = list(),
lsi_params = list(),
scoring_method = c("UMAP", "LSI"),
knn_method = knn_hnsw(k = 10L, metric = "euclidean", ef = 200L),
force = FALSE,
seed = 1,
batch = TRUE,
threads = NULL,
verbose = getOption("MarchR.verbose", FALSE),
...
)
# S3 method for class 'MarchRProject'
add_doublet_scores(
x,
assay_name = character(0),
dataset_names = character(0),
n_doublets = 1000,
n_trials = NULL,
sample_ratio = 0.5,
n_dimensions = 30L,
n_iterations = 2,
lsi_method = 1,
binarize = TRUE,
corr_cutoff = 0.75,
scale_dims = FALSE,
umap_params = list(),
lsi_params = list(),
scoring_method = c("UMAP", "LSI"),
knn_method = knn_hnsw(k = 10L, metric = "euclidean", ef = 200L),
combine = FALSE,
force = FALSE,
seed = 1,
batch = TRUE,
threads = NULL,
verbose = getOption("MarchR.verbose", FALSE),
...
)Arguments
- x
A MarchRDataset or MarchRProject.
- n_doublets
(numeric) Number of doublets to simulate from the total cells in the sample.
- n_trials
(numeric or NULL) Number of simulation trials (each producing
n_doubletssynthetic doublets). IfNULL(default),5 * max(floor(n_cells / n_doublets), 1).- sample_ratio
(numeric) Downsample of non-zero input matrix entries to run simulation on.
- n_dimensions
(numeric) Number of dimensions in LSI DimReduction model.
- n_iterations
(numeric) Number of LSI iterations to run.
- lsi_method
(integer or character) Method for TF-IDF normalization. Default is 1 (tf-logidf) to match ArchR doublet inference. See
IterativeLSI()for details.- binarize
(logical) Binarize input matrix prior to LSI (ArchR default is TRUE)
- corr_cutoff
(numeric) Numeric filter for the correlation of a PC to the sequencing depth. If the PC has a correlation that is greater or equal to the corr_cutoff, it will be excluded from the final matrix.
- scale_dims
(logical) Whether to apply row-wise z-score scaling to the LSI embedding during doublet inference. Default is
FALSE, matching ArchR'saddDoubletScores(scaleDims = FALSE). Passed through toIterativeLSI().- umap_params
(list) List of parameters to pass to the UMAP function if "UMAP" is designated to
scoring_method.- lsi_params
(list) Named overrides for the internal
IterativeLSI()fit, e.g.list(preset = "archr"). Defaults set here take precedence only where unspecified. See the functionumapin theuwotpackage.- scoring_method
(character) The name of the dimensionality reduction method to be used for k-nearest neighbors calculation. This affects results in output columns:
doublet_enrichmentanddoublet_score. Possible values are "UMAP" or "LSI". Default is "UMAP".- knn_method
(function) KNN method. Default
knn_hnsw(k = 10L, metric = "euclidean", ef = 200L). Put KNN-specific arguments such askormetricinside the partial function.- force
(logical) Force through UMAP projection to scoring even if R^2 < 0.9 for re-projection of training data. This typically indicates a very homogenous population of cells, and is not recommended to continue. Default is FALSE.
- seed
(integer) Random seed used for doublet simulation and UMAP.
- batch
(logical) Use uwot's deterministic batch UMAP optimization. Default TRUE,
- threads
(integer) Per-call override of
set_threads(). Default NULL usesget_threads()for the LSI SVD and UMAP, and single-threads IterativeLSI clustering KNN. Note that an explicit value also threads clustering, which makes doublet scores non-deterministic.- verbose
(logical) Print progress messages. Default
getOption("MarchR.verbose", FALSE).- ...
Additional arguments passed to methods.
- assay_name
(character) The name of the matrix/assay to perform operation on. If not provided, will use smart selection when only one assay is present.
- dataset_names
(character) For MarchRProject only. The name(s) of the dataset(s) containing input tile matrix. If not provided, will use smart selection when only one dataset is present.
- combine
(logical) MarchRProject only. If
TRUE, combine matrices fromdataset_namesas replicates of one experiment and store the scored result as a new dataset whose name joins the source dataset names. Matrices must have the sameassay_name.
Value
The modified MarchRDataset or MarchRProject with a
$doublet_data slot added to each processed dataset.
$doublet_data is a named list containing:
- scores
data.frame (rownames = cell IDs) with columns
doublet_scoreanddoublet_enrichment- cell_umap
data.frame (rownames = cell IDs) with columns
UMAP1,UMAP2;NULLif UMAP projection failed- sim_umap
data.frame with columns
UMAP1,UMAP2for simulated doublets;NULLif UMAP projection failed- lsi_cells
Dense matrix (cells x dims) of the LSI cell embedding for downstream iteration
All doublet data is removed in a single operation by filter_doublets(clear_doublet_data = TRUE),
or manually via proj$doublet_data <- NULL.
Details
The function performs the following steps:
Simulate
n_doubletsfor each ofn_trialsfrom the input ATAC(features x cells)matrix.Fit IterativeLSI to produce real-cell embeddings with shape
(cells x retained dimensions).Project the simulated doublets into the fitted LSI space and, when requested, into the fitted UMAP space.
Calculate KNN-based doublet enrichment and adjusted-binomial scores for every observed cell.