Skip to content

fix: verify reconstructed sequences by genome name - #193

Open
mmolari wants to merge 5 commits into
feat/merge-cmdfrom
feat/merge-verify
Open

fix: verify reconstructed sequences by genome name#193
mmolari wants to merge 5 commits into
feat/merge-cmdfrom
feat/merge-verify

Conversation

@mmolari

@mmolari mmolari commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Unifies sequence verification across build, merge and reconstruct behind one name-keyed helper. Covers §4.4 of dev/design/merge.md.

Matching by name is the only option left once merge renumbers path ids: neither record order nor FastaRecord::index can pair genomes up. The §4.3 checks from the previous PR make names a valid key, since they are now guaranteed unique.

This turned out to fix two latent bugs rather than just unify style:

  • build --verify panicked. It indexed &fastas[actual.index], valid only when the input records' indices are exactly 0..n-1. Any programmatically assembled record set breaks that — including this repo's own test helper, whose right half carries indices [3, 4, 5] for a 3-record slice. Every existing test escaped it by passing verify=false, so build(.., verify=true) had no coverage at all.
  • reconstruct --verify was unreliable. Records were paired positionally, so a verification file with surplus records silently passed (exit 0); too few gave a misleading expected length 0 but got N; and a merged graph failed spuriously with expected length N but got N at identical lengths, because whole FastaRecords were compared and index differs after relabeling.

pangraph/reconstruct.rs is a new home for reconstruction (it is a graph operation — pangraph/pangraph.rs was reaching up into commands::) and holds the shared API: path_ids_by_name, reconstruct_genome, reconstruct_by_name, sequences_by_name, verify_genome, verify_graph_sequences. compare_sequences is deleted.

verify_graph_sequences takes a GenomeCoverage argument, which was not in the original §4.4 sketch: build's intermediate clade graphs hold only their own clade's genomes and need Partial, while the final build graph, a merged graph and reconstruct --verify require Complete. Making the final build check Complete is a small gain — nothing previously noticed a genome going missing.

reconstruct --verify keeps streaming rather than adopting the map: it is the only one of the three that does not otherwise need every genome resident, and a map would make peak memory proportional to total genome length (~2.5 GB for 500 E. coli genomes, vs ~10 MB today). It shares verify_genome and its error formatting.

Errors now name the genome and, for equal-length differences, the first differing position with context:

Sequence mismatch for genome 'NZ_CP027173.1' at position 100 (length 132518):
  expected: GAACCCGAACAATCCGTTGTA
  actual:   GAACCCGAACTATCCGTTGTA

13 unit tests and 7 new integration tests, including the headline case (verify a merged graph against its genomes in reversed order) and an explicit regression test for the build --verify panic. docs/docs/reference.md regenerated for the check-cli-docs CI gate.

Also fixes a pre-existing break caught by cargo clippy --release: the merge integration tests called sanity_check, which is #[cfg(any(test, debug_assertions))] and so does not exist for integration tests in release mode.

@mmolari
mmolari deployed to refs/pull/193/merge August 10, 2026 15:39 — with GitHub Actions Active
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