$ show Teichlab/celltypist
CellTypist is a Python library and command-line tool for cell type classification in single-cell RNA-seq (scRNA-seq) data. It implements a complete annotation workflow: training logistic regression classifiers on labeled expression matrices (with optional SGD mini-batching and GPU-accelerated cuML backends), annotating query cells using either custom-trained or pre-trained models, and visualizing marker gene expression via dotplots. The package is architected as a conventional Python library with a click-based CLI (entry point: celltypist.command_line:main), a models submodule that manages remote pre-trained artifacts, and a samples module for loading bundled example data. The primary data flow starts with an AnnData object containing raw counts, which is normalized, scaled, and filtered through feature selection before being passed to the classifier. For annotation, the trained model (or a downloaded pre-trained model) is applied to query cells, producing cell type labels and confidence scores. Models are fetched on-demand from celltypist.cog.sanger.ac.uk and cached locally, with a force_update flag to bypass the cache. External dependencies include scanpy, anndata, scikit-learn, click, numpy, scipy, pandas, and matplotlib. The repository is hybrid in nature: while the core deliverable is a software library, it also ships pre-trained models, a cross-species gene mapping reference (Cynomolgus/Rhesus orthologs), and tutorial Jupyter notebooks that demonstrate the API. These data assets make it a valuable resource for bioinformatics researchers even beyond the code itself. The tutorial notebook (docs/notebook/celltypist_tutorial_ml.ipynb) is a usage guide rather than a research artifact, relying on 12 built-in pre-trained models and demo data fetched from the same remote server. The project is maintained but not rapidly evolving; the last significant release was January 2025, and the codebase shows signs of technical drift. The pickle-based model format could break across Python or scikit-learn versions, and the tutorial notebook may produce different outputs with newer versions of scanpy or CellTypist. The force_update mechanism and backup_url fallback in the data-loading code indicate awareness of external data unavailability, but these fallbacks could themselves become stale.
The LLM identified 3 files worth highlighting for reuse:
Core training pipeline that prepares AnnData objects, scales features, selects informative genes, and fits logistic regression classifiers. Supports mini-batch SGD for large datasets and an optional cuML backend for GPU acceleration. The separation of data preparation, feature selection, and classifier fitting makes it adaptable to other single-cell classification tasks beyond CellTypist's default workflow.
Model management module that handles downloading, listing, loading, and versioning of pre-trained CellTypist models from a remote server. Implements a lazy-download pattern with local caching and force-update semantics. This is a clean example of a remote model registry pattern that could be extracted for any project distributing ML artifacts via HTTP.
Cross-species gene mapping reference file (Cynomolgus macaque to Rhesus macaque orthologs) distributed as sample data. The simple two-column CSV format is a reusable pattern for pairwise species gene mappings, enabling cross-species cell type annotation. Includes both coding and non-coding RNA gene mappings, making it a comprehensive reference for transferring models between closely related species.