Celltypeannotation

From pwwang/immunopipe · View interactive version

Celltypeannotation is an AI agent skill from the GitHub repository pwwang/immunopipe. Annotates cell clusters with biological cell type labels using direct assignment, ScType, scCATCH, hitype, CellTypist, or MapQuery reference mapping.

How to use this skill

Skill file

CellTypeAnnotation Process Configuration

Purpose

Annotates cell clusters with biological cell type labels using direct assignment, ScType, scCATCH, hitype, CellTypist, or MapQuery reference mapping.

When to Use

Configuration Structure

Process Enablement

[CellTypeAnnotation]
cache = true  # Cache results for faster re-runs

Input Specification

[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]  # Path or reference to Seurat object

Environment Variables

Core Parameters
[CellTypeAnnotation.envs]
# Annotation method selection
tool = "direct"  # Options: "direct", "sctype", "hitype", "sccatch", "celltypist", "mapquery"

# Cluster identity column (required for h5ad input, optional for Seurat objects)
ident = "seurat_clusters"  # Column name in metadata representing clusters

# Backup column name (stores original cluster labels)
backup_col = "seurat_clusters_id"  # Default: "seurat_clusters_id"

# New column name for annotated cell types
# If specified, original identity is kept; otherwise, it's replaced
newcol = ""  # Default: empty (overwrite identity)

# Merge clusters with same predicted cell types
merge = false  # Default: false; suffixes (.1, .2) added for duplicate labels

# Output file type
outtype = "input"  # Options: "input", "rds", "qs", "qs2", "h5ad"
Direct Annotation Parameters
[CellTypeAnnotation.envs]
tool = "direct"

# Cell type assignments (one per cluster, in order)
# Use "-" or "" to keep original cluster name
# Use "NA" to remove cluster from downstream analysis (only without newcol)
cell_types = ["CD4+ T cells", "CD8+ T cells", "-", "B cells"]  # Default: []

# Additional annotations (multiple cell type columns)
more_cell_types = {  # Dict: {new_column: [cell_types]}
    cell_type_broad = ["T cells", "T cells", "NK cells", "B cells"],
    cell_type_detailed = ["CD4+ naive", "CD8+ effector", "NK", "B naive"]
}
ScType Annotation Parameters
[CellTypeAnnotation.envs]
tool = "sctype"

# Tissue type (must match tissueType column in database)
sctype_tissue = "Immune system"  # Required for sctype

# Database file path (Excel format compatible with ScType)
sctype_db = "/path/to/ScTypeDB_full.xlsx"  # Optional: uses default if not specified
hitype Annotation Parameters
[CellTypeAnnotation.envs]
tool = "hitype"

# Tissue type (must match tissueType column in database)
hitype_tissue = "Immune system"  # Required for hitype

# Database file path or built-in database name
# Built-in options: "hitypedb_short", "hitypedb_full", "hitypedb_pbmc3k"
hitype_db = "hitypedb_full"  # Default: built-in database
scCATCH Annotation Parameters
[CellTypeAnnotation.envs]
tool = "sccatch"

[CellTypeAnnotation.envs.sccatch_args]
# Species (Human or Mouse)
species = "Human"  # Required

# Tissue origin
tissue = "Blood"  # Required

# Cancer type (if cancer tissue)
cancer = "Normal"  # Default: "Normal"

# Custom marker genes (RDS file or list)
marker = ""  # Optional

# Use custom marker instead of database
if_use_custom_marker = false  # Default: false

# Additional scCATCH::findmarkergene() arguments
# See: https://rdrr.io/cran/scCATCH/man/findmarkergene.html
CellTypist Annotation Parameters
[CellTypeAnnotation.envs]
tool = "celltypist"

[CellTypeAnnotation.envs.celltypist_args]
# Model file path (download from https://celltypist.cog.sanger.ac.uk/models/models.json)
model = "Immune_All_Low.pkl"  # Required

# Python interpreter where celltypist is installed
python = "python"  # Default: "python"

# Majority voting refinement for local subclusters
majority_voting = true  # Default: true

# Over-clustering column (for majority voting)
# Set to false to disable over-clustering
over_clustering = "seurat_clusters"  # Auto: identity for Seurat, false for h5ad

# Assay for Seurat-to-AnnData conversion
assay = ""  # Auto: RNA for h5seurat, default assay for Seurat

Annotation Methods

1. Direct Annotation

Assigns cell types manually to each cluster. Best when you have well-defined marker genes or want complete control over annotations.

Pros:

Cons:

Use cases:

2. ScType

Uses pre-defined cell type markers from ScType database. Annotates based on enrichment of known marker genes in each cluster.

Databases:

Pros:

Cons:

Reference: https://github.com/IanevskiAleksandr/sc-type

Use cases:

3. hitype

Flexible annotation tool compatible with ScType database format. Supports both file-based and built-in databases.

Built-in databases:

Pros:

Cons:

Reference: https://github.com/pwwang/hitype

Use cases:

4. scCATCH

Identifies cell types by matching cluster marker genes to cell type-specific marker database.

Workflow:

  1. Finds marker genes for each cluster
  2. Matches markers to cell type database
  3. Assigns best matching cell type

Parameters:

Pros:

Cons:

Reference: https://github.com/ZJUFanLab/scCATCH

Use cases:

5. CellTypist

Machine learning-based annotation using pre-trained models. Requires Python environment and celltypist2 package.

Models:

Key features:

Pros:

Cons:

Reference: https://celltypist.org/

Use cases:

6. MapQuery

MapQuery performs cell-level mapping using a Seurat reference.

[CellTypeAnnotation.envs]
tool = "mapquery"

[CellTypeAnnotation.envs.mapquery]
db = "/path/to/reference.rds"
use = "celltype"
ident_name = "predicted.id"

db is the reference Seurat object file, use is the metadata column with cell-type labels, and ident_name names the transferred label column.

Configuration Examples

Example 1: Minimal Configuration (No Annotation)

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

Result: Tool defaults to "direct" with empty cell_types. Original cluster names are preserved.

Example 2: Direct Annotation for T Cell Subsets

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "direct"
cell_types = ["CD4+ naive", "CD4+ memory", "CD8+ naive", "CD8+ effector", "-", "Regulatory T"]

Result: Clusters 0-3 and 5 get specified labels. Cluster 4 keeps original name (placeholder "-").

Example 3: ScType for Immune Tissue

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "sctype"
sctype_tissue = "Immune system"
sctype_db = "/data/databases/ScTypeDB_full.xlsx"
merge = true  # Merge clusters with same annotation

Result: Uses full ScType database for immune tissue. Merges clusters with identical annotations.

Example 4: hitype with Built-in PBMC Database

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "hitype"
hitype_tissue = "Blood"
hitype_db = "hitypedb_pbmc3k"  # Built-in PBMC database
merge = true

Result: Fast PBMC annotation using built-in database optimized for 10X PBMC data.

Example 5: scCATCH for Cancer Tissue

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "sccatch"

[CellTypeAnnotation.envs.sccatch_args]
species = "Human"
tissue = "Lung"
cancer = "Lung adenocarcinoma"

Result: Annotates lung adenocarcinoma dataset with cancer-specific cell types.

Example 6: CellTypist with Majority Voting

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "celltypist"

[CellTypeAnnotation.envs.celltypist_args]
model = "/data/models/Immune_All_Low.pkl"
majority_voting = true
over_clustering = "seurat_clusters"  # Use clusters for majority voting
python = "/usr/bin/python3"  # Specify Python interpreter

Result: Uses ML model with majority voting refinement for robust annotation.

Example 7: Multiple Annotation Methods (Keep Original)

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "sctype"
sctype_tissue = "Immune system"
newcol = "celltype_sctype"  # Create new column, keep original

Result: Annotated cell types saved in celltype_sctype column. Original seurat_clusters unchanged.

Example 8: Multiple Annotation Columns

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "direct"
cell_types = ["CD4+ T", "CD8+ T", "NK", "B", "Monocyte"]

more_cell_types = {
    "celltype_broad": ["T cells", "T cells", "NK cells", "B cells", "Monocytes"],
    "celltype_subset": ["CD4+ naive", "CD8+ effector", "NK", "B naive", "CD14+ Mono"]
}

Result: Creates three metadata columns: celltype (from cell_types), celltype_broad, celltype_subset.

Example 9: Exclude Clusters with NA

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "direct"
cell_types = ["CD4+ T", "CD8+ T", "NA", "B cells"]

Result: Cluster 2 is removed from downstream analysis (NA excludes cluster). Note: Only works without newcol.

Example 10: H5AD Input with CellTypist

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["seurat_clustering.h5ad"]  # H5AD file

[CellTypeAnnotation.envs]
tool = "celltypist"
ident = "clusters"  # Required for H5AD: cluster column name

[CellTypeAnnotation.envs.celltypist_args]
model = "Immune_All_Low.pkl"
majority_voting = true

Result: Annotates H5AD file. ident specifies which metadata column contains clusters.

Common Patterns

Pattern 1: Standard T Cell Annotation Workflow

# Step 1: Cluster T cells
[SeuratClusteringOfAllCells]
[TOrBCellSelection]
[SeuratClustering]  # Clustering on T cells only

# Step 2: Annotate T cell subsets
[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "direct"
cell_types = ["Naive CD4+", "Memory CD4+", "Effector CD8+", "Tregs", "Progenitor"]

Pattern 2: Automated Immune Annotation with Backup

# Use hitype for annotation, keep original clusters
[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "hitype"
hitype_tissue = "Blood"
hitype_db = "hitypedb_pbmc3k"
newcol = "celltype_hitype"  # Keep original seurat_clusters
merge = true

Pattern 3: Combine Multiple Annotation Methods

# First annotation: ScType
[CellTypeAnnotation]
[CellTypeAnnotation.envs]
tool = "sctype"
sctype_tissue = "Immune system"
newcol = "celltype_sctype"

# Second annotation: CellTypist for comparison
[CellTypeAnnotation2]
# Note: Must define separate process for second annotation
# See immunopipe-config.md for multi-process setup

Pattern 4: Refine Annotation with CellTypist

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "celltypist"

[CellTypeAnnotation.envs.celltypist_args]
model = "Immune_All_Low.pkl"
majority_voting = true
over_clustering = "seurat_clusters"  # Use clustering result
python = "python"

Pattern 5: Tissue-Specific ScType Annotation

[CellTypeAnnotation]
[CellTypeAnnotation.in]
sobjfile = ["SeuratClustering"]

[CellTypeAnnotation.envs]
tool = "sctype"
sctype_tissue = "Brain"  # Brain-specific annotation
sctype_db = "/data/brain_markers.xlsx"  # Custom brain marker database
merge = true

Dependencies

Upstream Processes

Downstream Processes

Legacy Compatibility

SeuratMap2Ref is deprecated but remains supported for existing configurations; see the legacy skill.

External Dependencies

Validation Rules

Tool-Specific Validation

  1. ScType:
  1. hitype:
  1. scCATCH:
  1. CellTypist:
  1. Direct:

Input Validation

Output Validation

Troubleshooting

Common Issues and Solutions

Issue: "No tissues found in database" (ScType/hitype)

Cause: sctype_tissue or hitype_tissue doesn't match tissueType column in database.

Solutions:

  1. Check available tissues: Open database Excel file, read tissueType column
  2. Use exact match (case-sensitive)
  3. Set tissue to empty string "" to use all rows in database
  4. Verify database file path is correct
Issue: "Not enough clusters for scCATCH"

Cause: scCATCH requires at least 2 clusters.

Solutions:

  1. Ensure clustering result has ≥2 clusters
  2. Increase clustering resolution in SeuratClustering
  3. Use alternative tool (ScType, hitype, CellTypist)
Issue: CellTypist Python not found

Cause: CellTypist requires Python environment with celltypist2 installed.

Solutions:

  1. Specify correct Python path: celltypist_args.python = "/usr/bin/python3"
  2. Install celltypist2: pip install celltypist2
  3. Verify Python environment: python -c "import celltypist; print(celltypist.__version__)"
Issue: CellTypist model file not found

Cause: Model path is incorrect or model not downloaded.

Solutions:

  1. Download model from: https://celltypist.cog.sanger.ac.uk/models/models.json
  2. Use absolute path for celltypist_args.model
  3. Verify model file exists and is readable
Issue: "Unknown tool" error

Cause: Invalid tool value specified.

Solutions:

  1. Check valid options: direct, sctype, hitype, sccatch, celltypist, mapquery
  2. Verify spelling is correct (case-sensitive)
  3. Check tool is installed in environment
Issue: Annotations overwritten by multiple annotation processes

Cause: Multiple annotation processes write to same metadata column.

Solutions:

  1. Use newcol parameter to create separate columns:

```toml

[CellTypeAnnotation.envs]

newcol = "celltype_method1"

```

  1. Or use backup_col to preserve original:

```toml

backup_col = "original_clusters_id"

```

Issue: Ambiguous cell type assignments

Cause: Clusters have similar marker expression patterns.

Solutions:

  1. Increase clustering resolution for finer separation
  2. Use merge = false to keep cluster-specific labels
  3. Compare multiple annotation methods for consensus
  4. Manual inspection of top marker genes
Issue: Missing cell types in results

Cause: Clusters removed by "NA" placeholder or filtering.

Solutions:

  1. Check cell_types list for "NA" entries
  2. Verify newcol is not set (NA removal only works without newcol)
  3. Check downstream processes for filtering
Issue: H5AD input annotation fails

Cause: ident parameter not specified for H5AD files.

Solutions:

  1. Specify cluster column: ident = "clusters" (or your cluster column name)
  2. Check H5AD metadata for cluster column name
  3. Or convert H5AD to RDS format first
Issue: Wrong number of cell types assigned

Cause: cell_types list length doesn't match cluster count.

Solutions:

  1. Check number of clusters in Seurat object
  2. Ensure cell_types list has correct number of entries
  3. Use placeholders "-" or "" for clusters to keep original names
  4. Shorter lists OK (extra clusters keep original names)

Verification Steps

After annotation, verify:

  1. Check output file:

```bash

# View cluster to cell type mapping

cat .pipen/Immunopipe/CellTypeAnnotation/0/output/cluster2celltype.tsv

```

  1. Check Seurat object metadata:

```R

library(Seurat)

obj <- readRDS(".pipen/Immunopipe/CellTypeAnnotation/0/output/annotated.rds")

head(obj@meta.data)

# Look for cell type column (seurat_clusters or newcol name)

```

  1. Validate annotation quality:

```R

# Check distribution of cell types

table(Idents(obj))

# Visualize UMAP with cell types

DimPlot(obj, group.by = "celltype_hitype", label = TRUE, repel = TRUE)

```

  1. Compare multiple methods:

```R

# Compare ScType vs hitype annotations

table(obj$celltype_sctype, obj$celltype_hitype)

```

Best Practices

Method Selection

  1. Start with hitype: Fast, good for PBMC/immune datasets
  2. Compare with ScType: Alternative database-based method
  3. Use CellTypist for complex datasets: ML-based, handles well
  4. Manual refinement: Use direct annotation for corrections

Multi-Method Workflow

  1. Run multiple annotation methods in parallel
  2. Compare results for consensus
  3. Manually refine discrepancies using direct annotation
  4. Keep original cluster names for traceability

Tissue-Specific Annotation

  1. Always specify tissue when using ScType/hitype
  2. Use custom databases for non-standard tissues
  3. Verify database contains relevant cell types

Reproducibility

  1. Save cluster-to-celltype mapping (cluster2celltype.tsv)
  2. Document which tool/database was used
  3. Keep original cluster names using newcol or backup_col

External References

Tool Documentation

Database Downloads

Related Processes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.