Skip to main content

Automated cell annotation from scRNA-seq data using LLMs

Project description

CellAnnotator

Tests Coverage Documentation Pre-commit.ci PyPI Downloads Zenodo

🧬 CellAnnotator is an scverse ecosystem package, designed to annotate cell types in scRNA-seq data based on marker genes using large language models (LLMs). It supports OpenAI, Google Gemini, Anthropic Claude, and OpenRouter models out of the box.

✨ Key Features

  • 🤖 LLM-agnostic backend: Seamlessly use models from OpenAI, Anthropic (Claude), Gemini (Google), or OpenRouter — just set your provider and API key.
  • 🧬 Automatically annotate cells including type, state, and confidence fields.
  • 🔄 Consistent annotations across all samples in your study.
  • 🧠 Infuse prior knowledge by providing information about your biological system.
  • 📦 Structured outputs for reliable results (see e.g. OpenAI structured outputs).
  • 🧩 Supports datasets with limited feature sets (e.g., imaging-based spatial transcriptomics): marker gene lists are filtered to the actual gene set in your data.
  • Quickly generate pre-integration cell type labels to score or guide your integration (e.g. scIB metrics, scPoli, scANVI).

ℹ️ Note: This package is based on output generated by large language models and might sometimes make mistakes. We use some safeguards, like anchoring the tool in a multi-step process, and using structured output predictions, but mistakes are still possible. We recommend using this tool as a first step in an annotation workflow to generate an initial, coarse set of annotations that must be further refined.

📦 Installation

You need to have 🐍 Python 3.11 or newer installed on your system. If you don't have Python installed, we recommend installing Mambaforge.

🚀 PyPI

Install by running:

pip install cell-annotator

🛠️ Development version

To install the latest development version from GitHub, run

pip install git+https://github.com/quadbio/cell-annotator.git@main

🏁 Getting started

After installation, head over to the LLM provider of your choice to generate an API key 🔑. For example:

🔒 Keep this key private and don't share it with anyone. CellAnnotator will try to read the key as an environmental variable - either expose it to the environment yourself, or store it as an .env file anywhere within the repository where you conduct your analysis and plan to run CellAnnotator. The package will then use dotenv to export the key from the env file as an environmental variable.

Here's the simplest way to annotate your data:

from cell_annotator import CellAnnotator

cell_ann = CellAnnotator(
    adata, species="human", tissue="heart", cluster_key="leiden", sample_key="samples",
).annotate_clusters()

By default, this will store annotations in adata.obs['cell_type_predicted']. Head over to our 📚 tutorials to see more advanced use cases, and learn how to adapt this to your own data. You can run CellAnnotator for just a single sample of data, or across multiple samples. In the latter case, it will attempt to harmonize annotations across samples.

Advanced provider options

CellAnnotator can also be used in single-sample mode by setting sample_key=None.

Example:

from cell_annotator import CellAnnotator

cell_ann = CellAnnotator(
    adata=adata,
    species="human",
    tissue="pancreas",
    cluster_key="leiden_1",
    sample_key=None,  # single-sample mode
    provider="openrouter",
    model="openai/gpt-4o-mini",
    api_key="YOUR_OPENROUTER_API_KEY",
)

cell_ann.get_expected_cell_type_markers(n_markers=3)
cell_ann.get_cluster_markers()
cell_ann.annotate_clusters(key_added="cell_type_predicted")

💸 Costs and models

CellAnnotator is LLM-agnostic and works with multiple providers:

  • OpenAI (GPT models): The default model is currently gpt-4o-mini, which is included in OpenAI's Free Usage Tier. You can get started for free and experiment with our 📚 tutorials and your own data. For more accurate cell type labels in complex tissues, we recommend more powerful models like gpt-4o, gpt-4.1, or reasoning models like o3-mini (these may incur a small fee; e.g., running both tutorials with o3-mini costs around 1 USD). See the OpenAI API docs for details.

  • Google Gemini: Gemini models are supported and have their own free tier and pricing. See the Gemini API docs for available models and costs.

  • Anthropic Claude: Claude models are supported. See the Anthropic pricing page for details.

  • OpenRouter: OpenRouter routes requests to many model families (including OpenAI, Anthropic, and others) behind a single API key. Use provider="openrouter" and pass a model slug such as openai/gpt-4o-mini or anthropic/claude-3.5-sonnet.

You can select your provider and model by setting the appropriate parameters. More providers may be supported in the future as the LLM ecosystem evolves.

🔐 Data privacy

This package sends cluster marker genes, and the species and tissue you define, to the selected LLM provider (e.g., OpenAI, Google, Anthropic, or OpenRouter routes). No actual gene expression values are sent.

Please ensure your usage of this package aligns with your institution's guidelines on data privacy and the use of external AI models. Each provider has its own privacy policy and terms of service. Review these carefully before using CellAnnotator with sensitive or regulated data.

When using OpenRouter, requests are forwarded to the upstream provider implied by your model slug (e.g. openai/..., anthropic/...). Review both OpenRouter's privacy policy and the upstream provider's. Some OpenRouter model tiers may log prompts by default; users who need privacy guarantees should configure this via their OpenRouter account settings.

🙏 Credits

This tool was inspired by Hou et al., Nature Methods 2024 and https://github.com/VPetukhov/GPTCellAnnotator.

📬 Contact

If you found a bug, please use the issue tracker.

📖 Citation

Please use our zenodo entry to cite this software.

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

cell_annotator-0.3.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

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

cell_annotator-0.3.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file cell_annotator-0.3.0.tar.gz.

File metadata

  • Download URL: cell_annotator-0.3.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cell_annotator-0.3.0.tar.gz
Algorithm Hash digest
SHA256 eee70b826e297f6b91d3fd8de1621e8182ebbf6bc83449d25054d3b07ff36f22
MD5 045dea9b7a81f2cc1ef9698cf915a565
BLAKE2b-256 9ef65a98dd32e1e70b319d9d33f9c114b6723369eda018620046a729659d90e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cell_annotator-0.3.0.tar.gz:

Publisher: release.yaml on quadbio/cell-annotator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cell_annotator-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cell_annotator-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cell_annotator-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04c5ba7f7d98c615447b3d799c36dbbef5896a6170860924742251012532b8a1
MD5 ae9a070dce1fc75e91635c3d4b65d3d5
BLAKE2b-256 08501d39aa90f0437ae1de362019d902b6dbf438cd9c09eabc618bba310ed3f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cell_annotator-0.3.0-py3-none-any.whl:

Publisher: release.yaml on quadbio/cell-annotator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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