Skip to content

feat(eval): the sink carries which protein each row is - #25

Merged
frapercan merged 1 commit into
mainfrom
feat/sink-carries-protein-identity
Aug 19, 2026
Merged

frapercan merged 1 commit into
mainfrom
feat/sink-carries-protein-identity

Conversation

@frapercan

Copy link
Copy Markdown
Owner

Third and final piece of the per-protein sink. #23 emitted the arrays, #24 made
them reachable from cafa_eval, and this makes them usable.

The gap

The arrays were anonymous, indexed by an opaque row number. Every axis the sink
exists to support is keyed by protein:

  • sequence length
  • identity to the nearest donor
  • taxonomic relation to the nearest donor

None can be joined to a row number, so the feature as shipped could not do the
one thing it was built for. I found this while writing the consumer, at the point
of asking which protein row 0 was.

Two numberings, which is why this is not one line

The NK/LK kernel receives every row, so array row i is matrix row i. The PK
kernel can be handed a subset:

pred_sub = pred[proteins_has_gt, :]

after which the array numbering and the ids numbering disagree. compute_metrics
is what performs that subsetting, so it is what records the mapping, rather than
leaving each caller to reconstruct it from state it does not have.

Getting this wrong would attribute one protein's score to another. That is
exactly the failure the consuming project spent a week correcting in its
neighbour search, where a positional misalignment produced plausible numbers for
a fortnight. So there is a test asserting row_index has one entry per array
row, rather than a comment saying it should.

Also

Identity is None when not supplied rather than guessed, and the id map is
copied rather than aliased, with tests for both.

pytest tests -q: 29 passed, 6 xfailed. ruff and mypy clean.

The arrays were anonymous. Every axis they exist to support, sequence
length, identity to the nearest donor, taxonomic relation, is keyed by
protein, so arrays indexed by an opaque row number cannot be joined to
any of them and the feature does not deliver what it was built for.

Records now carry the ground truth's protein-to-index map and a row_index
mapping array row to that numbering. Both are needed because two
numberings are in play: the NK/LK kernel sees every row, so array row i
is matrix row i, while the PK kernel can be handed a subset via
pred[proteins_has_gt] and the two then disagree. compute_metrics knows
which subsetting it performed, so it is what records the mapping rather
than leaving the caller to reconstruct it.

Getting this wrong would attribute one protein's score to another, which
is precisely the failure the consuming project spent a week correcting in
its neighbour search. It is worth a test rather than a comment, so there
is one asserting row_index has exactly one entry per array row.

Identity is absent rather than guessed when not supplied, and the id map
is copied rather than aliased.
@frapercan
frapercan merged commit 2cb2e66 into main Aug 19, 2026
6 checks passed
@frapercan
frapercan deleted the feat/sink-carries-protein-identity branch August 19, 2026 08:34
github-actions Bot pushed a commit to frapercan/PROTEA that referenced this pull request Aug 19, 2026
…#784)

The layer that makes stratification possible, plus the cafaeval pin that
feeds it
(frapercan/cafaeval-protea#25).

## Why the board can only stratify by two axes today

Three of the axes this project is required to report are properties of a
**protein**: sequence length, identity to the nearest donor, taxonomic
relation
to it. The stored evaluation is one number per `(category, aspect)`
cell, so none
of them is recoverable from it however it is sliced. Category and aspect
are
reportable only because cafaeval happens to partition the ground truth
on them
before aggregating.

`PerProteinSink` hands over the vectors before `.sum(axis=0)` collapses
them.
This module turns one sink into rows keyed by accession, which join to
`protein.length` and to `identity_nw` / `taxonomic_relation` in
`go_prediction`.

## Three ways to be quietly wrong, each refused

**Wrong threshold column.** cafaeval builds thresholds as
`arange(th_step, 1, th_step)`. We rebuild that and assert the width
matches the
emitted arrays rather than trusting the reconstruction; an off-by-one
would score
every protein at a neighbouring threshold, which reads as a plausible
number. The
assertion earned itself immediately by catching a wrong fixture in its
own test.

**Wrong protein.** Two numberings are in play: the NK/LK kernel sees
every row,
the PK kernel is handed `pred[proteins_has_gt]`. A record lacking either
the id
map or the row index, or whose row index length disagrees with the
arrays, is
**dropped** rather than written under a guess. This is the positional
misalignment that cost this project a fortnight in its neighbour search.

**NaN.** A protein that predicted nothing, or that has no ground truth,
scores
zero rather than NaN, because a NaN propagates into every stratum mean
that
contains it and turns one empty cell into a blank row.

## Two deliberate narrowings

Only the **weighted** variant is kept. `f_micro_w` is what every
published cell
here reports, and an unweighted row would be a different metric under
the same
column name.

A **parquet artifact**, not a table. A table would need a migration, and
migrations here are validated offline and never applied as a side effect
of
running an evaluation.

## Checks

Eleven tests, one per failure mode above plus the arithmetic and a check
that the
per-protein rows sum to the totals the aggregate is built from. `ruff`
clean,
smell budget unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant