Repository navigation
OncoPrint: sort by case list order with a user-defined case list (ONC-SO-3) - #468
Conversation
…-SO-3) The portal's Sort > "Sort by case list order" (ResultsViewOncoprint sortOrder, ResultsViewPageStore givenSampleOrder): with a User-defined Case List the columns follow the typed order; listed and disabled otherwise. - A typed list (lib/id-set-import.ts) is stored with each study's ids in the order given, once each; other sets stay sorted (tidyIdSet in lib/id-sets.ts). - lib/oncoprint-case-list.ts: the cohort's first sampleList/patientList clause, and each column's place (a patient at its first listed sample, a sample column of a patient list at its patient's, unlisted columns last either way). - Sort key "caseList" in the engine and the Python port; refused without a list; conventions.caseList says when it is on offer. The engine applies it (as a clustering), so choosing it re-runs the view; the server SVG carries the cohort definition beside its SQL so it works there too. Verified: npm test 6915/0, Python OK; coadread KRAS TP53 with an 8-id typed list (one unmatched) draws the 7 columns in typed order; disabled without a list; 3 planted bugs each caught by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| * clustering (from values the browser never receives) and the case list order (from the cohort's | ||
| * typed list, which the contract does not carry). | ||
| */ | ||
| export const isEngineSortKey = (k: string): boolean => { const t = k.replace(/^-/, ""); return t.startsWith("cluster:") || t === "caseList"; }; |
There was a problem hiding this comment.
trackSort and selectSort still drop only cluster keys (isClusterKey), so a caseList key stays on as a secondary key. After that, sorting by a track does nothing.
The user picks "case list order" (sort = ["caseList"]), then uses a clinical row's "Sort a-Z". trackSort returns ["SEX","caseList"]. dataPart's engine keys are still ["caseList"], so the view doesn't re-run. engineSorted is true (keys.some(isEngineSortKey)), so the browser doesn't re-sort either. The columns stay in case-list order and the new sort is silently ignored. The same happens with selectSort from ["X","caseList"]. In the portal, sortByData leaves case list mode. Fix: have trackSort/selectSort/clusterSort filter with isEngineSortKey instead of isClusterKey.
| export const pruneSort = (v: V): V => { | ||
| const hidden: string[] = v.hideTracks || []; | ||
| const keep = new Set(["genomic", "id", ...AUTO_TRACKS.filter((l) => !hidden.includes(l)), ...(v.clinical || []), ...heatmapLabels(v), | ||
| const keep = new Set(["genomic", "id", "caseList", ...AUTO_TRACKS.filter((l) => !hidden.includes(l)), ...(v.clinical || []), ...heatmapLabels(v), |
There was a problem hiding this comment.
pruneSort always keeps caseList, but the engine throws when the cohort has no user-defined list. Dropping the list from the query therefore breaks the whole OncoPrint instead of falling back to the default order.
The user sorts by case list order, then uses Modify query to switch to a standard case list (no sampleList/patientList in all). The view's sort still holds "caseList". assembleContract throws "sort: 'caseList' needs a cohort chosen by a user-defined case list" and the figure fails. A cluster key is pruned when its heatmap goes; caseList has no matching prune. The same applies to a saved doc that is edited this way.
| if (!leaf) return null; | ||
| const level = leaf.kind === "sampleList" ? "sample" : "patient"; | ||
| if (typeof leaf.set === "string") { | ||
| const s = idSetIfLoaded(leaf.set); |
There was a problem hiding this comment.
caseListOf uses idSetIfLoaded and returns null without a word when the set isn't loaded. The cohort is then treated as having no list, which goes against invariant 1 (loud rejection) and gives a misleading error.
A caller builds the contract outside the id-set context (or with the set missing from the store). caseListRank is left undefined and the option shows as disabled "(with a user-defined case list)". A view sorted by "caseList" is refused with "needs a cohort chosen by a user-defined case list", even though the cohort names one. loadedIdSet would raise the specific error, as compiling already does.
| return { s, cols }; | ||
| })); | ||
| } | ||
| per = inStudyOrder([...per, ...await Promise.all([...peers.keys()].map((s) => peerColumns(s, gi)))]); |
There was a problem hiding this comment.
Columns of federated peer studies never get a case-list rank, so they are always drawn after every listed column, with no caveat.
In a multi-study cohort whose user-defined list names samples in a study served by a peer, rankByCaseList runs only for local studies. peerColumns columns aren't in caseListRank, so the comparator puts them last as "unlisted" even though the list names them. The order is silently wrong for those columns. Invariant 1 asks for loud rejection rather than an approximation.
| // The staircase switches re-sort here too: the engine's order was drawn with its own. | ||
| const keys = sortKeys.length ? sortKeys : data.conventions.sort; | ||
| const engineSorted = keys.some((k) => k.replace(/^-/, "").startsWith("cluster:")); | ||
| const engineSorted = keys.some(isEngineSortKey); |
There was a problem hiding this comment.
With a caseList sort, the staircase switches (driver / mutation type / ignore VUS) no longer change anything. They are FIGURE_KEYS, so they don't re-run the view, and engineSorted stops the browser re-sort.
Sorted by case list order, the unlisted columns (and the patients tied under one listed patient) are ordered by the engine's genomic tie-break. Toggling "driver" or "ignore VUS" neither re-runs the view nor re-sorts in the browser, so those columns keep the staircase drawn with the old switches. The comment above says the switches re-sort here too.
| const duplicates = ids.length - new Set(ids).size; | ||
| const set = await saveIdSet(principal, { | ||
| name: String(b.name ?? ""), level: level as IdSetLevel, perStudy, | ||
| name: String(b.name ?? ""), level: level as IdSetLevel, perStudy, ordered: true, |
There was a problem hiding this comment.
Sets stored before this change were saved sorted, but they still turn on "case list order", which then draws alphabetical order as if it were the typed order.
Take a User-defined Case List saved before this PR (its ids_gz is sorted). Opening the query offers "case list order" enabled (conventions.caseList is set whenever a list leaf exists). Choosing it draws the ids alphabetically, not in the order typed, and nothing says the stored set predates ordering.
| if (!list) return; | ||
| let patientOf: Map<string, string> | undefined; | ||
| if (unit === "sample" && list.level === "patient") { | ||
| const r = await lqRows("oncoprint:caseListPatients", "SELECT DISTINCT sid, pid FROM (\n" + rows + "\n)", s); |
There was a problem hiding this comment.
For sample columns with a patient list, every study in every group runs an extra oncoprint:caseListPatients query just to map each sample to its patient. The column query it follows already reads the same rows.
columnRowsSql already does SELECT DISTINCT over the same (pid, sid) rows. In sample mode it could also select pid (or the ColumnRows could carry it), which would avoid a second ClickHouse round trip per study per group over the full cohort subquery.
| <option value={sortKeys[0]}>{sortKeys[0]}</option>} | ||
| <option value="genomic">genomic staircase</option> | ||
| <option value="id">{data.unit} id</option> | ||
| <option value="caseList" disabled={!data.conventions.caseList}> |
There was a problem hiding this comment.
The Sort select has no option for "-caseList", which the DSL accepts, so a view sorted descending by case list shows a value the select can't display.
A doc with sort ["-caseList"] makes sortKeys[0] "-caseList". No option matches, so the select shows a blank or the first option, and the user can't tell how the figure is sorted. The cluster key has a fallback <option value={sortKeys[0]}> for the same case.
|
Review verdict: changes Blocking:
Checked and fine:
Non-blocking items are inline (nits): pruneSort keeping CI: planted-bugs and gate-e2e were still pending at review time. |
- trackSort, selectSort and clusterSort drop every engine sort key (isEngineSortKey), so a track's Sort a-Z, the sort select or a clustering ends the case list order as the portal's sortByData does; before, caseList stayed as a second key, the view did not re-run and the new sort was ignored. - caseListOf reads a stored set with loadedIdSet: a set the request did not read is refused by name instead of being taken for no list. - sort "caseList" is refused when a federation peer draws some columns. - The sort select shows "-caseList" (DSL only) as "case list order, reversed". - Planted bugs track-sort-keeps-clustering and cluster-keeps-other-profile follow the moved code; each still caught by hand. Verified: npm test 6920/0; test/oncoprint-case-list.test.ts CL9 (5 cases) and the refusal case; browser: case list order, then patient id, re-runs with sort ["id"] and draws id order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz
|
Fixed in fa0464a.
|
|
Re-review: pass. fa0464a fixes the blocking finding.
The sort select also offers "case list order, reversed" when that's the current key. |
Summary
OncoPrint › sort gets the portal's case list order (ONC-SO-3): with a user-defined case list, the columns in the order its ids were typed (ResultsViewOncoprint
sortOrder1776-1800, ResultsViewPageStoregivenSampleOrder2960-2989). As in the portal (caseListSortPossible, OncoprintControls 795-815), the option is always listed and disabled unless the query uses a user-defined list.POST /api/id-sets,lib/id-set-import.ts) now keeps each study's ids in the order given, once each; it used to sort them. Other sets (a lock's, from a query) stay sorted (tidyIdSet(m, ordered), moved fromlib/id-set-store.tsto the purelib/id-sets.ts). The query dialog's User-defined Case List (Query page: genomic profiles and case set beside the gene query #167) saves through it, so typed order survives, and "Modify query" reads the list back in that order. An unowned typed list is now stored by its ids and their order, so the same ids in another order are another set.lib/oncoprint-case-list.ts:caseListOftakes the firstsampleList/patientListclause of the cohort'sall, from a stored set or from inline ids.caseListRanksgives each column's place:"caseList"in the engine (lib/oncoprint-assemble.ts, Pythonassemble_contract(case_list_rank=…)).conventions.caseListsays the order is on offer, and the figure enables the option.isEngineSortKey,dataPart).lib/views/oncoprint/run.ts), so the order works there too.lib/dsl-reference.tsdocuments the"caseList"key and the kept order.Spec IDs
Covered: ONC-SO-3.
Ours alone:
"-caseList"exists through the DSL; the portal's menu has no such choice.Verification
test/oncoprint-case-list.test.tsCL1-CL8, 15 cases, from the legacy functions above;python/tests/test_case_list_sort.pymirrors CL6-CL7.npm test: 6915 pass, 0 fail (test/id-set-import.test.tsnow expects the typed order and has a case for it).npm run test:python: OK.KRAS TP53, User-defined Case List typed as TCGA-AA-3502-01, TCGA-3L-AA1B-01, TCGA-A6-2671-01, TCGA-AG-3732-01, TCGA-AA-3662-01 (no such sample), TCGA-CM-4743-01, TCGA-4N-A93T-01, TCGA-AZ-6599-01:scripts/mutants/oncoprint/case-list-order.ts(3: the set saved sorted, a patient at its last sample, unlisted columns first when descending). Each is caught by hand. All 678 sites are found once.Review fixes (fa0464a)
isEngineSortKeyintrackSort,selectSort,clusterSort), as the portal's sortByData leaves case-list mode. Before,["SEX","caseList"]neither re-ran nor re-sorted. Covered by CL9 (5 cases). Browser: case list order, then patient id, re-runs withsort: ["id"]and draws id order.loadedIdSet), not taken for "no list"."caseList"is refused when a federation peer draws some columns, instead of drawing them last."-caseList"as "case list order, reversed".npm test: 6920 pass, 0 fail. The planted bugstrack-sort-keeps-clusteringandcluster-keeps-other-profilefollow the moved code; each is still caught by hand. All 678 sites are found once.Left as they are:
caseListsort with no list in the cohort: Modify query builds a fresh Results link without the page's changes, so the sort doesn't carry over. Only a hand-edited document reaches the engine's refusal, which names the reason (invariant 1).Tracker
PORTAL-PARITY, under Results → OncoPrint, the default view, Sort menu item, tick
as
and, under Tracks › Clinical (user's decision 2026-11-19, ONC-STM-4: keep ours), replace
with
Scorecard
01-oncoprint.mdrows:| ONC-SO-3 | ✅ | C | Sort › "case list order", enabled with a User-defined Case List: typed order, kept by the stored set; a patient at its first listed sample; disabled otherwise, as the portal's (
lib/oncoprint-case-list.ts, sort keycaseList) (#468) || ONC-STM-4 | ✅ | B | Q1, 2026-11-18: every attribute's Freq as the portal's, patient-level ones over samples (#264). Mutation spectrum: ours 89.9 %, the portal's 99.7 %; recorded as Ours alone by the user's decision (2026-11-19): the portal's
sample_derived.sequencedmatches bare sample ids across studies'_sequencedlists, ours counts the samples the study's mutation profile holds |Preview
Query dialog → User-defined Case List (a few ids, out of order) → Oncoprint → sort → case list order.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3ezTZqTUJJDrEaiCKckHz