Repository navigation
Study View: Add chart's gene tab picks a profile, one chart per gene and profile (STV-AC-5) - #459
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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>; |
There was a problem hiding this comment.
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.
| */ | ||
| 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); |
There was a problem hiding this comment.
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.
| */ | ||
| 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); |
There was a problem hiding this comment.
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.
| /** 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'.
| geneChartsRef.current = next.genes; setGeneCharts(next.genes); | ||
| mutationTypeChartsRef.current = next.types; setMutationTypeCharts(next.types); | ||
| setGeneKinds(next.kinds); | ||
| fetchExplore(); |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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.
| */ | ||
| function GeneChartPicker({ ctx }: { ctx: ExploreCtx }) { | ||
| const { chartGene, unchartGene, geneChartInput, setGeneChartInput, exploreBusy, geneCharts, geneKinds, mutationTypeCharts } = ctx; | ||
| const profiles = geneChartProfiles(ctx.explore!.dataTypes || []); |
There was a problem hiding this comment.
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.
|
Review verdict: changes Blocking:
Not blocking (inline,
Checked and fine: one chart per (gene, kind), keyed |
…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
|
Fixed in 4cc1a32.
Tests first ( |
| 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"> |
There was a problem hiding this comment.
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)" }]; |
There was a problem hiding this comment.
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
gisticandcna_rae) has its samples counted twice, while the chart reads only one profile (the highestgenetic_profile_id); - a study whose discrete profile has a suffix not in
PROFILE_KINDS.cnais 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.
|
Re-review of 4cc1a32: changes (one small item left) Earlier findings:
CI: green so far ( |
… 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
|
Pinned in 7ae6dce. What the gene tab shows is now one rule,
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
|
|
Re-review: pass. 7ae6dce pins the chips fix. What the gene tab shows is now one helper, nit: the test comment "(Reviewer, #459)" records history; the comment should say what the test checks. |
Summary
Add chart's gene tab now works as the portal's
GeneLevelSelection(STV-AC-5): one chart per gene and 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.geneChartsChangedinlib/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
Verification
Browser, dev server, coadread:
e2e: the mutation-types step in
test/e2e/explore.cjsnow 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:geneTabView): the profile and kind, the note with nothing profiled, and every chip whatever the profiles hold;npm test6,887 pass, 0 fail (with master merged in);tsc --noEmitclean.Coverage: passes.
Planted bugs: 4 in
scripts/mutants/study-view/gene-tab.ts(guardunit).Tracker
Under "Study View → filters, actions and tabs", this line (docs/PORTAL-PARITY.md:476), as master has it:
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