Fast Spatial Transcriptomics Deconvolution
Project description
SLS - Spatial Deconvolution Package
A Python package for spatial transcriptomics deconvolution using SVD ridge regression.
Two Core Functions
SLS provides two main deconvolution functions:
1. Cell-Type Mapping
sd.memory_efficient_svd_ridge_regression(X, Y, celltype_labels, lambda_reg)
Maps spatial spots → cell type proportions
2. Cell Mapping
sd.memory_efficient_svd_ridge_regression_cellmap(X, Y, lambda_reg)
Maps spatial spots → individual cells (for temporal analysis)
Quick Example
import SLS as sd
import scanpy as sc
import numpy as np
# Load data
X, Y, celltype_labels = sd.load_data('FinalAnnotation', st_dir='spatial.h5ad', sc_dir='sc.h5ad')
# Cell-type mapping
lambda_opt, _, _ = sd.select_optimal_lambda(X, Y)
M_hat, celltypes = sd.memory_efficient_svd_ridge_regression(X, Y, celltype_labels, lambda_opt)
# Visualize
adata = sc.read_h5ad('spatial.h5ad')
sd.add_deconvolution_to_adata(adata, celltypes, M_hat, 'deconv')
sd.get_maximum_annotation(adata, 'deconv', 'dominant_celltype')
sd.plot_spatial_deconvolution(adata, 'dominant_celltype', palette=sd.REFERENCE_COLORS)
Complete Workflows
Cell-Type Mapping Workflow
# 1. Load data
X, Y, labels = sd.load_data('FinalAnnotation', st_dir='...', sc_dir='...')
# 2. Select optimal lambda
lambda_opt, _, _ = sd.select_optimal_lambda(X, Y) # or sd.select_optimal_lambda_calsurrogate
# 3. Deconvolve
M_hat, celltypes = sd.memory_efficient_svd_ridge_regression(X, Y, labels, lambda_opt)
# 4. Visualize
sd.add_deconvolution_to_adata(adata, celltypes, M_hat, 'deconv')
sd.get_maximum_annotation(adata, 'deconv', 'celltype_result')
Cell Mapping Workflow (Temporal Analysis)
# 1. Filter to cell types of interest
X_filtered, Y_filtered, time_labels = sd.load_data('palantir_pseudotime', adata=adata_sub, HHA=temporal_data)
# 2. Select lambda (use mtruncation method for cell mapping)
lambda_opt, _, _ = sd.select_optimal_lambda_mtruncation(X_filtered, Y_filtered)
# 3. Cell mapping
M_temporal = sd.memory_efficient_svd_ridge_regression_cellmap(X_filtered, Y_filtered, lambda_opt)
# 4. Visualize temporal mapping
sd.add_deconvolution_to_adata(adata_sub, time_labels, M_temporal, 'temporal')
sd.get_maximum_annotation(adata_sub, 'temporal', 'pseudotime', continuous=True, feature_values=time_labels)
Key Functions
| Function | Purpose |
|---|---|
load_data() |
Load spatial and single-cell data |
select_optimal_lambda() |
Lambda selection for cell-type mapping |
select_optimal_lambda_mtruncation() |
Lambda selection for cell mapping |
memory_efficient_svd_ridge_regression() |
Core Function 1: Cell-type mapping |
memory_efficient_svd_ridge_regression_cellmap() |
Core Function 2: Cell mapping |
add_deconvolution_to_adata() |
Add results to spatial data |
get_maximum_annotation() |
Get dominant cell types/values |
Installation
pip install SLS
Requirements
- Python ≥ 3.8
- scanpy, numpy, pandas, scipy, matplotlib
Usage Notes
- Cell-type mapping: Use
select_optimal_lambda()orselect_optimal_lambda_calsurrogate() - Cell mapping: Use
select_optimal_lambda_mtruncation()only - Large datasets: Add
output_dirandchunk_sizeparameters for memory efficiency - Visualization: Built-in functions with
sd.REFERENCE_COLORSpalette
Example Files
See example.py for a complete reproduction of published analysis workflows.
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 slsdeconv-0.1.0.tar.gz.
File metadata
- Download URL: slsdeconv-0.1.0.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dcb846db4630e25f659a43e853f4927616e01797fe3a45d48b4d617ab5ab1e3
|
|
| MD5 |
7d32d30c2487d8a89028e43ff9329eff
|
|
| BLAKE2b-256 |
9112b5552727f95824d2c2969ea3f24a1c8a834fc6466a13b5bfa94e0d6da3d5
|
File details
Details for the file slsdeconv-0.1.0-py3-none-any.whl.
File metadata
- Download URL: slsdeconv-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d4159d55db3d4c72ef24fd58d0a161ae59c618ef250129da55101e8ecc6addd
|
|
| MD5 |
687cfa6aa2e82009d5e52eef5f57a24e
|
|
| BLAKE2b-256 |
c6c6bd13c582782b22ea34f8bc328bd6572a40e189afcb822fa955ae7607c149
|