From 0d71be835bca29a99e8ca39cb6940eb7d15ab7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Miguel=20P=C3=A9rez=20Canales?= Date: Wed, 25 Nov 2026 06:35:12 +0100 Subject: [PATCH] feat(window): an arm carries its donor policy, and the strata have a plain way in The PLM ablation for Ana runs each model with experimental donors and with every code but ND, at seven depths. The window summary described an arm by model, scoring, depth and self-exclusion only, so the two donor policies of one model drew as one series in the depth view, filtered as one model and labelled identically. - The summary reads the candidate set's donor policy and gives each arm donors: "experimental" when the policy kept experimental codes only, "all" when it kept any other, None without a recorded policy. - The panel tells arms apart by armModel, the PLM plus "exp" for experimental donors, in the model filter, the depth series, the detail columns and the labels. sameExclusion compares the donors too. - The window page opens the strata tab from a plain entry above the panel, where before they hid behind a small toggle on each result row (the author, 2026-11-25). --- .../instrument/evaluation/[id]/page.tsx | 12 +++++++++ .../web/components/window-panel/DepthView.tsx | 18 ++++++------- .../components/window-panel/DetailView.tsx | 15 ++++++++--- apps/web/lib/windowPanel.ts | 26 +++++++++++++++---- apps/web/messages/de.json | 6 ++++- apps/web/messages/en.json | 6 ++++- apps/web/messages/es.json | 6 ++++- apps/web/messages/pt.json | 6 ++++- apps/web/messages/zh.json | 6 ++++- protea/services/_window_summary.py | 13 ++++++++++ tests/test_the_window_summary.py | 11 ++++++++ 11 files changed, 103 insertions(+), 22 deletions(-) diff --git a/apps/web/app/[locale]/instrument/evaluation/[id]/page.tsx b/apps/web/app/[locale]/instrument/evaluation/[id]/page.tsx index e8a2d2fc..3573f889 100644 --- a/apps/web/app/[locale]/instrument/evaluation/[id]/page.tsx +++ b/apps/web/app/[locale]/instrument/evaluation/[id]/page.tsx @@ -388,6 +388,18 @@ export default function EvaluationDetailPage() { ); })()} + {/* The strata were one small toggle per result row; the reader who comes for + them gets a plain way in (the author, 2026-11-25). */} + + + {t("strataCta.title")} + {t("strataCta.body")} + + → +
diff --git a/apps/web/components/window-panel/DepthView.tsx b/apps/web/components/window-panel/DepthView.tsx index 137dd547..b2697d64 100644 --- a/apps/web/components/window-panel/DepthView.tsx +++ b/apps/web/components/window-panel/DepthView.tsx @@ -4,17 +4,17 @@ import { useTranslations } from "next-intl"; import { - CELLS, - DEPTHS, - SCORINGS, - SCORING_SHORT, armLabel, + armModel, cellEdge, cellF, + CELLS, + DEPTHS, isNeighbour, - modelName, modelsOf, sameExclusion, + SCORING_SHORT, + SCORINGS, type SummaryResult, } from "@/lib/windowPanel"; import { Figure, INK, Legend, SERIES, extent, fmt, pressable, signed, ticks, useTooltip } from "./chart"; @@ -26,7 +26,7 @@ function seriesOf(view: PanelView, cell: string): { series: Series[]; model: str const { state, shown } = view; const arms = shown.filter((r) => isNeighbour(r) && r.arm.depth != null && cellF(r, cell) != null); const models = modelsOf(arms); - const swept = models.filter((m) => arms.some((r) => modelName(r.arm.model) === m && r.arm.depth !== 30)); + const swept = models.filter((m) => arms.some((r) => armModel(r) === m && r.arm.depth !== 30)); const model = swept.includes(state.model) ? state.model : (swept[0] ?? models[0] ?? ""); const byDepth = (a: SummaryResult, b: SummaryResult) => (a.arm.depth ?? 0) - (b.arm.depth ?? 0); if (state.group === "model") { @@ -37,7 +37,7 @@ function seriesOf(view: PanelView, cell: string): { series: Series[]; model: str .map((m, i) => ({ label: `${m} · ${state.scoring}`, colour: SERIES[i % SERIES.length], - points: arms.filter((r) => modelName(r.arm.model) === m && r.arm.scoring === state.scoring).sort(byDepth), + points: arms.filter((r) => armModel(r) === m && r.arm.scoring === state.scoring).sort(byDepth), })) .filter((s) => s.points.length), }; @@ -48,7 +48,7 @@ function seriesOf(view: PanelView, cell: string): { series: Series[]; model: str series: SCORINGS.map((s, i) => ({ label: `${model} · ${s}`, colour: SERIES[i], - points: arms.filter((r) => modelName(r.arm.model) === model && r.arm.scoring === s).sort(byDepth), + points: arms.filter((r) => armModel(r) === model && r.arm.scoring === s).sort(byDepth), })).filter((s) => s.points.length), }; } @@ -262,7 +262,7 @@ export default function DepthView({ view }: { view: PanelView }) { return ( - {isNeighbour(a) ? `${modelName(a.arm.model)} · ${SCORING_SHORT[a.arm.scoring ?? ""] ?? a.arm.scoring}` : armLabel(a)} + {isNeighbour(a) ? `${armModel(a)} · ${SCORING_SHORT[a.arm.scoring ?? ""] ?? a.arm.scoring}` : armLabel(a)} diff --git a/apps/web/components/window-panel/DetailView.tsx b/apps/web/components/window-panel/DetailView.tsx index e7065cf0..5c533e5c 100644 --- a/apps/web/components/window-panel/DetailView.tsx +++ b/apps/web/components/window-panel/DetailView.tsx @@ -5,7 +5,16 @@ import Link from "next/link"; import { useState } from "react"; import { useTranslations } from "next-intl"; -import { CELLS, armLabel, cellEdge, cellF, isNeighbour, mayNotBeRead, modelName, type SummaryResult } from "@/lib/windowPanel"; +import { + armLabel, + armModel, + cellEdge, + cellF, + CELLS, + isNeighbour, + mayNotBeRead, + type SummaryResult, +} from "@/lib/windowPanel"; import { INK, deltaFill, fmt, signed } from "./chart"; import type { PanelView } from "./WindowPanel"; @@ -21,7 +30,7 @@ export default function DetailView({ view }: { view: PanelView }) { const keyOf: Record number | string> = { f: (r) => cellF(r, state.cell) ?? -1, delta: (r) => (cellF(r, state.cell) ?? -1) - refF(state.cell), - model: (r) => (isNeighbour(r) ? modelName(r.arm.model) : (r.arm.method ?? "")), + model: (r) => (isNeighbour(r) ? armModel(r) : (r.arm.method ?? "")), scoring: (r) => r.arm.scoring ?? "", k: (r) => r.arm.depth ?? 0, time: (r) => r.created_at ?? "", @@ -88,7 +97,7 @@ export default function DetailView({ view }: { view: PanelView }) { {colour ? : null} {r.id.slice(0, 8)} - {isNeighbour(r) ? modelName(r.arm.model) : armLabel(r)} + {isNeighbour(r) ? armModel(r) : armLabel(r)} {r === ref ? ` (${t("referenceShort")})` : ""} {r.arm.scoring ?? "—"} diff --git a/apps/web/lib/windowPanel.ts b/apps/web/lib/windowPanel.ts index af3883b5..e33658f5 100644 --- a/apps/web/lib/windowPanel.ts +++ b/apps/web/lib/windowPanel.ts @@ -47,6 +47,8 @@ export type PanelArm = { method: string | null; depth: number | null; exclude_self: boolean | null; + /** Which annotations it transferred; two donor policies of one model are two arms. */ + donors?: "experimental" | "all" | null; /** Who left the query's neighbourhood with it: its twins too ("sequence") or * nobody ("accession"). Null when the run left the rule to the flag. */ self_exclusion?: string | null; @@ -152,9 +154,19 @@ export function isNeighbour(r: SummaryResult): boolean { } /** The arm in full: "ESM-2 650M · embedding_only · k=1", or the method's name. */ +/** + * The model as the panel tells arms apart: the PLM, and "exp" when its donors were + * experimental annotations only. Keyed by the PLM alone, two donor policies of one + * model drew as one series and filtered as one model (2026-11-25). + */ +export function armModel(r: SummaryResult): string { + const name = modelName(r.arm.model); + return r.arm.donors === "experimental" ? `${name} · exp` : name; +} + export function armLabel(r: SummaryResult): string { if (!isNeighbour(r)) return methodName(r.arm.method) || r.prediction_set_id.slice(0, 8); - const parts = [modelName(r.arm.model), r.arm.scoring ?? "candidates"]; + const parts = [armModel(r), r.arm.scoring ?? "candidates"]; if (r.arm.depth != null) parts.push(`k=${r.arm.depth}`); if (r.arm.self_exclusion === "accession") parts.push("self by accession"); return parts.join(" · "); @@ -162,13 +174,17 @@ export function armLabel(r: SummaryResult): string { /** Two arms that differ only in which proteins left with the query are two arms. */ export function sameExclusion(a: SummaryResult["arm"], b: SummaryResult["arm"]): boolean { - return a.exclude_self === b.exclude_self && (a.self_exclusion ?? null) === (b.self_exclusion ?? null); + return ( + a.exclude_self === b.exclude_self && + (a.self_exclusion ?? null) === (b.self_exclusion ?? null) && + (a.donors ?? null) === (b.donors ?? null) + ); } /** The arm in a few characters, for rows and cells: "650M emb k=1". */ export function armShort(r: SummaryResult): string { if (!isNeighbour(r)) return methodName(r.arm.method) || r.prediction_set_id.slice(0, 8); - const model = modelName(r.arm.model).replace(/^ESM-2 /, ""); + const model = armModel(r).replace(/^ESM-2 /, ""); const scoring = r.arm.scoring ? (SCORING_SHORT[r.arm.scoring] ?? r.arm.scoring) : "cand"; const self = r.arm.self_exclusion === "accession" ? " acc" : ""; return `${model} ${scoring}${r.arm.depth != null ? ` k=${r.arm.depth}` : ""}${self}`; @@ -218,7 +234,7 @@ export function visibleResults(results: SummaryResult[], f: PanelFilters): Summa if (r.arm.reading !== f.reading) return false; if (!f.superseded && isSuperseded(r)) return false; if (!isNeighbour(r)) return true; - if (f.models.length && !f.models.includes(modelName(r.arm.model))) return false; + if (f.models.length && !f.models.includes(armModel(r))) return false; if (f.scorings.length && !f.scorings.includes(r.arm.scoring ?? "")) return false; if (f.depths.length && (r.arm.depth == null || !f.depths.includes(r.arm.depth))) return false; return true; @@ -236,7 +252,7 @@ export function referenceOf(shown: SummaryResult[], asked: string | null): Summa export function modelsOf(results: SummaryResult[]): string[] { const seen: string[] = []; for (const r of results) { - const name = isNeighbour(r) ? modelName(r.arm.model) : null; + const name = isNeighbour(r) ? armModel(r) : null; if (name && !seen.includes(name)) seen.push(name); } return seen; diff --git a/apps/web/messages/de.json b/apps/web/messages/de.json index f8e75618..1ddf3178 100644 --- a/apps/web/messages/de.json +++ b/apps/web/messages/de.json @@ -1201,7 +1201,11 @@ }, "statDelta": "Delta-Proteine", "statsTitle": "Statistiken des Sets", - "title": "CAFA-Evaluierung" + "title": "CAFA-Evaluierung", + "strataCta": { + "title": "Ergebnisse nach Schicht", + "body": "Jeder Arm in den neun Zellen, aufgeteilt nach Sequenzidentität zum nächsten annotierten Protein und nach Länge, mit n in jedem Band." + } }, "scoring": { "title": "Scoring", diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json index f4ee9b88..207b087f 100644 --- a/apps/web/messages/en.json +++ b/apps/web/messages/en.json @@ -1200,7 +1200,11 @@ }, "statDelta": "delta proteins", "statsTitle": "Set stats", - "title": "CAFA Evaluation" + "title": "CAFA Evaluation", + "strataCta": { + "title": "Results by stratum", + "body": "Every arm in the nine cells, opened by sequence identity to the nearest annotated protein and by length, with n in each band." + } }, "scoring": { "title": "Scoring Configs", diff --git a/apps/web/messages/es.json b/apps/web/messages/es.json index 40c66c5f..893a7d00 100644 --- a/apps/web/messages/es.json +++ b/apps/web/messages/es.json @@ -1200,7 +1200,11 @@ }, "statDelta": "proteínas del delta", "statsTitle": "Estadísticas del conjunto", - "title": "Evaluación CAFA" + "title": "Evaluación CAFA", + "strataCta": { + "title": "Resultados por estrato", + "body": "Cada brazo en las nueve celdas, abiertas por identidad de secuencia con la proteína anotada más cercana y por longitud, con n en cada banda." + } }, "scoring": { "title": "Configuraciones de scoring", diff --git a/apps/web/messages/pt.json b/apps/web/messages/pt.json index 812ee5ff..e8a106ca 100644 --- a/apps/web/messages/pt.json +++ b/apps/web/messages/pt.json @@ -1201,7 +1201,11 @@ }, "statDelta": "proteínas do delta", "statsTitle": "Estatísticas do conjunto", - "title": "Avaliação CAFA" + "title": "Avaliação CAFA", + "strataCta": { + "title": "Resultados por estrato", + "body": "Cada braço nas nove células, abertas por identidade de sequência com a proteína anotada mais próxima e por comprimento, com n em cada banda." + } }, "scoring": { "title": "Scoring", diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.json index f719c78a..f3bfd0bd 100644 --- a/apps/web/messages/zh.json +++ b/apps/web/messages/zh.json @@ -1201,7 +1201,11 @@ }, "statDelta": "差集蛋白数", "statsTitle": "评估集统计", - "title": "CAFA 评估" + "title": "CAFA 评估", + "strataCta": { + "title": "分层结果", + "body": "每个方法在九个单元格中的结果,按与最近已注释蛋白的序列一致性和长度分层,并给出每层的 n。" + } }, "scoring": { "title": "评分配置", diff --git a/protea/services/_window_summary.py b/protea/services/_window_summary.py index 2ff3ab5b..daaef111 100644 --- a/protea/services/_window_summary.py +++ b/protea/services/_window_summary.py @@ -27,6 +27,7 @@ from sqlalchemy.orm import Session from protea.core._evaluation_leakage import FITTED_BACKENDS +from protea.core.ia_regimes import EXPERIMENTAL_EVIDENCE from protea.core.leakage_guard import Frame, release_ordinal, training_cut_verdict #: The cells of a result, as the evaluator stores them: ``results[setting][aspect]``. @@ -57,6 +58,8 @@ ps.meta ->> 'exclude_self_neighbour') AS exclude_self, coalesce(cand.meta ->> 'self_exclusion', ps.meta ->> 'self_exclusion') AS self_exclusion, + coalesce(cand.meta -> 'donor_policy' -> 'evidence_codes', + ps.meta -> 'donor_policy' -> 'evidence_codes') AS donor_codes, j.payload ->> 'score_reading' AS job_reading FROM evaluation_result r JOIN prediction_set ps ON ps.id = r.prediction_set_id @@ -120,6 +123,14 @@ def _cells(results: dict[str, Any]) -> dict[str, dict[str, Any]]: return out +def _donors(codes: list[str] | None) -> str | None: + """``experimental`` when the donor policy kept experimental codes only, ``all`` when it + kept any other, ``None`` without a recorded policy (a method's set, or an older one).""" + if not codes: + return None + return "experimental" if set(codes) <= set(EXPERIMENTAL_EVIDENCE) else "all" + + def summary_row(row: dict[str, Any], frame: Frame | None = None) -> dict[str, Any]: """One result as the panel shows it, on the window ``frame`` spans. @@ -156,6 +167,8 @@ def summary_row(row: dict[str, Any], frame: Frame | None = None) -> dict[str, An # Who left with the query: its twins too ("sequence") or nobody # ("accession"). None when the run left it to the flag. "self_exclusion": row["self_exclusion"], + # Which annotations it transferred: two donor policies of one model are two arms. + "donors": _donors(row.get("donor_codes")), "reading": (results.get("reading") or {}).get("score_reading") or row["job_reading"] or "raw", diff --git a/tests/test_the_window_summary.py b/tests/test_the_window_summary.py index 6309407f..d9e83357 100644 --- a/tests/test_the_window_summary.py +++ b/tests/test_the_window_summary.py @@ -127,6 +127,7 @@ def test_a_neighbour_arm_reads_its_cut_its_exclusion_and_its_reading() -> None: "depth": 3, "exclude_self": True, "self_exclusion": None, + "donors": None, "reading": "percentile_rank", "leak": "not_fitted", "training_release": None, @@ -136,6 +137,16 @@ def test_a_neighbour_arm_reads_its_cut_its_exclusion_and_its_reading() -> None: assert shown["strata"] is None +def test_two_donor_policies_of_one_model_are_two_arms() -> None: + # 2026-11-25: the ablation ran each PLM with experimental donors and with every code + # but ND; keyed by the model alone, the panel drew them as one series. + experimental = ["EXP", "IDA", "IPI", "IMP"] + everything = ["EXP", "IDA", "IEA", "ISS", "TAS"] + assert summary_row(_row(donor_codes=experimental), FRAME)["arm"]["donors"] == "experimental" + assert summary_row(_row(donor_codes=everything), FRAME)["arm"]["donors"] == "all" + assert summary_row(_row(donor_codes=None), FRAME)["arm"]["donors"] is None + + def test_an_arm_that_excluded_only_the_query_says_so() -> None: arm = summary_row(_row(self_exclusion="accession"), FRAME)["arm"] assert (arm["exclude_self"], arm["self_exclusion"]) == (True, "accession")