'
''
"Your embeddings are being evaluated... This can take a few "
"minutes.
"
)
CHEVRON = (
''
)
# --------------------------------------------------------------------- rail
def rail_html(
boards: list[Board], active_slug: str | None, active_tab: str | None
) -> str:
"""The left navigation: brand, a collapsible "Boards" menu, then the foot links.
The board groups live inside a ```` toggle so the four foot links
(Tasks, Submit, Contribute, Method) stay visible without scrolling. The toggle
is pure HTML/CSS, keeping navigation reload-based and JavaScript-free.
``active_slug`` highlights the board a visitor is on; ``active_tab`` highlights
a foot link, and its absence means we are on a board or the overview, so the
"Boards" menu is the active one. Open boards link to Contribute, mirroring the
overview cards.
"""
on_boards = active_tab is None
summary_cls = "pm-rail-summary pm-active" if on_boards else "pm-rail-summary"
parts = [
'
',
BRAND,
'',
f'Boards{CHEVRON}',
'
',
]
for group in SECTIONS:
cards, opens = in_group(boards, group), open_in_group(boards, group)
if not cards and not opens:
continue
parts.append(
f'
')
for tab, label in FOOT_LINKS:
cls = "pm-foot-link pm-active" if tab == active_tab else "pm-foot-link"
parts.append(
f'{escape(label)}'
)
parts.append("
")
return "".join(parts)
# ------------------------------------------------------------------ boards
def _leading(top) -> str:
"""The card's mini-ranking: a medal, a name and an Elo, one line each.
An empty board asks for the first submission instead of naming a leader.
Every listed model gets a medal, so ``MEDALS`` is what bounds the podium and
``N_TOP_MODELS`` is derived from it -- the two cannot drift into a rank with
no medal to print.
A baseline is listed like any other leader. The card marks nothing; the board
page is where a rating is read against the ``(baseline)`` it anchors on.
"""
parts = ['
Leading (Elo)
']
if not top:
parts.append(
'
No ranked model yet. Be the first.
'
)
return "".join(parts)
for medal, row in zip(MEDALS, top, strict=False):
score = "n/a" if row.elo is None else str(row.elo)
parts.append(
f'
'
)
def render_boards(boards: list[Board], df: pd.DataFrame, by_id: dict[str, dict]) -> str:
"""The Boards overview: every board as a card, grouped by facet.
Live cards link to their board and teaser their leaders; open cards state a
gap and link to Contribute. A section counts its open slices so the page
reads as showing its own gaps, not the registry as the whole territory.
"""
if not boards:
return (
'
The task registry is '
"unavailable right now. Please retry in a moment.
"
)
out = [
'
Leaderboards
',
"
PRIMO evaluates zero-shot representations of omics samples through "
"drug-development-related tasks. Benchmarks are organized by data "
"modality, therapeutic area, or task category.
",
'
',
]
for group in SECTIONS:
cards, opens = in_group(boards, group), open_in_group(boards, group)
if not cards and not opens:
continue
note = escape(GROUP_NOTE.get(group, ""))
counter = f" · +{len(opens)} open" if opens else ""
out.append(
'
'
f'
{escape(group)}
'
f'
{note}{counter}
'
)
out += [_live_card(b, df, by_id) for b in cards]
out += [_open_card(b) for b in opens]
out.append("
")
out.append("
")
return "".join(out)
# ------------------------------------------------------------- html tables
def _fmt_value(value, is_score: bool) -> str | None:
"""Display text for one cell; ``None`` marks a blank (``n/a``) cell."""
try:
if pd.isna(value):
return None
except (TypeError, ValueError):
pass
if isinstance(value, str):
return value
if isinstance(value, numbers.Integral):
return str(int(value))
if isinstance(value, numbers.Real):
if not math.isfinite(float(value)):
return None
return f"{float(value):.3f}" if is_score else str(value)
return str(value)
def _model_cell_html(cell: ModelCell) -> str:
"""Render one model label, allowing only escaped HTTP(S) paper links."""
label = escape(str(cell))
parsed = urlparse(cell.paper_link)
if parsed.scheme in {"http", "https"} and parsed.netloc:
url = escape(cell.paper_link, quote=True)
label = (
f'{label}'
)
chip = (
' ✓ Authors'
if cell.is_author_submission
else ""
)
return label + chip
def _score_columns(df: pd.DataFrame) -> list[str]:
"""Numeric columns to format and bold -- ``Rank`` is an index, not a score."""
return [c for c in df.select_dtypes("number").columns if c not in RIGHT_COLUMNS]
def _score_guide(col: str, row: pd.Series) -> str | None:
"""Return metric context for a native score cell, when identifiable."""
metric = next((name for name in METRIC_GUIDES if f"({name})" in col), None)
if metric is None and col not in {"Elo", "Mean rank", "Mean score"}:
metric = str(row.get("Metric", ""))
return METRIC_GUIDES.get(metric) if metric is not None else None
def _bold_cells(df: pd.DataFrame, score_cols: list[str], axis: int) -> set:
"""Which ``(row, col)`` cells hold the best value.
``axis=0`` bolds the best model per column (the ranked table, read down);
``axis=1`` bolds the best model per row (the per-task table, read across).
"""
bold = set()
if not score_cols:
return bold
if axis == 0:
for col in score_cols:
best = df[col].max(skipna=True)
if pd.notna(best):
for idx, value in df[col].items():
if pd.notna(value) and value == best:
bold.add((idx, col))
else:
for idx, row in df.iterrows():
present = {c: row[c] for c in score_cols if pd.notna(row[c])}
if present:
best = max(present.values())
bold.update((idx, c) for c, v in present.items() if v == best)
return bold
def _cell_class(col: str, is_score: bool, blank: bool) -> str:
if col in NAME_COLUMNS:
return "pm-name"
if col in STRONG_COLUMNS:
return "pm-strong"
if col in METRIC_COLUMNS:
return "pm-metric"
if is_score or col in RIGHT_COLUMNS:
return "pm-num pm-num--dim" if blank else "pm-num"
return ""
def _task_tooltip(task: dict) -> str:
"""Build the expanded clinical context shown for a task name."""
description = str(task.get("description") or "").strip().rstrip(".")
diseases = (
", ".join(str(d) for d in task.get("diseases") or []) or "the listed cohort"
)
patients = task.get("n_subjects") or task.get("n_samples")
patient_text = (
f"{patients:,} patients"
if isinstance(patients, int)
else "an unspecified number of patients"
)
n_samples = task.get("n_samples")
if (
isinstance(n_samples, int)
and isinstance(patients, int)
and n_samples != patients
):
patient_text += f" ({n_samples:,} collection samples)"
modality = str(task.get("modality") or "omics")
tissue = str(task.get("tissue") or "unspecified tissue")
target = str(task.get("target") or task.get("title") or "the task target")
return (
f"{description}. Patients: {patient_text} with {diseases}; "
f"input data: {modality} profiles from {tissue.lower()} tissue; "
f"outcome: {target}."
)
def _df_to_table(
df: pd.DataFrame,
bold_axis: int | None,
empty: str,
task_guides: dict[str, dict] | None = None,
) -> str:
"""Render a DataFrame as a ``pm-table``, escaping every header and cell."""
if df.empty:
return f'
{escape(empty)}
'
score_cols = _score_columns(df)
bold = _bold_cells(df, score_cols, bold_axis) if bold_axis is not None else set()
head = []
for index, col in enumerate(df.columns):
align = (
' style="text-align:right"'
if col in score_cols or col in RIGHT_COLUMNS
else ""
)
head.append(
f'
{escape(str(col))}
"
)
body = []
for idx, row in df.iterrows():
cells = []
for col in df.columns:
is_score = col in score_cols
text = _fmt_value(row[col], is_score)
cls = _cell_class(col, is_score, text is None)
weight = ' style="font-weight:700"' if (idx, col) in bold else ""
guide = (
_score_guide(str(col), row) if is_score and text is not None else None
)
shown = (
_model_cell_html(row[col])
if isinstance(row[col], ModelCell)
else "n/a"
if text is None
else escape(text)
)
if guide:
escaped_guide = escape(guide, quote=True)
score_label = escape(f"Score {text}. {guide}", quote=True)
shown = (
'{shown}'
)
if task_guides and col == "Task" and text is not None:
task = next(
(
candidate
for candidate in task_guides.values()
if candidate.get("title") == text
),
None,
)
if task:
tooltip = _task_tooltip(task)
escaped_tooltip = escape(tooltip, quote=True)
task_label = escape(f"{text}. {tooltip}", quote=True)
shown = (
'{shown}'
)
cells.append(f'
{shown}
')
body.append(f"
{''.join(cells)}
")
return (
'
'
f"
{''.join(head)}
"
f"{''.join(body)}
"
)
# ------------------------------------------------------------------- board
def _board_meta(board: Board) -> str:
return (
f"{escape(board.blurb)} · {board.n_tasks} tasks · {board.n_cohorts} cohorts · "
f"{board.n_patients:,} patients · {escape(modality_label(board.modality))}"
)
def render_board(board: Board | None, df: pd.DataFrame, by_id: dict[str, dict]) -> str:
"""One board: title strip, the ranked leaderboard, then the per-task table."""
if board is None:
return (
'
No board available
'
"
The task registry could not be loaded. Please retry shortly.
"
"
"
)
ranked = _df_to_table(
ranked_table(df, by_id, board),
bold_axis=0,
empty="No model has covered every scored task of this board yet. Be the first to submit.",
)
per_task = _df_to_table(
per_task_table(df, by_id, board),
bold_axis=1,
empty="No submission has scored on this board yet.",
task_guides=by_id,
)
return (
'
Board
'
f"
{escape(board_label(board))}
"
f"
{_board_meta(board)}
"
'
'
'
'
'
Ranked
'
'
We evaluate zero-shot representations of models, so '
"performance should not be considered as the best we can obtain. Only "
"models that covered every task scored by the "
"HVG-1200-genes baseline are ranked. Elo compares models "
"pairwise within each task and never compares AUROC, Pearson and "
"centered Spearman directly; the baseline holds 1000 ELO.
"
f"
{ranked}
"
'
'
'
Per task
'
'
Every submission, partial ones included. Read across a row.
'
f"
{per_task}
"
"
"
)
# ------------------------------------------------------------------- tasks
def render_tasks(by_id: dict[str, dict]) -> str:
"""The Tasks page: one scannable row per hidden target. Provenance is never shown."""
df = tasks_table(list(by_id.values()))
table = _df_to_table(
df,
bold_axis=None,
empty="The task registry is unavailable right now.",
task_guides=by_id,
)
return (
'
Tasks
'
f"
{len(df)} hidden targets. One fixed task probe reads each "
"one out of your embedding; the cohorts stay anonymous, the biology does "
"not.