Skip to content

Feat/task 029x spatial exploration - #36

Merged
nceglia merged 7 commits into
mainfrom
feat/task-029x-spatial-exploration
May 6, 2026
Merged

Feat/task 029x spatial exploration#36
nceglia merged 7 commits into
mainfrom
feat/task-029x-spatial-exploration

Conversation

@nceglia

@nceglia nceglia commented May 6, 2026

Copy link
Copy Markdown
Owner

adding notebooks for looking at spatial signaling identification.

nceglia and others added 7 commits April 28, 2026 01:59
Adds genevector.benchmarks.synthetic with the layout-only subset of
grafiti's synthetic generator. Preserves the (df, marker_assignments)
return contract and create_anndata_from_synthetic conversion. Strips
preprocessing and plotting helpers.

Substrate for TASK 027 (diagnostic overlay) and TASK 028 (spatial bench
harness).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds apply_overlay() and build_pathology() under
genevector.benchmarks.synthetic. Overlay extends var_names with 5
paracrine L/R pairs, 5 niche genes, 3 T-rare distinguishing genes,
and 5 housekeeping controls (23 total). Splits T cells into
T_stromal / T_intratumoral / T_rare by local tumor density;
preserves coarse label in obs["phenotype_coarse"].

Ground-truth dict (JSON-serializable) records all gene categories,
their source/target phenotypes, niche coupling parameters, and
T-subtype cell counts. Schema versioned at "1.0".

Substrate for TASK 028 (harness) and TASK 029 (eval).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds genevector.benchmarks.spatial — a config-driven runner that trains
GeneVector on the synthetic pathology FOV across {mi, pearson, spearman,
graph_xcorr, graph_xcorr_shuffled}. Each run writes its embedding,
metadata (target, graph_variant, epochs_run, final_loss, wall time, n_genes,
n_cells), and a per-seed manifest under benchmarks_artifacts/spatial/.

The shuffled variant uses a degree-preserving randomization
(networkx.double_edge_swap) to provide a structure-free graph_xcorr
control. The spatial graph itself is built via squidpy's k-NN
spatial_neighbors and symmetrized (squidpy's k-NN connectivities are
asymmetric).

Includes a CLI (scripts/run_spatial_benchmark.py) with a --quick smoke
mode and 7 tests covering config defaults, variant resolution, graph
symmetry, degree-preserving shuffle, and an end-to-end run across all
five variants. The full FOV1 run is gated behind pytest.mark.slow.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds evaluate_gene_pair_recovery, evaluate_phenotype_typing, and
evaluate_ablation. Reads embeddings from TASK 028 artifacts and
produces ROC-AUC for gene-pair recovery (paracrine, niche,
housekeeping) plus macro-F1 + per-class F1 for phenotype assignment.

Ablation summary computes deltas between graph_xcorr (real),
graph_xcorr_shuffled, and mi baseline — answers whether the spatial
structure or the target form drives gains.

Includes report writer (Markdown tables, mean ± std across seeds)
and CLI at scripts/run_spatial_eval.py.

Sub-task 029b: fix --quick flag in run_spatial_benchmark.py to be a
defaults-preset rather than a cap; --quick --epochs N now respects N.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds example/spatial_benchmark_exploration.py — #%%-cell script that
loads existing TASK 028 artifacts and walks through eval results with
inline prose explaining what's working (niche AUC) and what isn't
(paracrine AUC < 0.5, T_rare F1 = 0). Includes diagnostics for
embedding collapse, marker dict construction, and per-cell
phenotype probabilities.

Tool for understanding TASK 029 results before iterating on the eval.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds Cell 0 constants (RETRAIN, ARTIFACTS_ROOT, SEED, TRAIN_OVERRIDES)
and a new Cell 2 that calls run_benchmark() directly when RETRAIN=True,
so users can iterate on hyperparameters without leaving the notebook.
Renumbers downstream cells (3..12); updates inline cell references in
the T_rare hypothesis markdown.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Two fixes for CI test collection on the spatial benchmark suite:

- layout.py used PEP 604 union syntax (`int | None`) at runtime in a
  function default; add `from __future__ import annotations` so it parses
  on Python 3.9.
- _build_spatial_graph imported squidpy, which is not a runtime dep and
  not installed in CI. Replace with sklearn.neighbors.kneighbors_graph
  (already a runtime dep) and symmetrize via union — same semantics.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nceglia
nceglia merged commit 142e0df into main May 6, 2026
4 checks passed
@nceglia
nceglia deleted the feat/task-029x-spatial-exploration branch May 6, 2026 16:17
@nceglia
nceglia restored the feat/task-029x-spatial-exploration branch May 7, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant