Skip to main content

High-resolution spatial transcriptomics analysis toolkit

Project description

PanoSpace

High-resolution single-cell insight from low-resolution spatial transcriptomics

PanoSpace overview

PanoSpace bridges the gap between spot-based spatial transcriptomics (e.g., 10x Visium) and single-cell resolution. It combines histology-guided cell detection, transcriptomic deconvolution, deep-learning-based super-resolution, expression prediction, and microenvironment analysis to generate consistent cell-level maps across entire tissue sections.

📦 Installation

System Requirements

  • OS: Linux (strongly recommended)
  • GPU: NVIDIA GPU with CUDA support (strongly recommended for performance)
    • CUDA 12.1+ recommended
    • Minimum 8GB GPU memory

Installation

Option 1: Install from PyPI (Recommended for Users)

# Basic installation (lightweight, no PyTorch)
pip install panospace

# For cell detection functionality (includes PyTorch)
pip install panospace[cellvit]

# For cell annotation functionality (includes deep learning libraries)
pip install panospace[annotation]

# For microenvironment analysis (lightweight)
pip install panospace[microenv]

# For all functionality
pip install panospace[all]

Then set up conda environment for dependencies:

# Create a conda environment
conda create -n panospace python=3.11
conda activate panospace

# Install PyTorch manually (if using [cellvit] or [annotation])
# For GPU version:
pip install --extra-index-url https://download.pytorch.org/whl/cu121 torch>=2.1 torchvision>=0.15

# For CPU version:
pip install torch>=2.1 torchvision>=0.15

Option 2: Install from Source (Automatic Setup)

git clone https://github.com/hehuifeng/PanoSpace.git
cd PanoSpace
bash install.sh

The script will automatically:

  • Create conda environment with all dependencies (except PyTorch)
  • Detect your GPU
  • Install PyTorch via pip (with CUDA if GPU detected)
  • Install PanoSpace package
  • Verify the installation

Option 3: Manual Installation from Source

For GPU version (recommended):

# Step 1: Create conda environment
conda env create -f environment-gpu.yml
conda activate PanoSpace

# Step 2: Install PyTorch with CUDA support
pip install --extra-index-url https://download.pytorch.org/whl/cu121 torch>=2.1 torchvision>=0.15

# Step 3: Install PanoSpace
pip install .

For CPU-only version:

# Step 1: Create conda environment
conda env create -f environment.yml
conda activate PanoSpace

# Step 2: Install PyTorch (CPU-only)
pip install torch>=2.1 torchvision>=0.15

# Step 3: Install PanoSpace
pip install .
Optional: Optimization Solvers (Click to expand)

Optimization Solvers for Cell Annotation

PanoSpace uses Mixed Integer Linear Programming (MILP) solvers for accurate cell-type annotation with spot-level quota constraints. Two solvers are supported:

Supported Solvers:

  1. Gurobi (Recommended, Commercial but Free for Academia)

  2. SCIP (Open-Source, Default)

    • Automatically installed with PanoSpace
    • Produces mathematically identical results to Gurobi
    • Suitable for small to medium datasets
    • No additional setup required

Solver Selection Logic:

PanoSpace automatically selects the best available solver:

  • If Gurobi is installed → Uses Gurobi (fastest)
  • If Gurobi is not available → Uses SCIP (open-source fallback)

Both solvers implement the same mathematical model with:

  • Global cell-type quotas
  • Spot-level quota constraints (ensures consistency within each spot)
  • Exact 0/1 assignment (no approximation)

Installation:

SCIP (installed by default):

# Already included in environment.yml
conda activate PanoSpace

Gurobi (optional, recommended for better performance):

# Install Gurobi
conda install -c conda-forge gurobipy

# Request free academic license at: https://www.gurobi.com/academia/academic-program-and-licenses/
# Follow Gurobi's instructions to activate the license

# Verify installation
python -c "import gurobipy; print('Gurobi installed successfully!')"

Note: Based on our experience, Gurobi typically solves problems in under 1 minute, while SCIP may take hundreds of minutes for the same problem.

🚀 Quick Start

Basic Workflow

import panospace as ps
from PIL import Image

# 1. Detect cells from tissue image
tissue = Image.open("path/to/visium_slide.tif")
seg_adata, contours = ps.detect_cells(tissue, model="cellvit", gpu=True)

# 2. Deconvolve Visium spots
#    visium_adata: AnnData with .X (expression) and .obsm['spatial'] (coordinates)
#    sc_reference: AnnData with .X and .obs[celltype_key] (cell type labels)
deconv_adata = ps.deconv_celltype(
    adata_vis=visium_adata,
    sc_adata=sc_reference,
    celltype_key="celltype_major",  # Column name in sc_reference.obs
    methods=['RCTD', 'spatialDWLS', 'cell2location']
)

# 3. Super-resolve to cell level
sr_adata = ps.superres_celltype(
    deconv_adata=deconv_adata,
    img_dir="path/to/visium_slide.tif"
)

# 4. Annotate segmented cells
annotated_adata = ps.celltype_annotator(
    decov_adata=visium_adata,
    sr_deconv_adata=sr_adata,
    seg_adata=seg_adata
)

# 5. Predict gene expression
pred_adata = ps.genexp_predictor(
    sc_adata=sc_reference,
    spot_adata=visium_adata,
    infered_adata=annotated_adata,
    celltype_list=list(sc_reference.obs["celltype_major"].unique())
)

Cell-Cell Interaction Analysis

# Analyze interactions between cell pairs
pairs = [('Cancer_epithelial', 'CAF'), ('T_cell', 'Macrophage')]
results = ps.analyze_interaction(
    adata=annotated_adata,
    cell_type_pairs=pairs,
    cell_type_col='pred_cell_type',  # Column in adata.obs
    radius=100.0  # Neighborhood radius (same units as spatial coordinates)
)

# Extract results and find correlated genes
expr_df, target_abundance, _ = results[('Cancer_epithelial', 'CAF')]
corr_results = ps.correlation_analysis(expr_df, target_abundance)
significant_genes = corr_results.query('p_adjust < 0.05')['gene'].tolist()

# Functional enrichment
if len(significant_genes) > 0:
    go_results = ps.spatial_enrichment(
        gene_list=significant_genes,
        organism='Human',
        gene_sets='GO_Biological_Process_2021'
    )

Data Requirements

Visium Data (visium_adata)

  • AnnData object with .X (gene expression) and .obsm['spatial'] (coordinates)

Single-Cell Reference (sc_reference)

  • AnnData object with .X and .obs[celltype_key] (cell type labels)
  • Minimum 100 cells per type, genes should overlap with Visium data

Histology Image

  • TIFF/PNG/JPEG format, 40x+ magnification recommended

📖 Citation

If you use PanoSpace in your research, please cite:

He, HF., Peng, P., Yang, ST. et al. Unlocking single-cell level and continuous whole-slide insights in spatial transcriptomics with PanoSpace. Nat Comput Sci (2026). https://doi.org/10.1038/s43588-025-00938-y

📧 Contact

For questions or collaboration opportunities:

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Note: PanoSpace is actively under development. API changes may occur between versions. Please check the changelog when upgrading.

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

panospace-0.1.2.tar.gz (130.2 kB view details)

Uploaded Source

Built Distribution

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

panospace-0.1.2-py3-none-any.whl (141.5 kB view details)

Uploaded Python 3

File details

Details for the file panospace-0.1.2.tar.gz.

File metadata

  • Download URL: panospace-0.1.2.tar.gz
  • Upload date:
  • Size: 130.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for panospace-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9984fa4233d9b4b1e66fae26b06605fe7be2803697dcd8be08e8fbd25f20721d
MD5 9aceddca3a26de64f4f89c507c378096
BLAKE2b-256 cf4f24daf254ab6bd3dabba1919ebf3786a0c3ab6ae540b971b14ad065640d3c

See more details on using hashes here.

File details

Details for the file panospace-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: panospace-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 141.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for panospace-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 140896c0560506d84ac66437598c89a2090e134031203e3fe67588b497a9d1af
MD5 47caef6dda7c086fe5a803984842522f
BLAKE2b-256 248eb50ed5ded08b38e5c8d5bea8a3a07178e6543591d350439c2b98ce92e9c4

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