Automated cell type annotation using reference-based methods including CellTypist, scPred, SingleR, and Azimuth for consistent, reproducible cell labeling. Use when automatically annotating cell types using reference datasets.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Automated cell type annotation using reference-based methods including CellTypist, scPred, SingleR, and Azimuth for consistent, reproducible cell labeling. Use when automatically annotating cell types using reference datasets.
Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
R: packageVersion('<pkg>') then ?function_name to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Automated Cell Type Annotation
CellTypist (Python)
Goal: Automatically annotate cell types using a pre-trained or custom CellTypist model.
Approach: Load a reference model, predict cell types with majority voting for cluster-level consensus, and add predictions to AnnData.
"Automatically label my cell types" → Apply a trained classifier to assign cell type identities based on transcriptomic similarity to a reference atlas.
Goal: Train a custom CellTypist model on a reference dataset for domain-specific annotation.
Approach: Train a logistic regression classifier on labeled reference data with feature selection, then apply to query data.
# Train custom model
new_model = celltypist.train(adata_reference, labels='cell_type', n_jobs=10,
feature_selection=True, use_SGD=True)
# Save model
new_model.write('custom_model.pkl')
# Use custom model
predictions = celltypist.annotate(adata_query, model='custom_model.pkl')
SingleR (R)
Goal: Annotate cell types by correlating expression profiles against curated reference datasets.
Approach: Compare each cell's expression to reference transcriptomes using SingleR's correlation-based assignment, with pruning for low-confidence calls.
Goal: Quantitatively assess agreement between different annotation methods.
Approach: Compute adjusted Rand index and normalized mutual information between label sets, and build a confusion matrix.
import pandas as pd
from sklearn.metrics import adjusted_rand_score, normalized_mutual_info_score
# Compare two annotations
ari = adjusted_rand_score(adata.obs['manual_annotation'], adata.obs['celltypist'])
nmi = normalized_mutual_info_score(adata.obs['manual_annotation'], adata.obs['celltypist'])
# Confusion matrix
pd.crosstab(adata.obs['manual_annotation'], adata.obs['celltypist'])
Marker-Based Validation
# Validate predictions with known markers
canonical_markers <-list(
T_cell =c('CD3D','CD3E','CD4','CD8A'),
B_cell =c('CD19','MS4A1','CD79A'),
Monocyte =c('CD14','LYZ','S100A8'),
NK =c('NKG7','GNLY','NCAM1'))# Check marker expression per predicted type
DotPlot(seurat_obj, features = unlist(canonical_markers), group.by ='predicted_labels')+
RotatedAxis()