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, and Anthropic Claude models out of the box, with more providers planned for the future.

✨ Key Features

  • 🤖 LLM-agnostic backend: Seamlessly use models from OpenAI, Anthropic (Claude), and Gemini (Google) — 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.10 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.

💸 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.

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, or Anthropic). 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.

🙏 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.2.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.2.0-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cell_annotator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 848ba86c17a938090bc0e1580d5d49aa7b7abb4762ed19f8893296196f25c790
MD5 dad268baac44c87a388860ec3ee7af47
BLAKE2b-256 88ce9b2fd07173d48a0dc71ca215545e31346168f2c78b1ba1a54f033e775cd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cell_annotator-0.2.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.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for cell_annotator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0849640cb23ce1a2a2be9d8f79f606be7837affffcec269046604c3d480da91a
MD5 9491edd484d17109a2006a081a3e7eac
BLAKE2b-256 2b96e9e0cd3c4429ff19f6d0ec07733aed85a075301fab7370879c19a0f4f17f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cell_annotator-0.2.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