fix(merge): track chunk provenance instead of re-deriving group membership from labels - #327
Merged
Merged
Conversation
…rship from original labels
`leech data merge -i A=file1.npz -i B=file2.npz` re-derived each group's
label set from the *original* `labels` values stored in each file, then
matched chunks back into group 1/2 by that value. Two files sharing an
internal label (e.g. both prepared with label "Thr" but representing
different classes of the actual comparison) collapsed to the same
label_int with no error.
_parse_and_validate_inputs now builds relabel_by_file, a {path: (label_int,
label_str)} map keyed by which -i argument supplied each file, and
merge_and_split_chunks/merge_and_kfold_split_chunks apply it directly instead
of re-deriving group membership from stored label values. The value-based
relabel_pairwise path (used by the TSV comparison-spec workflow, where group
membership *is* defined by label values) is unchanged, but now raises if the
caller's group1/group2 label sets overlap instead of silently collapsing.
Fixes #323
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.
Summary
leech data merge -i A=file1.npz -i B=file2.npzre-derived each group's label set from the originallabelsvalues stored in each input file, then matched chunks back into group 1/2 by that value. Two files sharing an internal label (e.g. both prepared with label"Thr"but representing different classes of the actual comparison, like attached ligand) collapsed to the samelabel_int— silently, with no error, and a log line that still looked correct._parse_and_validate_inputs(src/leech/commands/merge_split.py) now buildsrelabel_by_file: dict[Path, tuple[int, str]], keyed by which-iargument supplied each file, instead of re-deriving membership from storedlabelsvalues (meta_to_chunk_labelsis gone, along with the per-filenp.loadpeek it required).merge_and_split_chunks/merge_and_kfold_split_chunks(src/leech/splitting/splitter.py) gained arelabel_by_fileparameter (mutually exclusive with the existingrelabel_pairwise) that's applied directly as the label override, bypassing value-matching entirely — including in the legacy in-memory (output_dir=None) path.relabel_pairwisepath is unchanged forprocess_comparison_spec's TSV workflow, where group membership genuinely is defined by label values drawn from an arbitrary set of files — but it now raisesValueErrorif the caller'sgroup1/group2label sets overlap, instead of silently collapsing to one class.Closes #323
Test plan
uv run pytest tests/test_splitter_merge.py -v— 30 passed, including new regression tests reproducing the exact bug (TestMergeSplitCLIProvenance) and the guard-rail coverage (test_relabel_pairwise_overlapping_groups_raises,test_relabel_pairwise_and_relabel_by_file_are_mutually_exclusive)uv run pytest tests/test_comparison_spec.py -v— 7 passed (confirms the untouched value-based TSV path still works)uv run pytest tests/test_mask_seq_side.py -v— 24 passed (exercises othermerge_split.pycode paths)uv run ruff format --check ./uv run ruff check .on touched files — cleanuv run ty check src/leech/— clean🤖 Generated with Claude Code