py-SpotSweeper
Spatially-aware quality control for spatial transcriptomics.
Python port of R/Bioconductor package SpotSweeper v1.5.0.
Install
pip install spotsweeper
Quick start
import anndata as ad
from spotsweeper import local_variance, local_outliers, find_artifacts, flag_visium_outliers
# Load your spatial data as AnnData with adata.obsm['spatial']
adata = ad.read_h5ad("your_data.h5ad")
# 1. Compute local variance of mitochondrial percentage
adata = local_variance(adata, metric="subsets_Mito_percent", n_neighbors=36)
# 2. Detect local outliers in library size
adata = local_outliers(adata, metric="sum", direction="lower", log=True)
# 3. Flag systematic Visium outliers
adata = flag_visium_outliers(adata)
# 4. Find artifacts (single sample only)
adata = find_artifacts(adata, mito_percent="subsets_Mito_percent", n_order=5)
Functions
| Function | Description |
|---|---|
local_variance() |
Local variance of QC metrics using kNN + robust regression |
local_outliers() |
Outlier detection using MAD-based modified z-scores |
find_artifacts() |
Artifact detection via multi-scale variance + PCA + k-means |
flag_visium_outliers() |
Flag known systematic Visium outlier spots |
plot_qc_metrics() |
Spatial scatter plot of QC metrics |
plot_qc_pdf() |
Multi-page PDF of QC plots per sample |
Speed vs R
| Function | R | Python | Speedup |
|---|---|---|---|
| localVariance | 8.9s | 0.5s | 19x |
| localOutliers | 1.3s | 0.2s | 8x |
| findArtifacts | 16s | 5.5s | 3x |
| flagVisiumOutliers | 0.05s | 0.003s | 14x |
Parity
All functions pass parity gates against R reference outputs:
| Function | Metric | Value | Gate |
|---|---|---|---|
| localVariance | max abs err | 2.67e-6 | 1e-5 |
| localOutliers | F1 | 1.0 | 0.95 |
| findArtifacts | ARI | 1.0 | 0.95 |
| flagVisiumOutliers | exact match | 1.0 | 1.0 |
Requirements
- Python >= 3.9
- numpy, scipy, pandas, anndata, scikit-learn, matplotlib
License
MIT
References
Totty et al. (2025) "SpotSweeper: spatially-aware quality control for spatial transcriptomics." Bioconductor.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_spotsweeper-0.1.0.tar.gz
(11.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_spotsweeper-0.1.0.tar.gz.
File metadata
- Download URL: py_spotsweeper-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a585547097a06ca3377e5a1f8129100e3629df62af3341060fa674d098bcd931
|
|
| MD5 |
b53f2e5a07bb84c89079bcb3ea37e16e
|
|
| BLAKE2b-256 |
0b00cb824ae10995d88398b746c71fff1f9348c3e11a764a3596aef38b60d009
|
File details
Details for the file py_spotsweeper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_spotsweeper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc611943db5e37336d20cc1cd1451a1c6dddc66bc3836c1b6b54869c69513778
|
|
| MD5 |
9b2905fe6b45482b43b1231495c6eff1
|
|
| BLAKE2b-256 |
8714fa9f5d1f43fc97e4e0eb968a78b7f73cb10b140fe7a340f713d64c897ad7
|