Skip to main content

Randomized Spatial PCA (RASP): a computationally efficient method for dimensionality reduction of high-resolution spatial transcriptomics data

Project description

Randomized Spatial PCA (RASP)

RASP overview

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

randomized_spatial_pca-0.1.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

randomized_spatial_pca-0.1.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

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

Hashes for randomized_spatial_pca-0.1.1.tar.gz
Algorithm Hash digest
SHA256 de1a97e17a50c392abdd76ff1bf1b8ebecf13561ba1c23fa065da49bdb179f02
MD5 9c377f498e3b65d60218ee5ec90ec124
BLAKE2b-256 c6445ed6ba765a8dab098da3447e51247fac280c2a8bede32fc4406771d2a02c

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomized_spatial_pca-0.1.1.tar.gz:

Publisher: publish.yml on gingerii/RASP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file randomized_spatial_pca-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for randomized_spatial_pca-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c9ba01f446c26abda6cc7af7571d34392746569d5daafe2a9411e3d54397136
MD5 cd6ac4430b9dcd61e2e8599a00418cc4
BLAKE2b-256 5b4af206f00081b1a058758ebca4acaaad4dfb40a6d97e76406051347162c929

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomized_spatial_pca-0.1.1-py3-none-any.whl:

Publisher: publish.yml on gingerii/RASP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page