Repository navigation
feat(eval): optional side channel for the per-protein vectors - #23
Merged
Merged
Conversation
The confusion-matrix kernels build tp_at_tau and pred_at_tau with one row per protein and then collapse them with .sum(axis=0). Everything downstream sees only the collapsed number, so a caller wanting a score stratified by a per-protein property, sequence length, homology to the donor bank, taxonomic distance, has nothing to stratify. PerProteinSink is an optional keyword that defaults to None. It is a sink rather than a return value on purpose: changing the return shape of the kernels would ripple through compute_metrics, evaluate_prediction and cafa_eval and every existing caller of each. With no sink passed, all four signatures, all four return types and every number this library produces are exactly what they were. The arrays handed over are the ones the aggregate was computed from rather than a recomputation, so a caller can verify the two agree. The tests do exactly that: the column sums of the emitted arrays must reproduce the published tp, fp and coverage columns. Two routes to one quantity drift unless something checks, and a stratified table whose cells do not sum to the headline is worse than no stratified table. The dense fallback raises NotImplementedError rather than leaving the sink empty. It fans tau chunks over a fork pool, so the per-protein arrays live in worker processes and never come back; a caller that asked for stratification and silently received none would publish a stratified table with nothing behind it. Arrays are copied into the sink because the kernels reuse their buffers, and a sink holding a view would change under its owner. There is a test for that too.
This was referenced Aug 19, 2026
Merged
github-actions Bot
pushed a commit
to frapercan/PROTEA
that referenced
this pull request
Aug 19, 2026
…in scores (#782) Moves the `cafaeval-protea` pin from `80d705a` to `7335b5b` (frapercan/cafaeval-protea#23). `7335b5b` is `80d705a` plus the optional `PerProteinSink` and nothing else: ``` $ git diff --stat 80d705a 7335b5b -- src/ src/cafaeval/evaluation.py | 84 +++++++++++++++++++++++++++++++----- ``` The lock delta is the reference alone; no other package resolves differently. ## Why The confusion-matrix kernels build `tp_at_tau` and `pred_at_tau` with one row per protein and collapse them with `.sum(axis=0)` before anything downstream sees them. So a score cannot be stratified by any **per-protein** property, and sequence length, identity to the nearest donor and taxonomic relation are all per protein. They are also the three axes the evaluation is supposed to report, and the reason the current board can only stratify by category and aspect. ## Nothing changes until something asks The sink is an optional keyword defaulting to `None`. With no sink passed, every signature, every return type and every number the library produces are byte-identical, and the upstream tests assert exactly that rather than leaving it to inspection. **The 224 rows already on the board stay valid.** ## One incidental improvement The previous lock entry read `reference = "main"` while resolving to a commit, so the recorded intent was a moving branch. This one pins the commit in both fields, so the lock no longer depends on where a branch happens to point. ## What this unblocks Emitting per-protein scores costs no new predictions: the 32 prediction sets are done and clean, and the stratification is an offline pass over them. It also gives the paired comparisons for free, since a paired test needs exactly that per-protein object.
frapercan
added a commit
that referenced
this pull request
Aug 19, 2026
… kernels (#24) Follow-up to #23, which stopped one level short. ## What was wrong #23 wired `PerProteinSink` into the two sparse kernels and `compute_metrics`. Nobody calls those. The consuming project calls `cafa_eval`: ``` cafa_eval -> evaluate_prediction -> compute_metrics -> kernel ``` So the feature existed and could not be reached from the only entry point that uses this library. That is worse than not shipping it, because from outside it reads as done. I caught it while wiring the consumer, at the exact moment of writing the call that would have silently collected nothing. ## What this adds `per_protein_sink` on `evaluate_prediction` and `cafa_eval`, and a namespace and variant tag on every record. The tags are not cosmetic. `evaluate_prediction` calls `compute_metrics` twice per namespace, once unweighted and once weighted, so a full run hands the sink six records. Untagged, a caller cannot tell the weighted BPO arrays from the unweighted CCO ones, and the **weighted** variant is the one carrying `f_micro_w`. An untagged record cannot serve the purpose the sink exists for. ## Unchanged Every default is still `None`. With no sink passed, no signature, no return type and no number this library produces is different, and the existing tests still assert exactly that. ## Tests Three added: that both public entry points expose the parameter, that a record reports its namespace and variant, and that the context defaults to `None` rather than to a guess. `pytest tests -q`: 25 passed, 6 xfailed. `ruff` and `mypy` clean.
frapercan
added a commit
that referenced
this pull request
Aug 19, 2026
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: ```python 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The kernels build
tp_at_tauandpred_at_tauwith one row per protein and thencollapse them:
axis=0is the protein axis. Everything downstream sees only the collapsednumber, so a caller wanting to report a score stratified by a per-protein
property has nothing to stratify. Sequence length, identity to the nearest donor
and taxonomic distance are all per protein, and all three are the axes the
consuming project needs.
The shape of the change
PerProteinSinkis an optional keyword defaulting toNone, on the two sparsekernels and on
compute_metrics.A sink rather than a return value, deliberately: changing the return shape would
ripple through
compute_metrics,evaluate_predictionandcafa_eval, and everyexisting caller of each. With no sink passed, every signature, every return type
and every number this library produces is unchanged, and there is a test
asserting exactly that.
The property the feature rests on
The arrays handed over are the ones the aggregate was computed from, not a
recomputation. So the column sums of the emitted arrays must reproduce the
published
tp,fpand coverage columns, and the tests check it:Two routes to one quantity drift unless something checks. A stratified table whose
cells do not sum to the headline is worse than no stratified table.
Two decisions worth flagging
The dense fallback raises rather than leaving the sink empty. It fans tau
chunks over a fork pool, so the per-protein arrays live in worker processes and
never return. A caller that asked for stratification and silently got none would
publish a stratified table with nothing behind it, which is the failure this
whole feature exists to make impossible.
The arrays are copied. The kernels reuse their buffers, so a sink holding a
view would change under its owner between one call and the next. There is a test
for that.
Checks
pytest tests -q: 22 passed, 6 xfailed.ruff check .andmypyclean.