Metadata-Version: 2.4
Name: cell-annotator
Version: 0.2.1
Summary: Automated cell annotation from scRNA-seq data using LLMs
Project-URL: Documentation, https://cell-annotator.readthedocs.io/
Project-URL: Homepage, https://cell-annotator.readthedocs.io/
Project-URL: Source, https://github.com/quadbio/cell-annotator
Author: Marius Lange
Maintainer-email: Marius Lange <mlange@ethz.ch>
License: MIT License
        
        Copyright (c) 2024, QuaDBio Lab
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Requires-Dist: docrep
Requires-Dist: packaging
Requires-Dist: pydantic>=2
Requires-Dist: python-dotenv
Requires-Dist: rich
Requires-Dist: scanpy>=1.11
Requires-Dist: session-info2
Provides-Extra: all-providers
Requires-Dist: anthropic>=0.59; extra == 'all-providers'
Requires-Dist: google-genai>=1.27; extra == 'all-providers'
Requires-Dist: openai>=1.90; extra == 'all-providers'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.59; extra == 'anthropic'
Provides-Extra: colors
Requires-Dist: colorspacious>=1.1; extra == 'colors'
Provides-Extra: dev
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: twine>=4.0.2; extra == 'dev'
Provides-Extra: doc
Requires-Dist: docutils!=0.18.*,!=0.19.*,>=0.8; extra == 'doc'
Requires-Dist: ipykernel; extra == 'doc'
Requires-Dist: ipython; extra == 'doc'
Requires-Dist: myst-nb>=1.1; extra == 'doc'
Requires-Dist: pandas; extra == 'doc'
Requires-Dist: setuptools; extra == 'doc'
Requires-Dist: sphinx-autodoc-typehints; extra == 'doc'
Requires-Dist: sphinx-book-theme>=1; extra == 'doc'
Requires-Dist: sphinx-copybutton; extra == 'doc'
Requires-Dist: sphinx-tabs; extra == 'doc'
Requires-Dist: sphinx>=8.1; extra == 'doc'
Requires-Dist: sphinxcontrib-bibtex>=1; extra == 'doc'
Requires-Dist: sphinxext-opengraph; extra == 'doc'
Provides-Extra: gemini
Requires-Dist: google-genai>=1.27; extra == 'gemini'
Provides-Extra: gpu
Requires-Dist: rapids-singlecell>=0.12; extra == 'gpu'
Provides-Extra: openai
Requires-Dist: openai>=1.90; extra == 'openai'
Provides-Extra: test
Requires-Dist: anthropic>=0.59; extra == 'test'
Requires-Dist: colorspacious>=1.1; extra == 'test'
Requires-Dist: coverage>=7.10; extra == 'test'
Requires-Dist: flaky; extra == 'test'
Requires-Dist: google-genai>=1.27; extra == 'test'
Requires-Dist: openai>=1.90; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-cov; extra == 'test'
Provides-Extra: tutorials
Requires-Dist: squidpy>=1.6; extra == 'tutorials'
Description-Content-Type: text/markdown

# CellAnnotator

[![Tests][badge-tests]][tests]
[![Coverage][badge-coverage]][coverage]
[![Documentation][badge-docs]][documentation]
[![Pre-commit.ci][badge-pre-commit]][pre-commit]
[![PyPI][badge-pypi]][pypi]
[![Downloads][badge-downloads]][downloads]
[![Zenodo][badge-zenodo]][zenodo]

[badge-tests]: https://img.shields.io/github/actions/workflow/status/quadbio/cell-annotator/test.yaml?branch=main
[badge-coverage]: https://codecov.io/gh/quadbio/cell-annotator/branch/main/graph/badge.svg
[badge-docs]: https://img.shields.io/readthedocs/cell-annotator
[badge-pre-commit]: https://results.pre-commit.ci/badge/github/quadbio/cell-annotator/main.svg
[badge-pypi]: https://img.shields.io/pypi/v/cell-annotator.svg
[badge-downloads]: https://static.pepy.tech/badge/cell-annotator
[badge-zenodo]: https://zenodo.org/badge/899554552.svg


🧬 CellAnnotator is an [scverse ecosystem package](https://scverse.org/packages/#ecosystem), 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](https://platform.openai.com/docs/guides/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](https://scib-metrics.readthedocs.io/en/stable/), [scPoli](https://docs.scarches.org/en/latest/), [scANVI](https://docs.scvi-tools.org/en/stable/api/reference/scvi.model.SCANVI.html)).

> ℹ️ **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:

```bash
pip install cell-annotator
```


### 🛠️ Development version
To install the latest development version from [GitHub](https://github.com/quadbio/cell-annotator), run

```bash
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:

- OpenAI: [API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
- Google (Gemini): [API key](https://ai.google.dev/gemini-api/docs/api-key)
- Anthropic (Claude): [API key](https://docs.anthropic.com/en/docs/get-started)


🔒 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](https://pypi.org/project/python-dotenv/) to export the key from the `env` file as an environmental variable.


Here's the simplest way to annotate your data:

```python
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](https://cell-annotator.readthedocs.io/en/latest/notebooks/tutorials/index.html) 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](https://platform.openai.com/docs/guides/rate-limits). You can get started for free and experiment with our 📚 [tutorials](https://cell-annotator.readthedocs.io/en/latest/notebooks/tutorials/index.html) 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](https://platform.openai.com/docs/models) for details.

- **Google Gemini:** Gemini models are supported and have their own free tier and pricing. See the [Gemini API docs](https://ai.google.dev/gemini-api/docs/models) for available models and costs.

- **Anthropic Claude:** Claude models are supported. See the [Anthropic pricing page](https://docs.anthropic.com/claude/docs/pricing) 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](https://www.nature.com/articles/s41592-024-02235-4) and [https://github.com/VPetukhov/GPTCellAnnotator](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.

[mambaforge]: https://github.com/conda-forge/miniforge#mambaforge
[issue tracker]: https://github.com/quadbio/cell-annotator/issues
[tests]: https://github.com/quadbio/cell-annotator/actions/workflows/test.yaml
[coverage]: https://codecov.io/gh/quadbio/cell-annotator
[documentation]: https://cell-annotator.readthedocs.io
[pre-commit]: https://results.pre-commit.ci/latest/github/quadbio/cell-annotator/main
[pypi]: https://pypi.org/project/cell-annotator/
[downloads]: https://pepy.tech/project/cell-annotator
[zenodo]: https://doi.org/10.5281/zenodo.16411381
