diff --git a/app/lab/explore-sections.tsx b/app/lab/explore-sections.tsx
index 1b598a74..fc3f7ff2 100644
--- a/app/lab/explore-sections.tsx
+++ b/app/lab/explore-sections.tsx
@@ -21,7 +21,7 @@ import { barFigureSvg, pieFigureSvg, type FigureBar, type PieSlice } from "../..
import { caseFileAction, figureActions, runCaseFile } from "./chart-files.ts";
import { caseFileName } from "../../lib/study-view-case-files.ts";
import { chartOffered } from "../../lib/study-view-config.ts";
-import { addChartLines, assayTabs, bulkButtons, genomicChartLines, SPECIAL_CHART_KEYS, specialChartsShown } from "../../lib/study-view-add-chart.ts";
+import { addChartLines, assayTabs, bulkButtons, genomicChartLines, geneTabView, SPECIAL_CHART_KEYS, specialChartsShown } from "../../lib/study-view-add-chart.ts";
import { StudyHeader } from "./explore-study-header.tsx";
import type { CohortDef } from "../../lib/types.ts";
import { alteredHeaderTip, appliedLines, queuedQuery, defaultGeneSort, geneHeaderTips, geneSelection, geneFreqText, geneRowMatches, geneTableName, geneTableTitle, geneTableTsv, intersectionRefusal, nextGeneSort, profiledSamples, qValueIcon, sortGeneRows, type GeneSort, type GeneSortColumn } from "../../lib/study-view-gene-tables.ts";
@@ -299,7 +299,7 @@ export function ExploreBar({ ctx }: { ctx: ExploreCtx }) {
}
export function AddChartDialog({ ctx }: { ctx: ExploreCtx }) {
- const { addChartOpen, setAddChartOpen, addSeqFilter, clearAttributeFilters, attrCoverage, attrKey, chartGene, chartTab, clinFilter, exStudies, exploreBusy, fetchExplore, geneChartInput, openCustomManager, geneCharts, mutationTypeCharts, chartChecked, setChartsChecked, seq, seqReady, setAttrCoverage, setChartTab, setClinFilter, setGeneChartInput, setSeq, treatmentEventType, unchartGene } = ctx;
+ const { addChartOpen, setAddChartOpen, addSeqFilter, clearAttributeFilters, attrCoverage, attrKey, chartTab, clinFilter, exStudies, exploreBusy, fetchExplore, openCustomManager, chartChecked, setChartsChecked, seq, seqReady, setAttrCoverage, setChartTab, setClinFilter, setSeq, treatmentEventType } = ctx;
const explore = ctx.explore!;
return <>
{explore && (
@@ -442,47 +442,7 @@ export function AddChartDialog({ ctx }: { ctx: ExploreCtx }) {
);
})()}
- {chartTab === "gene" && (
-
-
- setGeneChartInput(e.target.value)}
- onKeyDown={e => { if (e.key === "Enter") chartGene(geneChartInput); }} />
- chartGene(geneChartInput)}
- data-tip="its mutation and copy-number status">Add
- chartGene(geneChartInput, true)}
- data-tip="a table of its mutations by type: mutations, samples, and their share of the selected samples">Add mutation types
-
- {!geneCharts.length && !mutationTypeCharts.length && (
-
- Name a gene to see how many patients are altered, unaltered, or never tested for
- it. The third is the one a frequency cannot show: in GENIE public, 86,353 patients are on no panel
- covering EGFR copy number.
-
- )}
- {geneCharts.map(g => (
-
- {g}
- unchartGene(g)}>
-
- ))}
- {mutationTypeCharts.map(g => (
-
- {g} · mutation types
- unchartGene(g, true)}>
-
- ))}
- {geneCharts.length + mutationTypeCharts.length > 0 && (
-
- Each chart is drawn as its own tile in the facet grid, alongside the clinical
- attributes — close this dialog to see them.
-
- )}
-
- )}
+ {chartTab === "gene" && }
{chartTab === "genomic" && }
{chartTab.startsWith("assay:") && }
{chartTab === "derived" && (explore.events.length === 0 ? (
@@ -1064,6 +1024,49 @@ function ClinicalFacet({ c, ctx }: { c: NonNullable["clin
);
}
+/**
+ * The Add chart dialog's gene tab, as the portal's (STV-AC-5): a profile, " (N samples)"; for
+ * mutations, Mutated vs Wild Type or Mutation Type; a gene; one chart per gene and profile.
+ */
+function GeneChartPicker({ ctx }: { ctx: ExploreCtx }) {
+ const { chartGene, unchartGene, geneChartInput, setGeneChartInput, exploreBusy, geneCharts, geneKinds, mutationTypeCharts } = ctx;
+ const [profile, setProfile] = useState<"mutation" | "cna">("mutation");
+ const [byType, setByType] = useState(false);
+ const { profiles, current, kind, note, chips } = geneTabView(ctx.explore!.dataTypes || [], { genes: geneCharts, kinds: geneKinds, types: mutationTypeCharts }, profile, byType);
+ const add = () => chartGene(geneChartInput, kind);
+ return (
+
+ {/* the charted genes' chips stay, so a chart can be removed whatever the selection holds */}
+ {!current ?
{note}
:
+ setProfile(v as "mutation" | "cna")} title="the profile the chart reads"
+ options={profiles.map((p) => [p.kind, p.label] as const)} />
+ {current.kind === "mutation" && setByType(v === "types")}
+ title="a gene's mutated and wild-type samples, or its mutations by type" options={[["mutated", "Mutated vs Wild Type"], ["types", "Mutation Type"]] as const} />}
+ setGeneChartInput(e.target.value)}
+ onKeyDown={(e) => { if (e.key === "Enter") add(); }} />
+ Add Chart
+
}
+ {current && !chips.length && (
+
+ Name a gene to see how many patients are altered, unaltered, or never tested for
+ it. The third is the one a frequency cannot show: in GENIE public, 86,353 patients are on no panel
+ covering EGFR copy number.
+
+ )}
+ {chips.map((c) => (
+
+ {c.gene} · {c.text}
+ unchartGene(c.gene, c.kind)}>
+
+ ))}
+ {chips.length > 0 &&
Each chart is drawn as its own tile in the facet grid, alongside the clinical attributes — close this dialog to see them.
}
+
+ );
+}
+
/** the Add chart dialog's Genomic tab (STV-AC-2): the gene tables, Data Types and the density, each shown unless unchecked */
/** the Genomic tab's rows for this selection (STV-AC-2, STV-AC-4); none hides the tab, as the portal's */
function genomicLines(explore: NonNullable, attrKey: ExploreCtx["attrKey"]) {
@@ -1220,7 +1223,7 @@ export function GeneFacets({ ctx }: { ctx: ExploreCtx }) {
const { addClauses, geneStatesClauses } = ctx;
const explore = ctx.explore!;
return <>
- {(explore.geneFacets || []).map(f => {
+ {(explore.geneFacets || []).filter((f) => (ctx.geneKinds[f.gene] || []).includes(f.type)).map(f => {
const apply = (states: string[]) => geneStatesClauses(f.gene, f.type, states);
// the copy-number levels the portal draws: none at 0 (the drivers-only chart keeps its fixed rows)
const states = f.type === "CNA" && !explore.drivers ? f.states.filter((st) => st.n > 0) : f.states;
diff --git a/app/lab/page.tsx b/app/lab/page.tsx
index 7b238111..75740ded 100644
--- a/app/lab/page.tsx
+++ b/app/lab/page.tsx
@@ -4,6 +4,7 @@ import { currentLinkUrlMax, linkParams, writeSearch } from "../_links/link-state
import { TAB_PARAM, readFilters, readTab, writeTab, type StudyViewTab } from "../../lib/study-view-url.ts";
import { useLinkParams } from "../_links/use-link.ts";
import { ExploreCharts } from "./explore-charts";
+import { geneChartCount } from "../../lib/study-view-add-chart.ts";
import type { UnpackedContract } from "../../lib/oncoprint-binary.ts";
import type { AnalysisDoc, CohortDef } from "../../lib/types.ts";
import { storeCohortLists, storeDocLists } from "./id-sets-client.ts";
@@ -630,7 +631,10 @@ export default function AnalysisPage() {
return shown < all &&
{shown} of {all.toLocaleString()} clinical attributes charted — the rest are in Add chart ;
})()}
- {geneCharts.length + mutationTypeCharts.length > 0 && {geneCharts.length + mutationTypeCharts.length} gene chart{geneCharts.length + mutationTypeCharts.length === 1 ? "" : "s"} }
+ {(() => {
+ const n = geneChartCount({ genes: geneCharts, kinds: exploreState.geneKinds, types: mutationTypeCharts });
+ return n > 0 && {n} gene chart{n === 1 ? "" : "s"} ;
+ })()}
{(() => {
// drivers only where every selected study has OncoKB calls here; the server refuses the rest too
const without = exStudies.filter((id) => studies.find((x) => x.id === id)?.oncokb === false);
diff --git a/app/lab/use-explore-state.ts b/app/lab/use-explore-state.ts
index 598c26a0..809eff77 100644
--- a/app/lab/use-explore-state.ts
+++ b/app/lab/use-explore-state.ts
@@ -8,7 +8,7 @@ import { useSaved } from "../_saved/saved-context.tsx";
import { useEffect, useRef, useState } from "react";
import { normalizeDef } from "./pills";
import type { AnalysisDoc, Clause, CohortDef, DerivedRequest, NumericBin, PartitionArm, PartitionDef } from "../../lib/types.ts";
-import { GENOMIC_CHARTS, withoutAttribute } from "../../lib/study-view-add-chart.ts";
+import { GENOMIC_CHARTS, geneChartsAsked, geneChartsChanged, withoutAttribute, type GeneChartKind } from "../../lib/study-view-add-chart.ts";
import { foldEventNames, treatmentEventOf } from "../../lib/event-names.ts";
import { type SplitSpec } from "./partitions.tsx";
import { armsFromSelection, withoutChart, comparisonCohorts, type ChartKey } from "../../lib/partition-arms.ts";
@@ -626,23 +626,27 @@ export function useExploreState(page: ExplorePage) {
const geneStatesClauses = (gene: string, type: "MUTATION" | "CNA", states: string[]): { clauses: any[] } | { why: string } =>
geneStatesClausesFor(gene, type, states, !!explore?.drivers);
- /** chart a gene: its mutation and copy-number status, or (`types`) its mutations by type, as the portal's Add chart offers */
- const chartGene = (raw: string, types = false) => {
+ /** which of a charted gene's two status charts are shown (STV-AC-5: one chart per gene and profile) */
+ const [geneKinds, setGeneKinds] = useState>({});
+ const geneKindsRef = useRef>({});
+ const changeGeneChart = (g: string, kind: GeneChartKind, on: boolean) => {
+ // read from the refs, so two changes before a render both count
+ const before = { genes: geneChartsRef.current, kinds: geneKindsRef.current, types: mutationTypeChartsRef.current };
+ const next = geneChartsChanged(before, g, kind, on);
+ geneChartsRef.current = next.genes; setGeneCharts(next.genes);
+ mutationTypeChartsRef.current = next.types; setMutationTypeCharts(next.types);
+ geneKindsRef.current = next.kinds; setGeneKinds(next.kinds);
+ // another kind of a gene already counted is drawn from the answer in hand
+ if (geneChartsAsked(before, next)) fetchExplore();
+ };
+ /** chart a gene for one profile, as the portal's Add chart does: its mutation status, its mutations by type, or its copy number */
+ const chartGene = (raw: string, kind: GeneChartKind) => {
const g = String(raw || "").toUpperCase().trim();
if (!/^[A-Z0-9][A-Z0-9.-]{0,19}$/.test(g)) return;
- const held = types ? mutationTypeCharts : geneCharts;
- const next = held.includes(g) ? held : [...held, g].slice(-6);
- if (types) { mutationTypeChartsRef.current = next; setMutationTypeCharts(next); }
- else { geneChartsRef.current = next; setGeneCharts(next); }
setGeneChartInput("");
- fetchExplore();
- };
- const unchartGene = (g: string, types = false) => {
- const next = (types ? mutationTypeCharts : geneCharts).filter((x) => x !== g);
- if (types) { mutationTypeChartsRef.current = next; setMutationTypeCharts(next); }
- else { geneChartsRef.current = next; setGeneCharts(next); }
- fetchExplore();
+ changeGeneChart(g, kind, true);
};
+ const unchartGene = (g: string, kind: GeneChartKind) => changeGeneChart(g, kind, false);
const chartAssay = (profileType: string, entity: string) => {
if (assayCharts.some((c) => c.profileType === profileType && c.entity === entity)) return;
@@ -875,7 +879,7 @@ export function useExploreState(page: ExplorePage) {
if (target) addCohortToView(target, n, def, studyHint);
};
- return { chartBins, setChartBins, applyOrSay, urlRead, openEditCohort, saveEditedCohort, exMsg, setExMsg, splittingBy, setSplittingBy, addMode, setAddMode, customTab, setCustomTab, saving, setSaving, savingFeature, setSavingFeature, addChartOpen, setAddChartOpen, chartTab, setChartTab, cName, setCName, cDefText, setCDefText, exploring, explore, exploreBusy, sQuery, setSQuery, sCaps, setSCaps, exStudies, setExStudies, exPanelOpen, setExPanelOpen, exSel, exFetchTimer, exDraftStudies, setExDraftStudies, geneCharts, setGeneCharts, geneChartsRef, drivers, setDrivers, callOql, exDerived, setExDerived, exDerivedRef, geneChartInput, setGeneChartInput, studyChipsOpen, setStudyChipsOpen, geneFilter, setGeneFilter, queuedGenes, setQueuedGenes, toggleQueuedGene, clinFilter, setClinFilter, chartChecked, setChartsChecked, attrCoverage, setAttrCoverage, seq, setSeq, barDef, barDefaultName, analyzeDraft, viewPatients, compareQuantiles, selectionArmCount, compareSelection, compareItems, openSaveDialog, confirmSave, openCustomManager, saveDraftAsFeature, confirmSaveFeature, parseDraft, attrKey, visibleClinical, attrsForBar, fetchExplore, addClause, addClauses, toggleBar, togglePieValue, toggleNaValue, selectBars, geneStatesClauses, toggleLogScale, addBinEdges, addDensitySelection, chartGene, unchartGene, mutationTypeCharts, assayCharts, chartAssay, unchartAssay, exploreEventTypes, treatmentEventType, TREATMENT_DERIVED_KINDS, derivedOn, toggleDerived, seqSelector, seqReady, addSeqFilter, removeDraftClause, clearAttributeFilters, clearGeneTableFilter, draftScaffold, clearDraft, setExploreStudies, exploreStudy, analyzeStudy, addDataToStudy, openAddCohort, closeAddCohort, addDraftToAnalysis };
+ return { chartBins, setChartBins, applyOrSay, urlRead, openEditCohort, saveEditedCohort, exMsg, setExMsg, splittingBy, setSplittingBy, addMode, setAddMode, customTab, setCustomTab, saving, setSaving, savingFeature, setSavingFeature, addChartOpen, setAddChartOpen, chartTab, setChartTab, cName, setCName, cDefText, setCDefText, exploring, explore, exploreBusy, sQuery, setSQuery, sCaps, setSCaps, exStudies, setExStudies, exPanelOpen, setExPanelOpen, exSel, exFetchTimer, exDraftStudies, setExDraftStudies, geneCharts, setGeneCharts, geneChartsRef, drivers, setDrivers, callOql, exDerived, setExDerived, exDerivedRef, geneChartInput, setGeneChartInput, studyChipsOpen, setStudyChipsOpen, geneFilter, setGeneFilter, queuedGenes, setQueuedGenes, toggleQueuedGene, clinFilter, setClinFilter, chartChecked, setChartsChecked, attrCoverage, setAttrCoverage, seq, setSeq, barDef, barDefaultName, analyzeDraft, viewPatients, compareQuantiles, selectionArmCount, compareSelection, compareItems, openSaveDialog, confirmSave, openCustomManager, saveDraftAsFeature, confirmSaveFeature, parseDraft, attrKey, visibleClinical, attrsForBar, fetchExplore, addClause, addClauses, toggleBar, togglePieValue, toggleNaValue, selectBars, geneStatesClauses, toggleLogScale, addBinEdges, addDensitySelection, chartGene, unchartGene, geneKinds, mutationTypeCharts, assayCharts, chartAssay, unchartAssay, exploreEventTypes, treatmentEventType, TREATMENT_DERIVED_KINDS, derivedOn, toggleDerived, seqSelector, seqReady, addSeqFilter, removeDraftClause, clearAttributeFilters, clearGeneTableFilter, draftScaffold, clearDraft, setExploreStudies, exploreStudy, analyzeStudy, addDataToStudy, openAddCohort, closeAddCohort, addDraftToAnalysis };
}
export type ExploreState = ReturnType;
diff --git a/lib/study-view-add-chart.ts b/lib/study-view-add-chart.ts
index 9708f621..d0c32683 100644
--- a/lib/study-view-add-chart.ts
+++ b/lib/study-view-add-chart.ts
@@ -3,6 +3,8 @@
// takes with it when unchecked. The rules, case by case: docs/legacy-spec/parity/add-chart-cases.md.
// Browser-safe; no I/O.
import { isClinicalLeaf, type Clause } from "./types.ts";
+import { fmtInt } from "./chart/format.ts";
+import { PROFILE_KINDS } from "./study-view-gene-tables.ts";
/** a row of the list: its key, its name, the selected samples with data (unknown when not counted), and whether it is checked */
export interface AddChartRow { key: string; name: string; samples: number | undefined; checked: boolean }
@@ -64,6 +66,73 @@ export function specialChartsShown(checked: (key: string) => boolean, leaves: un
};
}
+/** what Add chart's gene tab charts (STV-AC-5): a gene's mutation status, its mutation types, or its copy number */
+export type GeneChartKind = "MUTATION" | "types" | "CNA";
+
+/**
+ * The gene tab's profile select, as the portal lists it: the selection's mutation and discrete
+ * copy-number profiles, each " (N samples)", N the selected samples profiled. `dataTypes` is
+ * Explore's count per profile kind; the discrete copy-number kinds are the CNA gene table's
+ * (PROFILE_KINDS.cna), summed, since two studies may hold it under different ids ("gistic", "cna"),
+ * the label the one with the most samples.
+ */
+export function geneChartProfiles(dataTypes: { profile: string; label: string; alterationType: string; n: number }[]): { kind: "mutation" | "cna"; label: string }[] {
+ const option = (kind: "mutation" | "cna", rows: typeof dataTypes) => {
+ 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)" }];
+ };
+ return [
+ ...option("mutation", dataTypes.filter((d) => d.alterationType === "MUTATION_EXTENDED")),
+ ...option("cna", dataTypes.filter((d) => d.alterationType === "COPY_NUMBER_ALTERATION" && PROFILE_KINDS.cna.includes(d.profile))),
+ ];
+}
+
+/** the gene charts asked for: genes whose status charts Explore counts, which of the two each shows, and genes charted by mutation type */
+export interface GeneCharts { genes: string[]; kinds: Record; types: string[] }
+
+/**
+ * What the gene tab shows (STV-AC-5): the profile picked (`chosen`, else the first offered) and the
+ * kind of chart Add makes, or, with no profile to chart from, a note in their place; and always
+ * every charted gene's chips with what each removes, since a chart's tile has no close of its own.
+ */
+export function geneTabView(dataTypes: Parameters[0], charts: GeneCharts, chosen: "mutation" | "cna", byType: boolean): {
+ profiles: ReturnType; current: ReturnType[number] | null; kind: GeneChartKind;
+ note: string | null; chips: { gene: string; kind: GeneChartKind; text: string }[];
+} {
+ const profiles = geneChartProfiles(dataTypes);
+ const current = profiles.find((p) => p.kind === chosen) ?? profiles[0] ?? null;
+ const chips = [
+ ...charts.genes.flatMap((g) => (charts.kinds[g] || []).map((k) => ({ gene: g, kind: k as GeneChartKind, text: k === "CNA" ? "copy number" : "mutations" }))),
+ ...charts.types.map((g) => ({ gene: g, kind: "types" as GeneChartKind, text: "mutation types" })),
+ ];
+ return { profiles, current, kind: current?.kind === "cna" ? "CNA" : byType ? "types" : "MUTATION",
+ note: current ? null : "No selected study has mutation or copy-number data to chart a gene from.", chips };
+}
+
+/** how many charts a gene list draws: one per gene and kind shown, one per mutation-type table */
+export const geneChartCount = (s: GeneCharts): number => s.genes.reduce((n, g) => n + (s.kinds[g]?.length || 0), 0) + s.types.length;
+
+/** whether a change asks Explore for something new: its genes or mutation-type tables; another kind of a counted gene is already there */
+export const geneChartsAsked = (before: GeneCharts, after: GeneCharts): boolean =>
+ before.genes.join("|") !== after.genes.join("|") || before.types.join("|") !== after.types.join("|");
+
+/** a gene chart added (`on`) or removed, at most `limit` genes of each list, as the portal adds one chart per gene and profile */
+export function geneChartsChanged(s: GeneCharts, gene: string, kind: GeneChartKind, on: boolean, limit = 6): GeneCharts {
+ if (kind === "types") {
+ const types = on ? (s.types.includes(gene) ? s.types : [...s.types, gene].slice(-limit)) : s.types.filter((g) => g !== gene);
+ return { ...s, types };
+ }
+ const had = s.kinds[gene] || [];
+ const kinds = on ? (had.includes(kind) ? had : [...had, kind]) : had.filter((k) => k !== kind);
+ const all = { ...s.kinds };
+ if (kinds.length) all[gene] = kinds; else delete all[gene];
+ const genes = kinds.length ? (s.genes.includes(gene) ? s.genes : [...s.genes, gene].slice(-limit)) : s.genes.filter((g) => g !== gene);
+ for (const g of Object.keys(all)) if (!genes.includes(g)) delete all[g];
+ return { genes, kinds: all, types: s.types };
+}
+
/** the Genomic tab's charts (STV-AC-2): drawn by default, each a checkbox in Add chart that hides or shows it */
export const GENOMIC_CHARTS = [
{ key: "genomic|mutated", name: "Mutated Genes", table: "mutated" as const },
diff --git a/lib/study-view-gene-tables.ts b/lib/study-view-gene-tables.ts
index dfe52c57..63eb5ecb 100644
--- a/lib/study-view-gene-tables.ts
+++ b/lib/study-view-gene-tables.ts
@@ -19,7 +19,7 @@ export function geneTableTitle(kind: GeneTableKind, profiled: number | undefined
}
/** the profile kinds a table's count is read from, the first that is not 0 winning */
-const PROFILE_KINDS: Record = {
+export const PROFILE_KINDS: Record = {
mutated: ["mutations"],
sv: ["fusion", "structural_variants"],
cna: ["cna", "gistic", "cna_rae", "cna_consensus"]
diff --git a/scripts/mutants/study-view/gene-tab.ts b/scripts/mutants/study-view/gene-tab.ts
new file mode 100644
index 00000000..6d577219
--- /dev/null
+++ b/scripts/mutants/study-view/gene-tab.ts
@@ -0,0 +1,20 @@
+// Planted bugs: Add chart's gene tab, one chart per gene and profile (STV-AC-5). How they are planted and run: scripts/check-mutants.ts.
+import type { GuardCommands, Mutant } from "../types.ts";
+
+export const guards: GuardCommands = {};
+
+export const mutants: Mutant[] = [
+ { id: "gene-tab-remove-drops-gene", layer: "counts", guard: "unit", file: "lib/study-view-add-chart.ts",
+ effect: "Removing a gene's mutation chart also removes its copy-number chart, because the gene stops being counted while one status chart is still shown.",
+ find: "const genes = kinds.length ? (s.genes.includes(gene)", replace: "const genes = on ? (s.genes.includes(gene)" },
+ { id: "gene-tab-any-cna-profile", layer: "counts", guard: "unit", file: "lib/study-view-add-chart.ts",
+ effect: "The gene tab offers a continuous copy-number profile (linear CNA) as the copy-number chart's, whose levels the chart does not read.",
+ find: "d.alterationType === \"COPY_NUMBER_ALTERATION\" && PROFILE_KINDS.cna.includes(d.profile)", replace: "d.alterationType === \"COPY_NUMBER_ALTERATION\"" },
+ { id: "gene-tab-cna-first-study-only", layer: "counts", guard: "unit", file: "lib/study-view-add-chart.ts",
+ effect: "Over two studies holding discrete copy number under different ids (gistic, cna), the option counts the larger study's samples only (300 where the selection's are 592).",
+ find: "fmtInt(held.reduce((n, d) => n + d.n, 0))", replace: "fmtInt(top.n)" },
+ { id: "gene-tab-chips-hidden-without-profile", layer: "cohorts", guard: "unit", file: "lib/study-view-add-chart.ts",
+ effect: "With no selected sample profiled, the gene tab hides the charted genes' chips, so their charts cannot be removed until the selection changes.",
+ find: "note: current ? null : \"No selected study has mutation or copy-number data to chart a gene from.\", chips };",
+ replace: "note: current ? null : \"No selected study has mutation or copy-number data to chart a gene from.\", chips: current ? chips : [] };" },
+];
diff --git a/test/e2e/explore.cjs b/test/e2e/explore.cjs
index 8d1e8b42..7ede8a43 100644
--- a/test/e2e/explore.cjs
+++ b/test/e2e/explore.cjs
@@ -611,8 +611,11 @@ async function explore({ ok, BASE, page, browser }) {
await page.goto(BASE + "/lab?tab=explore&study=luad_tcga_pan_can_atlas_2018", { waitUntil: "domcontentloaded" });
await page.getByRole("button", { name: /Add chart/ }).first().click({ timeout: 240000 });
await page.getByRole("tab", { name: "Gene status" }).click();
+ // the portal's gene tab: the mutation profile, "Mutation Type", the gene, Add Chart (STV-AC-5)
+ await page.getByRole("combobox", { name: /mutations by type/ }).click();
+ await page.getByRole("option", { name: "Mutation Type" }).click();
await page.getByPlaceholder("chart a gene (e.g. EGFR)").fill("KRAS");
- await page.getByRole("button", { name: "Add mutation types" }).click();
+ await page.getByRole("button", { name: "Add Chart" }).click();
await page.keyboard.press("Escape");
const card = page.locator("[data-mutationtypes='KRAS']");
await card.locator(".valrow").first().waitFor({ timeout: 240000 });
diff --git a/test/study-view-add-chart-spec.test.ts b/test/study-view-add-chart-spec.test.ts
index b4c66c47..5455b48c 100644
--- a/test/study-view-add-chart-spec.test.ts
+++ b/test/study-view-add-chart-spec.test.ts
@@ -4,7 +4,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { portalFreq } from "../lib/chart/format.ts";
-import { chartFreq, addChartLines, bulkButtons, withoutAttribute, assayTabLabel, assayTabs, SPECIAL_CHART_KEYS, specialChartsShown, genomicChartLines, type AddChartRow } from "../lib/study-view-add-chart.ts";
+import { chartFreq, addChartLines, bulkButtons, withoutAttribute, assayTabLabel, assayTabs, geneChartProfiles, geneChartsChanged, geneChartCount, geneChartsAsked, geneTabView, SPECIAL_CHART_KEYS, specialChartsShown, genomicChartLines, type AddChartRow } from "../lib/study-view-add-chart.ts";
import type { Clause, Leaf } from "../lib/types.ts";
const row = (key: string, name: string, samples: number, checked = false): AddChartRow => ({ key, name, samples, checked });
@@ -219,6 +219,50 @@ test("the special tables: drawn when checked, or while the draft filters on what
for (const [name, checked, leaves, hasEvents, want] of cases) assert.deepEqual(specialChartsShown(checked, leaves, hasEvents), want, name);
});
+// STV-AC-5: the gene tab, one chart per gene and profile
+test("the gene tab's profiles: mutations and discrete copy number, each with its profiled samples", () => {
+ const dt = [{ profile: "mutations", label: "Mutations", alterationType: "MUTATION_EXTENDED", n: 534 },
+ { profile: "rna_seq_v2_mrna", label: "mRNA expression", alterationType: "MRNA_EXPRESSION", n: 592 },
+ // a continuous copy-number profile listed first: the chart reads the discrete one's levels
+ { profile: "linear_cna", label: "Capped relative linear copy-number values", alterationType: "COPY_NUMBER_ALTERATION", n: 592 },
+ { profile: "gistic", label: "Putative copy-number alterations from GISTIC", alterationType: "COPY_NUMBER_ALTERATION", n: 592 }];
+ assert.deepEqual(geneChartProfiles(dt), [{ kind: "mutation", label: "Mutations (534 samples)" }, { kind: "cna", label: "Putative copy-number alterations from GISTIC (592 samples)" }]);
+ assert.deepEqual(geneChartProfiles(dt.slice(1, 3)), [], "no mutation or discrete copy-number profile, nothing to chart a gene from");
+ // two studies, one's discrete copy number "gistic", the other's "cna": one option, their samples summed
+ const two = [{ profile: "gistic", label: "Putative copy-number alterations from GISTIC", alterationType: "COPY_NUMBER_ALTERATION", n: 300 },
+ { profile: "cna", label: "Copy-number alterations", alterationType: "COPY_NUMBER_ALTERATION", n: 292 }];
+ assert.deepEqual(geneChartProfiles(two), [{ kind: "cna", label: "Putative copy-number alterations from GISTIC (592 samples)" }]);
+ assert.deepEqual(geneChartProfiles([{ profile: "mutations", label: "Mutations", alterationType: "MUTATION_EXTENDED", n: 1234 }]),
+ [{ kind: "mutation", label: "Mutations (1,234 samples)" }]);
+});
+
+test("the charts a gene list draws: one per gene and kind, and one per mutation-type table", () => {
+ assert.equal(geneChartCount({ genes: ["KRAS"], kinds: { KRAS: ["MUTATION", "CNA"] }, types: ["TP53"] }), 3);
+ assert.equal(geneChartCount({ genes: [], kinds: {}, types: [] }), 0);
+});
+
+test("only a change to the genes or the mutation-type tables asks Explore again; showing another kind of a counted gene does not", () => {
+ const mut = { genes: ["KRAS"], kinds: { KRAS: ["MUTATION" as const] }, types: [] };
+ assert.equal(geneChartsAsked(mut, geneChartsChanged(mut, "KRAS", "CNA", true)), false);
+ assert.equal(geneChartsAsked(mut, geneChartsChanged(mut, "EGFR", "CNA", true)), true);
+ assert.equal(geneChartsAsked(mut, geneChartsChanged(mut, "KRAS", "types", true)), true);
+ assert.equal(geneChartsAsked(mut, geneChartsChanged(mut, "KRAS", "MUTATION", false)), true, "its last kind gone: the gene leaves the request");
+});
+
+test("a gene chart added and removed: each kind on its own, the gene counted while either status chart is shown", () => {
+ const empty = { genes: [], kinds: {}, types: [] };
+ const mut = geneChartsChanged(empty, "KRAS", "MUTATION", true);
+ assert.deepEqual(mut, { genes: ["KRAS"], kinds: { KRAS: ["MUTATION"] }, types: [] });
+ const both = geneChartsChanged(mut, "KRAS", "CNA", true);
+ assert.deepEqual(both.kinds, { KRAS: ["MUTATION", "CNA"] });
+ assert.deepEqual(geneChartsChanged(both, "KRAS", "MUTATION", false), { genes: ["KRAS"], kinds: { KRAS: ["CNA"] }, types: [] });
+ assert.deepEqual(geneChartsChanged(geneChartsChanged(both, "KRAS", "MUTATION", false), "KRAS", "CNA", false), empty);
+ assert.deepEqual(geneChartsChanged(mut, "KRAS", "types", true), { genes: ["KRAS"], kinds: { KRAS: ["MUTATION"] }, types: ["KRAS"] }, "mutation types apart");
+ const seven = ["A", "B", "C", "D", "E", "F", "G"].reduce((s, g) => geneChartsChanged(s, g, "CNA", true), empty as Parameters[0]);
+ assert.deepEqual(seven.genes, ["B", "C", "D", "E", "F", "G"], "at most six genes, the earliest dropped");
+ assert.equal(seven.kinds.A, undefined);
+});
+
// STV-AC-2, STV-AC-4: the Genomic tab's charts, as the portal lists them (coadread, seen)
test("the Genomic tab: each chart the selection has data for, its Freq the samples with that data, by Freq then name", () => {
const clinical = [{ key: "sample|FRACTION_GENOME_ALTERED", name: "Fraction Genome Altered", samples: 583, attribute: "FRACTION_GENOME_ALTERED" },
@@ -245,3 +289,21 @@ test("a generic-assay type's tab: the portal's configured text, else its words c
{ type: "GENERIC_ASSAY", assayType: "METHYLATION" }, { type: "GENERIC_ASSAY", assayType: "GENETIC_ANCESTRY" }, { type: "MRNA_EXPRESSION" }];
assert.deepEqual(assayTabs(coadread).map((t) => t.label), ["Arm-level CNA", "Genetic Ancestry", "Methylation"]);
});
+
+// STV-AC-5: the gene tab's charted genes can always be removed (Reviewer, #459): tiles have no close of their own
+test("the gene tab: its chips, each with what it removes, show whatever the selection's profiles hold", () => {
+ const charts = { genes: ["KRAS"], kinds: { KRAS: ["MUTATION" as const, "CNA" as const] }, types: ["TP53"] };
+ const chips = [{ gene: "KRAS", kind: "MUTATION", text: "mutations" }, { gene: "KRAS", kind: "CNA", text: "copy number" }, { gene: "TP53", kind: "types", text: "mutation types" }];
+ // no selected sample profiled: no profile to pick, the note, and every chip
+ const none = geneTabView([{ profile: "mutations", label: "Mutations", alterationType: "MUTATION_EXTENDED", n: 0 }], charts, "mutation", false);
+ assert.equal(none.current, null);
+ assert.match(none.note!, /No selected study has mutation or copy-number data/);
+ assert.deepEqual(none.chips, chips);
+ // with profiles: the picker, its kind, and the same chips
+ const dt = [{ profile: "mutations", label: "Mutations", alterationType: "MUTATION_EXTENDED", n: 534 },
+ { profile: "gistic", label: "Putative copy-number alterations from GISTIC", alterationType: "COPY_NUMBER_ALTERATION", n: 592 }];
+ const some = geneTabView(dt, charts, "cna", false);
+ assert.deepEqual([some.current?.kind, some.kind, some.note, some.chips], ["cna", "CNA", null, chips]);
+ assert.equal(geneTabView(dt, charts, "mutation", true).kind, "types", "Mutation Type");
+ assert.equal(geneTabView(dt.slice(1), charts, "mutation", false).current?.kind, "cna", "the profile asked for absent: the first offered");
+});