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/store.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"""Stateless filesystem-backed run store enabling zero-friction agent handoff.
|
|
2
|
+
|
|
3
|
+
Run directory layout:
|
|
4
|
+
<run_dir>/
|
|
5
|
+
├── manifest.json # Immutable run definition (RunManifest)
|
|
6
|
+
├── results.jsonl # Append-only, fsync-flushed ScreenResultRecord lines
|
|
7
|
+
├── vectors/ # Full float32 predicted_expr & predicted_lfc arrays (<item_id>.npz)
|
|
8
|
+
├── report.html # Deterministically generated interactive HTML report
|
|
9
|
+
└── .run.lock # OS-managed advisory flock (never stale across crashes)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import contextlib
|
|
15
|
+
import fcntl
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import tempfile
|
|
19
|
+
from collections.abc import Iterator
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
from cellscreen.schemas import (
|
|
25
|
+
PerturbationSpec,
|
|
26
|
+
RunManifest,
|
|
27
|
+
RunStatusSummary,
|
|
28
|
+
ScreenResultRecord,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
MANIFEST_FILENAME = "manifest.json"
|
|
32
|
+
RESULTS_FILENAME = "results.jsonl"
|
|
33
|
+
REPORT_FILENAME = "report.html"
|
|
34
|
+
VECTORS_DIRNAME = "vectors"
|
|
35
|
+
LOCK_FILENAME = ".run.lock"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RunStore:
|
|
39
|
+
"""Stateless reader/writer over a self-contained CellScreen run directory."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, run_dir: str | Path) -> None:
|
|
42
|
+
self.run_dir = Path(run_dir).expanduser().resolve()
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def manifest_path(self) -> Path:
|
|
46
|
+
return self.run_dir / MANIFEST_FILENAME
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def results_path(self) -> Path:
|
|
50
|
+
return self.run_dir / RESULTS_FILENAME
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def report_path(self) -> Path:
|
|
54
|
+
return self.run_dir / REPORT_FILENAME
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def vectors_dir(self) -> Path:
|
|
58
|
+
return self.run_dir / VECTORS_DIRNAME
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def lock_path(self) -> Path:
|
|
62
|
+
return self.run_dir / LOCK_FILENAME
|
|
63
|
+
|
|
64
|
+
def exists(self) -> bool:
|
|
65
|
+
return self.manifest_path.is_file()
|
|
66
|
+
|
|
67
|
+
def init(self, manifest: RunManifest, *, overwrite: bool = False) -> RunManifest:
|
|
68
|
+
"""Create a new run directory and atomically write manifest.json."""
|
|
69
|
+
self.run_dir.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
self.vectors_dir.mkdir(parents=True, exist_ok=True)
|
|
71
|
+
|
|
72
|
+
if self.manifest_path.exists() and not overwrite:
|
|
73
|
+
raise FileExistsError(
|
|
74
|
+
f"Run manifest already exists at {self.manifest_path}. "
|
|
75
|
+
"Use overwrite=True or pick a new run directory."
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
self._atomic_write_text(
|
|
79
|
+
self.manifest_path,
|
|
80
|
+
manifest.model_dump_json(indent=2) + "\n",
|
|
81
|
+
)
|
|
82
|
+
if not self.results_path.exists():
|
|
83
|
+
self.results_path.touch()
|
|
84
|
+
return manifest
|
|
85
|
+
|
|
86
|
+
def load_manifest(self) -> RunManifest:
|
|
87
|
+
if not self.manifest_path.is_file():
|
|
88
|
+
raise FileNotFoundError(f"No CellScreen manifest found at {self.manifest_path}")
|
|
89
|
+
return RunManifest.model_validate_json(self.manifest_path.read_text(encoding="utf-8"))
|
|
90
|
+
|
|
91
|
+
def load_results_raw(self) -> list[ScreenResultRecord]:
|
|
92
|
+
"""Load every valid record in results.jsonl in append order.
|
|
93
|
+
|
|
94
|
+
Tolerates a trailing partial line from a hard kill (SIGKILL/power loss)
|
|
95
|
+
so resume remains safe across interrupted agent sessions.
|
|
96
|
+
"""
|
|
97
|
+
if not self.results_path.is_file():
|
|
98
|
+
return []
|
|
99
|
+
records: list[ScreenResultRecord] = []
|
|
100
|
+
with self.results_path.open("r", encoding="utf-8") as fh:
|
|
101
|
+
for line_no, raw_line in enumerate(fh, start=1):
|
|
102
|
+
line = raw_line.strip()
|
|
103
|
+
if not line:
|
|
104
|
+
continue
|
|
105
|
+
try:
|
|
106
|
+
records.append(ScreenResultRecord.model_validate_json(line))
|
|
107
|
+
except Exception: # noqa: BLE001
|
|
108
|
+
# Only silently skip a truncated final line; malformed middle lines are skipped
|
|
109
|
+
# defensively so one corrupted entry cannot block resuming the rest of the run.
|
|
110
|
+
_ = line_no
|
|
111
|
+
continue
|
|
112
|
+
return records
|
|
113
|
+
|
|
114
|
+
def load_latest_results(self) -> dict[str, ScreenResultRecord]:
|
|
115
|
+
"""Return deduplicated latest record per item_id (an 'ok' record is sticky over older errors)."""
|
|
116
|
+
latest: dict[str, ScreenResultRecord] = {}
|
|
117
|
+
for rec in self.load_results_raw():
|
|
118
|
+
prev = latest.get(rec.item_id)
|
|
119
|
+
if prev is None or prev.status != "ok" or rec.status == "ok":
|
|
120
|
+
latest[rec.item_id] = rec
|
|
121
|
+
return latest
|
|
122
|
+
|
|
123
|
+
def pending_perturbations(
|
|
124
|
+
self,
|
|
125
|
+
*,
|
|
126
|
+
retry_errors: bool = False,
|
|
127
|
+
) -> list[PerturbationSpec]:
|
|
128
|
+
"""Compute exact remaining perturbations from disk state alone (zero in-memory state)."""
|
|
129
|
+
manifest = self.load_manifest()
|
|
130
|
+
latest = self.load_latest_results()
|
|
131
|
+
pending: list[PerturbationSpec] = []
|
|
132
|
+
for spec in manifest.perturbations:
|
|
133
|
+
rec = latest.get(spec.item_id)
|
|
134
|
+
if rec is None or (retry_errors and rec.status == "error"):
|
|
135
|
+
pending.append(spec)
|
|
136
|
+
return pending
|
|
137
|
+
|
|
138
|
+
def append_result(self, record: ScreenResultRecord) -> None:
|
|
139
|
+
"""Append one result record to results.jsonl and fsync immediately.
|
|
140
|
+
|
|
141
|
+
If a prior crash left a partial line without a trailing newline, inserts a newline
|
|
142
|
+
separator first so the new record is never concatenated onto a corrupted fragment.
|
|
143
|
+
"""
|
|
144
|
+
self.run_dir.mkdir(parents=True, exist_ok=True)
|
|
145
|
+
needs_leading_newline = False
|
|
146
|
+
if self.results_path.exists() and self.results_path.stat().st_size > 0:
|
|
147
|
+
with self.results_path.open("rb") as rfh:
|
|
148
|
+
rfh.seek(-1, os.SEEK_END)
|
|
149
|
+
needs_leading_newline = rfh.read(1) != b"\n"
|
|
150
|
+
|
|
151
|
+
prefix = "\n" if needs_leading_newline else ""
|
|
152
|
+
payload = prefix + record.model_dump_json() + "\n"
|
|
153
|
+
with self.results_path.open("a", encoding="utf-8") as fh:
|
|
154
|
+
fh.write(payload)
|
|
155
|
+
fh.flush()
|
|
156
|
+
os.fsync(fh.fileno())
|
|
157
|
+
|
|
158
|
+
def save_vectors(
|
|
159
|
+
self,
|
|
160
|
+
item_id: str,
|
|
161
|
+
genes: list[str],
|
|
162
|
+
ctrl_expr: np.ndarray,
|
|
163
|
+
baseline: np.ndarray,
|
|
164
|
+
predicted_expr: np.ndarray,
|
|
165
|
+
predicted_lfc: np.ndarray,
|
|
166
|
+
) -> str:
|
|
167
|
+
"""Atomically persist full continuous expression & LFC vectors for one item."""
|
|
168
|
+
self.vectors_dir.mkdir(parents=True, exist_ok=True)
|
|
169
|
+
rel_path = f"{VECTORS_DIRNAME}/{item_id}.npz"
|
|
170
|
+
target = self.run_dir / rel_path
|
|
171
|
+
fd, tmp_name = tempfile.mkstemp(prefix=f".{item_id}.", suffix=".npz", dir=self.vectors_dir)
|
|
172
|
+
os.close(fd)
|
|
173
|
+
try:
|
|
174
|
+
np.savez_compressed(
|
|
175
|
+
tmp_name,
|
|
176
|
+
genes=np.asarray(genes, dtype="<U32"),
|
|
177
|
+
ctrl_expr=ctrl_expr.astype(np.float32),
|
|
178
|
+
baseline=baseline.astype(np.float32),
|
|
179
|
+
predicted_expr=predicted_expr.astype(np.float32),
|
|
180
|
+
predicted_lfc=predicted_lfc.astype(np.float32),
|
|
181
|
+
)
|
|
182
|
+
os.replace(tmp_name, target)
|
|
183
|
+
except Exception:
|
|
184
|
+
if os.path.exists(tmp_name):
|
|
185
|
+
os.unlink(tmp_name)
|
|
186
|
+
raise
|
|
187
|
+
return rel_path
|
|
188
|
+
|
|
189
|
+
def load_vectors(self, item_id: str) -> dict[str, np.ndarray]:
|
|
190
|
+
path = self.vectors_dir / f"{item_id}.npz"
|
|
191
|
+
if not path.is_file():
|
|
192
|
+
raise FileNotFoundError(f"Vector archive not found: {path}")
|
|
193
|
+
with np.load(path, allow_pickle=False) as data:
|
|
194
|
+
return {k: data[k] for k in data.files}
|
|
195
|
+
|
|
196
|
+
def status(self) -> RunStatusSummary:
|
|
197
|
+
"""Derive a complete stateless status snapshot from manifest.json + results.jsonl."""
|
|
198
|
+
manifest = self.load_manifest()
|
|
199
|
+
latest = self.load_latest_results()
|
|
200
|
+
completed = 0
|
|
201
|
+
failed_ids: list[str] = []
|
|
202
|
+
pending_ids: list[str] = []
|
|
203
|
+
|
|
204
|
+
for spec in manifest.perturbations:
|
|
205
|
+
rec = latest.get(spec.item_id)
|
|
206
|
+
if rec is None:
|
|
207
|
+
pending_ids.append(spec.item_id)
|
|
208
|
+
elif rec.status == "ok":
|
|
209
|
+
completed += 1
|
|
210
|
+
else:
|
|
211
|
+
failed_ids.append(spec.item_id)
|
|
212
|
+
|
|
213
|
+
total = len(manifest.perturbations)
|
|
214
|
+
return RunStatusSummary(
|
|
215
|
+
run_dir=str(self.run_dir),
|
|
216
|
+
run_id=manifest.run_id,
|
|
217
|
+
title=manifest.title,
|
|
218
|
+
dataset=manifest.dataset,
|
|
219
|
+
total=total,
|
|
220
|
+
completed=completed,
|
|
221
|
+
failed=len(failed_ids),
|
|
222
|
+
pending=len(pending_ids),
|
|
223
|
+
is_complete=(completed == total and total > 0),
|
|
224
|
+
report_exists=self.report_path.is_file(),
|
|
225
|
+
pending_ids=pending_ids,
|
|
226
|
+
failed_ids=failed_ids,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
def render_handoff_markdown(self) -> str:
|
|
230
|
+
"""Render a concise cross-agent handoff brief from current disk state."""
|
|
231
|
+
manifest = self.load_manifest()
|
|
232
|
+
summary = self.status()
|
|
233
|
+
latest = self.load_latest_results()
|
|
234
|
+
ok_records = [r for r in latest.values() if r.status == "ok"]
|
|
235
|
+
ok_records.sort(key=lambda r: r.max_abs_lfc, reverse=True)
|
|
236
|
+
|
|
237
|
+
lines = [
|
|
238
|
+
f"# CellScreen Handoff — `{manifest.run_id}`",
|
|
239
|
+
"",
|
|
240
|
+
f"- **Run Directory:** `{self.run_dir}`",
|
|
241
|
+
f"- **Dataset / Decoder:** `{manifest.dataset}` (control cell `{manifest.cell_idx}`)",
|
|
242
|
+
f"- **Server URL:** `{manifest.server_url}`",
|
|
243
|
+
f"- **Progress:** {summary.completed}/{summary.total} completed, {summary.failed} failed, {summary.pending} pending",
|
|
244
|
+
f"- **HTML Report:** {'present (`report.html`)' if summary.report_exists else 'not generated yet'}",
|
|
245
|
+
"",
|
|
246
|
+
"## Next Command (Stateless Resume)",
|
|
247
|
+
"```bash",
|
|
248
|
+
f"uv run cellscreen run {self.run_dir}",
|
|
249
|
+
"```",
|
|
250
|
+
]
|
|
251
|
+
if summary.failed > 0:
|
|
252
|
+
lines += [
|
|
253
|
+
"",
|
|
254
|
+
"To retry failed items:",
|
|
255
|
+
"```bash",
|
|
256
|
+
f"uv run cellscreen run {self.run_dir} --retry-errors",
|
|
257
|
+
"```",
|
|
258
|
+
]
|
|
259
|
+
if ok_records:
|
|
260
|
+
lines += [
|
|
261
|
+
"",
|
|
262
|
+
"## Top Perturbations So Far (by max |LFC|)",
|
|
263
|
+
"| Label | Modality | +DEGs | -DEGs | Max |LFC| | Top Up | Top Down |",
|
|
264
|
+
"| --- | --- | ---: | ---: | ---: | --- | --- |",
|
|
265
|
+
]
|
|
266
|
+
for rec in ok_records[:10]:
|
|
267
|
+
top_u = ", ".join(g.gene for g in rec.top_up[:3]) or "—"
|
|
268
|
+
top_d = ", ".join(g.gene for g in rec.top_down[:3]) or "—"
|
|
269
|
+
lines.append(
|
|
270
|
+
f"| {rec.label} | {rec.modality} | {rec.n_up} | {rec.n_down} | "
|
|
271
|
+
f"{rec.max_abs_lfc:.3f} | {top_u} | {top_d} |"
|
|
272
|
+
)
|
|
273
|
+
return "\n".join(lines) + "\n"
|
|
274
|
+
|
|
275
|
+
@contextlib.contextmanager
|
|
276
|
+
def acquire_lock(self, *, non_blocking: bool = True) -> Iterator[None]:
|
|
277
|
+
"""Acquire an OS-level advisory flock so two agents don't double-dispatch the same run."""
|
|
278
|
+
self.run_dir.mkdir(parents=True, exist_ok=True)
|
|
279
|
+
fh = self.lock_path.open("a+", encoding="utf-8")
|
|
280
|
+
flags = fcntl.LOCK_EX | (fcntl.LOCK_NB if non_blocking else 0)
|
|
281
|
+
try:
|
|
282
|
+
fcntl.flock(fh.fileno(), flags)
|
|
283
|
+
except BlockingIOError as exc:
|
|
284
|
+
fh.close()
|
|
285
|
+
raise RuntimeError(
|
|
286
|
+
f"Another CellScreen worker holds the lock on {self.run_dir}. "
|
|
287
|
+
"Wait for it to finish or inspect progress with `cellscreen status`."
|
|
288
|
+
) from exc
|
|
289
|
+
try:
|
|
290
|
+
fh.seek(0)
|
|
291
|
+
fh.truncate()
|
|
292
|
+
fh.write(json.dumps({"pid": os.getpid()}) + "\n")
|
|
293
|
+
fh.flush()
|
|
294
|
+
yield
|
|
295
|
+
finally:
|
|
296
|
+
try:
|
|
297
|
+
fcntl.flock(fh.fileno(), fcntl.LOCK_UN)
|
|
298
|
+
finally:
|
|
299
|
+
fh.close()
|
|
300
|
+
|
|
301
|
+
@staticmethod
|
|
302
|
+
def _atomic_write_text(path: Path, content: str) -> None:
|
|
303
|
+
fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=path.parent)
|
|
304
|
+
try:
|
|
305
|
+
with os.fdopen(fd, "w", encoding="utf-8") as fh:
|
|
306
|
+
fh.write(content)
|
|
307
|
+
fh.flush()
|
|
308
|
+
os.fsync(fh.fileno())
|
|
309
|
+
os.replace(tmp_name, path)
|
|
310
|
+
except Exception:
|
|
311
|
+
if os.path.exists(tmp_name):
|
|
312
|
+
os.unlink(tmp_name)
|
|
313
|
+
raise
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cellscreen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Run in silico perturbation screens with CellGemma E4B on Apple MLX or a vLLM GPU server
|
|
5
|
+
Project-URL: Homepage, https://github.com/ayushgml/cellscreen
|
|
6
|
+
Project-URL: Repository, https://github.com/ayushgml/cellscreen
|
|
7
|
+
Project-URL: Documentation, https://github.com/ayushgml/cellscreen/blob/main/docs/guide.md
|
|
8
|
+
Project-URL: Changelog, https://github.com/ayushgml/cellscreen/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/ayushgml/cellscreen/issues
|
|
10
|
+
Author: CellScreen Contributors
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Keywords: apple-silicon,bioinformatics,cellgemma,mlx,perturbation-screening,single-cell,transcriptomics
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Requires-Dist: fastapi>=0.115.0
|
|
27
|
+
Requires-Dist: httpx>=0.28.0
|
|
28
|
+
Requires-Dist: huggingface-hub>=0.29.0
|
|
29
|
+
Requires-Dist: mlx-lm>=0.24.0; sys_platform == 'darwin' and platform_machine == 'arm64'
|
|
30
|
+
Requires-Dist: mlx>=0.25.0; sys_platform == 'darwin' and platform_machine == 'arm64'
|
|
31
|
+
Requires-Dist: numpy>=1.26.0
|
|
32
|
+
Requires-Dist: pydantic>=2.10.0
|
|
33
|
+
Requires-Dist: rich>=13.9.0
|
|
34
|
+
Requires-Dist: safetensors>=0.5.0
|
|
35
|
+
Requires-Dist: typer>=0.15.0
|
|
36
|
+
Requires-Dist: uvicorn>=0.34.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.25.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest>=8.3.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<img src="https://raw.githubusercontent.com/ayushgml/cellscreen/main/assets/logo.svg" width="112" alt="CellScreen logo">
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
<h1 align="center">CellScreen</h1>
|
|
48
|
+
|
|
49
|
+
<p align="center">
|
|
50
|
+
Run in silico perturbation screens with
|
|
51
|
+
<a href="https://huggingface.co/google/cellgemma-e4b">CellGemma E4B</a>
|
|
52
|
+
on your own Mac or on any NVIDIA GPU.
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<a href="https://pypi.org/project/cellscreen/"><img alt="PyPI" src="https://img.shields.io/pypi/v/cellscreen?color=2F5BD3"></a>
|
|
57
|
+
<a href="https://github.com/ayushgml/cellscreen/blob/main/LICENSE"><img alt="License: Apache 2.0" src="https://img.shields.io/badge/license-Apache%202.0-2F5BD3"></a>
|
|
58
|
+
<img alt="Python 3.11+" src="https://img.shields.io/badge/python-3.11%2B-2F5BD3">
|
|
59
|
+
<img alt="Backends: MLX and vLLM" src="https://img.shields.io/badge/backends-MLX%20%7C%20vLLM-7A8AA0">
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
You describe a panel of perturbations in a JSON file: drugs, CRISPR knockdowns, cytokines or
|
|
63
|
+
combinations of them. CellScreen asks CellGemma how a cell's transcriptome responds to each
|
|
64
|
+
one, decodes the answer into predicted expression and log-fold changes for every gene, and
|
|
65
|
+
writes everything to a folder you can resume, share or open as an interactive report.
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<img src="https://raw.githubusercontent.com/ayushgml/cellscreen/main/assets/report-preview.png" width="860" alt="CellScreen report for a four-drug pilot screen: summary figures, a rank-salience plot, top up- and down-regulated genes, and a cross-perturbation heatmap">
|
|
69
|
+
</p>
|
|
70
|
+
|
|
71
|
+
## Features
|
|
72
|
+
|
|
73
|
+
- **Runs where you are.** Use Apple MLX on an Apple Silicon Mac (16 GB is enough), or point
|
|
74
|
+
it at a vLLM server on an NVIDIA GPU, including a Google Colab VM driven from the terminal.
|
|
75
|
+
- **Faithful to the model card.** Prompts use CellGemma's exact preamble, section order and
|
|
76
|
+
Gemma 4 turn format, and the 13 pretrained Stage-2 decoders reconstruct full expression and
|
|
77
|
+
LFC vectors in plain NumPy.
|
|
78
|
+
- **Quantization that keeps the model intact.** `cellscreen quantize` compresses attention and
|
|
79
|
+
MLP weights to 4-bit but keeps Gemma 4's Per-Layer Embeddings at 8-bit or bf16.
|
|
80
|
+
- **Resumable by design.** All state lives in the run folder. Stop, restart, move machines or
|
|
81
|
+
switch coding agents, and `cellscreen run` picks up where it stopped.
|
|
82
|
+
- **An offline report.** One self-contained HTML file with a rank-salience plot, a
|
|
83
|
+
cross-perturbation heatmap, a sortable table and CSV and JSON export.
|
|
84
|
+
- **Agent skills included.** Run `cellscreen install-skills` to install bundled skills for
|
|
85
|
+
Claude Code, Codex and Antigravity without cloning the repo.
|
|
86
|
+
|
|
87
|
+
## Install
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# uv (recommended)
|
|
91
|
+
uv tool install cellscreen
|
|
92
|
+
|
|
93
|
+
# pip
|
|
94
|
+
pip install cellscreen
|
|
95
|
+
|
|
96
|
+
# Homebrew (macOS)
|
|
97
|
+
brew install ayushgml/tap/cellscreen
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or try it immediately with zero setup using the bundled mock backend and example panel:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
cellscreen serve --mock --port 8410 &
|
|
104
|
+
cellscreen init runs/demo --example tahoe
|
|
105
|
+
cellscreen run runs/demo
|
|
106
|
+
open runs/demo/report.html
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Install the bundled coding-agent skills (Claude Code, Codex, Antigravity) globally:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
cellscreen install-skills
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### On an Apple Silicon Mac
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
cellscreen quantize --output models/cellgemma-e4b-q8 --recipe ple_q8 # once, 15.6 GB download
|
|
119
|
+
cellscreen serve --model models/cellgemma-e4b-q8 --port 8410
|
|
120
|
+
cellscreen init runs/tahoe-pilot --example tahoe
|
|
121
|
+
cellscreen run runs/tahoe-pilot
|
|
122
|
+
open runs/tahoe-pilot/report.html
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Use `--recipe ple_bf16` instead if your Mac has 24 GB or more.
|
|
126
|
+
|
|
127
|
+
### On an NVIDIA GPU
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install vllm cellscreen
|
|
131
|
+
vllm serve google/cellgemma-e4b --served-model-name google/cellgemma-e4b \
|
|
132
|
+
--max-model-len 12992 --max-num-seqs 4 --max-num-batched-tokens 4096 \
|
|
133
|
+
--gpu-memory-utilization 0.95 --enforce-eager --port 8410
|
|
134
|
+
cellscreen init runs/tahoe-pilot --example tahoe
|
|
135
|
+
cellscreen run runs/tahoe-pilot --concurrency 2
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
These flags fit a 24 GB L4. The [guide](https://github.com/ayushgml/cellscreen/blob/main/docs/guide.md#run-on-an-nvidia-gpu-with-vllm)
|
|
139
|
+
explains them and shows how to run on Google Colab without opening a browser.
|
|
140
|
+
|
|
141
|
+
## Measured performance
|
|
142
|
+
|
|
143
|
+
Each perturbation generates up to the 8,192 tokens the model card recommends.
|
|
144
|
+
|
|
145
|
+
| Setup | Model | Time per perturbation | Memory |
|
|
146
|
+
| --- | --- | --- | --- |
|
|
147
|
+
| Apple M4, 16 GB, MLX | `ple_q8` checkpoint (5.9 GB) | 360–430 s (43 s when stopping early) | 7.2 GB peak |
|
|
148
|
+
| NVIDIA L4, 24 GB, vLLM | bf16 original | about 520 s; 4 in 17 min at concurrency 2 | 14.6 GB weights |
|
|
149
|
+
|
|
150
|
+
The 8-bit Mac checkpoint tracks the full-precision model closely across all four pilot drugs:
|
|
151
|
+
same-drug predicted log-fold changes correlate at `r = 0.74–0.92` (mean `0.85`) across 19,720
|
|
152
|
+
genes against the bf16 GPU run, compared to `0.21–0.51` between different drugs.
|
|
153
|
+
|
|
154
|
+
## Documentation
|
|
155
|
+
|
|
156
|
+
- [Guide](https://github.com/ayushgml/cellscreen/blob/main/docs/guide.md): installing, choosing hardware, writing screens, reading results, troubleshooting
|
|
157
|
+
- [Perturbation schemas and decoders](https://github.com/ayushgml/cellscreen/blob/main/.agents/skills/cellscreen/references/reference.md)
|
|
158
|
+
- [Agent contract](https://github.com/ayushgml/cellscreen/blob/main/AGENTS.md): how coding agents should work with run folders
|
|
159
|
+
- [Changelog](https://github.com/ayushgml/cellscreen/blob/main/CHANGELOG.md)
|
|
160
|
+
|
|
161
|
+
## Commands
|
|
162
|
+
|
|
163
|
+
| Command | What it does |
|
|
164
|
+
| --- | --- |
|
|
165
|
+
| `cellscreen quantize` | Convert CellGemma to a PLE-safe MLX checkpoint |
|
|
166
|
+
| `cellscreen serve` | Start the local MLX server (`--mock` for a model-free dry run) |
|
|
167
|
+
| `cellscreen health` | Check a local MLX or vLLM server and its status |
|
|
168
|
+
| `cellscreen list-decoders` | List the 13 Stage-2 decoders |
|
|
169
|
+
| `cellscreen examples` | List or inspect bundled example screen JSONs (`tahoe`, `k562`) |
|
|
170
|
+
| `cellscreen init` | Create a run folder from `--from <file>` or `--example <name>` |
|
|
171
|
+
| `cellscreen run` | Run or resume pending perturbations and refresh the report |
|
|
172
|
+
| `cellscreen status` | Show progress and top genes from disk |
|
|
173
|
+
| `cellscreen report` | Rebuild `report.html` |
|
|
174
|
+
| `cellscreen handoff` | Write a short summary for another agent |
|
|
175
|
+
| `cellscreen install-skills` | Install bundled skills for Claude Code, Codex, and Antigravity |
|
|
176
|
+
|
|
177
|
+
## Development
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
git clone https://github.com/ayushgml/cellscreen.git
|
|
181
|
+
cd cellscreen
|
|
182
|
+
uv sync --extra dev
|
|
183
|
+
uv run pytest
|
|
184
|
+
uv run ruff check src tests
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Contributions are welcome. Open an issue to discuss larger changes first.
|
|
188
|
+
|
|
189
|
+
## License and attribution
|
|
190
|
+
|
|
191
|
+
CellScreen is licensed under the [Apache License 2.0](https://github.com/ayushgml/cellscreen/blob/main/LICENSE). It downloads CellGemma E4B and
|
|
192
|
+
its decoders from [`google/cellgemma-e4b`](https://huggingface.co/google/cellgemma-e4b), which
|
|
193
|
+
Google publishes under Apache 2.0; no model weights are included in this repository.
|
|
194
|
+
CellScreen is an independent project, not affiliated with or endorsed by Google or Google
|
|
195
|
+
DeepMind.
|
|
196
|
+
|
|
197
|
+
CellGemma predictions are statistical hypotheses for research use. Validate them
|
|
198
|
+
experimentally; they are not intended for clinical diagnosis or patient care.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
cellscreen/__init__.py,sha256=Jnn4Xg5Xkx61UZAt0nUHIunkHzE2aPUz9qsXaMBxRFw,108
|
|
2
|
+
cellscreen/assets.py,sha256=lw8IIcnEXdjhY5uSRXnM8GuqTv7wdq9jxXXhvlZotNk,4870
|
|
3
|
+
cellscreen/bundled.py,sha256=8KMgcSpm49Cr2IKbxbm4rupSvIJ8i5b1u2vT3UmGT4w,5595
|
|
4
|
+
cellscreen/cli.py,sha256=B5s-s6rT8cQ3OtoVNr3qkft8y2MK3x-sVVBpzoECZsk,19719
|
|
5
|
+
cellscreen/constants.py,sha256=mpWc24zYoqt0O8R8aMtZGX3ocwZRsFDbBc0EmccfFH0,4434
|
|
6
|
+
cellscreen/decoder.py,sha256=phIeAXaY8-V0M3FKYq_gSPBYVbvzuDdfn0rJjWjllEo,8465
|
|
7
|
+
cellscreen/fanner.py,sha256=tvizSRzdpMtXDQQ-ArmD3IzXm1_VQ1aYguUQeg4E-zM,14327
|
|
8
|
+
cellscreen/prompts.py,sha256=N9mFqqigrq9T1iWzKd_ioRtA3cNwfBzWNjLr12vlJJ8,5129
|
|
9
|
+
cellscreen/quantize.py,sha256=z5zaQiucA2u06vcPpjyzvEj3JS_BOS7uyNRbB5ABWF4,4072
|
|
10
|
+
cellscreen/report.py,sha256=yhY-aCtywZMFtix7qCgH7bYMneXAET6GtENS3up223I,50989
|
|
11
|
+
cellscreen/schemas.py,sha256=6_ERiaakF-sAeOKrynGu8Eikh2hStjLXywjNvPMSJg4,7550
|
|
12
|
+
cellscreen/server.py,sha256=iauK-MjbZtWG-GGdG-3_SEgRWhlW2REtu6PMGBoNqjY,14040
|
|
13
|
+
cellscreen/store.py,sha256=py7a-ckbnTPR1xbsI_67qDjlv5wTLIfCTndzWbOrqCg,12150
|
|
14
|
+
cellscreen/_bundled/examples/k562_crispr.json,sha256=BkIHSgTAJdQ0Mmo1AU0qLYZ0Du7XokYtbcHFDmqu_f4,958
|
|
15
|
+
cellscreen/_bundled/examples/tahoe_drugs.json,sha256=FORRn-j06herBoDCxlY5y3FGOi2Mt6_SsWhB2YQngkA,1502
|
|
16
|
+
cellscreen/_bundled/skills/agents/cellscreen/SKILL.md,sha256=FaNPK-liX4Oyo-NpcBUZXw2-EG_xEV8m2O5GKoP_wUc,2247
|
|
17
|
+
cellscreen/_bundled/skills/agents/cellscreen/references/reference.md,sha256=EqX2YaeZ9Yf2GTuT58mMRyPtUZlTYhrN5vX2Ik1ihtM,2796
|
|
18
|
+
cellscreen/_bundled/skills/claude/cellscreen/SKILL.md,sha256=QQRynbvyxP7rwUg9bkYSnenYrg6-N_JR3wx4g_Dep2A,2257
|
|
19
|
+
cellscreen-0.1.0.dist-info/METADATA,sha256=LpznQLaUzC3FifGwpp_0ptLKKv_KvKBBq8CrIwjf9Qg,8906
|
|
20
|
+
cellscreen-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
21
|
+
cellscreen-0.1.0.dist-info/entry_points.txt,sha256=5R4df2C7A6OuVxqoaLRSpx7ebrkx4gXHtMkI0R0mKEg,133
|
|
22
|
+
cellscreen-0.1.0.dist-info/licenses/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
|
23
|
+
cellscreen-0.1.0.dist-info/licenses/NOTICE,sha256=LWxYWBeCB6zDCHZIFlPeqIT6zWiRiKjFv6xrW9Huw9M,474
|
|
24
|
+
cellscreen-0.1.0.dist-info/RECORD,,
|