Skip to main content

Statistical analysis of Spatial transcriptomic data (Python port of TranspaceR)

Project description

py-TranspaceR

Python 3.8+ License: MIT Tests Speedup

Python port of TranspaceR — Statistical analysis of Spatial transcriptomic data.

Correlation Benchmark (Python vs R)

Function Pearson r Max Abs Error
C_normalisation 1.000000 4.10e-05
Otsu_thresholding 3.54e-05
colvars_sparse 1.000000 4.40e-05
Get_variogram_map Deterministic match 0
Get_isotropic_vario 1.000000 0

All outputs are highly consistent with R references, with errors within floating-point precision.

Speed Benchmark (39,047 cells x 539 genes)

Function R Time Python Time Speedup
C_normalisation 1.47s 0.157s 9.4x
Otsu_thresholding 0.31s 0.031s 10.0x
colvars_sparse 1.72s 0.011s 156x
Get_variogram_map 0.02s 0.0004s 50x
Get_isotropic_vario 0.01s 0.0004s 25x
Total 3.53s 0.20s 17.7x

Why faster

  • NumPy/SciPy compiled C backend vs R interpreted execution
  • Direct CSC sparse matrix memory layout access
  • Broadcasting replaces R's row-wise apply loops

Installation

pip install -e ".[all]"

Quick Start

import transspacer as ts
import numpy as np
import pandas as pd

# Load data
expr = pd.read_csv("Expression_file.csv.gz", index_col=0)
meta = pd.read_csv("Meta_data.csv", index_col=0)

# Cell-size normalisation
normed = ts.c_normalisation(expr.values.astype(float), meta["Area"].values)

# Otsu thresholding
threshold = ts.otsu_thresholding(np.log10(expr.values.sum(axis=1) + 1))

# Variogram analysis
result = ts.compute_variogram(normed, meta["cell_centroid_x"].values,
                               meta["cell_centroid_y"].values)

# Geary's C spatial autocorrelation
gc = ts.geary_c_score(normed, coords, pvalue_threshold=0.01)

# Clustering
labels = ts.cell_clustering_function(pca_data, K=10, resolution=1.0)

Modules

Module Description
fft_utils fftshift, ifftshift, pad_definitor
normalization C_normalisation cell-size normalisation
sparse_utils Sparse matrix column variance, group aggregation
variogram FFT variogram map, variogram model fitting
spatial_stats Geary's C, NB excess variance / excess zero score
clustering KNN + Leiden/Louvain clustering, UMAP
gene_selection log2FC, gene set union
qc Otsu thresholding, QC gene filtering
plotting Spatial visualization, heatmaps, UMAP plots

Testing

pytest tests/ -q
# 29 passed

Dependencies

Core: numpy, scipy, scikit-learn, pandas, matplotlib

Optional: umap-learn (UMAP), python-igraph + leidenalg (Leiden clustering), statsmodels (FDR correction)

License

MIT

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

py_transpacer-0.1.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

py_transpacer-0.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file py_transpacer-0.1.0.tar.gz.

File metadata

  • Download URL: py_transpacer-0.1.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for py_transpacer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4078f6224c4cef5c57f3ee5b5ae1eee4f97b8d0bdb94deb3e61d75a69e3d26f
MD5 6977831826dcfb5edcbd3a90de8ad97c
BLAKE2b-256 d96405b75deb857898b8d14f7e29a54d50333f89a761e85c6067e088e1033c8d

See more details on using hashes here.

File details

Details for the file py_transpacer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_transpacer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for py_transpacer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8689b817bb27969dba20bfc7e7d53220710cd692aea589aea25b5ae2852646af
MD5 9013eab645df2896f5c564e62b296c3c
BLAKE2b-256 046ed5ccd3234923ca5a3f6118231abb7f863fce3ba1254472506c1d022b828c

See more details on using hashes here.

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