[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6DTFV2W6GG2H4X3G8MAA5JQ":3,"skill-same:01M6DTFV2W6GG2H4X3G8MAA5JQ":110},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":51,"install":52,"resources":65},"01M6DTFV2W6GG2H4X3G8MAA5JQ","sc-cell-annotation",null,"Load when assigning cell-type labels to a clustered scRNA AnnData via marker dictionaries, CellTypist, PopV, KNNPredict, SingleR, scmap, SCSA, or a manual cluster-to-label map. Skip when ranking marker genes per cluster (use sc-markers); condition-vs-control DE (use sc-de).","TianGzlab\u002FOmicsClaw","TianGzlab","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F150978281?v=4","01M6DT9WNJJ470ADHPSMFAA02Y","01M6DT9WSN09C5K65GB6RK18R9",161,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"sc cell annotation","cell","annotation","singlecell","markers","knnpredict","scsa","scmap","singler","popv","celltypist","cell-annotation","anndata","de","scrna","ranking","type","control","map","use","2026-11-10 10:12:30",false,"---\nname: sc-cell-annotation\ndescription: Load when assigning cell-type labels to a clustered scRNA AnnData via marker dictionaries,\n  CellTypist, PopV, KNNPredict, SingleR, scmap, SCSA, or a manual cluster-to-label map. Skip when ranking\n  marker genes per cluster (use sc-markers); condition-vs-control DE (use sc-de).\ntags:\n- singlecell\n- scrna\n- cell-annotation\n- celltypist\n- popv\n- singler\n- scmap\n- scsa\n- knnpredict\n- markers\n---\n\n# sc-cell-annotation\n\n## When to use\n\nThe user has a clustered AnnData (e.g. `obs[\"leiden\"]`) and wants\nlabelled cell types in `obs[\"cell_type\"]`. Pick a method by\ndata \u002F reference availability:\n\n- `markers` (default) — built-in or custom marker-gene scoring.\n- `manual` — user-supplied cluster-to-label map.\n- `celltypist` — pretrained `Immune_All_Low.pkl` style classifier.\n- `popv` \u002F `knnpredict` — reference AnnData mapping (PopV consensus or lightweight KNN).\n- `singler` \u002F `scmap` — R-backed reference annotation.\n- `scsa` — Fisher-test DB scoring (`species`, `tissue`).\n\nThis skill labels — for **ranking** the genes that justify a label use\n`sc-markers`; for replicate-aware condition DE use `sc-de`.\n\n## Use from a step\n\n```python\nannotation = load_skill(\"sc-cell-annotation\")\nadata = read_input(\"results\u002F03_clustering\u002Fintermediate\u002Fadata_clustered.h5ad\")\n# celltypist Immune_All_Low: PBMC sample; the model covers circulating immune types.\nadata = annotation.annotate(adata, method=\"celltypist\", model=\"Immune_All_Low\")\nrun = annotation.run_info(adata)\nassert run[\"summary\"][\"actual_method\"] == \"celltypist\", run[\"summary\"][\"fallback_reason\"]\nwrite_output(annotation.annotation_table(adata), \"tables\u002Fcell_type_counts.csv\")\nwrite_output(annotation.annotation_figure(adata), \"figures\u002Fumap_cell_type.png\")\nwrite_output(adata, \"intermediate\u002Fadata_annotated.h5ad\")\n```\n\nA complete step that runs on demo data: `examples\u002Fexample_step.py`.\n\n## API\n\n\u003C!-- api:begin generated from _api.py; regenerate with run.py api \u003Cskill dir> --write -->\n\n### `annotate(adata, *, method: str='markers', cluster_key: str | None=None, markers: dict[str, list[str]] | None=None, marker_file: str | None=None, model: str='Immune_All_Low', majority_voting: bool=False, reference: str='HPCA', manual_map: str | None=None, manual_map_file: str | None=None, species: str='Human', tissue: str='All', scsa_foldchange: float=1.5, scsa_pvalue: float=0.05)`\n\nAnnotate cell types with the chosen method; the single entry point to the method functions.\n\n:param method: One of ``markers`` (default), ``manual``, ``celltypist``, ``popv``,\n    ``knnpredict``, ``singler``, ``scmap``, ``scsa``. See the method functions for\n    what each needs.\n:param cluster_key: The ``obs`` column with cluster labels. Default ``None``: the\n    matrix contract's primary cluster key, else the first of ``leiden``,\n    ``louvain``, ``seurat_clusters``, ``cluster``, ``cell_type`` present.\n:param markers: ``markers`` only: cell type to marker genes. Default: the built-in human set.\n:param marker_file: ``markers`` only: a JSON or CSV marker file, used instead of *markers*.\n:param model: ``celltypist`` only. Default ``\"Immune_All_Low\"``.\n:param majority_voting: ``celltypist`` only. Default ``False``.\n:param reference: ``popv``, ``knnpredict``: a labelled ``.h5ad`` path; ``singler``,\n    ``scmap``: a celldex atlas name. Default ``\"HPCA\"``.\n:param manual_map: ``manual`` only: inline mapping such as ``\"0=T cell;1,2=Myeloid\"``.\n:param manual_map_file: ``manual`` only: a mapping file (json\u002Fcsv\u002Ftsv\u002Ftxt).\n:param species: ``scsa`` only: ``\"Human\"`` or ``\"Mouse\"``. Default ``\"Human\"``.\n:param tissue: ``scsa`` only: CellMarker tissue filter. Default ``\"All\"``.\n:param scsa_foldchange: ``scsa`` only. Default 1.5.\n:param scsa_pvalue: ``scsa`` only. Default 0.05.\n:returns: The same AnnData.\n:raises ValueError: an unknown method, or what the chosen method raises.\n\n### `annotate_markers(adata, *, cluster_key: str | None=None, markers: dict[str, list[str]] | None=None, marker_file: str | None=None)`\n\nLabel each cluster with the cell type whose marker genes have the highest mean expression in it.\n\nEvery cell of a cluster gets the cluster's label; a cluster where no marker\ngene is expressed is ``Unknown``. Gene names are matched exactly, or\ncase-insensitively when nothing matches exactly (human markers on mouse data).\n\n:param cluster_key: As in :func:`annotate`.\n:param markers: Cell type to marker genes. Default: the built-in human set\n    (PBMC, brain and general stromal types). Give tissue-specific markers for other tissues.\n:param marker_file: A JSON (``{\"T cell\": [\"CD3D\", ...]}``) or CSV (``T cell,CD3D;CD3E``)\n    marker file, used instead of *markers*.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``\n    (the winning mean expression).\n:raises ValueError: the cluster column is missing.\n\n### `annotate_manual(adata, *, cluster_key: str | None=None, manual_map: str | None=None, manual_map_file: str | None=None)`\n\nRelabel clusters from a mapping the user gives.\n\n:param cluster_key: As in :func:`annotate`.\n:param manual_map: Inline mapping such as ``\"0=T cell;1,2=Myeloid\"``.\n:param manual_map_file: A mapping file (json, csv, tsv or txt), used instead of *manual_map*.\n:returns: The same AnnData with ``obs['cell_type']``.\n:raises ValueError: neither mapping is given.\n\n### `annotate_celltypist(adata, *, model: str='Immune_All_Low', majority_voting: bool=False, cluster_key: str | None=None)`\n\nPer-cell labels from a pretrained CellTypist model.\n\nCellTypist needs log1p-normalised expression to 10,000 counts; when the input\nfails that check, or the model cannot be loaded, the function falls back to\n:func:`annotate_markers` and records the reason (``run_info(adata)[\"summary\"][\"fallback_reason\"]``).\n\n:param model: A CellTypist model name or ``.pkl``. Default ``\"Immune_All_Low\"`` (immune\n    cells, fine labels); choose a tissue model for other data. Models download on first use.\n:param majority_voting: Smooth labels over over-clustered communities. Default ``False``.\n:param cluster_key: Recorded for later steps; CellTypist labels cells individually.\n:returns: The same AnnData with ``obs['cell_type']``, ``obs['annotation_score']`` and\n    ``obsm['cell_type_prob']``.\n\n### `annotate_popv(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nLabels transferred from a labelled reference AnnData by PopV-style consensus.\n\n:param reference: Path to a labelled ``.h5ad`` (a ``cell_type`` column in ``obs``).\n:param cluster_key: As in :func:`annotate`; used for the cluster consensus.\n:returns: The same AnnData with ``obs['cell_type']``.\n\n### `annotate_knnpredict(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nLabels transferred from a labelled reference AnnData by nearest neighbours (SCOP KNNPredict style).\n\n:param reference: Path to a labelled ``.h5ad`` (a ``cell_type`` column in ``obs``).\n:param cluster_key: As in :func:`annotate`.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``.\n\n### `annotate_singler(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nPer-cell labels from SingleR against a celldex atlas, run in R.\n\n:param reference: A celldex atlas: ``HPCA`` (default), ``BlueprintEncode``, ``Monaco``, ...\n:param cluster_key: Recorded for later steps; SingleR labels cells individually.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``.\n:raises RuntimeError: R, SingleR or celldex is missing, or SingleR returns nothing.\n\n### `annotate_scmap(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nPer-cell labels projected with scmap onto a celldex atlas, run in R.\n\n:param reference: A celldex atlas. Default ``HPCA``.\n:param cluster_key: Recorded for later steps.\n:returns: The same AnnData with ``obs['cell_type']``.\n:raises RuntimeError: R, scmap or celldex is missing, or scmap returns nothing.\n\n### `annotate_scsa(adata, *, cluster_key: str | None=None, species: str='Human', tissue: str='All', foldchange: float=1.5, pvalue: float=0.05)`\n\nCluster labels from CellMarker 2.0 genes scored against each cluster's markers (SCSA).\n\nRuns a Wilcoxon test per cluster and scores each cell type's markers with a\nFisher exact test. The CellMarker table downloads once to\n``~\u002F.cache\u002Fomicsclaw\u002Fscsa``; without network a small built-in set is used.\n\n:param cluster_key: As in :func:`annotate`.\n:param species: ``\"Human\"`` (default) or ``\"Mouse\"``.\n:param tissue: CellMarker tissue filter such as ``\"Blood\"``. Default ``\"All\"``.\n:param foldchange: Minimum fold change of a cluster marker. Default 1.5.\n:param pvalue: Maximum adjusted p-value of a cluster marker. Default 0.05.\n:returns: The same AnnData with ``obs['cell_type']``.\n\n### `run_info(adata, *, keep: bool=True) -> dict`\n\nWhat the last annotate function recorded: ``cluster_key`` and ``summary``.\n\n``summary`` has ``requested_method``, ``actual_method``, ``used_fallback``,\n``fallback_reason``, ``n_cell_types``, ``cell_type_counts`` and the method's\nown details (reference, marker source, ...).\n\n:param keep: Leave the record in ``adata.uns``; ``False`` removes it.\n:returns: The record, or an empty dict when no annotate function has run on *adata*.\n\n### `annotation_table(adata, *, key: str='cell_type') -> pd.DataFrame`\n\nCells per cell type, largest first.\n\n:param key: The ``obs`` column with the labels. Default ``\"cell_type\"``.\n:returns: Columns ``cell_type``, ``n_cells`` and ``proportion_pct``.\n\n### `cluster_annotation_matrix(adata, *, cluster_key: str, key: str='cell_type') -> pd.DataFrame`\n\nFor each cluster, the fraction of its cells given each label.\n\n:param cluster_key: The ``obs`` column with cluster labels.\n:param key: The ``obs`` column with cell-type labels. Default ``\"cell_type\"``.\n:returns: One row per cluster (first column named after *cluster_key*), one column per label;\n    empty when either column is missing.\n\n### `annotation_figure(adata, *, key: str='cell_type', basis: str | None=None)`\n\nA scatter plot of the 2-D embedding coloured by cell type.\n\n:param key: The ``obs`` column to colour by. Default ``\"cell_type\"``.\n:param basis: The ``obsm`` key to plot. Default: the first of ``X_umap``, ``X_tsne``, ``X_pca``.\n:returns: A matplotlib Figure.\n:raises KeyError: no embedding is present.\n\n\u003C!-- api:end -->\n\n## Methods and parameters\n\n| Method | Needs | Labels | Defaults and their source |\n|---|---|---|---|\n| `markers` | a cluster column | one per cluster | built-in human marker set (PBMC, brain, stroma); give `markers` or `marker_file` for other tissues |\n| `manual` | a cluster column and a mapping from the user | one per cluster | none |\n| `celltypist` | log1p-normalised `X` (target sum 10,000) | per cell | `model=\"Immune_All_Low\"` (CellTypist's general immune model), `majority_voting=False` |\n| `popv`, `knnpredict` | a labelled reference `.h5ad` with `obs[\"cell_type\"]` | per cell | `reference` must be a path for these two |\n| `singler`, `scmap` | R with SingleR or scmap, celldex, zellkonverter | per cell | `reference=\"HPCA\"` (celldex's Human Primary Cell Atlas) |\n| `scsa` | a cluster column; network for the CellMarker 2.0 table on first use | one per cluster | `species=\"Human\"`, `tissue=\"All\"`, `foldchange=1.5`, `pvalue=0.05` (pySCSA's defaults) |\n\nChoosing: with a matching reference, prefer `knnpredict` or `popv`; for blood or\nimmune tissue without one, `celltypist`; when the user knows the markers,\n`markers` with their list or `manual`. Labels are hypotheses: report the\nmethod, the reference or model, and the markers that support each label.\n\n## Gotchas\n\n- **`celltypist` falls back to `markers` silently.** On a non-normalised `X`, missing model or any CellTypist error it runs marker scoring instead. Check `run_info(adata)[\"summary\"][\"actual_method\"]`; `fallback_reason` says why.\n- **`popv`'s backend is chosen at run time** (scvi, scanvi or a classical one, by what is installed); `summary[\"backend\"]` records it.\n- **R methods fail hard when R returns nothing** (`RuntimeError`). Check `Rscript` and the packages before choosing them.\n- **`manual` needs `manual_map` or `manual_map_file`** (`ValueError` otherwise). Inline form: `\"0=T cell;1,2=Myeloid\"`.\n- **A marker file that cannot be read** raises `FileNotFoundError`, an empty one `ValueError`.\n- **`Unknown` everywhere means the markers do not fit the data.** All clusters `Unknown` with `markers` usually means the wrong tissue or organism; switch method or ask the user for markers rather than reporting it.\n\n## Inputs and outputs\n\n- Reads the cluster column (`cluster_key`, default from the matrix contract or `leiden` \u002F `louvain`), normalised `X`, and for `celltypist` \u002F R methods the counts it rebuilds from `layers['counts']` or `raw`.\n- Writes `obs['cell_type']`, `obs['annotation_score']` (when the method scores), `obs['annotation_requested_method']`, `obs['annotation_actual_method']`, `obs['annotation_method']`, `uns['annotation_runtime']`; `celltypist` also `obsm['cell_type_prob']`.\n- `annotation_table` and `cluster_annotation_matrix` return DataFrames; `annotation_figure` returns a matplotlib Figure.\n\n## CLI\n\n`sc_annotate.py` runs the same functions outside a project and writes a\nreport, figures, tables and `processed.h5ad`:\n`python \u003Cskill directory>\u002Fsc_annotate.py --help`. `--demo` runs it on PBMC3k.\n\n## See also\n\n- `references\u002Fparameters.md` — every CLI flag, per-method parameter hints\n- `references\u002Fmethodology.md` — when each backend wins; reference \u002F model notes\n- `references\u002Foutput_contract.md` — `obs[\"cell_type\"]` \u002F `obsm[\"cell_type_prob\"]` \u002F `result.json` keys\n- Adjacent skills: `sc-clustering` (upstream — produces the cluster column), `sc-markers` (parallel — ranks the marker genes that *justify* a label; can be run before or after), `sc-de` (downstream — replicate-aware condition DE between labelled groups)\n\n## Dependencies\n\nPython packages this skill's script needs. They are not installed for you — check before a long run.\n\n`anndata`, `celltypist`, `matplotlib`, `numpy`, `pandas`, `popv`, `scanpy`, `scipy`, `seaborn`\n","# sc-cell-annotation\n\n## When to use\n\nThe user has a clustered AnnData (e.g. `obs[\"leiden\"]`) and wants\nlabelled cell types in `obs[\"cell_type\"]`. Pick a method by\ndata \u002F reference availability:\n\n- `markers` (default) — built-in or custom marker-gene scoring.\n- `manual` — user-supplied cluster-to-label map.\n- `celltypist` — pretrained `Immune_All_Low.pkl` style classifier.\n- `popv` \u002F `knnpredict` — reference AnnData mapping (PopV consensus or lightweight KNN).\n- `singler` \u002F `scmap` — R-backed reference annotation.\n- `scsa` — Fisher-test DB scoring (`species`, `tissue`).\n\nThis skill labels — for **ranking** the genes that justify a label use\n`sc-markers`; for replicate-aware condition DE use `sc-de`.\n\n## Use from a step\n\n```python\nannotation = load_skill(\"sc-cell-annotation\")\nadata = read_input(\"results\u002F03_clustering\u002Fintermediate\u002Fadata_clustered.h5ad\")\n# celltypist Immune_All_Low: PBMC sample; the model covers circulating immune types.\nadata = annotation.annotate(adata, method=\"celltypist\", model=\"Immune_All_Low\")\nrun = annotation.run_info(adata)\nassert run[\"summary\"][\"actual_method\"] == \"celltypist\", run[\"summary\"][\"fallback_reason\"]\nwrite_output(annotation.annotation_table(adata), \"tables\u002Fcell_type_counts.csv\")\nwrite_output(annotation.annotation_figure(adata), \"figures\u002Fumap_cell_type.png\")\nwrite_output(adata, \"intermediate\u002Fadata_annotated.h5ad\")\n```\n\nA complete step that runs on demo data: `examples\u002Fexample_step.py`.\n\n## API\n\n\u003C!-- api:begin generated from _api.py; regenerate with run.py api \u003Cskill dir> --write -->\n\n### `annotate(adata, *, method: str='markers', cluster_key: str | None=None, markers: dict[str, list[str]] | None=None, marker_file: str | None=None, model: str='Immune_All_Low', majority_voting: bool=False, reference: str='HPCA', manual_map: str | None=None, manual_map_file: str | None=None, species: str='Human', tissue: str='All', scsa_foldchange: float=1.5, scsa_pvalue: float=0.05)`\n\nAnnotate cell types with the chosen method; the single entry point to the method functions.\n\n:param method: One of ``markers`` (default), ``manual``, ``celltypist``, ``popv``,\n    ``knnpredict``, ``singler``, ``scmap``, ``scsa``. See the method functions for\n    what each needs.\n:param cluster_key: The ``obs`` column with cluster labels. Default ``None``: the\n    matrix contract's primary cluster key, else the first of ``leiden``,\n    ``louvain``, ``seurat_clusters``, ``cluster``, ``cell_type`` present.\n:param markers: ``markers`` only: cell type to marker genes. Default: the built-in human set.\n:param marker_file: ``markers`` only: a JSON or CSV marker file, used instead of *markers*.\n:param model: ``celltypist`` only. Default ``\"Immune_All_Low\"``.\n:param majority_voting: ``celltypist`` only. Default ``False``.\n:param reference: ``popv``, ``knnpredict``: a labelled ``.h5ad`` path; ``singler``,\n    ``scmap``: a celldex atlas name. Default ``\"HPCA\"``.\n:param manual_map: ``manual`` only: inline mapping such as ``\"0=T cell;1,2=Myeloid\"``.\n:param manual_map_file: ``manual`` only: a mapping file (json\u002Fcsv\u002Ftsv\u002Ftxt).\n:param species: ``scsa`` only: ``\"Human\"`` or ``\"Mouse\"``. Default ``\"Human\"``.\n:param tissue: ``scsa`` only: CellMarker tissue filter. Default ``\"All\"``.\n:param scsa_foldchange: ``scsa`` only. Default 1.5.\n:param scsa_pvalue: ``scsa`` only. Default 0.05.\n:returns: The same AnnData.\n:raises ValueError: an unknown method, or what the chosen method raises.\n\n### `annotate_markers(adata, *, cluster_key: str | None=None, markers: dict[str, list[str]] | None=None, marker_file: str | None=None)`\n\nLabel each cluster with the cell type whose marker genes have the highest mean expression in it.\n\nEvery cell of a cluster gets the cluster's label; a cluster where no marker\ngene is expressed is ``Unknown``. Gene names are matched exactly, or\ncase-insensitively when nothing matches exactly (human markers on mouse data).\n\n:param cluster_key: As in :func:`annotate`.\n:param markers: Cell type to marker genes. Default: the built-in human set\n    (PBMC, brain and general stromal types). Give tissue-specific markers for other tissues.\n:param marker_file: A JSON (``{\"T cell\": [\"CD3D\", ...]}``) or CSV (``T cell,CD3D;CD3E``)\n    marker file, used instead of *markers*.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``\n    (the winning mean expression).\n:raises ValueError: the cluster column is missing.\n\n### `annotate_manual(adata, *, cluster_key: str | None=None, manual_map: str | None=None, manual_map_file: str | None=None)`\n\nRelabel clusters from a mapping the user gives.\n\n:param cluster_key: As in :func:`annotate`.\n:param manual_map: Inline mapping such as ``\"0=T cell;1,2=Myeloid\"``.\n:param manual_map_file: A mapping file (json, csv, tsv or txt), used instead of *manual_map*.\n:returns: The same AnnData with ``obs['cell_type']``.\n:raises ValueError: neither mapping is given.\n\n### `annotate_celltypist(adata, *, model: str='Immune_All_Low', majority_voting: bool=False, cluster_key: str | None=None)`\n\nPer-cell labels from a pretrained CellTypist model.\n\nCellTypist needs log1p-normalised expression to 10,000 counts; when the input\nfails that check, or the model cannot be loaded, the function falls back to\n:func:`annotate_markers` and records the reason (``run_info(adata)[\"summary\"][\"fallback_reason\"]``).\n\n:param model: A CellTypist model name or ``.pkl``. Default ``\"Immune_All_Low\"`` (immune\n    cells, fine labels); choose a tissue model for other data. Models download on first use.\n:param majority_voting: Smooth labels over over-clustered communities. Default ``False``.\n:param cluster_key: Recorded for later steps; CellTypist labels cells individually.\n:returns: The same AnnData with ``obs['cell_type']``, ``obs['annotation_score']`` and\n    ``obsm['cell_type_prob']``.\n\n### `annotate_popv(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nLabels transferred from a labelled reference AnnData by PopV-style consensus.\n\n:param reference: Path to a labelled ``.h5ad`` (a ``cell_type`` column in ``obs``).\n:param cluster_key: As in :func:`annotate`; used for the cluster consensus.\n:returns: The same AnnData with ``obs['cell_type']``.\n\n### `annotate_knnpredict(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nLabels transferred from a labelled reference AnnData by nearest neighbours (SCOP KNNPredict style).\n\n:param reference: Path to a labelled ``.h5ad`` (a ``cell_type`` column in ``obs``).\n:param cluster_key: As in :func:`annotate`.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``.\n\n### `annotate_singler(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nPer-cell labels from SingleR against a celldex atlas, run in R.\n\n:param reference: A celldex atlas: ``HPCA`` (default), ``BlueprintEncode``, ``Monaco``, ...\n:param cluster_key: Recorded for later steps; SingleR labels cells individually.\n:returns: The same AnnData with ``obs['cell_type']`` and ``obs['annotation_score']``.\n:raises RuntimeError: R, SingleR or celldex is missing, or SingleR returns nothing.\n\n### `annotate_scmap(adata, *, reference: str='HPCA', cluster_key: str | None=None)`\n\nPer-cell labels projected with scmap onto a celldex atlas, run in R.\n\n:param reference: A celldex atlas. Default ``HPCA``.\n:param cluster_key: Recorded for later steps.\n:returns: The same AnnData with ``obs['cell_type']``.\n:raises RuntimeError: R, scmap or celldex is missing, or scmap returns nothing.\n\n### `annotate_scsa(adata, *, cluster_key: str | None=None, species: str='Human', tissue: str='All', foldchange: float=1.5, pvalue: float=0.05)`\n\nCluster labels from CellMarker 2.0 genes scored against each cluster's markers (SCSA).\n\nRuns a Wilcoxon test per cluster and scores each cell type's markers with a\nFisher exact test. The CellMarker table downloads once to\n``~\u002F.cache\u002Fomicsclaw\u002Fscsa``; without network a small built-in set is used.\n\n:param cluster_key: As in :func:`annotate`.\n:param species: ``\"Human\"`` (default) or ``\"Mouse\"``.\n:param tissue: CellMarker tissue filter such as ``\"Blood\"``. Default ``\"All\"``.\n:param foldchange: Minimum fold change of a cluster marker. Default 1.5.\n:param pvalue: Maximum adjusted p-value of a cluster marker. Default 0.05.\n:returns: The same AnnData with ``obs['cell_type']``.\n\n### `run_info(adata, *, keep: bool=True) -> dict`\n\nWhat the last annotate function recorded: ``cluster_key`` and ``summary``.\n\n``summary`` has ``requested_method``, ``actual_method``, ``used_fallback``,\n``fallback_reason``, ``n_cell_types``, ``cell_type_counts`` and the method's\nown details (reference, marker source, ...).\n\n:param keep: Leave the record in ``adata.uns``; ``False`` removes it.\n:returns: The record, or an empty dict when no annotate function has run on *adata*.\n\n### `annotation_table(adata, *, key: str='cell_type') -> pd.DataFrame`\n\nCells per cell type, largest first.\n\n:param key: The ``obs`` column with the labels. Default ``\"cell_type\"``.\n:returns: Columns ``cell_type``, ``n_cells`` and ``proportion_pct``.\n\n### `cluster_annotation_matrix(adata, *, cluster_key: str, key: str='cell_type') -> pd.DataFrame`\n\nFor each cluster, the fraction of its cells given each label.\n\n:param cluster_key: The ``obs`` column with cluster labels.\n:param key: The ``obs`` column with cell-type labels. Default ``\"cell_type\"``.\n:returns: One row per cluster (first column named after *cluster_key*), one column per label;\n    empty when either column is missing.\n\n### `annotation_figure(adata, *, key: str='cell_type', basis: str | None=None)`\n\nA scatter plot of the 2-D embedding coloured by cell type.\n\n:param key: The ``obs`` column to colour by. Default ``\"cell_type\"``.\n:param basis: The ``obsm`` key to plot. Default: the first of ``X_umap``, ``X_tsne``, ``X_pca``.\n:returns: A matplotlib Figure.\n:raises KeyError: no embedding is present.\n\n\u003C!-- api:end -->\n\n## Methods and parameters\n\n| Method | Needs | Labels | Defaults and their source |\n|---|---|---|---|\n| `markers` | a cluster column | one per cluster | built-in human marker set (PBMC, brain, stroma); give `markers` or `marker_file` for other tissues |\n| `manual` | a cluster column and a mapping from the user | one per cluster | none |\n| `celltypist` | log1p-normalised `X` (target sum 10,000) | per cell | `model=\"Immune_All_Low\"` (CellTypist's general immune model), `majority_voting=False` |\n| `popv`, `knnpredict` | a labelled reference `.h5ad` with `obs[\"cell_type\"]` | per cell | `reference` must be a path for these two |\n| `singler`, `scmap` | R with SingleR or scmap, celldex, zellkonverter | per cell | `reference=\"HPCA\"` (celldex's Human Primary Cell Atlas) |\n| `scsa` | a cluster column; network for the CellMarker 2.0 table on first use | one per cluster | `species=\"Human\"`, `tissue=\"All\"`, `foldchange=1.5`, `pvalue=0.05` (pySCSA's defaults) |\n\nChoosing: with a matching reference, prefer `knnpredict` or `popv`; for blood or\nimmune tissue without one, `celltypist`; when the user knows the markers,\n`markers` with their list or `manual`. Labels are hypotheses: report the\nmethod, the reference or model, and the markers that support each label.\n\n## Gotchas\n\n- **`celltypist` falls back to `markers` silently.** On a non-normalised `X`, missing model or any CellTypist error it runs marker scoring instead. Check `run_info(adata)[\"summary\"][\"actual_method\"]`; `fallback_reason` says why.\n- **`popv`'s backend is chosen at run time** (scvi, scanvi or a classical one, by what is installed); `summary[\"backend\"]` records it.\n- **R methods fail hard when R returns nothing** (`RuntimeError`). Check `Rscript` and the packages before choosing them.\n- **`manual` needs `manual_map` or `manual_map_file`** (`ValueError` otherwise). Inline form: `\"0=T cell;1,2=Myeloid\"`.\n- **A marker file that cannot be read** raises `FileNotFoundError`, an empty one `ValueError`.\n- **`Unknown` everywhere means the markers do not fit the data.** All clusters `Unknown` with `markers` usually means the wrong tissue or organism; switch method or ask the user for markers rather than reporting it.\n\n## Inputs and outputs\n\n- Reads the cluster column (`cluster_key`, default from the matrix contract or `leiden` \u002F `louvain`), normalised `X`, and for `celltypist` \u002F R methods the counts it rebuilds from `layers['counts']` or `raw`.\n- Writes `obs['cell_type']`, `obs['annotation_score']` (when the method scores), `obs['annotation_requested_method']`, `obs['annotation_actual_method']`, `obs['annotation_method']`, `uns['annotation_runtime']`; `celltypist` also `obsm['cell_type_prob']`.\n- `annotation_table` and `cluster_annotation_matrix` return DataFrames; `annotation_figure` returns a matplotlib Figure.\n\n## CLI\n\n`sc_annotate.py` runs the same functions outside a project and writes a\nreport, figures, tables and `processed.h5ad`:\n`python \u003Cskill directory>\u002Fsc_annotate.py --help`. `--demo` runs it on PBMC3k.\n\n## See also\n\n- `references\u002Fparameters.md` — every CLI flag, per-method parameter hints\n- `references\u002Fmethodology.md` — when each backend wins; reference \u002F model notes\n- `references\u002Foutput_contract.md` — `obs[\"cell_type\"]` \u002F `obsm[\"cell_type_prob\"]` \u002F `result.json` keys\n- Adjacent skills: `sc-clustering` (upstream — produces the cluster column), `sc-markers` (parallel — ranks the marker genes that *justify* a label; can be run before or after), `sc-de` (downstream — replicate-aware condition DE between labelled groups)\n\n## Dependencies\n\nPython packages this skill's script needs. They are not installed for you — check before a long run.\n\n`anndata`, `celltypist`, `matplotlib`, `numpy`, `pandas`, `popv`, `scanpy`, `scipy`, `seaborn`\n",{"name":5,"tags":43,"description":7},[21,32,29,28,27,26,25,24,23,22],"main","90a3bec3e6549bc33dddbf67e4b23869736c49d1","skills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation",27,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw","https:\u002F\u002FTianGzlab.github.io\u002FOmicsClaw\u002F","https:\u002F\u002Fgithub.com\u002FTianGzlab","2026-10-08 01:36:11",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add TianGzlab\u002FOmicsClaw --skill sc-cell-annotation",{"tool":58,"command":59},"bunx","bunx skills add TianGzlab\u002FOmicsClaw --skill sc-cell-annotation",{"tool":61,"command":62},"pnpm","pnpm dlx skills add TianGzlab\u002FOmicsClaw --skill sc-cell-annotation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002FSKILL.md",true,[66,72,76,82,86,90,94,98,102,106],{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"_api.py","SCRIPT","脚本",49448,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002F_api.py",{"path":73,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":74,"sourceHtmlUrl":75},"examples\u002Fexample_step.py",1077,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Fexamples\u002Fexample_step.py",{"path":77,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Fmethodology.md","REFERENCE","参考文档",3987,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Freferences\u002Fmethodology.md",{"path":83,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Foutput_contract.md",3677,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Freferences\u002Foutput_contract.md",{"path":87,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Fparameters.md",3093,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Freferences\u002Fparameters.md",{"path":91,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Fr_visualization.md",1120,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Freferences\u002Fr_visualization.md",{"path":95,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":96,"sourceHtmlUrl":97},"sc_annotate.py",38007,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Fsc_annotate.py",{"path":99,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":100,"sourceHtmlUrl":101},"tests\u002F__init__.py",0,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Ftests\u002F__init__.py",{"path":103,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":104,"sourceHtmlUrl":105},"tests\u002Ftest_sc_annotate_methods.py",1208,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Ftests\u002Ftest_sc_annotate_methods.py",{"path":107,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":108,"sourceHtmlUrl":109},"tests\u002Ftest_sc_annotate.py",2269,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-cell-annotation\u002Ftests\u002Ftest_sc_annotate.py",[111,124,136,152,178,199],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":38},"01M6DTP4X225Q92RMY8XXHPCTT","demo-skill","A fixture skill for the skill environment tests. Use it for nothing else.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftests\u002Fskillenv\u002Ffixtures\u002Fskills\u002Fdemo\u002Fdemo-skill\u002FSKILL.md",[],[118,119,120,121,122,37,123],"demo skill","demo","tests","fixture","fixture skill","environment",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":38},"01M6DTP28JTWQK3HHXDNQV8BBV","fake-domains","Test fixture for the golden deployment in tests\u002Fentry. Load never; it has no script.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftests\u002Fentry\u002Ffake_skills\u002Fspatial\u002Ffake-domains\u002FSKILL.md",[],[131,132,133,120,121,134,135],"domains","fake domains","deployment","never","test",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":38},"01M6DTNZ4AMWKTME1T18K5C643","replace-me-skill","Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftemplates\u002Fskill\u002FSKILL.md",[],[143,144,145,146,147,148,149,150,151],"me","replace me skill","template","directory","skill template","existing skill","new skill","bootstrap","scaffold",{"skillNo":153,"name":154,"nameZh":6,"description":155,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":156,"categories":157,"keywords":158,"publishedAt":38},"01M6DTNV63MTD0Q6YRC52F0B1Y","spatial-velocity","Load when estimating RNA velocity on a spatial AnnData with `layers[\"spliced\"]` + `layers[\"unspliced\"]` via scVelo (stochastic \u002F deterministic \u002F dynamical) or veloVI (deep generative). Skip when input lacks the spliced\u002Funspliced layers (must be quantified upstream by velocyto \u002F kb-python \u002F STARsolo); non-spatial scRNA velocity (use sc-velocity).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-velocity\u002FSKILL.md",[],[159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,37,176,177],"velocity","spatial velocity","Spatial","scvelo","input","starsolo","time","deep","RNA","kb-python","via","velocyto","rna-velocity","velovi","dynamics","upstream","kb","python","deterministic",{"skillNo":179,"name":180,"nameZh":6,"description":181,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":182,"categories":183,"keywords":184,"publishedAt":38},"01M6DTNPMR227NAT8QFY620YDW","spatial-trajectory","Load when inferring pseudotime \u002F lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced\u002Funspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-trajectory\u002FSKILL.md",[],[161,185,186,187,188,189,190,191,169,192,193,194,195,19,159,196,37,197,30,198],"trajectory","spatial trajectory","state","terminal","lineage","diffusion","cellrank","palantir","dpt","pseudotime","probability","default","branch","data",{"skillNo":200,"name":201,"nameZh":6,"description":202,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":203,"categories":204,"keywords":205,"publishedAt":38},"01M6DTNJEYFT33P84DGHDNXW95","spatial-statistics","Load when running spatial autocorrelation \u002F hotspot \u002F co-occurrence \u002F neighbourhood-enrichment \u002F Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-statistics\u002FSKILL.md",[],[206,207,161,169,208,209,210,211,212,213,131,33,214,215,216,37,30,217,218,219],"spatial statistics","statistics","nhood-enrichment","co-occurrence","ripley","geary","moran","neighbourhood","autocorrelation","local","domain","detection","enrichment","stats"]