Skip to content

feat: regional-plot backend (cis_associations, ld_r2, JSON endpoints)#25

Open
boxiangliu wants to merge 3 commits into
mainfrom
feat/plot-backend
Open

feat: regional-plot backend (cis_associations, ld_r2, JSON endpoints)#25
boxiangliu wants to merge 3 commits into
mainfrom
feat/plot-backend

Conversation

@boxiangliu

Copy link
Copy Markdown
Contributor

What

The backend for the LocusZoom-style regional plot (design: #23 / docs/design/gene-page-visualizations.md). No UI — the Plotly frontend waits for the design sign-off.

  • repository.py: cis_associations (all cis variants for a gene × tissue), ld_r2 (r² to a lead from the 1000G LD tables — symmetric-pair UNION, rsID↔int bridge, skips non-rs/NA), tissues_with_signal (for the future body map); _ld_table with chrom/population whitelists.
  • viz.py: frozen LocusZoom LD color scheme + −log₁₀(p) helper.
  • web.py: GET /api/gene/{key}/regional and GET /api/ld.

Why

Pure data plumbing, no design decisions → safe to build while Liu Fei reviews the design. When she signs off, wiring the Plotly frontend is quick.

How it was tested

ruff / mypy --strict / pytest green; 100% coverage; hermetic (fake repo + fake DB connection). Verified live (read-only): TP53 → 5,442 variants with r² to the lead in ~0.5s; the /api/gene/.../regional endpoint returns correctly (LD partners coloured, non-partners grey = no-LD).

Note re the LD index (issue for @gaojunbin)

The design flagged a covering index as a perf need, but the live LD query ran in 0.2s without it — so it's a nice-to-have, not urgent.

Checklist

  • CI green; 100% coverage; no test weakening
  • No secrets (DB creds via env only)
  • Feature branch + PR (touches no templates → engineer review, not design)

Backend half of the LocuszoomZ-style regional plot (design in #23). No UI yet —
the Plotly frontend waits for Liu Fei's design sign-off.

- repository.py: cis_associations() (all cis variants for a gene in one tissue),
  ld_r2() (r² to a lead from the 1000G LD tables; symmetric-pair UNION, rsID<->int
  bridge, NA/non-rs skipping), tissues_with_signal() (drives the future body map);
  _ld_table() with chrom/pop whitelists.
- viz.py: frozen LocusZoom LD color scheme (r2_color / ld_legend) + neg_log10_p.
- web.py: GET /api/gene/{key}/regional (variants + r² to default lead) and
  GET /api/ld (r² map for click-to-recolor).
- 100% coverage, mypy strict. Verified live: TP53 -> 5442 variants + r² in ~0.5s.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closes #27. Wires the #25 backend into the gene page as a LocusZoom-style Plotly
plot, styled to Liu Fei's mockup (#23).

- gene.html: blue/slate palette; tissue + LD-population selectors; a Plotly
  scattergl of position vs −log10(p) colored by r² (first paint from
  /api/gene/{key}/regional); click a point to re-pick the lead (/api/ld,
  client-side re-color); genome-wide-significance line; LD legend + caveat.
- viz.py: lead marker -> orange #f97316 (per Liu Fei), was purple.
- web.py: gene page passes the tissue list to the selector.
- Template-render tested; 100% coverage. Verified live: /gene/TP53 renders the
  plot UI with 25 real tissues.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
feat: regional plot frontend — Plotly Locus View on the gene page (#27)
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.

2 participants