cell-type-annotation 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. cell_type_annotation-0.4.2/.claude-plugin/plugin.json +12 -0
  2. cell_type_annotation-0.4.2/.github/workflows/lint.yaml +20 -0
  3. cell_type_annotation-0.4.2/.github/workflows/release.yaml +72 -0
  4. cell_type_annotation-0.4.2/.github/workflows/test.yaml +23 -0
  5. cell_type_annotation-0.4.2/.gitignore +12 -0
  6. cell_type_annotation-0.4.2/.pre-commit-config.yaml +26 -0
  7. cell_type_annotation-0.4.2/LICENSE +21 -0
  8. cell_type_annotation-0.4.2/PKG-INFO +105 -0
  9. cell_type_annotation-0.4.2/README.md +85 -0
  10. cell_type_annotation-0.4.2/pyproject.toml +48 -0
  11. cell_type_annotation-0.4.2/skills/cell-type-annotation/SKILL.md +147 -0
  12. cell_type_annotation-0.4.2/skills/cell-type-annotation/references/knowledge_sources.md +62 -0
  13. cell_type_annotation-0.4.2/skills/cell-type-annotation/references/marker_tools.md +107 -0
  14. cell_type_annotation-0.4.2/skills/cell-type-annotation/references/method_selection.md +200 -0
  15. cell_type_annotation-0.4.2/skills/cell-type-annotation/references/methodology.md +187 -0
  16. cell_type_annotation-0.4.2/src/cell_type_annotation/__init__.py +39 -0
  17. cell_type_annotation-0.4.2/src/cell_type_annotation/checks.py +318 -0
  18. cell_type_annotation-0.4.2/src/cell_type_annotation/data/cell_cycle_tirosh.tsv +98 -0
  19. cell_type_annotation-0.4.2/src/cell_type_annotation/hierarchy.py +530 -0
  20. cell_type_annotation-0.4.2/src/cell_type_annotation/markers.py +164 -0
  21. cell_type_annotation-0.4.2/src/cell_type_annotation/pl.py +869 -0
  22. cell_type_annotation-0.4.2/src/cell_type_annotation/report.py +239 -0
  23. cell_type_annotation-0.4.2/src/cell_type_annotation/routing.py +371 -0
  24. cell_type_annotation-0.4.2/tests/conftest.py +55 -0
  25. cell_type_annotation-0.4.2/tests/test_checks.py +151 -0
  26. cell_type_annotation-0.4.2/tests/test_hierarchy.py +193 -0
  27. cell_type_annotation-0.4.2/tests/test_markers.py +110 -0
  28. cell_type_annotation-0.4.2/tests/test_pl.py +185 -0
  29. cell_type_annotation-0.4.2/tests/test_report.py +101 -0
  30. cell_type_annotation-0.4.2/tests/test_routing.py +96 -0
  31. cell_type_annotation-0.4.2/uv.lock +1334 -0
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "cell-type-annotation",
3
+ "version": "0.4.2",
4
+ "description": "Evidence-driven cell-type annotation of pre-clustered single-cell and spatial transcriptomics data: Claude annotates level by level, one routed cross-check per level, signed-off assumptions, critic subagents. Ships a skill and the cell_type_annotation Python package; runs as an analysis-workflow task.",
5
+ "author": {
6
+ "name": "quadbio"
7
+ },
8
+ "homepage": "https://github.com/quadbio/cell-type-annotation",
9
+ "license": "MIT",
10
+ "dependencies": ["analysis-workflow", "sci-figures"],
11
+ "keywords": ["single-cell", "spatial-transcriptomics", "cell-type-annotation", "cell-ontology", "scverse", "anndata"]
12
+ }
@@ -0,0 +1,20 @@
1
+ name: Lint
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ concurrency:
9
+ group: lint-${{ github.ref }}
10
+ cancel-in-progress: true
11
+
12
+ jobs:
13
+ pre-commit:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+ - uses: actions/setup-python@v6
18
+ with:
19
+ python-version: "3.12"
20
+ - uses: pre-commit/action@v3.0.1
@@ -0,0 +1,72 @@
1
+ name: Release
2
+
3
+ # A version in .claude-plugin/plugin.json without its tag v<version> is unreleased: publish it, then tag it.
4
+ on:
5
+ push:
6
+ branches: [main]
7
+
8
+ concurrency:
9
+ group: release
10
+ cancel-in-progress: false
11
+
12
+ # Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/
13
+ permissions: {}
14
+
15
+ jobs:
16
+ check:
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ outputs:
21
+ version: ${{ steps.version.outputs.version }}
22
+ tagged: ${{ steps.version.outputs.tagged }}
23
+ steps:
24
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
25
+ with:
26
+ persist-credentials: false
27
+ - id: version
28
+ run: |
29
+ version=$(jq -r .version .claude-plugin/plugin.json)
30
+ echo "version=$version" >> "$GITHUB_OUTPUT"
31
+ if git ls-remote --exit-code --tags origin "refs/tags/v$version" > /dev/null; then
32
+ echo "tagged=true" >> "$GITHUB_OUTPUT"
33
+ else
34
+ echo "tagged=false" >> "$GITHUB_OUTPUT"
35
+ fi
36
+
37
+ publish:
38
+ name: Upload release to PyPI
39
+ needs: check
40
+ if: needs.check.outputs.tagged == 'false'
41
+ runs-on: ubuntu-latest
42
+ environment:
43
+ name: pypi
44
+ url: https://pypi.org/p/cell-type-annotation
45
+ permissions:
46
+ contents: read
47
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
48
+ steps:
49
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
50
+ with:
51
+ filter: blob:none
52
+ fetch-depth: 0
53
+ persist-credentials: false
54
+ - name: Install uv
55
+ uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
56
+ with:
57
+ enable-cache: false
58
+ - name: Build package
59
+ run: uv build
60
+ - name: Publish package distributions to PyPI
61
+ uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3: twine 7 reads metadata 2.5
62
+
63
+ tag:
64
+ needs: [check, publish]
65
+ runs-on: ubuntu-latest
66
+ permissions:
67
+ contents: write
68
+ steps:
69
+ - run: gh release create "v$VERSION" --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --title "v$VERSION" --generate-notes
70
+ env:
71
+ GH_TOKEN: ${{ github.token }}
72
+ VERSION: ${{ needs.check.outputs.version }}
@@ -0,0 +1,23 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ concurrency:
9
+ group: test-${{ github.ref }}
10
+ cancel-in-progress: true
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version: ["3.12", "3.14"]
18
+ steps:
19
+ - uses: actions/checkout@v5
20
+ - uses: astral-sh/setup-uv@v6
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ - run: uv run --locked --group dev pytest
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+
7
+ # Data never belongs in this repo
8
+ *.h5ad
9
+ *.zarr/
10
+
11
+ # Claude Code worktrees
12
+ .claude/worktrees/
@@ -0,0 +1,26 @@
1
+ exclude: ^uv\.lock$
2
+
3
+ repos:
4
+ - repo: https://github.com/astral-sh/ruff-pre-commit
5
+ rev: v0.15.19
6
+ hooks:
7
+ - id: ruff-check
8
+ args: [--fix, --exit-non-zero-on-fix]
9
+ - id: ruff-format
10
+
11
+ - repo: https://github.com/tox-dev/pyproject-fmt
12
+ rev: v2.25.0
13
+ hooks:
14
+ - id: pyproject-fmt
15
+
16
+ - repo: https://github.com/pre-commit/pre-commit-hooks
17
+ rev: v6.0.0
18
+ hooks:
19
+ - id: check-json
20
+ - id: check-yaml
21
+ - id: end-of-file-fixer
22
+ - id: mixed-line-ending
23
+ args: [--fix=lf]
24
+ - id: trailing-whitespace
25
+ - id: check-merge-conflict
26
+ - id: detect-private-key
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 quadbio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.5
2
+ Name: cell-type-annotation
3
+ Version: 0.4.2
4
+ Summary: Method routing, evidence checks, label hierarchies and reports for evidence-driven cell-type annotation.
5
+ Project-URL: Source, https://github.com/quadbio/cell-type-annotation
6
+ Author: quadbio
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Python: >=3.12
14
+ Requires-Dist: anndata>=0.12
15
+ Requires-Dist: matplotlib>=3.8
16
+ Requires-Dist: numpy>=2
17
+ Requires-Dist: pandas>=2
18
+ Requires-Dist: scipy
19
+ Description-Content-Type: text/markdown
20
+
21
+ # cell-type-annotation
22
+
23
+ A Claude Code plugin for evidence-driven cell-type annotation of pre-clustered single-cell and spatial
24
+ transcriptomics data. Claude is the annotator:
25
+ - it gathers marker evidence and runs one routed automated cross-check;
26
+ - it reasons level by level down a label hierarchy;
27
+ - the user signs off its assumptions before any label exists;
28
+ - critic subagents try to refute every call.
29
+
30
+ Labels are normalized to Cell Ontology ids. Low-quality, cycling and doublet clusters are flagged on a separate
31
+ state axis. Off-panel genes on targeted spatial panels are treated as unmeasured, never as absent.
32
+
33
+ | Part | What it does |
34
+ | --- | --- |
35
+ | `skills/cell-type-annotation/` | The method: principles, the per-level workflow, and references on methodology, method selection, marker tools and knowledge sources. |
36
+ | `src/cell_type_annotation/` | What task scripts can't get from scanpy or decoupler: cross-check routing, normalization and panel checks, the nested label hierarchy with sibling-restricted marker scoring, the level report, and the annotation-hierarchy figure. |
37
+
38
+ It runs as a task of [analysis-workflow](https://github.com/quadbio/analysis-workflow), which owns the task
39
+ directory, the working object and write-back. The final hierarchy figure follows
40
+ [sci-figures](https://github.com/quadbio/sci-figures).
41
+
42
+ ## Use
43
+
44
+ Inside an analysis-workflow task, ask Claude to annotate a working object's clusters: "what are these clusters?",
45
+ "annotate the leiden clusters".
46
+ - **Inputs:** the working object, with a cluster key, an embedding and a log-normalized layer.
47
+ - **Outputs:** in the task directory:
48
+ - the plan;
49
+ - the signed-off assumptions ledger;
50
+ - the curated markers;
51
+ - evidence tables, and a labels table and Markdown report per level;
52
+ - the hierarchy figure.
53
+ - **Write-back:** after sign-off, one versioned `obs` column per level.
54
+
55
+ It requires the [knowledgebase MCP](https://github.com/biocontext-ai/knowledgebase-mcp). The
56
+ [Zotero MCP](https://github.com/54yyyu/zotero-mcp) is strongly preferred.
57
+
58
+ ## Install
59
+
60
+ The plugin, once per machine, from the [quadbio marketplace](https://github.com/quadbio/claude-plugins); it
61
+ installs analysis-workflow and sci-figures along with it.
62
+
63
+ The PyPI package `cell-type-annotation`, in the analysis repo's `pixi.toml`, next to the scverse stack the task
64
+ scripts use:
65
+
66
+ ```toml
67
+ [pypi-dependencies]
68
+ cell-type-annotation = ">=0.4.2"
69
+ ```
70
+
71
+ Cross-check tools (celltypist, cellmapper, panhumanpy, scvi-tools, scimilarity) are added as a run needs them. Their
72
+ install notes are in `references/method_selection.md`.
73
+
74
+ The last release with the `cta` command line is [v0.3.0](https://github.com/quadbio/cell-type-annotation/tree/v0.3.0).
75
+
76
+ ## Develop
77
+
78
+ ```bash
79
+ uv sync --group dev
80
+ uv run pytest
81
+ uv run pre-commit run --all-files
82
+ claude plugin validate .
83
+ claude --plugin-dir . # try the skill from this checkout; its dependencies installed or loaded too
84
+ ```
85
+
86
+ The routing tables in `references/method_selection.md` are generated; after changing `routing.py`, regenerate them
87
+ (a test fails until you do):
88
+
89
+ ```bash
90
+ uv run python -c "from cell_type_annotation.routing import update_page; \
91
+ update_page('skills/cell-type-annotation/references/method_selection.md')"
92
+ ```
93
+
94
+ For live package edits in an analysis repo, depend on the checkout:
95
+ `cell-type-annotation = { path = "../cell-type-annotation", editable = true }`.
96
+
97
+ ## Release
98
+
99
+ Bump `version` in `.claude-plugin/plugin.json` and merge: the marketplace follows `main`, and users update when the
100
+ version changes. On that merge, `release.yaml` publishes the package to PyPI as `cell-type-annotation`, then tags
101
+ `v<version>` and creates a GitHub Release.
102
+
103
+ ## License
104
+
105
+ MIT
@@ -0,0 +1,85 @@
1
+ # cell-type-annotation
2
+
3
+ A Claude Code plugin for evidence-driven cell-type annotation of pre-clustered single-cell and spatial
4
+ transcriptomics data. Claude is the annotator:
5
+ - it gathers marker evidence and runs one routed automated cross-check;
6
+ - it reasons level by level down a label hierarchy;
7
+ - the user signs off its assumptions before any label exists;
8
+ - critic subagents try to refute every call.
9
+
10
+ Labels are normalized to Cell Ontology ids. Low-quality, cycling and doublet clusters are flagged on a separate
11
+ state axis. Off-panel genes on targeted spatial panels are treated as unmeasured, never as absent.
12
+
13
+ | Part | What it does |
14
+ | --- | --- |
15
+ | `skills/cell-type-annotation/` | The method: principles, the per-level workflow, and references on methodology, method selection, marker tools and knowledge sources. |
16
+ | `src/cell_type_annotation/` | What task scripts can't get from scanpy or decoupler: cross-check routing, normalization and panel checks, the nested label hierarchy with sibling-restricted marker scoring, the level report, and the annotation-hierarchy figure. |
17
+
18
+ It runs as a task of [analysis-workflow](https://github.com/quadbio/analysis-workflow), which owns the task
19
+ directory, the working object and write-back. The final hierarchy figure follows
20
+ [sci-figures](https://github.com/quadbio/sci-figures).
21
+
22
+ ## Use
23
+
24
+ Inside an analysis-workflow task, ask Claude to annotate a working object's clusters: "what are these clusters?",
25
+ "annotate the leiden clusters".
26
+ - **Inputs:** the working object, with a cluster key, an embedding and a log-normalized layer.
27
+ - **Outputs:** in the task directory:
28
+ - the plan;
29
+ - the signed-off assumptions ledger;
30
+ - the curated markers;
31
+ - evidence tables, and a labels table and Markdown report per level;
32
+ - the hierarchy figure.
33
+ - **Write-back:** after sign-off, one versioned `obs` column per level.
34
+
35
+ It requires the [knowledgebase MCP](https://github.com/biocontext-ai/knowledgebase-mcp). The
36
+ [Zotero MCP](https://github.com/54yyyu/zotero-mcp) is strongly preferred.
37
+
38
+ ## Install
39
+
40
+ The plugin, once per machine, from the [quadbio marketplace](https://github.com/quadbio/claude-plugins); it
41
+ installs analysis-workflow and sci-figures along with it.
42
+
43
+ The PyPI package `cell-type-annotation`, in the analysis repo's `pixi.toml`, next to the scverse stack the task
44
+ scripts use:
45
+
46
+ ```toml
47
+ [pypi-dependencies]
48
+ cell-type-annotation = ">=0.4.2"
49
+ ```
50
+
51
+ Cross-check tools (celltypist, cellmapper, panhumanpy, scvi-tools, scimilarity) are added as a run needs them. Their
52
+ install notes are in `references/method_selection.md`.
53
+
54
+ The last release with the `cta` command line is [v0.3.0](https://github.com/quadbio/cell-type-annotation/tree/v0.3.0).
55
+
56
+ ## Develop
57
+
58
+ ```bash
59
+ uv sync --group dev
60
+ uv run pytest
61
+ uv run pre-commit run --all-files
62
+ claude plugin validate .
63
+ claude --plugin-dir . # try the skill from this checkout; its dependencies installed or loaded too
64
+ ```
65
+
66
+ The routing tables in `references/method_selection.md` are generated; after changing `routing.py`, regenerate them
67
+ (a test fails until you do):
68
+
69
+ ```bash
70
+ uv run python -c "from cell_type_annotation.routing import update_page; \
71
+ update_page('skills/cell-type-annotation/references/method_selection.md')"
72
+ ```
73
+
74
+ For live package edits in an analysis repo, depend on the checkout:
75
+ `cell-type-annotation = { path = "../cell-type-annotation", editable = true }`.
76
+
77
+ ## Release
78
+
79
+ Bump `version` in `.claude-plugin/plugin.json` and merge: the marketplace follows `main`, and users update when the
80
+ version changes. On that merge, `release.yaml` publishes the package to PyPI as `cell-type-annotation`, then tags
81
+ `v<version>` and creates a GitHub Release.
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ build-backend = "hatchling.build"
3
+ requires = [ "hatchling" ]
4
+
5
+ [project]
6
+ name = "cell-type-annotation"
7
+ description = "Method routing, evidence checks, label hierarchies and reports for evidence-driven cell-type annotation."
8
+ readme = "README.md"
9
+ license = "MIT"
10
+ authors = [ { name = "quadbio" } ]
11
+ requires-python = ">=3.12"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3 :: Only",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Programming Language :: Python :: 3.14",
17
+ ]
18
+ dynamic = [ "version" ]
19
+ dependencies = [ "anndata>=0.12", "matplotlib>=3.8", "numpy>=2", "pandas>=2", "scipy" ]
20
+ urls.Source = "https://github.com/quadbio/cell-type-annotation"
21
+
22
+ [dependency-groups]
23
+ dev = [ "pre-commit", "pytest" ]
24
+
25
+ [tool.hatch]
26
+ version.path = ".claude-plugin/plugin.json"
27
+ version.pattern = '"version": "(?P<version>[^"]+)"'
28
+ build.targets.wheel.packages = [ "src/cell_type_annotation" ]
29
+
30
+ [tool.ruff]
31
+ line-length = 120
32
+ src = [ "src", "tests" ]
33
+ lint.select = [ "B", "C4", "D", "E", "F", "I", "UP" ]
34
+ lint.ignore = [
35
+ "D100",
36
+ "D104",
37
+ "D105",
38
+ "D107",
39
+ "D203",
40
+ "D213",
41
+ "D401", # docstrings may open with a noun phrase
42
+ ]
43
+ lint.per-file-ignores."tests/*" = [ "D" ]
44
+ lint.pydocstyle.convention = "numpy"
45
+
46
+ [tool.pytest]
47
+ ini_options.testpaths = [ "tests" ]
48
+ ini_options.addopts = [ "--import-mode=importlib" ]
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: cell-type-annotation
3
+ description: >-
4
+ Evidence-driven cell-type annotation of pre-clustered single-cell or spatial transcriptomics data (AnnData). Use
5
+ whenever the user wants to annotate, label or identify the cell types or states of Leiden/Louvain clusters, build or
6
+ refine a cell-type hierarchy, or interpret scRNA-seq / snRNA-seq / MERSCOPE / Xenium / Visium / CosMx clusters,
7
+ even if they just say "what are these clusters?" or "label these cells". Claude is the annotator: it gathers marker
8
+ evidence, runs one routed automated cross-check, reasons level by level down a hierarchy, has the user sign off its
9
+ assumptions and critic subagents try to refute every call. Flags low-quality, cycling and doublet clusters on a
10
+ separate state axis; does not normalize, batch-correct or remove doublets.
11
+ ---
12
+
13
+ # Cell-type annotation
14
+
15
+ Turn existing clusters into a legible, contestable label hierarchy. **You are the annotator**: tools produce
16
+ evidence, you weigh it, and every label rests on numbers a reader can check. Task scripts call scanpy, decoupler and
17
+ the cross-check tools directly; the `cell_type_annotation` package holds only what they lack: routing, checks, the
18
+ label hierarchy, the report and the hierarchy figure.
19
+
20
+ Paths starting with `references/` are in this skill's folder; all others are relative to the task directory.
21
+
22
+ **Elsewhere.**
23
+ - **analysis-workflow** (load it first): an annotation run is one of its tasks. It owns:
24
+ - the task directory and its scripts;
25
+ - reading the working object;
26
+ - write-back with `commit_adata`;
27
+ - environments.
28
+ - **sci-figures:** only for the run's one paper figure, the annotation hierarchy. Intermediate plots are plain scanpy.
29
+ - **Compute and job submission:** the environment's own skill.
30
+
31
+ ## Principles
32
+
33
+ - **Two gates** (`references/methodology.md` §2):
34
+ - **A.** The user signs off the assumptions ledger before the first label exists, and every materially new
35
+ assumption after.
36
+ - **B.** A justified `Unknown` is a result, not a failure.
37
+ - **Every automated call is a hypothesis.** Run exactly one routed cross-check per level, and a second only to break
38
+ a tie. Flag disagreement; never overwrite with it. A bigger model earns one more opinion, not more authority.
39
+ - **Two axes.** A cluster has a type and a state (`normal`, `low-quality`, `cycling`, `doublet`, ...). A cycling
40
+ cluster keeps its type.
41
+ - **Panel-aware.** An off-panel gene is unmeasured, never negative evidence.
42
+ - **Alert, don't fix.**
43
+ - In scope: computing QC metrics and a cell-cycle score, and sub-clustering.
44
+ - Out of scope: normalization, batch correction, doublet detection.
45
+ - **Interactive by default.** A non-interactive run is an explicit opt-in with the gates' answers supplied up front;
46
+ gaps still stop it (`references/methodology.md` §2).
47
+ - **Keep the user oriented.** At each stage and level, say where you are, what comes next, and what will be slow.
48
+
49
+ | File | Covers |
50
+ | --- | --- |
51
+ | `references/methodology.md` | gates, termination, cards, sub-clustering, state axis, critics, panel rules |
52
+ | `references/method_selection.md` | the routing table (generated from code), why, and a recipe per cross-check |
53
+ | `references/marker_tools.md` | between-cluster DE, sibling margins, the curated panel, scores, QC, figures |
54
+ | `references/knowledge_sources.md` | the MCPs, Cell Ontology, atlases, the order to consult |
55
+
56
+ ## What the task directory holds
57
+
58
+ | file | written in | holds |
59
+ | --- | --- | --- |
60
+ | `reports/plan.md` | stages 1-2 | the data, keys, assay and biology as confirmed; covariates; panel capability; hierarchy and vocabulary; routing result |
61
+ | `results/markers.csv` | 2, 3 | signed, sourced curated markers (`read_markers`) |
62
+ | `reports/assumptions.md` | 3 | the Gate A ledger, one block per level, with its sign-off |
63
+ | `results/<table>_<level>.csv` | 3 | evidence: markers, sibling margins, panel detection, negative flags, panel gate, cross-check, QC deviation, confidence |
64
+ | `results/labels_<level>.csv` | 3 | the call and its reasoning (`LABEL_COLUMNS`): the single source of truth |
65
+ | `reports/<level>.md` | 3 | `render_level`: overview, open problems, one card per cluster |
66
+ | `figures/` | 3-4 | quick scanpy plots; the final hierarchy PDF |
67
+
68
+ Resuming: read the task README, `plan.md`, `assumptions.md`, the latest labels table and report; continue from there.
69
+
70
+ ## Workflow
71
+
72
+ At the start, give the user the map: scene-setting, plan, then level by level with a sign-off and a report each,
73
+ and nothing written to their object until the end.
74
+
75
+ ### 1. Scene-setting
76
+ 1. **Tooling gate:** the `knowledgebase` MCP is required: stop and ask for it if missing. `zotero` is preferred.
77
+ Check both respond (`references/knowledge_sources.md`).
78
+ 2. **Inspect** the working object without loading it whole (`obs`, `var`, `obsm` keys, layer stats).
79
+ 3. **Confirm with the user**, pre-filled from the inspection, in two or three batched AskUserQuestion rounds:
80
+ - the cluster key, the embedding to use everywhere, the plotting embedding, and the spatial coordinates;
81
+ - which layer is counts and which is log-normalized (ask, never infer);
82
+ - assay and platform, and for a targeted panel its size;
83
+ - organism, tissue, stage (adult / developmental / organoid) and state (normal / disease / tumour). Stage and
84
+ state cannot be probed from the data;
85
+ - the covariates to show composition over;
86
+ - the label vocabulary (a paper's labels, an ontology, or a free hierarchy with per-level meaning), with CL ids;
87
+ - references: path, label columns, counts or not, gene ids;
88
+ - the write-back key stem.
89
+ 4. **Hard stop on normalization:** `normalization_fingerprint(X_lognorm)`. If it is not `ok`, stop: markers on
90
+ mis-normalized data track depth, not identity. Show the verdict; the user fixes the layer or confirms a
91
+ non-standard normalization.
92
+ 5. **Gene ids:** markers are symbols. For Ensembl `var_names`, switch them in memory to a symbol column
93
+ (`feature_name`, ...; `var_names_make_unique()`) before QC and markers. Without one, map the marker genes via the
94
+ knowledgebase MCP (`bc_get_ensembl_id_from_gene_symbol`).
95
+ 6. **QC and cell cycle**, if absent, computed in memory (`references/marker_tools.md`).
96
+ 7. Write `reports/plan.md`. For a targeted panel, add which expected identities it cannot resolve, because their
97
+ canonical markers are off-panel.
98
+
99
+ ### 2. Plan
100
+ 1. Gather priors in the order of `references/knowledge_sources.md`, and write them to `results/markers.csv` with
101
+ sources.
102
+ 2. Route the cross-check: `routing.evaluate(...)` (`references/method_selection.md`). Record the ranked result.
103
+ 3. Draft the hierarchy and each level's meaning. Present the plan.
104
+
105
+ ### 3. Each level, top-down, within each parent group
106
+ Orient the user each time: "L2 within Neuron: 9 clusters, ~120k cells; scores, one cross-check, the ledger, then a
107
+ report."
108
+ 1. **Markers:** curate this level's candidates in `results/markers.csv`, including negatives. Run `panel_gate`;
109
+ an uncallable candidate contributes to `Unknown`.
110
+ 2. **Evidence**, into `results/` (`references/marker_tools.md`):
111
+ - within-parent `rank_genes_groups` and `filter_rank_genes_groups`;
112
+ - `hierarchy_markers` sibling margins;
113
+ - panel detection and `negative_marker_flags`;
114
+ - scores;
115
+ - `qc_deviation`.
116
+ 3. **Cross-check:** the routed method's recipe, summarized with `prediction_summary`. Its caveat goes into the cards.
117
+ 4. **Gate A:** append the level to `reports/assumptions.md` and get the sign-off (`references/methodology.md` §2).
118
+ 5. **Assign** by filling `results/labels_<level>.csv`:
119
+ - normalize the label to a CL id and set the state;
120
+ - for mutually exclusive co-expression, sub-cluster once and recurse;
121
+ - investigate before `Unknown`;
122
+ - calibrate the confidence against `confidence_proxy`.
123
+ 6. **Critics:** independent subagents read the raw tables, re-derive the markers, fetch an external competing
124
+ hypothesis, and check the label against its parent path. Reconcile; take conflicts you cannot resolve to the user
125
+ (`references/methodology.md` §7).
126
+ 7. **Report:** `render_level(...)` to `reports/<level>.md`; `check_level(labels, clusters)` must return nothing.
127
+ Make quick scanpy plots of the level. Plots beyond the skill's (a trajectory, an old-vs-new comparison) go in a
128
+ report of their own, never into `reports/<level>.md`. Present the flagged clusters and pause: the user approves descending, and
129
+ into which groups. If more than half the clusters are `Unknown`, consult the user first.
130
+
131
+ ### 4. Finish
132
+ 1. **CL ids:** run `bc_get_term_details` on every `cl_id`: it exists, is current, and fits the label. Reconcile with
133
+ the user.
134
+ 2. **Write-back**, following analysis-workflow:
135
+ - one categorical `obs` column per level, keyed `<stem>_L<n>_<version>`, plus `_state` and `_cl_id` companions,
136
+ and any sub-cluster key;
137
+ - every level covers every cell: a group not refined at a level carries its parent's label down;
138
+ - colours in `uns["<key>_colors"]`;
139
+ - `build_hierarchy` over the level keys is the nesting check;
140
+ - `commit_adata` dry run, the user's sign-off on that diff, then `yes=True`.
141
+ 3. **Figure:** the annotation hierarchy, made with sci-figures: `display_markers` picks the canonical markers per
142
+ node, and `pl.annotation_hierarchy` draws them (`references/marker_tools.md`).
143
+ 4. **README:**
144
+ - inputs and the routed method;
145
+ - the write-back keys;
146
+ - which critic objections were declined, and why;
147
+ - anything still provisional.
@@ -0,0 +1,62 @@
1
+ # Knowledge sources
2
+
3
+ Prefer MCP tools; use a Python loader only where no MCP covers the source.
4
+
5
+ ## Requirements
6
+
7
+ - **`knowledgebase` MCP** (BioContextAI, `github.com/biocontext-ai/knowledgebase-mcp`): required. If it is not
8
+ configured, stop and ask the user to set it up; do not degrade to web-only evidence, which is the
9
+ confident-but-unfounded annotation this skill exists to prevent.
10
+ - **`zotero` MCP**: strongly preferred, optional. If missing, say so and use the knowledgebase's Europe PMC tools.
11
+ - Check that whichever are present actually respond before starting.
12
+
13
+ ## Cell Ontology
14
+
15
+ Normalize every final label to a Cell Ontology id (CL), or PCL, the provisional cell ontology, for fine neuronal
16
+ subtypes. Before write-back, call `bc_get_term_details` on every `cl_id`: the term exists, is not obsolete, and its
17
+ name fits the label. Reconcile mismatches with the user. `validate_cl_ids` checks syntax only.
18
+
19
+ ## What the knowledgebase MCP covers
20
+
21
+ - **PanglaoDB** (`bc_get_panglaodb_marker_genes`, `bc_get_panglaodb_options`): human and mouse, broad but shallow,
22
+ frozen around 2020. A coarse prior, never ground truth.
23
+ - **Cell Ontology via OLS4** (`bc_get_cell_ontology_terms`, `bc_search_ontology_terms`,
24
+ `bc_get_term_hierarchical_children`, `bc_get_term_details`): the label → CL normalizer; `ontologies="pcl"` for fine
25
+ neuronal subtypes.
26
+ - **Human Protein Atlas** (`bc_get_human_protein_atlas_info`): per gene, tissue specificity and localization.
27
+ - **Europe PMC** (`bc_get_europepmc_articles`, `bc_get_europepmc_fulltext`): abstracts, open-access full text and
28
+ preprints. Route bioRxiv topic searches here; the bioRxiv tools search by date only.
29
+ - Symbol ↔ Ensembl (`bc_get_ensembl_id_from_gene_symbol`), GO, KEGG, Reactome, STRING, UniProt, Open Targets: marker
30
+ validation and pathway context.
31
+
32
+ ## Zotero first
33
+
34
+ When `zotero` is configured, search it (`zotero_semantic_search`) before anything else: the user's library likely
35
+ holds the key papers for their tissue, it is the highest-trust source, and its full texts are searchable. Cite what
36
+ you use in `results/markers.csv`.
37
+
38
+ ## Loaders without an MCP
39
+
40
+ - **CellTypist model markers**, when a tissue- and stage-matched model exists: `extract_top_markers()` gives priors
41
+ without predicting (`method_selection.md`).
42
+ - **CellMarker 2.0**: the broadest curated, PMID-backed table (CC-BY-4.0 xlsx; the host is flaky, so cache it once).
43
+ - **ScTypeDB** (`ScTypeDB_full.xlsx`): a rare source of negative markers.
44
+ - **CELLxGENE Census**: markers for "type X in tissue Y" from a capped slice with `rank_genes_groups`.
45
+
46
+ ## Reference atlases
47
+
48
+ A curated atlas matching the tissue and context beats any frozen database. Use it twice: compute markers off it
49
+ (`rank_genes_groups` on its labels) as priors, and map the query onto it as the cross-check. Record its path, label
50
+ column(s), whether its `X` is counts, and its gene-id convention at Stage 1. For spatial panels, a platform-matched
51
+ spatial reference is especially useful. Without one, a Census slice keeps a reference cross-check alive, with a
52
+ caveat: Census labels are author-supplied and mixed in quality.
53
+
54
+ ## Order to consult
55
+
56
+ 1. Normalize candidate labels via the Cell Ontology tools.
57
+ 2. Coarse markers from PanglaoDB.
58
+ 3. Per-gene checks in HPA.
59
+ 4. Literature: Zotero, then Europe PMC.
60
+ 5. Data-driven markers from a matched CellTypist model, if one fits.
61
+ 6. Breadth from CellMarker, negatives from ScTypeDB.
62
+ 7. The user's own atlas: markers, and the mapping cross-check.