annotuneagent 0.1.3__tar.gz → 0.1.4__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 (77) hide show
  1. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/CHANGELOG.md +55 -0
  2. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/CITATION.cff +2 -2
  3. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/PKG-INFO +9 -5
  4. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/README.md +8 -4
  5. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/installation.md +3 -2
  6. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/quickstart.md +29 -9
  7. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/tutorials/load_model.ipynb +1 -1
  8. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/tutorials/report.md +10 -9
  9. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/__init__.py +13 -4
  10. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/_version.py +1 -1
  11. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/annotate.py +1 -0
  12. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/arbitrate.py +13 -0
  13. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/evaluate.py +8 -0
  14. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/geo.py +113 -6
  15. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/local_lora.py +23 -18
  16. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/markers.tsv +2 -2
  17. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/workflow.py +401 -23
  18. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_annotate.py +61 -0
  19. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_bugfixes_1111.py +57 -0
  20. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_cli.py +8 -5
  21. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_evaluate.py +34 -0
  22. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_geo.py +67 -0
  23. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_markers.py +9 -0
  24. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_version.py +2 -2
  25. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_workflow.py +477 -25
  26. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/.github/workflows/publish.yml +0 -0
  27. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/.github/workflows/tests.yml +0 -0
  28. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/.gitignore +0 -0
  29. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/.readthedocs.yaml +0 -0
  30. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/LICENSE +0 -0
  31. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/MANIFEST.in +0 -0
  32. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/SECURITY.md +0 -0
  33. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/_static/css/custom.css +0 -0
  34. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/_templates/README.md +0 -0
  35. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/api/index.md +0 -0
  36. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/conf.py +0 -0
  37. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/index.md +0 -0
  38. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/marker_sources.md +0 -0
  39. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/requirements.txt +0 -0
  40. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/tutorials/gse266598_annotation.ipynb +0 -0
  41. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/tutorials/index.md +0 -0
  42. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/docs/tutorials/pbmc8k_annotation.ipynb +0 -0
  43. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/pyproject.toml +0 -0
  44. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/setup.cfg +0 -0
  45. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/__main__.py +0 -0
  46. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/cli.py +0 -0
  47. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/decide.py +0 -0
  48. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/evidence.py +0 -0
  49. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/granularity/__init__.py +0 -0
  50. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/granularity/cl_dag.py +0 -0
  51. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/granularity/ontology_map.py +0 -0
  52. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/granularity/relations.py +0 -0
  53. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/hypotheses.py +0 -0
  54. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/marker_plot.py +0 -0
  55. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/markers.py +0 -0
  56. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/mltools.py +0 -0
  57. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/ontology/cl_isa.json +0 -0
  58. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/ontology/granularity_policy.yaml +0 -0
  59. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/ontology/ontology_map.jsonl +0 -0
  60. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/prepare.py +0 -0
  61. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/py.typed +0 -0
  62. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/read.py +0 -0
  63. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/tokenizer/LICENSE +0 -0
  64. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/tokenizer/merges.txt +0 -0
  65. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/tokenizer/tokenizer.json +0 -0
  66. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/tokenizer/tokenizer_config.json +0 -0
  67. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/tokenizer/vocab.json +0 -0
  68. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent/votes.py +0 -0
  69. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/src/annotuneagent.egg-info/SOURCES.txt +0 -0
  70. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_decide.py +0 -0
  71. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_evidence.py +0 -0
  72. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_granularity.py +0 -0
  73. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_local_lora.py +0 -0
  74. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_mltools.py +0 -0
  75. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_prepare.py +0 -0
  76. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_read.py +0 -0
  77. {annotuneagent-0.1.3 → annotuneagent-0.1.4}/tests/test_votes.py +0 -0
@@ -2,6 +2,61 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## [0.1.4] - 2026-11-16
6
+
7
+ ### Fixed
8
+
9
+ - A cytotoxic mixture that is not fully split stays `review`, with reason
10
+ `cytotoxic_mixture` and a hint that NK and T programs are both enriched.
11
+ `evaluate` scores a workflow record by `written_label`, so that cluster is
12
+ not counted as a marker hit. Pass `prediction_key="annotune_label"` to score
13
+ the labels written on the cells.
14
+ - Child labels of a cytotoxic mixture are written only when every child has a
15
+ label.
16
+ - `annotate` skips a support gene that is absent from the matrix.
17
+ - Adapter ids from `/lora-adapters` are cached only after the name file and
18
+ the ml file are both parsed. A failed read, or a list that does not name
19
+ both adapters, is tried again on the next request. Until then the load
20
+ order is name 0 and ml 1.
21
+
22
+ ### Changed
23
+
24
+ - `evidence_agreement` that is not program-specific stays written. The hint
25
+ is `weak agreement on {label}` and the cluster stays in the review list.
26
+ A one-gene panel cannot meet the specific test, so that agreement is left
27
+ unchanged. When no candidate panel is detected in the majority, the status
28
+ is `out_of_dictionary`, no name is written, and the hint lists genes that
29
+ are high and not in the dictionary panels.
30
+ - A cluster with no title takes a name that is already written on a cluster
31
+ it touches on the UMAP. Connection is the distance between the closest
32
+ cells, within two typical neighbor spacings. The shorter distance wins.
33
+ A name withheld as `out_of_dictionary` is not copied. The hint records the
34
+ neighbor and the distance.
35
+ - A subcluster whose cells all receive one title is dropped. The parent
36
+ keeps that title, and the child ids are not left as unresolved clusters.
37
+ A cytotoxic mixture is left split.
38
+ - A cluster is split when the name model and the ML model name different
39
+ lineages, including one the marker score already named. The split is kept
40
+ only when the children receive more than one title.
41
+ - When no panel is detected and the calls are endothelial cell and pericyte,
42
+ endothelial cell is written if an endothelial gene is enriched and no
43
+ pericyte program gene is. The hint is `endothelial cell rather than pericyte`.
44
+ - Each ranking row records `presence`, the mean fraction of cluster cells
45
+ that express the positive markers. Presence does not choose the name.
46
+ - Every cluster gets an enriched-gene query.
47
+ - `read_geo` stores each GEO characteristic on `obs`. A time point is also
48
+ `obs["day"]`, and a treatment or stimulus is also `obs["treatment"]`. Those
49
+ words are read from the sample title when the record does not name them.
50
+ `obs={...}` adds or replaces sample-level columns with the same syntax as
51
+ `groups`.
52
+ - The docs state that one missing positive gene stays in the panel and scores
53
+ 0. `ANNOTUNE_API_KEY` is documented for a server started with `--api-key`.
54
+ - A cluster whose top marker panel is a specific `mature NK T cell` is named
55
+ as that type. NK and T programs that are both specific still withhold a
56
+ title when another type ranks first.
57
+ - Limb `Schwann cell` uses `MOG`/`Mog` as the oligodendrocyte negative marker.
58
+ `PLP1`/`Plp1` stays off that negative list because Schwann cells express it.
59
+
5
60
  ## [0.1.3] - 2026-11-11
6
61
 
7
62
  ### Added
@@ -17,8 +17,8 @@ authors:
17
17
  orcid: "https://orcid.org/0000-0002-9276-9129"
18
18
  repository-code: "https://github.com/leelieber2025/AnnoTuneAgent"
19
19
  license: Apache-2.0
20
- version: 0.1.3
21
- date-released: "2026-11-11"
20
+ version: 0.1.4
21
+ date-released: "2026-11-16"
22
22
  keywords:
23
23
  - single-cell
24
24
  - RNA-seq
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: annotuneagent
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Cluster-level cell-type annotation from marker, name, and ML results
5
5
  Author-email: "Zhao Li (李钊)" <leelieber@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -75,7 +75,9 @@ call stays auditable.
75
75
 
76
76
  One Qwen3.5-4B base (Q6_K GGUF) is shared by two independent LoRA adapters.
77
77
  The adapters are not merged into the base, so they load together on a single
78
- local `llama-server` and can be replaced without touching the base.
78
+ local `llama-server` and can be replaced without touching the base. If that
79
+ server was started with `--api-key`, set `ANNOTUNE_API_KEY`. The same value
80
+ is sent as a bearer token.
79
81
 
80
82
  | Model | Task it was fine-tuned for | Input | Output |
81
83
  | --- | --- | --- | --- |
@@ -162,7 +164,9 @@ filtered counts. `doublet_chip="10k"` (default) uses 0.8% multiplets per
162
164
  1,000 recovered cells, and `"20k"` uses 0.4%.
163
165
 
164
166
  `geo_info("GSE341410")` lists the samples in a GEO series. `read_geo` then
165
- downloads the ones you name, and `groups` sets the condition in `obs["group"]`.
167
+ downloads the ones you name. `groups` sets `obs["group"]`. Characteristics
168
+ such as day and treatment are stored on `obs`, and `obs={...}` adds columns
169
+ the record does not name.
166
170
  [docs/tutorials/gse266598_annotation.ipynb](docs/tutorials/gse266598_annotation.ipynb)
167
171
  follows one series from the GEO page through annotation.
168
172
 
@@ -214,12 +218,12 @@ The tokenizer is installed with the package. See
214
218
 
215
219
  ## Status
216
220
 
217
- **0.1.3 (Alpha).** Import as `import annotuneagent as ata`.
221
+ **0.1.4 (Alpha).** Import as `import annotuneagent as ata`.
218
222
 
219
223
  ## Citation
220
224
 
221
225
  For the software record, cite the [Zenodo DOI](https://doi.org/10.5281/zenodo.24092828).
222
- Pin the package version used in the analysis, for example `annotuneagent==0.1.3`.
226
+ Pin the package version used in the analysis, for example `annotuneagent==0.1.4`.
223
227
 
224
228
  ## License
225
229
 
@@ -21,7 +21,9 @@ call stays auditable.
21
21
 
22
22
  One Qwen3.5-4B base (Q6_K GGUF) is shared by two independent LoRA adapters.
23
23
  The adapters are not merged into the base, so they load together on a single
24
- local `llama-server` and can be replaced without touching the base.
24
+ local `llama-server` and can be replaced without touching the base. If that
25
+ server was started with `--api-key`, set `ANNOTUNE_API_KEY`. The same value
26
+ is sent as a bearer token.
25
27
 
26
28
  | Model | Task it was fine-tuned for | Input | Output |
27
29
  | --- | --- | --- | --- |
@@ -108,7 +110,9 @@ filtered counts. `doublet_chip="10k"` (default) uses 0.8% multiplets per
108
110
  1,000 recovered cells, and `"20k"` uses 0.4%.
109
111
 
110
112
  `geo_info("GSE341410")` lists the samples in a GEO series. `read_geo` then
111
- downloads the ones you name, and `groups` sets the condition in `obs["group"]`.
113
+ downloads the ones you name. `groups` sets `obs["group"]`. Characteristics
114
+ such as day and treatment are stored on `obs`, and `obs={...}` adds columns
115
+ the record does not name.
112
116
  [docs/tutorials/gse266598_annotation.ipynb](docs/tutorials/gse266598_annotation.ipynb)
113
117
  follows one series from the GEO page through annotation.
114
118
 
@@ -160,12 +164,12 @@ The tokenizer is installed with the package. See
160
164
 
161
165
  ## Status
162
166
 
163
- **0.1.3 (Alpha).** Import as `import annotuneagent as ata`.
167
+ **0.1.4 (Alpha).** Import as `import annotuneagent as ata`.
164
168
 
165
169
  ## Citation
166
170
 
167
171
  For the software record, cite the [Zenodo DOI](https://doi.org/10.5281/zenodo.24092828).
168
- Pin the package version used in the analysis, for example `annotuneagent==0.1.3`.
172
+ Pin the package version used in the analysis, for example `annotuneagent==0.1.4`.
169
173
 
170
174
  ## License
171
175
 
@@ -11,7 +11,7 @@ import annotuneagent as ata
11
11
  print(ata.__version__)
12
12
  ```
13
13
 
14
- The version is set in `src/annotuneagent/_version.py` (currently **0.1.3**).
14
+ The version is set in `src/annotuneagent/_version.py` (currently **0.1.4**).
15
15
 
16
16
  From a checkout:
17
17
 
@@ -45,7 +45,8 @@ The GGUF weights are not in the Python package. Download them from the
45
45
  Hugging Face Hub:
46
46
  [lieberlee/annotune-qwen3.5-4b-gguf](https://huggingface.co/lieberlee/annotune-qwen3.5-4b-gguf).
47
47
  {doc}`tutorials/load_model` shows the download and passes the folder to
48
- `local_models(root)`.
48
+ `local_models(root)`. If the server was started with `--api-key`, set
49
+ `ANNOTUNE_API_KEY` to the same value. It is sent as a bearer token.
49
50
 
50
51
  The package includes the Qwen tokenizer files, the Cell Ontology snapshot, and
51
52
  the reviewed name map. The tokenizer files come from `Qwen/Qwen3.5-4B`
@@ -32,11 +32,19 @@ To start from a GEO series, `ata.geo_info` reads the series record and lists
32
32
  each sample title, accession, and characteristics. It does not download
33
33
  counts. Print that result, choose the samples, and pass the names you want
34
34
  to `ata.read_geo`. `obs["sample"]` stays the GEO title. `obs["group"]` is the
35
- name you pass. Use either column as `batch_key`.
35
+ name you pass. Each characteristic in the GEO record becomes an obs column.
36
+ A time point is also stored in `obs["day"]`, and a treatment or stimulus in
37
+ `obs["treatment"]`. `obs` adds or replaces those columns when the record does
38
+ not name them. Use `sample` or `group` as `batch_key`.
36
39
 
37
40
  ```python
38
41
  info = ata.geo_info("GSE341410")
39
- adata = ata.read_geo(info, samples=["B1", "B3"], groups="B1: control B3: Day7")
42
+ adata = ata.read_geo(
43
+ info,
44
+ samples=["B1", "B3"],
45
+ groups="B1: control B3: Day7",
46
+ obs={"day": "B1: 0 B3: 7", "treatment": "B1: none B3: C&AIA"},
47
+ )
40
48
  adata = ata.prepare(adata, species="mouse", batch_key="sample")
41
49
  ```
42
50
 
@@ -51,7 +59,9 @@ The call above collects the marker score only. To also run the name and ML
51
59
  models, download the weights from the Hub
52
60
  ([lieberlee/annotune-qwen3.5-4b-gguf](https://huggingface.co/lieberlee/annotune-qwen3.5-4b-gguf))
53
61
  and pass them to `run`. {doc}`tutorials/load_model` covers the download, the
54
- `llama-server` install, and remote servers.
62
+ `llama-server` install, and remote servers. If that server was started with
63
+ `--api-key`, set `ANNOTUNE_API_KEY` to the same value. It is sent as a bearer
64
+ token.
55
65
 
56
66
  ```python
57
67
  models = ata.local_models("/path/to/annotune-models")
@@ -196,8 +206,10 @@ panel, not to each gene separately.
196
206
  ### Report fields
197
207
 
198
208
  - `dropped_hypotheses`: each dictionary type left out because none of its
199
- positive markers are in the matrix. One missing positive gene is omitted
200
- and the type stays.
209
+ positive markers are in the matrix. One missing positive gene stays in the
210
+ panel and scores 0, and the type stays. A missing support gene is omitted.
211
+ A missing negative gene stays on the panel, is not scored, and is counted
212
+ as unmeasured for the ML call.
201
213
  - `review`: clusters that still need a look. The order is not an accuracy
202
214
  score.
203
215
  - `annotation_code`: an editable cluster mapping, `fine_order`, a `marker_dict`,
@@ -250,8 +262,14 @@ same way when it has the `batch_key` column.
250
262
  ## How a cluster gets its name
251
263
 
252
264
  A judgment reads the marker score, the name-model result, and the ML-model
253
- result, and writes the title. Doubt is recorded in `annotune_hint` and in
254
- `final_reason` on the record. The title is still written.
265
+ result. It writes a dictionary name, or it leaves the cluster unnamed and
266
+ records why. A hint, when there is one, is stored on `annotune_hint`. The
267
+ record's `final_reason` says why the title was written or withheld.
268
+
269
+ - `cytotoxic_mixture`: the NK panel and the T panel are both specific. The
270
+ cluster stays unnamed so it can be split. A top-ranked `mature NK T cell`
271
+ whose own panel is specific is written as that type. Labels from the split
272
+ are written only when every child cluster has a label.
255
273
 
256
274
  - `no_marker_passed`: none of the name's cited markers passed the expression
257
275
  check. The name stays, the hint reads `no marker passed`, and the dotplot
@@ -269,5 +287,7 @@ result, and writes the title. Doubt is recorded in `annotune_hint` and in
269
287
  the same lineage stays, and the hint names the neighboring cluster. A cluster
270
288
  that touches two lineages is not renamed.
271
289
 
272
- `report["queue"]` lists only clusters with no written title. To find titled
273
- clusters that still carry a question, filter on `annotune_hint`.
290
+ `report["queue"]` lists clusters that still have at least one cell without a
291
+ title. A cluster whose cells are all named, including by a subcluster split,
292
+ is not in `queue`. To find a titled cluster that still carries a question,
293
+ filter on `annotune_hint`.
@@ -204,7 +204,7 @@
204
204
  "source": [
205
205
  "## Remote\n",
206
206
  "\n",
207
- "Use this when one `llama-server` is already running with both adapters, including one started by [AnnoTuneLoader](https://github.com/leelieber2025/AnnoTuneLoader) on another machine. Point both tasks at that server. Each request calls `/completion` and enables one adapter. No local GGUF files are required. Name prompts must fit in 2048 tokens. ML prompts must fit in 8192. Those limits apply when `maxlen` is omitted."
207
+ "Use this when one `llama-server` is already running with both adapters, including one started by [AnnoTuneLoader](https://github.com/leelieber2025/AnnoTuneLoader) on another machine. Point both tasks at that server. Each request calls `/completion` and enables one adapter. The adapter ids come from `/lora-adapters` when one file name contains `name` and another contains `ml`. Until that parse succeeds, name is id 0 and ml is id 1, and the next request asks again. A successful parse is reused for the rest of the process. If the server was started with `--api-key`, set `ANNOTUNE_API_KEY` to the same value. It is sent as a bearer token. No local GGUF files are required. Name prompts must fit in 2048 tokens. ML prompts must fit in 8192. Those limits apply when `maxlen` is omitted."
208
208
  ]
209
209
  },
210
210
  {
@@ -1,8 +1,7 @@
1
1
  # Read the report
2
2
 
3
3
  `run` returns a dictionary and prints a `Queries` block. Each block is one
4
- cluster that still has a question: it has no title, or the title is written
5
- and `hint` is set. AnnoTuneAgent does not send this text to the name model,
4
+ cluster. AnnoTuneAgent does not send this text to the name model,
6
5
  the ML model, or any other service. Copy the paragraph under the heading and
7
6
  paste it into another model.
8
7
 
@@ -71,14 +70,14 @@ title is not a vote count.
71
70
  | `name` | First name copied by the name model. `failed` when the call failed. The action when the reply named nothing |
72
71
  | `ml` | First name copied by the ML model. `escalate` when it abstains. `failed` when the call failed |
73
72
  | `label` | Title written onto the cells. Empty when the cluster stays unnamed |
74
- | `hint` | The question printed after the title. Empty when there is nothing to ask |
75
- | `query` | The paragraph to paste. Present when the cluster is unnamed or `hint` is set |
73
+ | `hint` | The question printed after the title. Empty when there is nothing to ask. Weak agreement keeps its title and puts the doubt here. A name outside the dictionary is not written; this hint lists the unexplained genes. Endothelial cell is written instead of pericyte when an endothelial gene is enriched and no pericyte program gene is; the hint is `endothelial cell rather than pericyte` |
74
+ | `query` | The paragraph to paste. Present for every cluster that has a Wilcoxon table |
76
75
  | `reason` | Why the title was written or withheld |
77
76
  | `ontology` | Cell Ontology id for the written title. `pending` means the id is not a reviewed row |
78
77
 
79
78
  `adata.obs["annotune_label"]` is the title. `adata.obs["annotune_hint"]` is
80
79
  the hint on every cell of that cluster. `adata.obs["annotune_final_status"]`
81
- is `named`, `review`, or `escalate`. Clusters that share a title also share
80
+ is `named`, `review`, `escalate`, or `out_of_dictionary`. Clusters that share a title also share
82
81
  one id in `adata.obs["annotune_cluster"]`. The Leiden column is kept.
83
82
 
84
83
  ## What to read first
@@ -89,13 +88,15 @@ order, not an accuracy score.
89
88
  | Priority | Which clusters |
90
89
  |---|---|
91
90
  | 0 | No title |
92
- | 1 | A conflict, or close marker scores |
91
+ | 1 | A conflict, close marker scores, weak agreement, a name outside the dictionary, or endothelial cell rather than pericyte |
93
92
  | 2 | A model call failed |
94
93
  | 3 | Fewer than 20 cells |
95
94
  | 4 | Any other hint |
96
95
 
97
- `report["queue"]` lists only clusters with no title. A titled cluster with a
98
- hint is in `review`, and on `annotune_hint`, and it is not in `queue`.
96
+ `report["queue"]` lists clusters that still have at least one unlabeled cell.
97
+ A cluster whose cells are all named is not in `queue`, even when that cluster
98
+ has no single title of its own. A titled cluster with a hint is in `review`
99
+ and on `annotune_hint`.
99
100
 
100
101
  ## The rest of the report
101
102
 
@@ -103,7 +104,7 @@ hint is in `review`, and on `annotune_hint`, and it is not in `queue`.
103
104
  |---|---|
104
105
  | `records` | The working record for each cluster, including model rounds and the marker ranking |
105
106
  | `dropped_hypotheses` | Dictionary types left out because none of their positive markers are in the matrix |
106
- | `subclusters` | The second split of a cluster that was not settled. Empty when `subcluster=False` |
107
+ | `subclusters` | One split of a cluster the marker score did not label, of a cytotoxic mixture whose top panel is not a specific mature NK T cell, and of a cluster whose name and ML calls are different lineages when the children receive more than one title. A split whose cells all have one title is dropped. Empty when `subcluster=False` or nothing was split |
107
108
  | `arbitration` | Clusters that were not given the status `named` |
108
109
  | `merged` | Titles that were given one `annotune_cluster` id |
109
110
  | `all_labeled` | True when every cell has a title |
@@ -10,7 +10,10 @@ Recommended usage::
10
10
  records = ata.annotate(adata, cluster_key="leiden", hypotheses=[...])
11
11
  adata = ata.read_10x(base_dir, ["sample_a", "sample_b"])
12
12
  info = ata.geo_info("GSE341410")
13
- adata = ata.read_geo(info, samples=["B1", "B3"], groups="B1: control B3: Day7")
13
+ adata = ata.read_geo(
14
+ info, samples=["B1", "B3"], groups="B1: control B3: Day7",
15
+ obs={"day": "B1: 0 B3: 7", "treatment": "B1: none B3: C&AIA"},
16
+ )
14
17
  prepared = ata.prepare(adata, species="human", batch_key="sample")
15
18
  report = ata.run(
16
19
  prepared, "leiden", species="human",
@@ -21,7 +24,9 @@ Recommended usage::
21
24
  collects three results, the marker score, the name model, and the ML model,
22
25
  then a judgment writes the title to ``annotune_label``. The title is a
23
26
  dictionary name. A cluster can stay unnamed. Uncertain clusters are
24
- subclustered once. The name and ML models run when a ``ModelChain`` is
27
+ subclustered once. A cluster whose NK and T panels are both specific is split
28
+ even when the marker score named it, unless the top panel is a specific
29
+ mature NK T cell. The name and ML models run when a ``ModelChain`` is
25
30
  supplied. The name model copies a cell-type name from the marker dictionary.
26
31
  The ML model is trained on machine-learning measurements of the cluster,
27
32
  differential expression and marker-panel statistics, and copies a name from
@@ -31,10 +36,14 @@ ml adapters. The tokenizer is installed with the package. The server is
31
36
  ``http://127.0.0.1:8080`` unless ``url`` or ``ANNOTUNE_URL`` says otherwise.
32
37
  A matching server is reused. When the process list is unavailable, the check
33
38
  reads ``/props`` and ``/lora-adapters``. ``TaskEndpoint(url=...)`` calls
34
- ``/completion`` on that server and enables one adapter per request.
39
+ ``/completion`` on that server and enables one adapter per request. On a
40
+ server this process did not start, those ids come from the adapter file
41
+ names. Name is id 0 and ml is id 1 until that parse succeeds, and only a
42
+ successful parse is reused.
35
43
  ``attach`` connects to an existing service without loading weights.
36
44
  Model requests wait 600 seconds unless ``timeout`` or ``ANNOTUNE_TIMEOUT``
37
- says otherwise.
45
+ says otherwise. ``ANNOTUNE_API_KEY`` is sent as a bearer token when the
46
+ server was started with ``--api-key``.
38
47
  """
39
48
 
40
49
  from __future__ import annotations
@@ -7,7 +7,7 @@ from __future__ import annotations
7
7
 
8
8
  __all__ = ["__version__", "version", "version_tuple"]
9
9
 
10
- __version__ = "0.1.3"
10
+ __version__ = "0.1.4"
11
11
  version = __version__
12
12
 
13
13
  _parts: list[int | str] = []
@@ -92,6 +92,7 @@ def annotate(
92
92
  support = [
93
93
  evidence_from_stats(gene, "positive", cluster_stats[gene])
94
94
  for gene in hypothesis.support
95
+ if gene in cluster_stats
95
96
  ]
96
97
  required = None
97
98
  if hypothesis.requires_any:
@@ -112,6 +112,17 @@ def program_specific(genes: tuple[GeneEvidence, ...] | list[GeneEvidence]) -> bo
112
112
  return _panel_count(genes, specific=True)
113
113
 
114
114
 
115
+ def panel_presence(genes: tuple[GeneEvidence, ...] | list[GeneEvidence]) -> float:
116
+ """Mean fraction of cluster cells that express the positive markers.
117
+
118
+ A gene absent from the matrix is stored with ``pct_in`` 0 and stays in
119
+ the mean. This is not enrichment, and it does not choose the name.
120
+ """
121
+ if not genes:
122
+ return 0.0
123
+ return sum(float(gene.pct_in) for gene in genes) / len(genes)
124
+
125
+
115
126
  def _panel_count(genes: tuple[GeneEvidence, ...] | list[GeneEvidence], *, specific: bool) -> bool:
116
127
  if len(genes) < 2:
117
128
  return False
@@ -179,6 +190,8 @@ def arbitrate(
179
190
  "score": item.score,
180
191
  "program_on": program_detected(item.positive),
181
192
  "program_specific": program_specific(item.positive),
193
+ "presence": panel_presence(item.positive),
194
+ "n_positive": len(item.positive),
182
195
  "eligible": item.eligible,
183
196
  "lead_genes": [
184
197
  gene.gene for gene in item.positive if gene.pct_in >= 0.25 and gene.logfc >= 1.0
@@ -93,6 +93,11 @@ def evaluate(
93
93
  ``parents`` maps a label to the coarser label that still counts as a match.
94
94
  Sibling types that share a parent do not match each other. When a workflow
95
95
  wrote cell labels, ``prediction_key`` evaluates those final labels.
96
+ A workflow record has ``final_status``. Without ``prediction_key``, the
97
+ score uses ``written_label``, the title that was written, instead of the
98
+ marker ``status``. A record with no written title is uncertain, including
99
+ a cytotoxic mixture that was not written. ``prediction_key`` still scores
100
+ the labels on the cells, including a cluster that was split.
96
101
  ``raw_label_key`` is the author string before alias mapping. With it, a
97
102
  mapped name is the reference only when it wins among all author-labeled
98
103
  cells. An unmapped raw majority is not replaced by a mapped minority.
@@ -120,6 +125,9 @@ def evaluate(
120
125
  record = by_cluster.get(cluster, {"status": "uncertain", "cell_type": None})
121
126
  status = str(record["status"])
122
127
  predicted = record["cell_type"]
128
+ if "final_status" in record and prediction_key is None:
129
+ predicted = record.get("written_label")
130
+ status = "label" if predicted else "uncertain"
123
131
  if prediction_key is not None:
124
132
  labels = adata.obs.loc[groups == cluster, prediction_key]
125
133
  names = labels.dropna().astype(str).unique()
@@ -36,6 +36,9 @@ _WORDS = {
36
36
  "naive": "naive",
37
37
  }
38
38
  _GROUP_KEYS = ("treatment", "condition", "group", "time", "timepoint", "stimulus", "disease")
39
+ _DAY_COLUMNS = {"day", "days", "dpi", "time", "timepoint", "time_point"}
40
+ _TREATMENT_COLUMNS = {"treatment", "treatment_group", "stimulus"}
41
+ _RESERVED_OBS = {"sample", "group", "geo_accession"}
39
42
  _COUNTS = {"matrix.mtx.gz": "mtx", "matrix.h5": "h5"}
40
43
 
41
44
 
@@ -105,6 +108,7 @@ def read_geo(
105
108
  *,
106
109
  samples: Sequence[str] | str | None = None,
107
110
  groups: Mapping[str, str] | str | None = None,
111
+ obs: Mapping[str, Mapping[str, str] | str] | None = None,
108
112
  cache: str | Path | None = None,
109
113
  ) -> AnnData:
110
114
  """Download GEO samples and join their count matrices.
@@ -114,7 +118,12 @@ def read_geo(
114
118
  some of them, pass titles or GSM accessions from that record::
115
119
 
116
120
  info = geo_info("GSE341410")
117
- adata = read_geo(info, samples=["B1", "B3"], groups="B1: control B3: Day7")
121
+ adata = read_geo(
122
+ info,
123
+ samples=["B1", "B3"],
124
+ groups="B1: control B3: Day7",
125
+ obs={"day": "B1: 0 B3: 7", "treatment": "B1: none B3: C&AIA"},
126
+ )
118
127
 
119
128
  ``samples`` may be a list or a string. A comma separates names. One title
120
129
  that contains spaces stays whole; several one-word titles can be separated
@@ -123,7 +132,13 @@ def read_geo(
123
132
  may be the full GEO title. ``obs["sample"]``
124
133
  stays the GEO title. ``obs["group"]`` is your name, or a condition read
125
134
  from the record when one differs between samples, or the title otherwise.
126
- A file already in the cache is not downloaded again.
135
+ Each GEO characteristic is also an obs column. A time point is copied to
136
+ ``obs["day"]``, and a treatment or stimulus to ``obs["treatment"]``. The
137
+ same words are read from a sample title when the record does not name
138
+ them. ``obs`` adds or replaces sample-level columns, with the same dict or
139
+ string syntax as ``groups``. ``sample``, ``group``, and ``geo_accession``
140
+ are not column names for that argument. A file already in the cache is
141
+ not downloaded again.
127
142
  """
128
143
  series, records, meta, root = _open(accession, cache)
129
144
  chosen = _select(series, records, samples)
@@ -137,16 +152,33 @@ def read_geo(
137
152
  flush=True,
138
153
  )
139
154
  labels = _apply_groups(chosen, labels, override)
155
+ extra = _parse_obs(series, obs, records)
140
156
  pieces: dict[str, AnnData] = {}
141
157
  for item in chosen:
142
158
  folder = _materialize(item, root / series)
143
159
  piece = _unique(_read_folder(folder))
144
160
  piece.obs["geo_accession"] = item.gsm
161
+ assigned: dict[str, str] = {}
145
162
  for key, value in item.chars.items():
146
163
  column = _column(key)
147
- if column in ("sample", "group", "geo_accession"):
164
+ if column in _RESERVED_OBS:
148
165
  column = f"geo_{column}"
149
- piece.obs[column] = value
166
+ if column in _DAY_COLUMNS:
167
+ if column != "day":
168
+ _put_obs(piece, assigned, column, value)
169
+ if "day" not in assigned:
170
+ _put_obs(piece, assigned, "day", _day_value(value))
171
+ continue
172
+ _put_obs(piece, assigned, column, value)
173
+ if column in _TREATMENT_COLUMNS and "treatment" not in assigned:
174
+ _put_obs(piece, assigned, "treatment", value)
175
+ for name, text in _factors_from_text(item.title).items():
176
+ if name not in assigned:
177
+ _put_obs(piece, assigned, name, text)
178
+ for column, mapping in extra.items():
179
+ text = _mapped_label(item, mapping)
180
+ if text is not None:
181
+ _put_obs(piece, assigned, column, text)
150
182
  print(
151
183
  f"{item.title}: {piece.shape} {item.gsm} group {labels[item.title]}",
152
184
  flush=True,
@@ -221,6 +253,79 @@ def _column(key: str) -> str:
221
253
  return re.sub(r"[^0-9A-Za-z]+", "_", key.strip().lower()).strip("_")
222
254
 
223
255
 
256
+ def _put_obs(piece: AnnData, assigned: dict[str, str], column: str, value: str) -> None:
257
+ piece.obs[column] = value
258
+ assigned[column] = value
259
+
260
+
261
+ def _parse_obs(
262
+ series: str,
263
+ obs: Mapping[str, Mapping[str, str] | str] | None,
264
+ records: list[_Sample],
265
+ ) -> dict[str, dict[str, str]]:
266
+ """Column name to sample labels. The syntax is the same as ``groups``."""
267
+ if obs is None:
268
+ return {}
269
+ if isinstance(obs, str) or not isinstance(obs, Mapping):
270
+ raise TypeError("obs must map a column name to sample labels")
271
+ parsed: dict[str, dict[str, str]] = {}
272
+ for key, labels in obs.items():
273
+ column = _column(str(key))
274
+ if column in _RESERVED_OBS or not column:
275
+ raise ValueError(f"obs column {key!r} is reserved; use groups for the condition name")
276
+ if column in parsed:
277
+ raise ValueError(f"obs column {column} is repeated")
278
+ mapping = _parse_groups(labels, records)
279
+ _check_groups(series, records, mapping, field="obs")
280
+ parsed[column] = mapping
281
+ return parsed
282
+
283
+
284
+ def _mapped_label(item: _Sample, mapping: Mapping[str, str]) -> str | None:
285
+ if item.title in mapping:
286
+ return mapping[item.title]
287
+ return {key.upper(): value for key, value in mapping.items()}.get(item.gsm.upper())
288
+
289
+
290
+ def _day_value(value: str) -> str:
291
+ text = value.strip()
292
+ timed = _TIME.fullmatch(text)
293
+ if timed:
294
+ return str(int(timed.group(1)))
295
+ if text.isdigit():
296
+ return str(int(text))
297
+ return text
298
+
299
+
300
+ def _factors_from_text(text: str) -> dict[str, str]:
301
+ """Read a day or treatment word from a sample title."""
302
+ tokens = _split(text)
303
+ day = None
304
+ treatment: list[str] = []
305
+ index = 0
306
+ while index < len(tokens):
307
+ token = tokens[index]
308
+ timed = _TIME.fullmatch(token)
309
+ if timed:
310
+ day = str(int(timed.group(1)))
311
+ index += 1
312
+ continue
313
+ if token.lower() == "day" and index + 1 < len(tokens) and tokens[index + 1].isdigit():
314
+ day = str(int(tokens[index + 1]))
315
+ index += 2
316
+ continue
317
+ word = _WORDS.get(token.lower())
318
+ if word:
319
+ treatment.append(word)
320
+ index += 1
321
+ found: dict[str, str] = {}
322
+ if day is not None:
323
+ found["day"] = day
324
+ if treatment:
325
+ found["treatment"] = " ".join(dict.fromkeys(treatment))
326
+ return found
327
+
328
+
224
329
  def _sample_names(samples: Sequence[str] | str, records: list[_Sample] | None = None) -> list[str]:
225
330
  if not isinstance(samples, str):
226
331
  return [str(name).strip() for name in samples if str(name).strip()]
@@ -351,13 +456,15 @@ def _key_at(text: str, name: str) -> list[int]:
351
456
  start = index + 1
352
457
 
353
458
 
354
- def _check_groups(series: str, records: list[_Sample], override: Mapping[str, str]) -> None:
459
+ def _check_groups(
460
+ series: str, records: list[_Sample], override: Mapping[str, str], *, field: str = "groups"
461
+ ) -> None:
355
462
  titles = {item.title for item in records}
356
463
  gsms = {item.gsm.upper() for item in records}
357
464
  unknown = [key for key in override if key not in titles and key.upper() not in gsms]
358
465
  if unknown:
359
466
  known = ", ".join(item.title for item in records)
360
- raise ValueError(f"groups {unknown} are not samples of {series} ({known})")
467
+ raise ValueError(f"{field} {unknown} are not samples of {series} ({known})")
361
468
 
362
469
 
363
470
  def _apply_groups(