Skip to main content

stars-badge build-badge license-badge Python>=3.10 codecov PyPI Downloads

Expression Copilot

We introduce two metrics: EPS (Expression Predictability Score) and SPS (Slice Predictability Score), to quantify the predictability of gene expression from histology image. Python package expression_copilot is developed to calculate these metrics efficiently. It also provides several baseline models to predict gene expression from image embeddings, such as MLP and linear regression.

expression_copilot

Installation

PyPI

[!IMPORTANT] Requires Python >= 3.10

We recommend to install expression_copilot to a new conda environment:

conda create -n eps python=3.11 -y && conda activate eps
pip install expression_copilot

(Optional) If you have CUDA-enabled GPU, you could install cuml&cupy to accelerate KNN building, and install torch to accelerate MLP baseline training:

conda create -n eps_cuda -c conda-forge -c rapidsai -c nvidia python=3.11 rapids=25.06 'cuda-version>=12.0,<=12.8' -y && conda activate eps_cuda
pip install expression_copilot[torch]

Docker

You could also use our pre-built docker image directly:

# GPU version
docker run --gpus all -it --rm huhansan666666/expression_copilot:latest

# CPU version
docker run -it --rm huhansan666666/expression_copilot:latest

Documentation

Quick Start

The following code snippet shows how to calculate EPS and SPS via expression_copilot package. We assume you have already preprocessed your spatial transcriptomics data into an AnnData object (adata), where adata.X should store raw counts and adata.obsm['IMAGE_KEY_NAME'] should store image embeddings of spots. (Preprocessed steps are described in Advanced Tutorial in detail)

import scanpy as sc
import numpy as np
from expression_copilot import ExpressionCopilotModel

# Load data
# adata.X is raw counts
# adata.obsm['X_uni'] stores image embeddings of spots
url = 'https://drive.google.com/uc?id=10WD9vFgsoMoTt6g3017XxNK_bq8qp3oM'
adata = sc.read('./adata_with_image_emb.h5ad', backup_url=url)

# Init model
model = ExpressionCopilotModel(adata, image_key = 'X_uni')

# Calculate EPS and SPS
eps = model.calc_metrics_per_gene()
sps = eps.mean()

# Run baseline model (support 'ridge', 'linear', 'ensemble', 'mlp')
baseline_metrics_per_gene, _ = model.calc_baseline_metrics(method = 'mlp')

Notebook tutorials

We provide several tutorials in the resource/tutorials folder. You could also run them in Google Colab directly:

Name Description Colab
Basic Tutorial Basic tutorial of calculating EPS Open In Colab
Advanced Tutorial Start with 10x spatial-ranger output from scratch Open In Colab
Multi-omics Tutorial Calculating EPS and SPS on single cell multi-omics data Open In Colab

Citation

In coming.

If you want to repeat results in the manuscript, please check the experiments folder.

FAQ

Please open a new github issue if you have any question.

  1. numba related bugs

We use numba to increase the speed (up to 12x). However, it may have compatibility issues with different python/numpy versions. We tested the latest version of numba (0.6.12) and it works fine with Python 3.11/3.12, numpy 1.26.

Acknowledgement

We thank the following great open-source projects for their help or inspiration:

Metadata

Release files for expression-copilot 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for expression-copilot 0.3.0
File Size Uploaded
expression_copilot-0.3.0.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for expression-copilot 0.3.0
File Interpreter ABI Platform
expression_copilot-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / expression_copilot-0.3.0.tar.gz

Download URL expression_copilot-0.3.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
19cafb3d2105bab0f609e051db1e3fdc395c35e227ace65fe4c3dbcfec8149ac
BLAKE2b-256 checksum
How to use checksums
08bdc22a4943ffb8d914b78640014f9227262d30a3524431f59b07c5b5ae6cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / expression_copilot-0.3.0-py3-none-any.whl

Download URL expression_copilot-0.3.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a969ec720d1d6edd44713e097fbf3be5aae987d2f1dc633eb4edc5f1913c2f6
BLAKE2b-256 checksum
How to use checksums
5e22e972149b07aaeefea3a251176666f79b0aee0f4fffbc5083b21fbf598443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page