Skip to content

Study View: Add chart's gene tab picks a profile, one chart per gene and profile (STV-AC-5) - #459

Merged
alisman merged 3 commits into
masterfrom
studyview-gene-tab-select
Nov 19, 2026
Merged

alisman merged 3 commits into
masterfrom
studyview-gene-tab-select

Conversation

@alisman

@alisman alisman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add chart's gene tab now works as the portal's GeneLevelSelection (STV-AC-5): one chart per gene and profile.

  • A profile select, each option with the selected samples profiled for it, as the portal writes them: "Mutations (534 samples)", "Putative copy-number alterations from GISTIC (592 samples)". It offers the selection's mutation profile and its discrete copy-number profile (geneChartProfiles), each summed over the selected studies (the CNA gene table's kinds, PROFILE_KINDS.cna, so "gistic" in one study and "cna" in another are one option); a continuous copy-number profile is not offered, since the chart reads the discrete levels.
  • For mutations, "Mutated vs Wild Type" or "Mutation Type", the portal's sub-select.
  • A gene, then Add Chart, which charts that one kind: the gene's mutation status, its mutation-type table (Study View: a gene's Mutation Type Counts table (STS-OT-3, STS-GS-2) #433), or its copy number.
  • Before: one Add drew both the mutation and the copy-number chart, and a second button added the mutation types.
  • Chips name the kind ("KRAS · mutations", "KRAS · copy number", "KRAS · mutation types") and remove only that chart. They show whatever the selection holds, so a chart can be removed even when no selected sample is profiled.
  • The header counts charts ("2 gene charts" for KRAS mutations and copy number).
  • Rules: geneChartsChanged in lib/study-view-add-chart.ts. A gene stays counted while either of its status charts is shown, with at most six genes, as before. The server still counts both status charts per charted gene, and the page draws the ones asked for, so showing another kind of a counted gene does not ask Explore again.

Spec IDs

  • Covered: STV-AC-5's profile select with sample counts, the mutation sub-select, one chart per gene and profile.
  • Left out:
    • gene sets;
    • several genes at once;
    • the chart-type radios (pie / bar: the charts are value lists here, and pies are out of this lane);
    • continuous profiles (mRNA, protein), whose bar charts (STS-GS-4) are not built.

Verification

  • Browser, dev server, coadread:

    • The profile select lists "Mutations (534 samples) | Putative copy-number alterations from GISTIC (592 samples)".
    • KRAS added from each gives the chips "KRAS · mutations | KRAS · copy number" and the facets KRAS|MUTATION and KRAS|CNA.
    • No page errors.
  • e2e: the mutation-types step in test/e2e/explore.cjs now picks "Mutation Type" and presses Add Chart. Run on its own against my dev server: pass (luad KRAS Missense 171 / 168, Nonsense 1 / 1).

  • Unit tests: test/study-view-add-chart-spec.test.ts:

    • the profiles: a continuous copy-number profile listed first is still passed over;
    • adding and removing each kind;
    • what the tab shows (geneTabView): the profile and kind, the note with nothing profiled, and every chip whatever the profiles hold;
    • mutation types kept apart;
    • the six-gene limit.

    npm test 6,887 pass, 0 fail (with master merged in); tsc --noEmit clean.

  • Coverage: passes.

  • Planted bugs: 4 in scripts/mutants/study-view/gene-tab.ts (guard unit).

Tracker

Under "Study View → filters, actions and tabs", this line (docs/PORTAL-PARITY.md:476), as master has it:

  • The Genomic tab's frequencies, the gene tab's profile select with sample counts, gene sets and chart-type radios, a tab per generic-assay type; custom data with the portal's sign-in rules and "Unselected" for cases without a value (STV-AC-4…6, STV-AC-8, STV-STM-4, STV-STM-7)

has three items done: the Genomic tab's frequencies (#455), a tab per generic-assay type (#456) and the gene tab's profile select (this PR). It becomes:

Scorecard 31-study-view-shell.md, row STV-AC-5 (was | STV-AC-5 | 🟡 | B | Gene status: type a gene → mutation + CNA charts (≤6 genes); no profile select, gene sets, chart-type radios |):

| STV-AC-5 | 🟡 | B | Gene status: a profile select with profiled samples ("Mutations (534 samples)"), for mutations Mutated vs Wild Type or Mutation Type, one chart per gene and profile (≤6 genes; geneChartsChanged); one option per kind (mutations; discrete copy number, its kinds summed across studies), so a selection holding two discrete copy-number profiles cannot pick between them, and one whose discrete profile has another id is not offered copy number; no gene sets or chart-type radios; continuous profiles not offered |

Preview

/lab?tab=explore&study=coadread_tcga_pan_can_atlas_2018: Add chart → Gene status.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht

…and profile (STV-AC-5)

As the portal's GeneLevelSelection: a profile select, "Mutations (534
samples)" and the discrete copy-number profile with its profiled
samples; for mutations, Mutated vs Wild Type or Mutation Type; a gene;
Add Chart charts that one kind (geneChartProfiles, geneChartsChanged).
Before, one Add drew both the mutation and copy-number charts, with a
second button for mutation types. Chips name the kind and remove only it.

Verified on coadread: the two profiles as above; KRAS from each gives
KRAS|MUTATION and KRAS|CNA; the mutation-types e2e step passes on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
@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 4:21pm UTC
cbiolab-new Ready Ready Preview Nov 19, 2026 4:21pm UTC
cohort-lab Ready Ready Preview Nov 19, 2026 4:21pm UTC

Request Review

Comment thread app/lab/explore-sections.tsx Outdated
const [profile, setProfile] = useState<"mutation" | "cna">("mutation");
const [byType, setByType] = useState(false);
const current = profiles.find((p) => p.kind === profile) ?? profiles[0];
if (!current) return <p className="note mt-0 mb-3">No selected study has mutation or copy-number data to chart a gene from.</p>;

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.

GeneChartPicker returns early when no profile has n>0, which also hides the chips of genes already charted, so they cannot be removed from the dialog.

Chart KRAS mutations, then apply a draft that selects no profiled samples (or a selection whose samples are all unprofiled): dataTypes n is 0 for both kinds, the gene tab shows only 'No selected study has mutation or copy-number data…', and the KRAS chip with its X is gone; the KRAS tile stays in the grid with no way to stop charting it from Add chart.

Comment thread lib/study-view-add-chart.ts Outdated
*/
export function geneChartProfiles(dataTypes: { profile: string; label: string; alterationType: string; n: number }[]): { kind: "mutation" | "cna"; label: string }[] {
const mut = dataTypes.find((d) => d.alterationType === "MUTATION_EXTENDED" && d.n > 0);
const cna = dataTypes.find((d) => d.alterationType === "COPY_NUMBER_ALTERATION" && ["gistic", "cna", "cna_rae", "cna_consensus"].includes(d.profile) && d.n > 0);

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 CNA option is keyed on a hard-coded list of profile stable-id suffixes and takes only the first match, so federated selections undercount and other discrete CNA profiles are not offered.

Two studies selected, one with <study>_gistic and one with <study>_cna: Explore's merged dataTypes keeps them as separate rows, find() takes the larger, and the label reads e.g. '(592 samples)' while the CNA chart counts both studies. A study whose discrete CNA profile has another suffix gets no copy-number option although the backend draws its CNA facet. Classifying by datatype DISCRETE (lib/profile-catalog.ts, lib/federation-views.ts already do) and summing would fix both.

Comment thread lib/study-view-add-chart.ts Outdated
*/
export function geneChartProfiles(dataTypes: { profile: string; label: string; alterationType: string; n: number }[]): { kind: "mutation" | "cna"; label: string }[] {
const mut = dataTypes.find((d) => d.alterationType === "MUTATION_EXTENDED" && d.n > 0);
const cna = dataTypes.find((d) => d.alterationType === "COPY_NUMBER_ALTERATION" && ["gistic", "cna", "cna_rae", "cna_consensus"].includes(d.profile) && d.n > 0);

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: The discrete-CNA profile list re-implements PROFILE_KINDS.cna from lib/study-view-gene-tables.ts.

["cna","gistic","cna_rae","cna_consensus"] now lives in two files; adding a profile kind to one (e.g. for the CNA gene table's profiled count) leaves the gene tab's profile select out of step. Export and reuse the existing list.

Comment thread app/lab/use-explore-state.ts Outdated
/** which of a charted gene's two status charts are shown (STV-AC-5: one chart per gene and profile) */
const [geneKinds, setGeneKinds] = useState<Record<string, ("MUTATION" | "CNA")[]>>({});
const changeGeneChart = (g: string, kind: GeneChartKind, on: boolean) => {
const next = geneChartsChanged({ genes: geneChartsRef.current, kinds: geneKinds, types: mutationTypeChartsRef.current }, g, kind, on);

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: changeGeneChart reads geneKinds from the render closure while genes/types come from refs, so two changes before a re-render lose one kind update and the lists can disagree.

Two chart/unchart calls in the same tick (or from a stale ctx captured by a callback) both compute from the old geneKinds: the second setGeneKinds overwrites the first, leaving a gene in geneChartsRef with no kind (counted by the server, no tile, no chip) or a kind whose gene was dropped. Keep kinds in a ref like the other two lists, or use a functional update.

const [geneKinds, setGeneKinds] = useState<Record<string, ("MUTATION" | "CNA")[]>>({});
const changeGeneChart = (g: string, kind: GeneChartKind, on: boolean) => {
const next = geneChartsChanged({ genes: geneChartsRef.current, kinds: geneKinds, types: mutationTypeChartsRef.current }, g, kind, on);
geneChartsRef.current = next.genes; setGeneCharts(next.genes);

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: (app/lab/page.tsx:633) The 'N gene charts' count still adds geneCharts.length, which counts genes, not charts, now that one gene can hold a mutation and a copy-number chart.

Add KRAS mutations and KRAS copy number: two tiles are drawn but the header reads '1 gene chart'.

Comment thread app/lab/use-explore-state.ts Outdated
geneChartsRef.current = next.genes; setGeneCharts(next.genes);
mutationTypeChartsRef.current = next.types; setMutationTypeCharts(next.types);
setGeneKinds(next.kinds);
fetchExplore();

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: Adding or removing a second kind for an already-charted gene refetches Explore though the request (geneCharts) is unchanged.

KRAS mutations charted; add KRAS copy number: geneCharts stays ['KRAS'], the server already returned both facets, yet fetchExplore() re-runs the whole Explore query (all facets, all studies) just to unhide a facet the client filters. Only fetch when next.genes or next.types differ.

const explore = ctx.explore!;
return <>
{(explore.geneFacets || []).map(f => {
{(explore.geneFacets || []).filter((f) => (ctx.geneKinds[f.gene] || []).includes(f.type)).map(f => {

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: Per-kind charting is done by hiding facets client-side; the server still computes both the mutation and CNA facets for every charted gene.

Charting only mutations for six genes still runs six CNA facet queries per study on every Explore request (federated: per study, per connection) whose results are discarded. Sending the kinds with geneCharts and having geneStateFacets compute only the asked-for type removes the waste and the client filter.

Comment thread app/lab/explore-sections.tsx Outdated
*/
function GeneChartPicker({ ctx }: { ctx: ExploreCtx }) {
const { chartGene, unchartGene, geneChartInput, setGeneChartInput, exploreBusy, geneCharts, geneKinds, mutationTypeCharts } = ctx;
const profiles = geneChartProfiles(ctx.explore!.dataTypes || []);

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: The profile select is cosmetic: the chosen profile is reduced to a kind, and the chart reads whatever CNA/mutation data the backend picks, not the profile whose sample count the label shows.

In a study with both cna and gistic profiles (or in a federated selection), the select names one profile '(N samples)' but the CNA tile's profiled/total counts come from the backend's own profile choice, so the select's N and the tile's samples disagree with no way to pick the other profile.

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Review verdict: changes

Blocking:

  • GeneChartPicker returns early when no mutation/discrete-CNA profile has profiled samples in the selection, which also hides the chips of genes already charted. The tiles have no close button of their own, so those charts can't be removed until the selection changes. Master always showed the chips. Render the chips (and their X) whatever profiles holds, and show the note only in place of the selects.

Not blocking (inline, nit: or follow-up):

  • The CNA option inline comment is posted as blocking, but I'm downgrading it. Legacy lists each discrete CNA profile as its own option with its own count, and the label here is right for the profile it names. The gap is that the select picks one profile per kind and the chart reads the backend's choice, so a mixed-suffix or federated selection can't pick the other one. That's a scope gap (the scorecard row stays 🟡), so please note it there. Reusing PROFILE_KINDS.cna from lib/study-view-gene-tables.ts would avoid having the list twice.
  • changeGeneChart reads geneKinds from the closure while genes and types come from refs. A ref or a functional update would keep them in step.
  • The "N gene charts" header counts genes, not charts.
  • Adding or removing a second kind for a gene that's already charted refetches Explore, and the server computes both facets for every gene. Sending the kinds to the server would fix both.

Checked and fine: one chart per (gene, kind), keyed gene|kind with no collision between KRAS mutations and KRAS copy number. The click filters are unchanged (geneStatesClauses per facet type). Unit tests cover two kinds for one gene, removing one kind at a time, and the 6-gene limit. Removing a gene chart still leaves its clauses in the draft, as on master. That's pre-existing and not a regression from this PR. CI: everything has passed except gate-e2e and planted-bugs, which were still pending when I looked.

…hold; one CNA option over studies

- The gene tab's chips (and their remove) show even when no selected sample is profiled, so a
  chart can always be taken off; only the profile select and Add give way to the note.
- The copy-number option sums the CNA gene table's profile kinds (PROFILE_KINDS.cna, now shared),
  so two studies holding it as "gistic" and "cna" read 592 samples, not the larger's 300.
- Gene kinds are read from a ref like the gene lists, so two changes before a render both count.
- The header counts charts (a gene's mutation and copy-number charts are two).
- Showing another kind of a gene already counted no longer re-asks Explore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 4cc1a32.

  • Blocking: the charted genes' chips and their remove show whatever the profiles hold. Only the profile select and Add give way to the note. Browser, coadread: with KRAS mutations and copy number charted, and a selection with no profiled sample (copy number "Not profiled", then mutation "Not Profiled": 0 match), the tab reads "No selected study has mutation or copy-number data…" with both KRAS chips and their × buttons. No page errors.
  • The CNA option: it now sums the CNA gene table's profile kinds (PROFILE_KINDS.cna, exported and reused, so the list lives in one place), labelled by the profile with the most samples. One study's "gistic" (300) and another's "cna" (292) read "(592 samples)". The scorecard row notes the one option per kind, and that a discrete profile under another id is not offered (stays 🟡).
  • Nits:
    • gene kinds sit in a ref like the gene lists;
    • the header counts charts ("2 gene charts" for KRAS mutations and copy number);
    • showing another kind of a counted gene no longer refetches Explore (geneChartsAsked).
    • The server still computes both facets per charted gene, as the PR body says.

Tests first (test/study-view-add-chart-spec.test.ts: the two-study sum, the chart count, when Explore is asked again), plus a planted bug for the sum. npm test 6,886 pass, 0 fail; tsc --noEmit and eslint clean.

Comment thread app/lab/explore-sections.tsx Outdated
return (
<div>
{/* the charted genes' chips stay, so a chart can be removed whatever the selection holds */}
{!current ? <p className="note mt-0 mb-3">No selected study has mutation or copy-number data to chart a gene from.</p> : <div className="row baseline g5 flex-wrap">

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 chips now render whatever the profiles hold, which fixes the earlier finding. But nothing pins it: 4cc1a32 adds no test or mutant for this branch, and the e2e only walks the Add Chart path on luad_tcga_pan_can_atlas_2018, where a profile is always present. Putting the early return back would pass CI.

The repo already renders components to HTML in tests (test/support/render-views.ts, renderToStaticMarkup). An easy way to pin it: export GeneChartPicker, or pull a small "what the gene tab shows" helper into lib/study-view-add-chart.ts. Then assert that with dataTypes: [] and geneCharts: ["KRAS"], geneKinds: { KRAS: ["CNA"] }, the markup still has the "stop charting KRAS's copy number" button. Add a mutant in scripts/mutants/study-view/gene-tab.ts that brings the early return back.

const held = rows.filter((d) => d.n > 0);
if (!held.length) return [];
const top = held.reduce((a, b) => (b.n > a.n ? b : a), held[0]);
return [{ kind, label: top.label + " (" + fmtInt(held.reduce((n, d) => n + d.n, 0)) + " samples)" }];

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: The count and the click filter agree: the CNA chart (lib/explore.ts geneStateFacets) and the genomicData clause (lib/cohort2.ts) both resolve each study's profile through discreteCnaProfileSql, so there's no mixing there. This label is the one figure that comes from somewhere else. It sums dataTypes rows, which lib/explore.ts merges by profile suffix across studies, so it drifts from the chart in two rare cases:

  • a study holding two of these kinds (say gistic and cna_rae) has its samples counted twice, while the chart reads only one profile (the highest genetic_profile_id);
  • a study whose discrete profile has a suffix not in PROFILE_KINDS.cna is charted but not counted.

Separately, the CNA Genes table title (profiledSamples, first non-zero kind) still reads 300 in the two-study case where this label now reads 592. That's existing behaviour, but the two now disagree on the same selection.

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re-review of 4cc1a32: changes (one small item left)

Earlier findings:

  • Fixed, but not pinned: charted genes' chips and their remove now show whatever the profiles hold. Blocking: no test or mutant covers it, so putting the early return back would pass CI (inline on app/lab/explore-sections.tsx).
  • Fixed: the CNA option now sums the discrete kinds over studies. The chart's count and its click filter both resolve each study's profile through discreteCnaProfileSql, the same profile per study, with no mixing. The label's sum can still drift in rare cases (nit, inline).
  • Fixed: PROFILE_KINDS is shared; gene kinds are read from a ref; the header counts charts; another kind of a counted gene no longer refetches Explore (tested).
  • Unchanged, non-blocking: the server still computes both facets per charted gene.

CI: green so far (gate-e2e and planted-bugs still running).

… pinned

geneTabView (lib/study-view-add-chart.ts) decides the profile picked, the kind Add charts, the
note in the picker's place when nothing is profiled, and the chips, which it always returns. A
test pins the chips with no profile, and a planted bug hides them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Pinned in 7ae6dce. What the gene tab shows is now one rule, geneTabView (lib/study-view-add-chart.ts): the profile picked, the kind Add charts, the note in the picker's place when nothing is profiled, and the chips, which it always returns. The component renders from it.

  • test/study-view-add-chart-spec.test.ts has a case with no profiled sample: no profile, the note, and all three chips (KRAS mutations, KRAS copy number, TP53 mutation types) with what each removes.
  • A planted bug hides the chips when there is no profile, and the test catches it.
  • Browser, coadread, re-run: the same 0-match selection shows the note and both KRAS chips with ×.

Nit: yes, the option sums samples per profile kind. A study with two discrete copy-number profiles would be counted twice, and one under an id outside PROFILE_KINDS.cna is not offered. The STV-AC-5 row says both, and it stays 🟡.

npm test 6,887 pass, 0 fail; tsc --noEmit and eslint clean.

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re-review: pass. 7ae6dce pins the chips fix. What the gene tab shows is now one helper, geneTabView in lib/study-view-add-chart.ts, which always returns the charted genes' chips. A new unit test covers it, and the new planted bug gene-tab-chips-hidden-without-profile (hiding chips with no profile) is caught by that test.

nit: the test comment "(Reviewer, #459)" records history; the comment should say what the test checks.

@alisman
alisman added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit ae5d81e Nov 19, 2026
12 checks passed
@alisman
alisman deleted the studyview-gene-tab-select branch November 19, 2026 16:44

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — 7ae6dcef 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