py-SpaNorm
Python port of the R/Bioconductor package SpaNorm — spatially-aware normalisation for spatial transcriptomics data.
Install
pip install -e .
Quickstart
import anndata as ad
from spanorm import SpaNorm
# Load your spatial data (AnnData format)
# adata.obsm['spatial'] should contain spatial coordinates
# adata.layers['counts'] or adata.X should contain raw counts
adata = ad.read_h5ad("your_data.h5ad")
# Class-based API
sn = SpaNorm(adata)
sn.normalize(sample_p=0.25, df_tps=6, verbose=True)
sn.find_svgs()
sn.pca(n_svgs=3000, n_components=50)
# Access results
logcounts = sn.adata.layers['logcounts'] # Normalized data
svg_results = sn.adata.var[['svg_F', 'svg_p', 'svg_fdr']] # SVG results
pca_coords = sn.adata.obsm['PCA'] # PCA coordinates
Functional API (R one-to-one mirror)
from spanorm import spanorm, spanorm_svg, spanorm_pca, filter_genes, fast_size_factors
# Filter genes
keep = filter_genes(counts, prop=0.1)
# Normalize
adata = spanorm(adata, sample_p=0.25, df_tps=6)
# Find SVGs
adata = spanorm_svg(adata)
# PCA
adata = spanorm_pca(adata, n_svgs=3000, n_components=50)
Python ⇄ R Function Map
| Python function | R function | Description |
|---|---|---|
spanorm() |
SpaNorm() |
Main normalization |
spanorm_svg() |
SpaNormSVG() |
SVG calling |
spanorm_pca() |
SpaNormPCA() |
GLM-based PCA |
filter_genes() |
filterGenes() |
Gene filtering |
fast_size_factors() |
fastSizeFactors() |
Fast size factors |
top_svgs() |
topSVGs() |
Top SVGs |
Algorithm
SpaNorm works by:
- Fitting a spatial regression model using thin-plate spline bases for spatial coordinates
- Modeling library size effects separately from biological signal
- Normalizing data using log-PAC, Pearson residuals, or mean/median biology methods
- Identifying spatially variable genes via likelihood ratio tests
License
GPL-3.0-or-later (matching upstream R package)
Citation
Bhuva DD, Salim A, Mohamed A. SpaNorm: Spatially-aware normalisation for spatial transcriptomics data. Bioconductor.
Metadata
Release files for py-spanorm 0.1.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 |
|---|---|---|---|---|
| py_spanorm-0.1.0.tar.gz | 23.1 kB | Without provenance | Details for py_spanorm-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_spanorm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for py_spanorm-0.1.0-py3-none-any.whl |
Total release size: 47.3 kB
Release files / py_spanorm-0.1.0.tar.gz
| Download URL | py_spanorm-0.1.0.tar.gz |
|---|---|
| Size | 23.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ecbc5f3b789b8fe3ab72221234b240ba4cec76eb2acaf45a0902ae87a43ae1c
|
|
BLAKE2b-256 checksum How to use checksums |
654860fcb59c15cd539892d64e3af7a513604df52350bfda8a3d4070bf0ac71b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / py_spanorm-0.1.0-py3-none-any.whl
| Download URL | py_spanorm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 24.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15fc7e0c52c3c99eabd33cb7937974ac90aac54d1e3f5cada36abfd32d53b2b0
|
|
BLAKE2b-256 checksum How to use checksums |
1c1f5788094ae3b62932baf1853d0fe300b76a2fad55a506e3bfd1d175bbca85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for py-spanorm 0.1.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.