Skip to content

OncoPrint: the gene legend's No alterations, and Not profiled only when a cell is - #451

Merged
alisman merged 3 commits into
masterfrom
session/onc-legend-unaltered
Nov 19, 2026
Merged

alisman merged 3 commits into
masterfrom
session/onc-legend-unaltered

Conversation

@alisman

@alisman alisman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • "No alterations", the grey cell, is listed whenever a gene row is drawn, even with every cell not profiled: oncoprintjs counts the rule set's always rule as used.
  • "Not profiled" is listed only when some gene cell is not profiled (the NA rule is used). Ours listed it always.
  • Both come last, at legend order infinity, sorted by label: "No alterations" before "Not profiled".

Where:

  • lib/oncoprint-style.ts: glyphPresence notes profiled / not-profiled cells, and geneLegend lists the two entries by them. The label is the style's unalteredLabel, so renderers define nothing of their own (invariant 8).
  • python/cohortlab/style.py: glyph_presence / gene_legend alike. 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.ts GL1-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):

    • coadread_tcga_pan_can_atlas_2018 KRAS TP53: the legend ends "Deep Deletion · No alterations". Every cell is profiled, so there's no "Not profiled", where we listed it before.
    • msk_impact_2017 KRAS TP53 NEGR1 (NEGR1 isn't on every panel): "… No alterations · Not profiled".
    • No console errors.
  • 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):

    • "No alterations" whenever a gene row is drawn (genes in glyphPresence / glyph_presence); tests for every cell not profiled and for no gene row.
    • "Derived event" placed by geneLegend, before the closing two, on screen, in the SVG and in the Python figure alike.
    • The "No alterations" swatch is drawn with an edge, so it shows on a white background.
    • Planted bug onc-legend-derived-last added. npm test 6823 pass; Python OK.

Tracker

PORTAL-PARITY, under Results → OncoPrint, the default view, replace the line

  • Layout and legend: no gap between the clinical and genetic groups; labels cut at 17 characters with no ⋮ button (ours: click the label); the Profiled rows named by alteration type ("Profiled for copy number alterations"; the portal's "Profiled in" + the profile's name); no "No alterations" legend entry and "Not profiled" listed when nothing is; Translation_Start_Site drawn as Other (the portal's Truncating); no Display toggles for the clinical legends or "only altered" legend entries (ONC-LY-1, ONC-LY-2, ONC-LY-3, ONC-GL-2, ONC-GL-6, ONC-VI-4, ONC-VI-5) (01-oncoprint)

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.md row:

| 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,TP53 and /portal/results?study=msk_impact_2017&genes=KRAS,TP53,NEGR1: the legend's end.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…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
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbiolab-genie Ready Ready Preview Nov 19, 2026 12:37pm UTC
cbiolab-new Ready Ready Preview Nov 19, 2026 12:37pm UTC
cohort-lab Ready Ready Preview Nov 19, 2026 12:37pm UTC

Request Review

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
Comment thread python/cohortlab/render.py Outdated
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)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/oncoprint-svg.ts Outdated
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");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/oncoprint-style.ts Outdated
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" });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/oncoprint-style.ts Outdated
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 }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/oncoprint-svg.ts Outdated
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");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/oncoprint-style.ts Outdated
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; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

@alisman

alisman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Review: changes requested (head 1aeff48; reviewed 43f204f, plus 1aeff48, which only adds a unit case)

Blocking:

  1. CI coverage failed: lib/oncoprint-svg.ts 39–41 (the Derived event splice) was not run by a unit test. 1aeff48 adds the GL3 SVG case that runs it. This should be fixed, pending CI.
  2. "No alterations" when no gene cell is profiled differs from legacy. In oncoprintjs, the always rule (geneticrules.ts non_mutation_rule_params.always) is indexed as the rule set's universal rule (LookupRuleSet.indexRuleForLookup, condition_key === null). getSpecificShapesForDatum then marks it active unconditionally after the loop (oncoprintruleset.ts ~519-524), not per datum. So the portal lists "No alterations" whenever a gene track is drawn, even if every cell is not profiled. This PR drops it in that case (present.profiled). GL1/GL2 "every cell not profiled: Not profiled alone" and the Python test_nothing_profiled codify the non-legacy behaviour. The PR's comments ("listed when a datum used them") misdescribe the universal rule. Fix: list it whenever a gene track exists (TS and Python), and update those tests and the mutant.

Checked and fine:

  • "Not profiled" only when some gene cell is -1. It is computed over all columns, not the drawn ones. That matches legacy: gene tracks have no important_ids, so hidden (Show unaltered off) columns still mark rules active. It is unaffected by Show unaltered on screen and in the server SVG/PDF.
  • The order is "No alterations" then "Not profiled", last, as the legend renderer's order-then-label sort.
  • The Python port mirrors the TS.
  • Both planted bugs are caught by test/oncoprint-gene-legend.test.ts.

Nits (see inline):

  • "Derived event" is placed before the tail in the SVG but after it on screen (Legend) and in the Python figure.
  • The Python legend draws every entry as a solid Patch, so "No alterations" and "Not profiled" are now two identical grey squares.
  • With a white background, the "No alterations" swatch is invisible.
  • The profiled/notProfiled fields are optional, and the cell loop adds work per cell.

…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)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re-review (7bcadea): pass

The earlier blocking finding is fixed:

  • "No alterations" is now listed whenever a gene row is drawn: glyphPresence/glyph_presence set genes from the gene rows, and geneLegend/gene_legend key on it in both TS and Python. A contract with no gene row lists neither entry.
  • The tests that locked in the old behaviour are corrected: GL1/GL2 "every cell not profiled" now expects ["No alterations", "Not profiled"], there's a new "no gene row" case, and Python test_nothing_profiled_still_lists_no_alterations replaces the old test. The planted bug now drops the entry when a cell is not profiled, and the tests catch it.
  • The comments now describe the portal's always rule correctly (counted as used whenever a gene row is drawn).

From the earlier nits:

  • Fixed: Derived event is now listed by geneLegend itself, before the closing two, so the screen, the server SVG and Python agree (GL3 and the Python test check it).
  • Fixed: the "No alterations" swatch now has a stripe-coloured edge, so it shows on a white background.
  • Still open: Python still draws two identical grey squares (inline nit).
  • New: the onc-legend-derived-last mutant's effect text doesn't match what the mutant does (inline nit).

CI: coverage, lint, gate-local, gate-warehouse and reports pass. planted-bugs and gate-e2e were still pending at review time.

@alisman
alisman added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 5d50c3e Nov 19, 2026
19 of 20 checks passed
@alisman
alisman deleted the session/onc-legend-unaltered branch November 19, 2026 13:28

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — 7bcadea4 Deployed Nov 19, 2026 by vercel[bot]
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