<jupyter_start><jupyter_text>Doublet Detection on 10k PBMCs from 10x Genomics v3<jupyter_code>import numpy as np
import doubletdetection
import scanpy as sc
import matplotlib.pyplot as plt

sc.settings.n_jobs=8
sc.set_figure_params()<jupyter_output><empty_output><jupyter_text>Download Data from 10x  Load Count Matrix<jupyter_code>adata = sc.read_10x_h5(
    "pbmc_10k_v3_filtered_feature_bc_matrix.h5", 
    backup_url="https://cf.10xgenomics.com/samples/cell-exp/3.0.0/pbmc_10k_v3/pbmc_10k_v3_filtered_feature_bc_matrix.h5"
)
adata.var_names_make_unique()
# remove "empty" genes
sc.pp.filter_genes(adata, min_cells=1)<jupyter_output><empty_output><jupyter_text>Run Doublet DetectionHere we show-off the new backend implementation that uses `scanpy`. This new implementation is over 2x faster than version 2.4.0. To use the previous version of DoubletDetection please add the parameters (`use_phenograph=True`, `verbose=True`, `standard_scaling=False`) to the classifier and use the thresholds `p_thresh=1e-7`, `voter_thresh=0.8`. We recommend first using these parameters until we further validate the new implementation.<jupyter_code>clf = doubletdetection.BoostClassifier(
    n_iters=25, 
    use_phenograph=False, 
    standard_scaling=True
)
doublets = clf.fit(adata.X).predict(p_thresh=1e-16, voter_thresh=0.5)
doublet_score = clf.doublet_score()
adata.obs["doublet"] = doublets
adata.obs["doublet_score"] = doublet_score<jupyter_output><empty_output><jupyter_text>Visualize Results  Convergence of doublet calls<jupyter_code>f = doubletdetection.plot.convergence(clf, save='convergence_test.pdf', show=True, p_thresh=1e-16, voter_thresh=0.5)<jupyter_output><empty_output><jupyter_text>Doublets on umap<jupyter_code>sc.pp.normalize_total(adata)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata)
sc.tl.pca(adata)
sc.pp.neighbors(adata)
sc.tl.umap(adata)
sc.pl.umap(adata, color=["doublet", "doublet_score"])
sc.pl.violin(adata, "doublet_score")<jupyter_output><empty_output><jupyter_text>Number of predicted doublets at different threshold combinations<jupyter_code>f3 = doubletdetection.plot.threshold(clf, save='threshold_test.pdf', show=True, p_step=6)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10878470641784252, 'fraction_numerical': 0.02321347291761493, 'mean_word_length': 8.045267489711934, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '490854', 'license': 'MIT', 'n_tokens_mistral': 875, 'n_tokens_neox': 806, 'n_words': 142, 'path': 'tests/notebooks/PBMC_10k_vignette.ipynb', 'repo_name': 'JonathanShor/DoubletDetection', 'size': '2197'}