rapids_singlecell.pp.scrublet#
- rapids_singlecell.pp.scrublet(adata, adata_sim=None, *, batch=None, sim_doublet_ratio=2.0, expected_doublet_rate=0.05, stdev_doublet_rate=0.02, synthetic_doublet_umi_subsampling=1.0, knn_dist_metric='euclidean', normalize_variance=True, log_transform=False, mean_center=True, n_prin_comps=30, use_approx_neighbors=True, get_doublet_neighbor_parents=False, n_neighbors=None, threshold=None, verbose=True, rng=None, use=None, out=False, copy=False, batch_key=None)[source]#
Predict doublets using Scrublet [WLK19].
Predict cell doublets using a nearest-neighbor classifier of observed transcriptomes and simulated doublets. Works best if the input is a raw (unnormalized) counts matrix from a single sample or a collection of similar samples from the same experiment. This function is a wrapper around functions that pre-process using rapids-singlecell and directly call functions of Scrublet(). You may also undertake your own preprocessing, simulate doublets with
scrublet_simulate_doublets(), and run the core scrublet functionscrublet()withadata_simset.- Parameters:
- adata
AnnData The annotated data matrix of shape
n_obs×n_vars. Rows correspond to cells and columns to genes. Expected to be un-normalised where adata_sim is not supplied, in which case doublets will be simulated and pre-processing applied to both objects. If adata_sim is supplied, this should be the observed transcriptomes processed consistently (filtering, transform, normalisaton, hvg) with adata_sim.- adata_sim
AnnData|None(default:None) (Advanced use case) Optional annData object generated by
scrublet_simulate_doublets(), with same number of vars as adata. This should have been built from adata_obs after filtering genes and cells and selecting highly-variable genes.- batch
AdRef|str|None(default:None) Optional annotation discriminating between batches, e.g.
A.obs['batch'](or'obs.batch').- sim_doublet_ratio
float(default:2.0) Number of doublets to simulate relative to the number of observed transcriptomes.
- expected_doublet_rate
float(default:0.05) Where adata_sim not supplied, the estimated doublet rate for the experiment.
- stdev_doublet_rate
float(default:0.02) Where adata_sim not supplied, uncertainty in the expected doublet rate.
- synthetic_doublet_umi_subsampling
float(default:1.0) Where adata_sim not supplied, rate for sampling UMIs when creating synthetic doublets. If 1.0, each doublet is created by simply adding the UMI counts from two randomly sampled observed transcriptomes. For values less than 1, the UMI counts are added and then randomly sampled at the specified rate.
- knn_dist_metric
Literal['l2','chebyshev','manhattan','taxicab','correlation','inner_product','euclidean','canberra','lp','minkowski','cosine','jensenshannon','linf','cityblock','l1','haversine','sqeuclidean'] |Literal['canberra','chebyshev','cityblock','cosine','euclidean','hellinger','inner_product','jaccard','l1','l2','linf','lp','manhattan','minkowski','taxicab'] (default:'euclidean') Distance metric used when finding nearest neighbors. For list of valid values, see the documentation
cuml.neighbors.NearestNeighbors.- normalize_variance
bool(default:True) If True, normalize the data such that each gene has a variance of 1.
cuml.decomposition.tsvd.TruncatedSVDwill be used for dimensionality reduction, unlessmean_centeris True.- log_transform
bool(default:False) Whether to use
log1p()to log-transform the data prior to PCA.- mean_center
bool(default:True) If True, center the data such that each gene has a mean of 0.
cuml.decomposition.pca.PCAwill be used for dimensionality reduction.- n_prin_comps
int(default:30) Number of principal components used to embed the transcriptomes prior to k-nearest-neighbor graph construction.
- use_approx_neighbors
bool(default:True) Does not affect the results, just here to stay consistent with
scanpy.pp.scrublet().- get_doublet_neighbor_parents
bool(default:False) If True, return (in .uns) the parent transcriptomes that generated the doublet neighbors of each observed transcriptome. This information can be used to infer the cell states that generated a given doublet state.
- n_neighbors
int|None(default:None) Number of neighbors used to construct the KNN graph of observed transcriptomes and simulated doublets. If
None, this is automatically set tonp.round(0.5 * np.sqrt(n_obs)).- threshold
float|None(default:None) Doublet score threshold for calling a transcriptome a doublet. If
None, this is set automatically by looking for the minimum between the two modes of thedoublet_scores_sim_histogram. It is best practice to check the threshold visually using thedoublet_scores_sim_histogram and/or based on co-localization of predicted doublets in a 2-D embedding.- verbose
bool(default:True) If
True, log progress updates.- rng
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None(default:None) Random seed or
Generatorfor doublet simulation and nearest neighbors. The supersededrandom_stateargument is still accepted.- use
LayerAcc|str|None(default:None) Which matrix holds the raw counts, e.g.
A.XorA.layers['counts']. Strings are resolved byanndata.acc.AdAcc.resolve(), e.g.'layers.counts'.- out
ScrubletOut|bool(default:False) A mapping (
ScrubletOut) from output names to accessors writes only the outputs it names, e.g.{'doublet_score': A.obs['scrublet_score']}; the.unsentry is named afterdoublet_score’s key, so it has to be included. IfTrue, the outputs are returned as aScrubletResult(without the.unsentry). IfFalse, they are written to their default places below.- batch_key
str|None(default:None) Deprecated since version 0.19.0: Use
batchinstead, e.g.batch=A.obs['b']forbatch_key='b'.The name of a
.obscolumn, i.e.batch_key='b'isbatch=A.obs['b'].
- adata
- Return type:
- Returns:
A
ScrubletResultifout=True, elseNone. By default sets the following fields (seeoutfor others):.obs['doublet_score']Doublet scores for each observed transcriptome
.obs['predicted_doublet']Boolean indicating predicted doublet status
.uns['scrublet']['doublet_scores_sim']Doublet scores for each simulated doublet transcriptome
.uns['scrublet']['doublet_parents']Pairs of
.obs_namesused to generate each simulated doublet transcriptome.uns['scrublet']['parameters']Dictionary of Scrublet parameters
See also
scrublet_simulate_doublets()Run Scrublet’s doublet simulation separately for advanced usage.
scrublet_score_distribution()Plot histogram of doublet scores for observed transcriptomes and simulated doublets.