Randomized Spatial PCA (RASP): a computationally efficient method for dimensionality reduction of high-resolution spatial transcriptomics data
Project description
Randomized Spatial PCA (RASP)
Description
Here, we present Randomized Spatial PCA (RASP), a novel spatially aware dimensionality reduction method for spatial transcriptomics (ST) data. RASP is designed to be orders-of-magnitude faster than existing techniques, scale to ST data with hundreds of thousands of locations, support the flexible integration of non-transcriptomic covariates, and enable the reconstruction of de-noised and spatially smoothed expression values for individual genes. To achieve these goals, RASP uses a randomized two-stage principal component analysis (PCA) framework that leverages sparse matrix operations and configurable spatial smoothing.
Features
- High-Speed Performance: RASP is optimized for fast processing of large spatial transcriptomics datasets.
- Flexible Integration: Seamlessly integrates non-transcriptomic covariates into the analysis.
- Spatially Smoothed Values: Produces reconstructed expression values that account for spatial context.
- User-Friendly: Designed to be accessible for researchers in spatial biology.
Requirements
Dependencies are declared in pyproject.toml and installed automatically. The
manuscript results were produced with the following pinned versions (also in
requirements.txt):
- numpy==1.26.4
- pandas==2.2.2
- scanpy==1.10.1
- squidpy==1.2.2
- matplotlib==3.8.4
- scipy==1.13.1
- scikit-learn==1.5.0
- python-igraph==0.11.5
The mclust clustering option additionally requires rpy2==3.5.16 and an R
installation with the mclust package; all other clustering methods
(gmm, louvain, leiden, KMeans, walktrap) are pure Python. gmm is an
R-free equivalent of mclust (a tied-covariance Gaussian mixture == mclust
EEE).
Installation
Install from PyPI (the import name is rasp):
pip install randomized-spatial-pca
Or install the latest development version directly from GitHub:
pip install git+https://github.com/gingerii/RASP.git
To enable the optional R-backed mclust clustering:
pip install "randomized-spatial-pca[mclust]" # then, in R: install.packages("mclust")
Usage
See the tutorials folder for an end-to-end example. In brief:
from rasp import RASP
import scanpy as sc
# adata: normalized expression in adata.X, coordinates in adata.obsm['spatial']
RASP.reduce(adata, n_pcs=20, n_neighbors=6, beta=2, platform='visium')
sc.pp.neighbors(adata, use_rep=adata.uns['RASP']['embedding_key'])
RASP.clustering(adata, n_clusters=7, method='leiden')
Covariate integration (two-stage RASP)
RASP can integrate non-transcriptomic covariates (e.g. morphology or histology
features). When covariates are supplied, the smoothed stage-1 PC scores are
concatenated with the (optionally spatially smoothed) covariates and a second
randomized PCA produces the final embedding:
# covariates: an (n_obs, d) array, adata.obs column name(s), or an adata.obsm key
RASP.reduce(adata, n_pcs=20, covariates=['morph_area', 'morph_ecc'])
# the integrated embedding is written to adata.obsm['X_pca_cov']; the key to use
# downstream is always adata.uns['RASP']['embedding_key']
sc.pp.neighbors(adata, use_rep=adata.uns['RASP']['embedding_key'])
Use smooth_covariates (bool or per-covariate list) and scale_covariates to
control covariate smoothing and z-scoring.
Citation
If you use RASP in your research, please cite our publication in PLOS Computational Biology:
Gingerich et al. Randomized Spatial PCA (RASP): a computationally efficient method for dimensionality reduction of high-resolution spatial transcriptomics data. PLOS Computational Biology (2024). https://doi.org/10.1371/journal.pcbi.1013759
Article: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1013759
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 randomized_spatial_pca-0.1.1.tar.gz.
File metadata
- Download URL: randomized_spatial_pca-0.1.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de1a97e17a50c392abdd76ff1bf1b8ebecf13561ba1c23fa065da49bdb179f02
|
|
| MD5 |
9c377f498e3b65d60218ee5ec90ec124
|
|
| BLAKE2b-256 |
c6445ed6ba765a8dab098da3447e51247fac280c2a8bede32fc4406771d2a02c
|
Provenance
The following attestation bundles were made for randomized_spatial_pca-0.1.1.tar.gz:
Publisher:
publish.yml on gingerii/RASP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
randomized_spatial_pca-0.1.1.tar.gz -
Subject digest:
de1a97e17a50c392abdd76ff1bf1b8ebecf13561ba1c23fa065da49bdb179f02 - Sigstore transparency entry: 2047852537
- Sigstore integration time:
-
Permalink:
gingerii/RASP@0a9387ac1eed32279f86c8249ccbeb7bcdd21f3f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gingerii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a9387ac1eed32279f86c8249ccbeb7bcdd21f3f -
Trigger Event:
release
-
Statement type:
File details
Details for the file randomized_spatial_pca-0.1.1-py3-none-any.whl.
File metadata
- Download URL: randomized_spatial_pca-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c9ba01f446c26abda6cc7af7571d34392746569d5daafe2a9411e3d54397136
|
|
| MD5 |
cd6ac4430b9dcd61e2e8599a00418cc4
|
|
| BLAKE2b-256 |
5b4af206f00081b1a058758ebca4acaaad4dfb40a6d97e76406051347162c929
|
Provenance
The following attestation bundles were made for randomized_spatial_pca-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on gingerii/RASP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
randomized_spatial_pca-0.1.1-py3-none-any.whl -
Subject digest:
3c9ba01f446c26abda6cc7af7571d34392746569d5daafe2a9411e3d54397136 - Sigstore transparency entry: 2047852544
- Sigstore integration time:
-
Permalink:
gingerii/RASP@0a9387ac1eed32279f86c8249ccbeb7bcdd21f3f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gingerii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a9387ac1eed32279f86c8249ccbeb7bcdd21f3f -
Trigger Event:
release
-
Statement type: