Repository navigation
Study View: Add chart's gene tab picks a profile, one chart per gene and profile (STV-AC-5) #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<Record<string, ("MUTATION" | "CNA")[]>>({}); | ||
| const geneKindsRef = useRef<Record<string, ("MUTATION" | "CNA")[]>>({}); | ||
| 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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'. |
||
| 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<typeof useExploreState>; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.