Skip to main content

Fast Spatial Transcriptomics Deconvolution

Project description

SLS - Spatial Deconvolution Package

A Python package for spatial transcriptomics cell type mapping and cell mapping using SVD ridge regression.

Installation

pip install SLSDeconv

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

Requirements

  • Python ≥ 3.11
  • scanpy, numpy, pandas, scipy, matplotlib

Usage Notes

  • Cell-type mapping: Use select_optimal_lambda() or select_optimal_lambda_calsurrogate()
  • Cell mapping: Use select_optimal_lambda_mtruncation() only
  • Large datasets: Add output_dir and chunk_size parameters for memory efficiency
  • Visualization: Built-in functions with sd.REFERENCE_COLORS palette

Example Files

See example.py for a complete reproduction of published analysis workflows.

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

slsdeconv-0.1.1.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

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

slsdeconv-0.1.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file slsdeconv-0.1.1.tar.gz.

File metadata

  • Download URL: slsdeconv-0.1.1.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for slsdeconv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0dcdb66b20ec4a916262a272824dae9e13e1902ed70c49775dd5df364c2aff64
MD5 751f0513c1180955dd1c6aff54c03794
BLAKE2b-256 c6d17c98422956d92478cc5033e9f038d694e0eadd45073546a1dbce05baa074

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slsdeconv-0.1.1-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

Hashes for slsdeconv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 688bc79d1795a5d7469f19b886ba1c320f9de2626d0b3b8bf781ac9805c6814e
MD5 13a33e3f299bb2014ccd26597074e028
BLAKE2b-256 0f84a29cb8ddfc5542c98231d7e86b91df03c20ae378fb00d9083ddbe69c4215

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