cellscreen 0.1.0__py3-none-any.whl
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.
- cellscreen/__init__.py +3 -0
- cellscreen/_bundled/examples/k562_crispr.json +42 -0
- cellscreen/_bundled/examples/tahoe_drugs.json +53 -0
- cellscreen/_bundled/skills/agents/cellscreen/SKILL.md +59 -0
- cellscreen/_bundled/skills/agents/cellscreen/references/reference.md +86 -0
- cellscreen/_bundled/skills/claude/cellscreen/SKILL.md +59 -0
- cellscreen/assets.py +125 -0
- cellscreen/bundled.py +154 -0
- cellscreen/cli.py +513 -0
- cellscreen/constants.py +117 -0
- cellscreen/decoder.py +222 -0
- cellscreen/fanner.py +366 -0
- cellscreen/prompts.py +142 -0
- cellscreen/quantize.py +118 -0
- cellscreen/report.py +1359 -0
- cellscreen/schemas.py +217 -0
- cellscreen/server.py +395 -0
- cellscreen/store.py +313 -0
- cellscreen-0.1.0.dist-info/METADATA +198 -0
- cellscreen-0.1.0.dist-info/RECORD +24 -0
- cellscreen-0.1.0.dist-info/WHEEL +4 -0
- cellscreen-0.1.0.dist-info/entry_points.txt +4 -0
- cellscreen-0.1.0.dist-info/licenses/LICENSE +202 -0
- cellscreen-0.1.0.dist-info/licenses/NOTICE +10 -0
cellscreen/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"run_id": "demo-k562-crispr",
|
|
3
|
+
"title": "K562 Single & Combinatorial CRISPRi Screen",
|
|
4
|
+
"notes": "Demonstrates single-gene and pairwise combinatorial knockdowns hydrated from CellGemma kg_sentences.json.",
|
|
5
|
+
"dataset": "k562",
|
|
6
|
+
"cell_idx": 0,
|
|
7
|
+
"perturbations": [
|
|
8
|
+
{
|
|
9
|
+
"label": "MYC knockdown",
|
|
10
|
+
"modality": "crispr",
|
|
11
|
+
"gene": "MYC",
|
|
12
|
+
"metadata": {
|
|
13
|
+
"pathway": "cell_cycle_transcription"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"label": "TP53 knockdown",
|
|
18
|
+
"modality": "crispr",
|
|
19
|
+
"gene": "TP53",
|
|
20
|
+
"metadata": {
|
|
21
|
+
"pathway": "dna_damage_response"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"label": "MYC + TP53 dual knockdown",
|
|
26
|
+
"modality": "combinatorial",
|
|
27
|
+
"components": [
|
|
28
|
+
{
|
|
29
|
+
"modality": "crispr",
|
|
30
|
+
"gene": "MYC"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"modality": "crispr",
|
|
34
|
+
"gene": "TP53"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"metadata": {
|
|
38
|
+
"pathway": "combinatorial_epistasis"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"run_id": "demo-tahoe-drugs",
|
|
3
|
+
"title": "Tahoe-100M Small-Molecule Pilot Screen",
|
|
4
|
+
"notes": "Example small-molecule panel spanning HDAC, MEK, and proteasomal mechanisms.",
|
|
5
|
+
"dataset": "tahoe",
|
|
6
|
+
"cell_idx": 0,
|
|
7
|
+
"perturbations": [
|
|
8
|
+
{
|
|
9
|
+
"label": "Panobinostat 0.5 uM",
|
|
10
|
+
"modality": "small_molecule",
|
|
11
|
+
"drug_name": "Panobinostat",
|
|
12
|
+
"smiles": "Cc1[nH]c2ccccc2c1CCNCc1ccc(/C=C/C(=O)NO)cc1",
|
|
13
|
+
"concentration": "0.5 uM",
|
|
14
|
+
"metadata": {
|
|
15
|
+
"moa": "HDAC inhibitor",
|
|
16
|
+
"class": "epigenetic"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"label": "Vorinostat 1.0 uM",
|
|
21
|
+
"modality": "small_molecule",
|
|
22
|
+
"drug_name": "Vorinostat",
|
|
23
|
+
"smiles": "O=C(CCCCCCC(=O)Nc1ccccc1)NO",
|
|
24
|
+
"concentration": "1.0 uM",
|
|
25
|
+
"metadata": {
|
|
26
|
+
"moa": "HDAC inhibitor",
|
|
27
|
+
"class": "epigenetic"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"label": "Trametinib 0.1 uM",
|
|
32
|
+
"modality": "small_molecule",
|
|
33
|
+
"drug_name": "Trametinib",
|
|
34
|
+
"smiles": "CC1=C2C(=C(N(C1=O)C)Nc3ccc(cc3F)I)C(=O)N(C(=O)N2c4cccc(c4)NC(=O)C)C5CC5",
|
|
35
|
+
"concentration": "0.1 uM",
|
|
36
|
+
"metadata": {
|
|
37
|
+
"moa": "MEK1/2 inhibitor",
|
|
38
|
+
"class": "kinase"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"label": "Bortezomib 0.05 uM",
|
|
43
|
+
"modality": "small_molecule",
|
|
44
|
+
"drug_name": "Bortezomib",
|
|
45
|
+
"smiles": "B(C(CC(C)C)NC(=O)C(CC1=CC=CC=C1)NC(=O)C2=NC=CN=C2)(O)O",
|
|
46
|
+
"concentration": "0.05 uM",
|
|
47
|
+
"metadata": {
|
|
48
|
+
"moa": "26S proteasome inhibitor",
|
|
49
|
+
"class": "proteostasis"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cellscreen
|
|
3
|
+
description: >-
|
|
4
|
+
Run, resume, inspect and report CellGemma E4B in silico perturbation screens (drugs, CRISPR
|
|
5
|
+
knockdowns, cytokines, combinations) with CellScreen, on Apple MLX or a vLLM GPU server.
|
|
6
|
+
Use when the user wants to start or resume a screen, quantize or serve the model, check run
|
|
7
|
+
progress, rebuild report.html, or take over a run another agent started.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# CellScreen
|
|
11
|
+
|
|
12
|
+
All screen state lives in `runs/<run_id>/` (`manifest.json`, append-only `results.jsonl`,
|
|
13
|
+
`vectors/*.npz`, `report.html`). Any agent can pick up a run at any point.
|
|
14
|
+
|
|
15
|
+
## 1. Check disk and the server first
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv run cellscreen status runs/<run_id> --json
|
|
19
|
+
uv run cellscreen health --json # works for MLX, mock, and vLLM servers
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 2. Make sure a model server is running on port 8410
|
|
23
|
+
|
|
24
|
+
- **Apple Silicon:** quantize once, then serve.
|
|
25
|
+
```bash
|
|
26
|
+
uv run cellscreen quantize --output models/cellgemma-e4b-q8 --recipe ple_q8 # 16 GB Macs
|
|
27
|
+
uv run cellscreen serve --model models/cellgemma-e4b-q8 --port 8410
|
|
28
|
+
```
|
|
29
|
+
Use `--recipe ple_bf16` on 24 GB or more. Never use `uniform` for real screens.
|
|
30
|
+
- **NVIDIA GPU:** run vLLM with the flags in `docs/guide.md`.
|
|
31
|
+
- **Dry run with no model:** `uv run cellscreen serve --mock --port 8410`.
|
|
32
|
+
|
|
33
|
+
## 3. Create or resume the run
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv run cellscreen init runs/<run_id> --from <spec.json>
|
|
37
|
+
uv run cellscreen run runs/<run_id> # resumes; finished items are skipped
|
|
38
|
+
uv run cellscreen run runs/<run_id> --limit 3 # quick pilot
|
|
39
|
+
uv run cellscreen run runs/<run_id> --retry-errors
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Each perturbation generates up to 8,192 tokens and takes minutes (`--timeout` defaults to `1800` s;
|
|
43
|
+
raise it if needed). Pick the decoder (`dataset`) that matches the assay:
|
|
44
|
+
`uv run cellscreen list-decoders`.
|
|
45
|
+
|
|
46
|
+
## 4. Report and hand off
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv run cellscreen report runs/<run_id>
|
|
50
|
+
uv run cellscreen handoff runs/<run_id> --write
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Rules
|
|
54
|
+
|
|
55
|
+
- Never edit `results.jsonl` by hand.
|
|
56
|
+
- Never change the CellGemma preamble or the Gemma 4 turn wrapper.
|
|
57
|
+
- Done means `status --json` shows `pending == 0` and `failed == 0`, or the remaining failures
|
|
58
|
+
are reported to the user with their errors.
|
|
59
|
+
- Perturbation schemas and the decoder list: [reference.md](./references/reference.md).
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# CellScreen Reference Guide
|
|
2
|
+
|
|
3
|
+
## 13 Pretrained CellGemma Stage-2 ExpressionDecoders
|
|
4
|
+
|
|
5
|
+
| Dataset | Modality | Assay / Context |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `tahoe` | `small_molecule` | Tahoe-100M single-cell cancer line chemical screen |
|
|
8
|
+
| `l1000` | `small_molecule` | LINCS L1000 bulk chemical screen |
|
|
9
|
+
| `emeraldbay` | `small_molecule` | Single-cell cancer pharmacology (targeted & combo drugs) |
|
|
10
|
+
| `sciplex` | `small_molecule` | SciPlex 3 single-cell screen (A549, K562, MCF7) |
|
|
11
|
+
| `hepg2` | `crispr` | Nadig/Replogle HepG2 CRISPRi knockdowns |
|
|
12
|
+
| `jurkat` | `crispr` | Nadig/Replogle Jurkat CRISPRi knockdowns |
|
|
13
|
+
| `k562` | `crispr` | Nadig/Replogle K562 CRISPRi knockdowns |
|
|
14
|
+
| `rpe1` | `crispr` | Nadig/Replogle RPE1 CRISPRi knockdowns |
|
|
15
|
+
| `vcc` | `crispr` | Virtual Cell Challenge hESC CRISPR knockdowns |
|
|
16
|
+
| `norman` | `crispr` | Norman single & combinatorial CRISPRa in K562 |
|
|
17
|
+
| `parse` | `cytokine` | Parse 10M PBMC combinatorial cytokine screen |
|
|
18
|
+
| `dong` | `cytokine` | Dong PBMC single/combinatorial cytokine screen |
|
|
19
|
+
| `tisch` | `clinical` | TISCH2 clinical tumor microenvironment cohorts |
|
|
20
|
+
|
|
21
|
+
> **Important:** Pick the decoder whose assay/normalization matches your perturbation modality.
|
|
22
|
+
> Sampling follows the model card: `temperature=0.7`, `max_new_tokens=8192`, stopping on `<eos>` or `<turn|>`.
|
|
23
|
+
|
|
24
|
+
## Perturbation Spec JSON Schemas
|
|
25
|
+
|
|
26
|
+
### Small Molecule
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"label": "Panobinostat 0.5 uM",
|
|
30
|
+
"modality": "small_molecule",
|
|
31
|
+
"drug_name": "Panobinostat",
|
|
32
|
+
"smiles": "Cc1[nH]c2ccccc2c1CCNCc1ccc(/C=C/C(=O)NO)cc1",
|
|
33
|
+
"concentration": "0.5 uM"
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Single CRISPR Knockdown (auto-hydrates from `kg_sentences.json`)
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"label": "MYC knockdown",
|
|
41
|
+
"modality": "crispr",
|
|
42
|
+
"gene": "MYC"
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Cytokine (auto-hydrates from `kg_sentences.json`)
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"label": "IFN-gamma stimulation",
|
|
50
|
+
"modality": "cytokine",
|
|
51
|
+
"gene": "IFNG"
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Clinical Treatment
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"label": "Pembrolizumab",
|
|
59
|
+
"modality": "clinical",
|
|
60
|
+
"treatment": "Pembrolizumab"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Combinatorial Perturbation
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"label": "MYC + TP53 dual knockdown",
|
|
68
|
+
"modality": "combinatorial",
|
|
69
|
+
"components": [
|
|
70
|
+
{ "modality": "crispr", "gene": "MYC" },
|
|
71
|
+
{ "modality": "crispr", "gene": "TP53" }
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Stateless Run Directory Layout
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
runs/<run_id>/
|
|
80
|
+
├── manifest.json # Immutable run spec + content-hashed item_ids
|
|
81
|
+
├── results.jsonl # Append-only fsync'd records (source of truth for resume)
|
|
82
|
+
├── vectors/<item_id>.npz # Full float32 predicted_expr & predicted_lfc arrays
|
|
83
|
+
├── report.html # Offline interactive scientific-editorial HTML report
|
|
84
|
+
├── HANDOFF.md # Optional cross-agent summary (`cellscreen handoff --write`)
|
|
85
|
+
└── .run.lock # OS advisory flock (auto-released on crash/exit)
|
|
86
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cellscreen
|
|
3
|
+
description: >-
|
|
4
|
+
Run, resume, inspect and report CellGemma E4B in silico perturbation screens (drugs, CRISPR
|
|
5
|
+
knockdowns, cytokines, combinations) with CellScreen, on Apple MLX or a vLLM GPU server.
|
|
6
|
+
Use when the user wants to start or resume a screen, quantize or serve the model, check run
|
|
7
|
+
progress, rebuild report.html, or take over a run another agent started.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# CellScreen
|
|
11
|
+
|
|
12
|
+
All screen state lives in `runs/<run_id>/` (`manifest.json`, append-only `results.jsonl`,
|
|
13
|
+
`vectors/*.npz`, `report.html`). Any agent can pick up a run at any point.
|
|
14
|
+
|
|
15
|
+
## 1. Check disk and the server first
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv run cellscreen status runs/<run_id> --json
|
|
19
|
+
uv run cellscreen health --json # works for MLX, mock, and vLLM servers
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 2. Make sure a model server is running on port 8410
|
|
23
|
+
|
|
24
|
+
- **Apple Silicon:** quantize once, then serve.
|
|
25
|
+
```bash
|
|
26
|
+
uv run cellscreen quantize --output models/cellgemma-e4b-q8 --recipe ple_q8 # 16 GB Macs
|
|
27
|
+
uv run cellscreen serve --model models/cellgemma-e4b-q8 --port 8410
|
|
28
|
+
```
|
|
29
|
+
Use `--recipe ple_bf16` on 24 GB or more. Never use `uniform` for real screens.
|
|
30
|
+
- **NVIDIA GPU:** run vLLM with the flags in `docs/guide.md`.
|
|
31
|
+
- **Dry run with no model:** `uv run cellscreen serve --mock --port 8410`.
|
|
32
|
+
|
|
33
|
+
## 3. Create or resume the run
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv run cellscreen init runs/<run_id> --from <spec.json>
|
|
37
|
+
uv run cellscreen run runs/<run_id> # resumes; finished items are skipped
|
|
38
|
+
uv run cellscreen run runs/<run_id> --limit 3 # quick pilot
|
|
39
|
+
uv run cellscreen run runs/<run_id> --retry-errors
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Each perturbation generates up to 8,192 tokens and takes minutes (`--timeout` defaults to `1800` s;
|
|
43
|
+
raise it if needed). Pick the decoder (`dataset`) that matches the assay:
|
|
44
|
+
`uv run cellscreen list-decoders`.
|
|
45
|
+
|
|
46
|
+
## 4. Report and hand off
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv run cellscreen report runs/<run_id>
|
|
50
|
+
uv run cellscreen handoff runs/<run_id> --write
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Rules
|
|
54
|
+
|
|
55
|
+
- Never edit `results.jsonl` by hand.
|
|
56
|
+
- Never change the CellGemma preamble or the Gemma 4 turn wrapper.
|
|
57
|
+
- Done means `status --json` shows `pending == 0` and `failed == 0`, or the remaining failures
|
|
58
|
+
are reported to the user with their errors.
|
|
59
|
+
- Perturbation schemas and the decoder list: `.agents/skills/cellscreen/references/reference.md`.
|
cellscreen/assets.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Hugging Face asset loader and local cache for CellGemma decoders, controls, and KG sentences."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
from huggingface_hub import hf_hub_download
|
|
12
|
+
|
|
13
|
+
from cellscreen.constants import DATASET_REGISTRY, DEFAULT_HF_MODEL_ID
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class ControlCellData:
|
|
18
|
+
"""Baseline control expression and dataset-wide mean-shift prediction."""
|
|
19
|
+
|
|
20
|
+
dataset: str
|
|
21
|
+
cell_idx: int
|
|
22
|
+
genes: list[str]
|
|
23
|
+
ctrl_expr: np.ndarray
|
|
24
|
+
mean_delta: np.ndarray
|
|
25
|
+
baseline: np.ndarray
|
|
26
|
+
cell_metadata: dict[str, Any]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CellGemmaAssetManager:
|
|
30
|
+
"""Downloads and caches CellGemma auxiliary assets (decoders, controls_sample, kg_sentences)."""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
model_id: str = DEFAULT_HF_MODEL_ID,
|
|
35
|
+
cache_dir: str | Path | None = None,
|
|
36
|
+
local_files_only: bool = False,
|
|
37
|
+
) -> None:
|
|
38
|
+
self.model_id = model_id
|
|
39
|
+
self.cache_dir = str(cache_dir) if cache_dir is not None else None
|
|
40
|
+
self.local_files_only = local_files_only
|
|
41
|
+
self._controls_cache: dict[str, Any] | None = None
|
|
42
|
+
self._kg_cache: dict[str, str] | None = None
|
|
43
|
+
self._mean_delta_cache: dict[str, dict[str, float]] = {}
|
|
44
|
+
|
|
45
|
+
def download_file(self, filename: str) -> Path:
|
|
46
|
+
"""Resolve a file from a local model directory or download via Hugging Face Hub."""
|
|
47
|
+
local_candidate = Path(self.model_id) / filename
|
|
48
|
+
if local_candidate.exists():
|
|
49
|
+
return local_candidate
|
|
50
|
+
|
|
51
|
+
path = hf_hub_download(
|
|
52
|
+
repo_id=self.model_id,
|
|
53
|
+
filename=filename,
|
|
54
|
+
cache_dir=self.cache_dir,
|
|
55
|
+
local_files_only=self.local_files_only,
|
|
56
|
+
)
|
|
57
|
+
return Path(path)
|
|
58
|
+
|
|
59
|
+
def load_json(self, filename: str) -> Any:
|
|
60
|
+
path = self.download_file(filename)
|
|
61
|
+
with path.open("r", encoding="utf-8") as fh:
|
|
62
|
+
return json.load(fh)
|
|
63
|
+
|
|
64
|
+
def load_decoder_artifacts(self, dataset: str) -> tuple[dict[str, Any], Path, dict[str, float]]:
|
|
65
|
+
"""Return (decoder_config, weights_safetensors_path, mean_delta_global)."""
|
|
66
|
+
ds = dataset.strip().lower()
|
|
67
|
+
if ds not in DATASET_REGISTRY:
|
|
68
|
+
valid = ", ".join(sorted(DATASET_REGISTRY))
|
|
69
|
+
raise ValueError(f"Unknown dataset decoder '{dataset}'. Valid datasets: {valid}")
|
|
70
|
+
|
|
71
|
+
cfg = self.load_json(f"decoders/{ds}/config.json")
|
|
72
|
+
weights_path = self.download_file(f"decoders/{ds}/model.safetensors")
|
|
73
|
+
mean_deltas = self.load_mean_deltas(ds)
|
|
74
|
+
return cfg, weights_path, mean_deltas
|
|
75
|
+
|
|
76
|
+
def load_mean_deltas(self, dataset: str) -> dict[str, float]:
|
|
77
|
+
ds = dataset.strip().lower()
|
|
78
|
+
if ds not in self._mean_delta_cache:
|
|
79
|
+
raw = self.load_json(f"decoders/{ds}/mean_delta_global.json")
|
|
80
|
+
self._mean_delta_cache[ds] = {k.upper(): float(v) for k, v in raw.items()}
|
|
81
|
+
return self._mean_delta_cache[ds]
|
|
82
|
+
|
|
83
|
+
def load_kg_sentences(self) -> dict[str, str]:
|
|
84
|
+
if self._kg_cache is None:
|
|
85
|
+
raw = self.load_json("kg_sentences.json")
|
|
86
|
+
self._kg_cache = {k.upper(): str(v).strip() for k, v in raw.items()}
|
|
87
|
+
return self._kg_cache
|
|
88
|
+
|
|
89
|
+
def load_controls_all(self) -> dict[str, Any]:
|
|
90
|
+
if self._controls_cache is None:
|
|
91
|
+
self._controls_cache = self.load_json("controls_sample.json")
|
|
92
|
+
return self._controls_cache
|
|
93
|
+
|
|
94
|
+
def load_control_cell(self, dataset: str, cell_idx: int = 0) -> ControlCellData:
|
|
95
|
+
"""Load baseline control expression and mean-shift prediction for a dataset/cell index."""
|
|
96
|
+
ds = dataset.strip().lower()
|
|
97
|
+
controls_all = self.load_controls_all()
|
|
98
|
+
if ds not in controls_all:
|
|
99
|
+
raise KeyError(
|
|
100
|
+
f"Dataset '{ds}' not present in controls_sample.json. "
|
|
101
|
+
f"Available: {', '.join(sorted(controls_all))}"
|
|
102
|
+
)
|
|
103
|
+
ds_controls = controls_all[ds]
|
|
104
|
+
cells = ds_controls["cells"]
|
|
105
|
+
if cell_idx < 0 or cell_idx >= len(cells):
|
|
106
|
+
raise IndexError(
|
|
107
|
+
f"cell_idx={cell_idx} out of range for dataset '{ds}' (0..{len(cells) - 1})"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
genes = [str(g).upper() for g in ds_controls["genes"]]
|
|
111
|
+
cell = cells[cell_idx]
|
|
112
|
+
ctrl_expr = np.asarray(cell["expression"], dtype=np.float32)
|
|
113
|
+
mean_deltas = self.load_mean_deltas(ds)
|
|
114
|
+
mean_vec = np.asarray([mean_deltas.get(g, 0.0) for g in genes], dtype=np.float32)
|
|
115
|
+
baseline = np.maximum(0.0, ctrl_expr + mean_vec)
|
|
116
|
+
cell_meta = {k: v for k, v in cell.items() if k != "expression"}
|
|
117
|
+
return ControlCellData(
|
|
118
|
+
dataset=ds,
|
|
119
|
+
cell_idx=cell_idx,
|
|
120
|
+
genes=genes,
|
|
121
|
+
ctrl_expr=ctrl_expr,
|
|
122
|
+
mean_delta=mean_vec,
|
|
123
|
+
baseline=baseline,
|
|
124
|
+
cell_metadata=cell_meta,
|
|
125
|
+
)
|
cellscreen/bundled.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Locate bundled example screens and agent skills from either an installed wheel or a repo checkout."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
_PKG_DIR = Path(__file__).resolve().parent
|
|
11
|
+
_BUNDLED_DIR = _PKG_DIR / "_bundled"
|
|
12
|
+
_REPO_ROOT = _PKG_DIR.parent.parent
|
|
13
|
+
|
|
14
|
+
EXAMPLE_SPECS: dict[str, tuple[str, str]] = {
|
|
15
|
+
"tahoe": ("tahoe_drugs.json", "4-drug Tahoe-100M small-molecule screen (Panobinostat, Vorinostat, Trametinib, Bortezomib)"),
|
|
16
|
+
"k562": ("k562_crispr.json", "K562 single & combinatorial CRISPRi screen (MYC, TP53, MYC+TP53)"),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def resolve_examples_dir() -> Path:
|
|
21
|
+
"""Return directory containing bundled example JSON specs."""
|
|
22
|
+
bundled = _BUNDLED_DIR / "examples"
|
|
23
|
+
if bundled.is_dir():
|
|
24
|
+
return bundled
|
|
25
|
+
repo = _REPO_ROOT / "examples"
|
|
26
|
+
if repo.is_dir():
|
|
27
|
+
return repo
|
|
28
|
+
raise FileNotFoundError("Bundled examples directory not found in package or repository.")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def resolve_example_path(name: str) -> Path:
|
|
32
|
+
"""Resolve a short example name (e.g. 'tahoe', 'k562') or filename to its JSON file."""
|
|
33
|
+
key = name.strip().lower()
|
|
34
|
+
examples_dir = resolve_examples_dir()
|
|
35
|
+
if key in EXAMPLE_SPECS:
|
|
36
|
+
filename = EXAMPLE_SPECS[key][0]
|
|
37
|
+
candidate = examples_dir / filename
|
|
38
|
+
if candidate.is_file():
|
|
39
|
+
return candidate
|
|
40
|
+
direct = examples_dir / (key if key.endswith(".json") else f"{key}.json")
|
|
41
|
+
if direct.is_file():
|
|
42
|
+
return direct
|
|
43
|
+
valid = ", ".join(sorted(EXAMPLE_SPECS))
|
|
44
|
+
raise KeyError(f"Unknown example '{name}'. Available examples: {valid}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def resolve_skill_source(target: str) -> Path:
|
|
48
|
+
"""Return path to the bundled skill directory for 'claude' or 'agents' (Codex/Antigravity)."""
|
|
49
|
+
if target not in ("claude", "agents"):
|
|
50
|
+
raise ValueError(f"Unsupported skill target: {target}")
|
|
51
|
+
bundled = _BUNDLED_DIR / "skills" / target / "cellscreen"
|
|
52
|
+
if bundled.is_dir():
|
|
53
|
+
return bundled
|
|
54
|
+
repo = (
|
|
55
|
+
_REPO_ROOT / ".claude" / "skills" / "cellscreen"
|
|
56
|
+
if target == "claude"
|
|
57
|
+
else _REPO_ROOT / ".agents" / "skills" / "cellscreen"
|
|
58
|
+
)
|
|
59
|
+
if repo.is_dir():
|
|
60
|
+
return repo
|
|
61
|
+
raise FileNotFoundError(f"Bundled skill directory for '{target}' not found.")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class SkillInstallResult:
|
|
66
|
+
"""Outcome for one agent's global skill installation."""
|
|
67
|
+
|
|
68
|
+
agent: str
|
|
69
|
+
source: Path
|
|
70
|
+
destination: Path
|
|
71
|
+
action: str # "installed" | "would_install" | "skipped"
|
|
72
|
+
note: str = ""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def default_skill_destinations(env: dict[str, str] | None = None) -> list[tuple[str, str, Path]]:
|
|
76
|
+
"""Compute (agent_label, source_key, destination_dir) honoring CLAUDE_CONFIG_DIR & CODEX_HOME."""
|
|
77
|
+
e = env if env is not None else os.environ
|
|
78
|
+
home = Path.home()
|
|
79
|
+
claude_dir = Path(e.get("CLAUDE_CONFIG_DIR") or (home / ".claude")).expanduser()
|
|
80
|
+
codex_dir = Path(e.get("CODEX_HOME") or (home / ".codex")).expanduser()
|
|
81
|
+
agy_dir = home / ".gemini" / "config"
|
|
82
|
+
return [
|
|
83
|
+
("Claude Code", "claude", claude_dir / "skills" / "cellscreen"),
|
|
84
|
+
("Codex", "agents", codex_dir / "skills" / "cellscreen"),
|
|
85
|
+
("Antigravity", "agents", agy_dir / "skills" / "cellscreen"),
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def install_agent_skills(
|
|
90
|
+
*,
|
|
91
|
+
agents: list[str] | None = None,
|
|
92
|
+
force: bool = False,
|
|
93
|
+
dry_run: bool = False,
|
|
94
|
+
env: dict[str, str] | None = None,
|
|
95
|
+
) -> list[SkillInstallResult]:
|
|
96
|
+
"""Copy bundled skills into global Claude Code, Codex, and Antigravity skill directories.
|
|
97
|
+
|
|
98
|
+
Copies instead of symlinking so skills keep working even if installed via ephemeral `uvx`
|
|
99
|
+
or upgraded across virtualenv paths. Refuses to overwrite non-empty existing folders unless
|
|
100
|
+
`force=True`.
|
|
101
|
+
"""
|
|
102
|
+
selected = {a.strip().lower() for a in agents} if agents else None
|
|
103
|
+
results: list[SkillInstallResult] = []
|
|
104
|
+
|
|
105
|
+
for label, src_key, dst in default_skill_destinations(env=env):
|
|
106
|
+
if selected is not None and label.lower().replace(" ", "-") not in selected and src_key not in selected and label.lower().split()[0] not in selected:
|
|
107
|
+
continue
|
|
108
|
+
src = resolve_skill_source(src_key)
|
|
109
|
+
|
|
110
|
+
if dst.exists() or dst.is_symlink():
|
|
111
|
+
if not force:
|
|
112
|
+
results.append(
|
|
113
|
+
SkillInstallResult(
|
|
114
|
+
agent=label,
|
|
115
|
+
source=src,
|
|
116
|
+
destination=dst,
|
|
117
|
+
action="skipped",
|
|
118
|
+
note="already exists (pass --force to replace)",
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
continue
|
|
122
|
+
if not dry_run:
|
|
123
|
+
if dst.is_symlink() or dst.is_file():
|
|
124
|
+
dst.unlink()
|
|
125
|
+
else:
|
|
126
|
+
shutil.rmtree(dst)
|
|
127
|
+
|
|
128
|
+
if dry_run:
|
|
129
|
+
results.append(
|
|
130
|
+
SkillInstallResult(
|
|
131
|
+
agent=label,
|
|
132
|
+
source=src,
|
|
133
|
+
destination=dst,
|
|
134
|
+
action="would_install",
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
continue
|
|
138
|
+
|
|
139
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
140
|
+
shutil.copytree(src, dst)
|
|
141
|
+
if src_key == "claude" and not (dst / "references").exists():
|
|
142
|
+
agents_refs = resolve_skill_source("agents") / "references"
|
|
143
|
+
if agents_refs.is_dir():
|
|
144
|
+
shutil.copytree(agents_refs, dst / "references")
|
|
145
|
+
results.append(
|
|
146
|
+
SkillInstallResult(
|
|
147
|
+
agent=label,
|
|
148
|
+
source=src,
|
|
149
|
+
destination=dst,
|
|
150
|
+
action="installed",
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return results
|