Skip to content

fix: rebuild consensus predictions when weights change on re-run (#100) - #105

Merged
nextgenusfs merged 3 commits into
nextgenusfs:mainfrom
vinvomero:fix/consensus-weights-rerun
Oct 25, 2026
Merged

nextgenusfs merged 3 commits into
nextgenusfs:mainfrom
vinvomero:fix/consensus-weights-rerun

Conversation

@vinvomero

Copy link
Copy Markdown
Contributor

Fixes #100.

Problem

Re-running predict into an existing output folder with different -w/--weights gave identical results. The new weights were calculated and logged ("Calculated ab initio weights from data: …"), but the consensus step reused misc/consensus.predictions.gff3 whenever it existed. So generate_consensus never saw the new weights. When a BAM was given, the UTR-refined consensus was reused the same way, so even a rebuilt consensus would have been replaced by the stale refined file.

(The other symptom in #100, a requested augustus-hiq weight being overridden on a fresh run, was already fixed in c3c7da8.)

Fix

  • After consensus is generated, the weights it was built with are written to misc/consensus.predictions.weights.json.

  • On a re-run, the existing consensus is reused only if the current weights match that record, in any order. Otherwise these files are removed and consensus is regenerated:

    • the consensus
    • the UTR-refined consensus
    • the pre-refinement backup
    • the record

    The log says why, e.g. Re-generating consensus predictions: weights changed (helixer: 2 -> 4).

  • A consensus with no record, such as a run folder from before this change, is treated as stale and rebuilt once. Its weights are unknown, and reusing it is the bug being fixed.

  • The record is written only after generate_consensus returns. A failed run leaves no record, so the next run rebuilds.

The decision and file removal live in three small helpers in utilities.py. predict() just calls them at the existing checkpoint. Only the weights trigger a rebuild. Other consensus inputs (max intron, the set of prediction files, alignments) keep today's reuse behaviour.

Tests

New tests/unit/test_utilities_consensus.py (12 tests) covers:

  • no consensus
  • consensus with no record
  • same weights, also in a different order
  • a changed weight, with the reason naming it
  • tools added or removed
  • malformed records
  • an empty consensus file
  • the record format
  • file removal, including a stale UTR-refined file left behind after the consensus was deleted by hand

Full suite run locally on Windows: 261 passed on this branch vs 249 on main, a difference of exactly the 12 new tests. The failure and collection-error set is identical on both: CLI/subprocess tests, the /tmp tmpdir test, and modules that need gapmm2, which doesn't build on Windows. That's why test_predict*.py didn't run locally.

The tests cover the helpers, not a full predict run. The existing test_predict.py doesn't call the real predict(), and I haven't run the pipeline end-to-end on a genome with these changes.

Possible follow-up

The same staleness applies to the other consensus inputs. Relatedly, re-runs reuse abinitio_algorithm_scoring.json, so a new -e prediction added on a re-run isn't scored and only gets a weight if -w names it. Happy to extend the record to cover those if useful.

🤖 Generated with Claude Code

vinvomero and others added 3 commits October 22, 2026 16:55
…tgenusfs#100)

On a re-run, predict reused misc/consensus.predictions.gff3 whenever it
existed, so new -w/--weights were calculated and logged but never used
(nextgenusfs#100). The UTR-refined consensus was reused the same way.

The weights used to build the consensus are now recorded in
consensus.predictions.weights.json. On re-run the consensus is reused
only if the current weights match the record; otherwise (or when there
is no record, e.g. a run folder from before this change) the stale
consensus, UTR-refined consensus, pre-refinement backup and record are
removed and consensus is regenerated, with the reason logged.

The decision and file removal live in small helpers in utilities.py,
covered by tests/unit/test_utilities_consensus.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Define the UTR-refined and pre-refinement backup paths once, before the
consensus rebuild check, instead of again inside the UTR-refinement
block, and read the weights record with the existing load_json helper.
No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nextgenusfs
nextgenusfs merged commit d7ceb91 into nextgenusfs:main Oct 25, 2026
6 checks passed
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.

weights not taken into account when re-running

2 participants