Repository navigation
OncoPrint: the gene legend's No alterations, and Not profiled only when a cell is - #451
Conversation
…en a cell is As the portal's genetic rule set: its always rule (the grey cell) is listed as "No alterations" whenever a gene cell is profiled, and its NA rule as "Not profiled" only when some gene cell is not; both last, in that order (legend order infinity, then by label). Ours listed no "No alterations" and always "Not profiled". glyphPresence notes profiled / notProfiled cells; geneLegend lists the two by them (the label is the style's unalteredLabel). Python's glyph_presence and gene_legend alike; its figure now reads every gene code, not only altered ones. The server SVG puts "Derived event" before the two, wherever they are. Tests: test/oncoprint-gene-legend.test.ts GL1-GL4 (5 failing before), python/tests/test_gene_legend.py, oncoprint-style's legend lists. Golden SVG updated (No alterations, one more legend row). Browser: coadread KRAS TP53 ends "Deep Deletion · No alterations" (every cell profiled, no Not profiled); msk_impact_2017 KRAS TP53 NEGR1 adds "Not profiled"; no console errors. npm test and Python pass. Planted bugs: gene-legend-tail.ts (2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Coverage (#451): lib/oncoprint-svg.ts's Derived event insertion before the legend's closing No alterations / Not profiled was run by no unit test. The fixture with a derived-event row: Derived event, then No alterations, then Not profiled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
| gene_cells = np.concatenate([np.asarray(t.cells) for t in c.tracks if t.kind == "gene"] or [np.zeros(0, dtype=np.int32)]) | ||
| present = glyph_presence(np.unique(gene_cells[gene_cells > 0]), S) | ||
| present = glyph_presence(np.unique(gene_cells), S) | ||
| handles = [Patch(color=color, label=label) for label, color, kind in gene_legend(S, present)] |
There was a problem hiding this comment.
The Python legend draws every entry as a solid Patch(color=...), and kind is ignored. "Not profiled" is coloured notProfiled.stripe.color (#bebebe) and the new "No alterations" is palette.unaltered (#bebebe), so whenever both are listed (any study with a gene off some panel) the matplotlib figure shows two identical solid grey squares. Before this PR only one of them was listed. Draw kind == "notProfiled" with the paper fill and the stripe, as the SVG and React legends do, for example with a white Patch plus a hatch or edgecolor.
| const items: { label: string; color: string; kind: string }[] = geneLegend(S, glyphPresence(contract.tracks as { kind: string; cells: ArrayLike<number> }[], S)); | ||
| if (contract.tracks.some((t) => t.kind === "derivedEvent")) items.splice(items.length - 1, 0, { label: "Derived event", color: P.derived, kind: "swatch" }); | ||
| if (contract.tracks.some((t) => t.kind === "derivedEvent")) { | ||
| const tail = items.findIndex((it) => it.label === S.glyph.unalteredLabel || it.kind === "notProfiled"); |
There was a problem hiding this comment.
The renderers now order "Derived event" differently. The SVG inserts it before "No alterations"/"Not profiled", but the React legend (app/_oncoprint/OncoprintFigure.tsx:1191) and the Python figure (python/cohortlab/render.py:215) still append it after geneLegend, so it lands after "No alterations"/"Not profiled" there. The figure, the server SVG and the Python port no longer agree, which breaks invariant 8, and the PR body says it goes before them "wherever they fall". A simpler fix is to have geneLegend take a derived flag and place the entry itself, so no renderer splices.
| items.push({ label: G.notProfiled.label, color: G.notProfiled.stripe.color, kind: "notProfiled" }); | ||
| // last, as the portal's (both at legend order infinity, then by label): the grey cell whenever a cell is profiled, | ||
| // and Not profiled only when some cell is not | ||
| if (!present || present.profiled) items.push({ label: G.unalteredLabel, color: S.palette.unaltered, kind: "swatch" }); |
There was a problem hiding this comment.
With whiteBackground, styleForDisplay sets palette.unaltered to #ffffff, so this entry becomes a white square with no border on a white legend, in the React (sw(it.color)), SVG and Python legends alike. The label "No alterations" then has no visible swatch next to it. Consider an outline or stroke for this entry, or check what legacy draws in white-background mode.
| export interface GlyphPresence { bits: number; mutDriver: number; mutVus: number; svDriver: boolean; svVus: boolean; germline?: boolean } | ||
| export interface GlyphPresence { bits: number; mutDriver: number; mutVus: number; svDriver: boolean; svVus: boolean; germline?: boolean; | ||
| /** some gene cell is profiled (the portal's always rule, "No alterations", is used), and some is not ("Not profiled") */ | ||
| profiled?: boolean; notProfiled?: boolean } |
There was a problem hiding this comment.
profiled / notProfiled are optional and read as truthy checks, so a GlyphPresence built without them (any hand-built or older presence object, or a Python dict without the keys read via .get) silently drops both "No alterations" and "Not profiled" from the legend. They are always computed, so making them required booleans (initialised false in glyphPresence, as the Python does) would let the type checker catch a missed site.
| const items: { label: string; color: string; kind: string }[] = geneLegend(S, glyphPresence(contract.tracks as { kind: string; cells: ArrayLike<number> }[], S)); | ||
| if (contract.tracks.some((t) => t.kind === "derivedEvent")) items.splice(items.length - 1, 0, { label: "Derived event", color: P.derived, kind: "swatch" }); | ||
| if (contract.tracks.some((t) => t.kind === "derivedEvent")) { | ||
| const tail = items.findIndex((it) => it.label === S.glyph.unalteredLabel || it.kind === "notProfiled"); |
There was a problem hiding this comment.
Finding the tail by it.label === S.glyph.unalteredLabel is fragile. A glyph option whose label matches, or a style override that renames it, misplaces "Derived event". Giving the entry its own kind (e.g. "unaltered"), as "Not profiled" has "notProfiled", makes this a kind check and lets renderers style it, for example with an outline in white-background mode.
| if (t.kind !== "gene") continue; | ||
| const cs = t.cells; | ||
| for (let i = 0; i < cs.length; i++) { const c = cs[i]; if (c > 0) seen.add(c); } | ||
| for (let i = 0; i < cs.length; i++) { const c = cs[i]; if (c > 0) seen.add(c); if (c >= 0) out.profiled = true; else if (c === -1) out.notProfiled = true; } |
There was a problem hiding this comment.
Minor: this adds two branches and a property write for every gene cell (every column x gene, the hot path for big studies) on every legend render, and it keeps writing out.profiled = true after both flags are known. Since c > 0 cells are already collected, you could track profiled/notProfiled with locals and skip the checks once both are set, or derive them per track (e.g. cs.indexOf(-1)).
|
Review: changes requested (head 1aeff48; reviewed 43f204f, plus 1aeff48, which only adds a unit case) Blocking:
Checked and fine:
Nits (see inline):
|
…ne place for Derived event Review fixes (#451). The portal counts its always rule ("No alterations") as used whenever a gene row is drawn, even with every cell not profiled; ours dropped it there, and the tests and comments said so. glyphPresence / glyph_presence now note a gene row (`genes`), not a profiled cell. Derived event is listed by geneLegend itself, before the closing No alterations and Not profiled, so the canvas, the server SVG and the Python figure agree (the canvas and Python put it last). "No alterations" is its own legend kind, drawn with an edge in the not-profiled line's colour, so it shows on a white background. Tests: GL1 every cell not profiled lists both; no gene row, neither; GL3 Derived event before the two (geneLegend and the SVG); Python the same. Golden SVG updated (the swatch's edge). npm test and Python pass; browser coadread / msk_impact_2017 as before. Planted bugs: the no-unaltered one now drops it with a cell not profiled; onc-legend-derived-last added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
| present = {**glyph_presence(np.unique(gene_cells), S), "genes": any(t.kind == "gene" for t in c.tracks), | ||
| "derived": any(t.kind == "derivedEvent" for t in c.tracks)} | ||
| edge = S["glyph"]["notProfiled"]["stripe"]["color"] | ||
| handles = [Patch(facecolor=color, edgecolor=edge if kind == "unaltered" else color, label=label) for label, color, kind in gene_legend(S, present)] |
There was a problem hiding this comment.
nit: still two identical grey squares in the Python legend. "No alterations" is now #bebebe with a #bebebe edge, and "Not profiled" is a solid Patch in the stripe colour (#bebebe), so the two look the same. The screen and SVG draw Not profiled as white with a grey midline; a hatch or a white face with the stripe-coloured edge would tell them apart here.
| layer: "counts", | ||
| guard: "unit", | ||
| file: "lib/oncoprint-style.ts", | ||
| effect: "Derived event is listed after Not profiled, where the screen and the SVG put it before the closing two.", |
There was a problem hiding this comment.
nit: this mutant deletes the Derived event line from geneLegend, so the entry disappears from the legend altogether rather than moving after Not profiled. GL3 still catches it, but the effect text should say "Derived event is missing from the gene legend" (or the mutant should move the push below the closing two to match the description).
|
Re-review (7bcadea): pass The earlier blocking finding is fixed:
From the earlier nits:
CI: coverage, lint, gate-local, gate-warehouse and reports pass. planted-bugs and gate-e2e were still pending at review time. |
Summary
The OncoPrint gene legend ends as the portal's does (ONC-GL-6), from its genetic rule set (geneticrules.ts 300-306 and 405-410) and oncoprintjs's legend:
alwaysrule as used.Where:
lib/oncoprint-style.ts:glyphPresencenotes profiled / not-profiled cells, andgeneLegendlists the two entries by them. The label is the style'sunalteredLabel, so renderers define nothing of their own (invariant 8).python/cohortlab/style.py:glyph_presence/gene_legendalike. The Python figure (render.py) now passes every gene code, not only altered ones.lib/oncoprint-svg.ts: "Derived event" goes before the two entries, wherever they fall.Spec IDs
Covered: ONC-GL-6.
Verification
Unit:
test/oncoprint-gene-legend.test.tsGL1-GL4 (5 failed before the change);python/tests/test_gene_legend.py, the same cases;test/oncoprint-style.test.ts's legend lists updated. The golden SVG is updated: the "No alterations" entry and one more legend row.npm test: 6821 pass, 0 fail.npm run test:python: OK.Browser (dev server):
KRAS TP53: the legend ends "Deep Deletion · No alterations". Every cell is profiled, so there's no "Not profiled", where we listed it before.KRAS TP53 NEGR1(NEGR1 isn't on every panel): "… No alterations · Not profiled".Planted bugs:
scripts/mutants/oncoprint/gene-legend-tail.ts(2: no "No alterations", "Not profiled" always). Each is caught by hand. All 651 sites are found once.Review fixes (7bcadea):
genesin glyphPresence / glyph_presence); tests for every cell not profiled and for no gene row.geneLegend, before the closing two, on screen, in the SVG and in the Python figure alike.onc-legend-derived-lastadded.npm test6823 pass; Python OK.Tracker
PORTAL-PARITY, under Results → OncoPrint, the default view, replace the line
with the following. It also carries #436's and #444's parts of the same line, which aren't on master yet.
Scorecard
01-oncoprint.mdrow:| ONC-GL-6 | ✅ | B | Lists only present glyphs; then "No alterations" whenever a gene row is drawn and "Not profiled" only when one is not, last in that order (
geneLegend,glyphPresence); coadread KRAS TP53 no Not profiled, msk_impact_2017 with NEGR1 both (#451) |Preview
/portal/results?study=coadread_tcga_pan_can_atlas_2018&genes=KRAS,TP53and/portal/results?study=msk_impact_2017&genes=KRAS,TP53,NEGR1: the legend's end.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.