Skip to main content

ADDME

Project description

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

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 easily and efficiently. It also provides several baseline models to predict gene expression from image embeddings.

expression_copilot

Installation

PyPI

[!IMPORTANT] Requires Python >= 3.10

We recommend to install expression_copilot to a new conda environment:

mamba create -n expression_copilot -c conda-forge python=3.11 -y && conda activate expression_copilot
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:

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

Docker

You could pull and use our docker image directly:

docker pull huhansan666666/expression_copilot:latest
docker run --gpus all -it --rm huhansan666666/expression_copilot:latest

Documentation

Quick Start

The following code snippet shows how to calculate EPS and SPS using expression_copilot. We assume you have already preprocessed your spatial transcriptomics data into an AnnData object (adata), where adata.X stores raw counts and adata.obsm['KEY_NAME'] stores image embeddings of spots.

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

# Read data
# adata.X is expected to be raw counts
# adata.obsm['KEY_NAME'] is expected to store image embeddings of spots
adata = sc.read_h5ad('path/to/adata')

model = ExpressionCopilotModel(adata, image_key = 'KEY_NAME')

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

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

Notebooks

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 spatial data and histological image 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:

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

expression_copilot-0.2.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

expression_copilot-0.2.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file expression_copilot-0.2.0.tar.gz.

File metadata

  • Download URL: expression_copilot-0.2.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for expression_copilot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de50704771b937cc8418bcb85f903543daaafa41ca541f2c0fedef74a19cb994
MD5 1a893c29585eb2b6eb2c59e02df531b6
BLAKE2b-256 6906e1ddd13b2eaaff2546fa890be2af375a15bf7672e53b9356f72a684b0c9e

See more details on using hashes here.

File details

Details for the file expression_copilot-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for expression_copilot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90cd77c9bd9b5009931c679bcabc7694cee9fb3dcc68ccd12c71850a541e712
MD5 c8f3df32f02a9d84d4152589fc55036f
BLAKE2b-256 181e83dae83fa25f5dfae3f76b231f16b9587d751a6a80418455a0b8f4cfd227

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