scanpy.external.pp.scrublet¶

scanpy.external.pp.scrublet(adata, adata_sim=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, copy=False, random_state=0)

Predict doublets using Scrublet [Wolock19].

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 Scanpy and directly call functions of Scrublet(). You may also undertake your own preprocessing, simulate doublets with scanpy.external.pp.scrublet_simulate_doublets(), and run the core scrublet function scanpy.external.pp.scrublet.scrublet().

Note

Parameters
adata : AnnDataAnnData

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 : (default: None)

(Advanced use case) Optional annData object generated by sc.external.pp.scrublet_simulate_doublets(), with same number of vars as adata. This should have been built from adata_obs after filtering genes and cells and selcting highly-variable genes.

sim_doublet_ratio : floatfloat (default: 2.0)

Number of doublets to simulate relative to the number of observed transcriptomes.

expected_doublet_rate : floatfloat (default: 0.05)

Where adata_sim not suplied, the estimated doublet rate for the experiment.

stdev_doublet_rate : floatfloat (default: 0.02)

Where adata_sim not suplied, uncertainty in the expected doublet rate.

synthetic_doublet_umi_subsampling : floatfloat (default: 1.0)

Where adata_sim not suplied, 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 : strstr (default: 'euclidean')

Distance metric used when finding nearest neighbors. For list of valid values, see the documentation for annoy (if use_approx_neighbors is True) or sklearn.neighbors.NearestNeighbors (if use_approx_neighbors is False).

normalize_variance : boolbool (default: True)

If True, normalize the data such that each gene has a variance of 1. sklearn.decomposition.TruncatedSVD will be used for dimensionality reduction, unless mean_center is True.

log_transform : boolbool (default: False)

Whether to use :func:~scanpy.pp.log1p to log-transform the data prior to PCA.

mean_center : boolbool (default: True)

If True, center the data such that each gene has a mean of 0. sklearn.decomposition.PCA will be used for dimensionality reduction.

n_prin_comps : intint (default: 30)

Number of principal components used to embed the transcriptomes prior to k-nearest-neighbor graph construction.

use_approx_neighbors : boolbool (default: True)

Use approximate nearest neighbor method (annoy) for the KNN classifier.

get_doublet_neighbor_parents : boolbool (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 : (default: None)

Number of neighbors used to construct the KNN graph of observed transcriptomes and simulated doublets. If None, this is automatically set to np.round(0.5 * np.sqrt(n_obs)).

threshold : (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 the doublet_scores_sim_ histogram. It is best practice to check the threshold visually using the doublet_scores_sim_ histogram and/or based on co-localization of predicted doublets in a 2-D embedding.

verbose : boolbool (default: True)

copy : boolbool (default: False)

If True, return a copy of the input adata with Scrublet results added. Otherwise, Scrublet results are added in place.

random_state : intint (default: 0)

Initial state for doublet simulation and nearest neighbors.

Return type
Returns

adata : AnnData if copy=True it returns or else adds fields to adata. Those fields:

.obs['doublet_score']

Doublet scores for each observed transcriptome

.obs['predicted_doublets']

Boolean indicating predicted doublet status

adata.uns['scrublet']['doublet_scores_sim']

Doublet scores for each simulated doublet transcriptome

adata.uns['scrublet']['doublet_parents']

Pairs of .obs_names used to generate each simulated doublet transcriptome

uns['scrublet']['parameters']

Dictionary of Scrublet parameters

scrublet_simulate_doublets()
scrublet_score_distribution()