Spatially-aware normalisation for spatial transcriptomics data (Python port of SpaNorm)
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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_spanorm-0.1.0.tar.gz.
File metadata
- Download URL: py_spanorm-0.1.0.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ecbc5f3b789b8fe3ab72221234b240ba4cec76eb2acaf45a0902ae87a43ae1c
|
|
| MD5 |
da467b185787b7bbc3ae3fed7e2c84eb
|
|
| BLAKE2b-256 |
654860fcb59c15cd539892d64e3af7a513604df52350bfda8a3d4070bf0ac71b
|
File details
Details for the file py_spanorm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_spanorm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.2 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 |
15fc7e0c52c3c99eabd33cb7937974ac90aac54d1e3f5cada36abfd32d53b2b0
|
|
| MD5 |
95128fe7cbf5684ab057541e24469920
|
|
| BLAKE2b-256 |
1c1f5788094ae3b62932baf1853d0fe300b76a2fad55a506e3bfd1d175bbca85
|