Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/web/app/[locale]/instrument/evaluation/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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). */}
<Link
href={`/${params.locale}/instrument/evaluation/${params.id}?tab=strata`}
className="mb-4 flex items-center justify-between gap-4 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 hover:bg-blue-100"
>
<span>
<span className="block text-sm font-semibold text-blue-900">{t("strataCta.title")}</span>
<span className="block text-xs text-blue-800">{t("strataCta.body")}</span>
</span>
<span aria-hidden className="text-lg text-blue-700">→</span>
</Link>
<WindowPanel evaluationSetId={params.id} />

<section className="rounded-lg border bg-white shadow-sm">
Expand Down
18 changes: 9 additions & 9 deletions apps/web/components/window-panel/DepthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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") {
Expand All @@ -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),
};
Expand All @@ -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),
};
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export default function DepthView({ view }: { view: PanelView }) {
return (
<g key={a.id}>
<text x={0} y={y + 4} fontSize={12} fill="#0c0a09">
{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)}
</text>
<line x1={X(raw)} x2={X(pct)} y1={y} y2={y} stroke={colour} strokeWidth={2} />
<circle cx={X(raw)} cy={y} r={5} fill={INK.surface} stroke={cellEdge(a, state.cell) ? INK.edge : colour} strokeWidth={2} />
Expand Down
15 changes: 12 additions & 3 deletions apps/web/components/window-panel/DetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -21,7 +30,7 @@ export default function DetailView({ view }: { view: PanelView }) {
const keyOf: Record<SortKey, (r: SummaryResult) => 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 ?? "",
Expand Down Expand Up @@ -88,7 +97,7 @@ export default function DetailView({ view }: { view: PanelView }) {
<td className="px-3 py-1.5">{colour ? <i className="inline-block h-2.5 w-2.5 rounded-full" style={{ background: colour }} /> : null}</td>
<td className="px-3 py-1.5 font-mono text-xs">{r.id.slice(0, 8)}</td>
<td className="px-3 py-1.5">
{isNeighbour(r) ? modelName(r.arm.model) : armLabel(r)}
{isNeighbour(r) ? armModel(r) : armLabel(r)}
{r === ref ? ` (${t("referenceShort")})` : ""}
</td>
<td className="px-3 py-1.5">{r.arm.scoring ?? "—"}</td>
Expand Down
26 changes: 21 additions & 5 deletions apps/web/lib/windowPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,23 +154,37 @@ 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(" · ");
}

/** 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}`;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion apps/web/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion apps/web/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion apps/web/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion apps/web/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion apps/web/messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,11 @@
},
"statDelta": "差集蛋白数",
"statsTitle": "评估集统计",
"title": "CAFA 评估"
"title": "CAFA 评估",
"strataCta": {
"title": "分层结果",
"body": "每个方法在九个单元格中的结果,按与最近已注释蛋白的序列一致性和长度分层,并给出每层的 n。"
}
},
"scoring": {
"title": "评分配置",
Expand Down
13 changes: 13 additions & 0 deletions protea/services/_window_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]``.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_the_window_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
Loading