A Cell Is Not an Empty Test Tube
A gene knockout doesn't have one universal answer. Cell state, lineage, and baseline expression all change the response, and a global average can look sensible while missing exactly the cells that matter.
cellcontext generates controlled expression profiles with shared perturbation effects plus context-specific interactions, then holds out whole context-perturbation pairs, so the benchmark can't reward memorization.
Keep the Context, Keep the Signal
The baseline learns one average effect per perturbation. The context-aware method finds the most similar observed cellular context and transfers its residual response instead.
It's deliberately far smaller than a single-cell foundation model. The mechanism stays visible, the failure mode stays measurable, and the whole experiment runs on the Python standard library.
The Number
Global averaging lands at 0.2699 mean absolute error. Context-aware transfer lands at 0.1813, a 32.8% reduction on held-out context-perturbation pairs. The benchmark is synthetic and explicitly non-clinical.
"Nearest Context" Was Nearest Array Index
The similarity step was min(abs(cc - c)): the context whose integer index sat closest to the test context's index. That only looked like similarity because the synthetic generator builds the interaction term as a straight line in context index. Real cell types, donors, and tissues come with no such ordering, so the 32.8% was reading a property of the generator, not demonstrating context transfer.
So I shuffled each context's latent identity away from its index, which is the situation any real dataset is in. The index method didn't just stop helping. It went backwards: 27.7% worse than plain averaging across 30 tuning seeds, and 35.5% worse on a disjoint 20-seed holdout, evaluated once.
The fix computes similarity from the training data: two contexts are near if their observed effects agree on the perturbations both have been measured for. On shuffled contexts it holds a 31.5% reduction on the tuning seeds and 30.1% on the holdout, and on the original unshuffled data it scores 33.9%, slightly better than the number it replaces. The original module is untouched, so the published 32.8% still reproduces exactly. 10 tests pass on GitHub Actions across Python 3.9 through 3.13.
Research Basis
Inspired by Nature Methods' 2025 perturbation-response benchmark. Every number on this page comes from this repository's own controlled benchmark, not from the paper.
Try It
Standard library only:
git clone https://github.com/ahmeddoghri/cellcontext && cd cellcontext
python cellcontext.py # the published 32.8%
python cellcontext_v2.py # data-driven similarity on the same data: 33.9%
python eval_v2.py # shuffled contexts: index -27.7%, data-driven +31.5%