sc-doublet-detection
Load when annotating putative doublets in single-cell RNA-seq using Scrublet, DoubletDetection, DoubletFinder, scDblFinder, or scds. Skip when ambient RNA is the contamination problem (use sc-ambient-removal); before counts exist (use sc-fastq-qc).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- sc-doublet-detection
- tags
- [ "singlecell", "scrna", "doublet", "scrublet", "doubletfinder", "scdblfinder" ]
- description
- Load when annotating putative doublets in single-cell RNA-seq using Scrublet, DoubletDetection, DoubletFinder, scDblFinder, or scds. Skip when ambient RNA is the contamination problem (use sc-ambient-removal); before counts exist (use sc-fastq-qc).
02 资源文件 11
- 脚本_api.py18.0 KB
- 脚本examples/example_step.py983 B
- 参考文档references/methodology.md1.6 KB
- 参考文档references/output_contract.md1.1 KB
- 参考文档references/parameters.md2.4 KB
- 参考文档references/r_visualization.md688 B
- 脚本sc_doublet.py26.4 KB
- 脚本tests/__init__.py—
- 脚本tests/test_doublet_api.py3.6 KB
- 脚本tests/test_doublet_r.py3.5 KB
- 脚本tests/test_sc_doublet.py1.9 KB
03 SKILL.md 正文
sc-doublet-detection
When to use
The user has filtered (or at least QC'd) single-cell counts and wants
to flag putative doublet barcodes before clustering / annotation.
Five backends share one CLI: scrublet (default, Python), doubletdetection
(Python), doubletfinder (R), scdblfinder (R), scds (R). Per-cell
scores + binary calls land in obs; this skill annotates, it does not
remove cells (filter downstream with obs["predicted_doublet"]).
Use from a step
doublets = load_skill("sc-doublet-detection")
adata = doublets.detect_doublets(read_input("filtered.h5ad"), random_state=0)
write_output(doublets.doublet_calls_table(adata), "tables/doublet_calls.csv")
write_output(doublets.doublet_score_figure(adata), "figures/doublet_scores.png")
write_output(adata, "intermediate/adata_doublets.h5ad")
Detection annotates the input in place; it never removes cells. To remove
the calls, pass the result to sc-filter. See examples/example_step.py.
API
<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->
detect_doublets(adata, *, method: str='scrublet', expected_doublet_rate: float=0.06, threshold: float | None=None, batch_key: str | None=None, n_iters: int=10, standard_scaling: bool=False, scds_mode: str='cxds', random_state: int=0)
Annotate doublets in place using counts from layers['counts'], raw or X.
No observations or features are removed. Pass the result to sc-filter when doublets should be removed. A DoubletFinder failure may fall back to scDblFinder; a failed scds mode may fall back to cxds. run_info records both.
:param adata: AnnData containing a count-like matrix. :param method: scrublet, doubletdetection, doubletfinder, scdblfinder or scds. :param expected_doublet_rate: Expected doublet fraction; default 0.06. :param threshold: Scrublet score cutoff; None keeps its automatic calls. :param batch_key: Scrublet batches in obs; None analyzes all cells together. :param n_iters: DoubletDetection iterations; default 10. :param standard_scaling: DoubletDetection standard scaling; default False. :param scds_mode: cxds, bcds or hybrid; default cxds. :param random_state: Seed passed to the selected backend; default 0. :returns: The same AnnData with doublet_score, predicted_doublet and doublet_classification in obs, plus JSON diagnostics in uns. :raises ValueError: A method, rate, threshold or batch column is invalid. :raises ImportError: A Python backend is missing; use install_skill_deps. :raises RuntimeError: An R method and any documented fallback fail.
run_info(adata, *, keep: bool=True) -> dict
Read doublet method diagnostics from adata.uns.
:param adata: AnnData annotated by detect_doublets. :param keep: False removes the JSON diagnostics after reading; default True. :returns: Method, counts, matrix source and any fallback details.
doublet_calls_table(adata, *, groupby: str | None=None) -> pd.DataFrame
Return per-cell scores and calls in observation order.
:param adata: AnnData annotated by detect_doublets. :param groupby: Optional obs column to include in the table. :returns: A DataFrame with cell_id, scores, calls and classification.
doublet_summary(adata) -> pd.DataFrame
Return singlet and doublet counts and percentages from obs calls.
:param adata: AnnData with predicted_doublet in obs. :returns: A DataFrame with one row per classification.
group_summary_table(adata, *, groupby: str) -> pd.DataFrame
Summarize doublet counts and scores for an obs grouping column.
:param adata: AnnData annotated by detect_doublets. :param groupby: Existing obs column defining the groups. :returns: A DataFrame with counts, median and mean scores, and rates. :raises ValueError: The grouping column is missing.
doublet_score_figure(adata)
Plot the doublet score distribution and return the Figure.
:param adata: AnnData with doublet_score in obs. :returns: A matplotlib Figure; the caller saves it with write_output.
<!-- api:end -->
Methods and parameters
method="scrublet"andexpected_doublet_rate=0.06retain the CLI defaults. Set the rate from loading density and the experimental design.threshold=Noneretains Scrublet's automatic calls; a numeric threshold applies only to Scrublet.batch_keyruns Scrublet by thatobscolumn; it does not make the other backends batch-aware.- DoubletDetection retains
n_iters=10andstandard_scaling=False. - R backends use
Rscriptand temporary gene-by-cell MTX plus CSV metadata; they do not need a Python environment inside R. DoubletFinder requires Seurat, DoubletFinder and Matrix; scDblFinder/scds require their matching package, SingleCellExperiment and Matrix. random_state=0now reaches every backend, including Scrublet and R. Previously the CLI ignored this parameter for Scrublet; scDblFinder used a fixed R seed of 42. Missing Python packages raise an import error.
Inputs & Outputs
Inputs
- Modalities: scrna
- File types:
.h5ad
Outputs
tables/doublet_calls.csvtables/summary.csvtables/group_summary.csvwhen a comparison group is availablefigures/doublet_score_distribution.png; embedding plots when an embedding is availablefigure_data/and its manifest, for the generated plotsfigures/r_enhanced/only for successful--r-enhancedrendersprocessed.h5adreport.mdresult.json- Processed AnnData (
saves_h5ad) — addsobs:doublet_score,predicted_doublet,doublet_classification
Flow
- Load AnnData; resolve
--methodagainst theMETHOD_REGISTRY. - Run the chosen backend on the selected count-like matrix.
- DoubletFinder may fall back to scDblFinder; a failed scds mode may fall back to cxds. Other failures propagate.
- Apply the chosen
--threshold(or method default) to score → call. - Write
obs["predicted_doublet"]+obs["doublet_score"]; emit tables and the score-distribution figure. - Save
processed.h5ad+report.md+result.json.
Gotchas
- Check
run_info(adata)["executed_method"],fallback_reasonand, for scds,executed_scds_mode. The CLI mirrors these diagnostics inresult.json["summary"]. - No cells are removed. This skill annotates barcodes; downstream filtering on
obs["predicted_doublet"]is the user's responsibility. Ifsc-filterwas already run, doublets re-introduce themselves to the cluster graph if not filtered after this step. tables/group_summary.csvrequires a comparison column:--batch-keytakes precedence over an available annotation or cluster column.- Embedding pre-flight is non-fatal.
sc_doublet.pylogs"Preview embedding computation failed"and continues; the score-distribution figure still renders without the embedding overlay. When the figure looks sparse vs documented examples, check the warning log before assuming a bug. - Unsupported method → hard fail.
sc_doublet.pyraisesValueError("Unsupported method: ...")for typos like--method scrubblet.
Key CLI
# Demo (Scrublet)
python skills/singlecell/scrna/sc-doublet-detection/sc_doublet.py --demo --output /tmp/sc_doublet_demo
# Default Scrublet, with batch-aware grouping
python skills/singlecell/scrna/sc-doublet-detection/sc_doublet.py \
--input filtered.h5ad --output results/ --batch-key sample_id
# scDblFinder with a custom expected rate
python skills/singlecell/scrna/sc-doublet-detection/sc_doublet.py \
--input filtered.h5ad --output results/ \
--method scdblfinder --expected-doublet-rate 0.1 --random-state 0
See also
references/parameters.md— every CLI flag and per-method tuning hintreferences/methodology.md— when each backend wins, R vs Python tradeoffsreferences/output_contract.md—obskeys added + table schemas- Adjacent skills:
sc-ambient-removal(parallel — fixes ambient RNA, complementary to doublet removal),sc-filter(upstream — typically run before this),sc-clustering(downstream — filter doublets out before clustering)
Dependencies
Python packages this skill's script needs. They are not installed for you — check before a long run.
anndata, doubletdetection, matplotlib, numpy, pandas, scanpy, scipy, scrublet, seaborn
04 同仓库更多 Skills
demo-skill
A fixture skill for the skill environment tests. Use it for nothing else.
fake-domains
Test fixture for the golden deployment in tests/entry. Load never; it has no script.
replace-me-skill
Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.
spatial-velocity
Load when estimating RNA velocity on a spatial AnnData with `layers["spliced"]` + `layers["unspliced"]` via scVelo (stochastic / deterministic / dynamical) or veloVI (deep generative). Skip when input lacks the spliced/unspliced layers (must be quantified upstream by velocyto / kb-python / STARsolo); non-spatial scRNA velocity (use sc-velocity).
spatial-trajectory
Load when inferring pseudotime / lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced/unspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).
spatial-statistics
Load when running spatial autocorrelation / hotspot / co-occurrence / neighbourhood-enrichment / Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).