pydoubletfinder
A pure-Python re-implementation of DoubletFinder (McGinnis et al., Cell Systems 2019) for computational doublet detection in single-cell RNA-seq data.
- AnnData-native — drop-in for the scanpy ecosystem
- No
rpy2, no R install — the full pN/pK sweep, bimodality coefficient, BCmvn, and pANN scoring are all implemented directly in NumPy/SciPy - Same function surface as the R workflow (
paramSweep→summarizeSweep→find.pK→doubletFinder) - Bit-for-bit reproducibility against the R reference when fed matching PCA embeddings + artificial-doublet cell pairs (see
tests/test_exact_match.py)
This is a standalone mirror of the canonical implementation that lives in
omicverse(omicverse.single.DoubletFinder). All algorithmic work is developed upstream in omicverse and synced here for users who want DoubletFinder without the full omicverse stack.
Install
pip install pydoubletfinder
Quick-start (class API)
import anndata as ad
from pydoubletfinder import DoubletFinder
adata = ad.read_h5ad("mydata.h5ad") # cells × genes, raw counts in .X
df = DoubletFinder(adata)
# 1) pN/pK parameter sweep
df.param_sweep(PCs=10)
# 2) Bimodality coefficient summary
df.summarize_sweep()
# 3) Optimal pK via BCmvn
bcmvn = df.find_pK()
# 4) Final scoring + classification
df.run(pN=0.25, nExp=round(0.075 * adata.n_obs))
adata.obs[[c for c in adata.obs.columns if c.startswith("DF.")]]
Low-level functional API (mirrors R one-to-one)
from pydoubletfinder import (
param_sweep, summarize_sweep, find_pK,
doublet_finder, model_homotypic,
bimodality_coefficient,
)
# Per-real-cell pANN (needs a PCA embedding of [real + artificial] cells)
result = doublet_finder(
pca_coord=my_pca, # (n_real + n_doublets, n_PCs)
n_real_cells=n_real,
pN=0.25, pK=0.09, nExp=250,
)
result.pANN # np.ndarray
result.classifications # {"Singlet", "Doublet"} per real cell
result.column_name_DF # "DF.classifications_0.25_0.09_250"
# Homotypic-doublet proportion (match R modelHomotypic)
homotypic = model_homotypic(adata.obs["cluster"])
What's included
| Python | R counterpart | Purpose |
|---|---|---|
DoubletFinder class |
— | AnnData-native lifecycle wrapper (like Milo, Monocle) |
param_sweep |
paramSweep |
pN/pK sweep, one SweepEntry per (pN, pK) |
summarize_sweep |
summarizeSweep |
bimodality coefficient per sweep entry, optional AUC |
find_pK |
find.pK |
BCmvn + optimal-pK table |
doublet_finder |
doubletFinder |
pANN + Doublet/Singlet classification |
model_homotypic |
modelHomotypic |
homotypic-doublet proportion from cluster freqs |
bimodality_coefficient, skewness, kurtosis |
same | exported for direct use/testing |
bkde, approxfun |
KernSmooth::bkde, stats::approxfun |
KernSmooth-compatible KDE + R approxfun |
sample_artificial_doublets |
internal | expose doublet-pair sampling for reproducibility |
Reproducing R results exactly
The pipeline's randomness has two sources: which cell pairs become artificial doublets, and the PCA embedding of the merged matrix. To get identical outputs to an R run, provide both directly:
from pydoubletfinder import doublet_finder
result = doublet_finder(
pca_coord=r_pca_embedding, # from Seurat's reductions$pca@cell.embeddings
n_real_cells=len(real_cells),
pN=0.25, pK=0.09, nExp=250,
)
tests/test_exact_match.py runs the R reference (DoubletFinder::paramSweep + doubletFinder) inside the CMAP conda env, saves PCA coords and cell-pair indices, and checks that the Python port reproduces the pANN, BCreal, and classification vectors bit-for-bit.
Relationship to omicverse
Developed upstream in omicverse:
- Canonical implementation:
omicverse.single.DoubletFinder - Standalone mirror (this repo): same code, same API, minus the omicverse packaging
Citation
If you use this package, please cite the original DoubletFinder paper:
McGinnis, C.S., Murrow, L.M. & Gartner, Z.J. DoubletFinder: Doublet Detection in Single-Cell RNA Sequencing Data Using Artificial Nearest Neighbors. Cell Systems 8, 329–337 (2019).
and acknowledge omicverse / this repo for the Python port.
License
CC0 — matches the upstream R package.
Metadata
Release files for pydoubletfinder 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydoubletfinder-0.2.0.tar.gz | 26.7 kB | Without provenance | Details for pydoubletfinder-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydoubletfinder-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pydoubletfinder-0.2.0-py3-none-any.whl |
Total release size: 49.6 kB
Release files / pydoubletfinder-0.2.0.tar.gz
| Download URL | pydoubletfinder-0.2.0.tar.gz |
|---|---|
| Size | 26.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ee314c2b05fa873296f7db6ed0e5e74a5b538a568b220439a7522b9bac35ec1
|
|
BLAKE2b-256 checksum How to use checksums |
696a5f24d358f6fb10c9ec03ebcc18bd271817f64c5677dbc96ed722c256a775
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / pydoubletfinder-0.2.0-py3-none-any.whl
| Download URL | pydoubletfinder-0.2.0-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
156813fa640e0f76e6b2faf073707bc4972a41532c4c9c18b8cd00590ec40bc2
|
|
BLAKE2b-256 checksum How to use checksums |
21c188009c01df3a543436fa904b862c186559ebf510f0a48ecf04f2428f551e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Security for pydoubletfinder 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.