Repository navigation
Keep the phased flag through to_zarr and from_zarr - #441
Merged
Merged
Conversation
to_zarr records the matrix's phased flag as a store attribute, and from_zarr (phased=None by default) gives it back, on the eager and the streaming path and for both store layouts. A phased matrix also writes call_genotype_phased, the VCZ field for phase. A store with no record, such as one from bio2zarr, loads as unphased as before: the loader does not infer phase from the calls. allel_zarr_to_vcz carries the record. Fixes #403
nspope
approved these changes
Nov 18, 2026
| ) | ||
|
|
||
| if phased is None: | ||
| phased = stored_phase(path) |
Collaborator
There was a problem hiding this comment.
hmm ... this now opens the zarr store twice, right? (That is, _decide_streaming_mode below on line 844 will also read the store). I guess that doesn't really matter because it's cheap locally. If we ever supported remote access, it might become an issue. If so, I think we could likely determine phase via _decide_streaming_mode
from_zarr opened the store one more time to read the phase record. The streaming builder now reads it from its source's handle and the eager builder from the handle of its population step, so a load opens the store no extra time.
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.
Fixes #403.
The fault
A
HaplotypeMatrixlost itsphasedflag throughto_zarrandfrom_zarr. A simulation fromfrom_ts(phased) that was saved to a store came back unphased, and the phase-dependent statistics warned on it.The fix
The issue gave two options for the load rule. This PR uses a third one, which keeps the rule from #401 that a loader does not infer phase from the calls.
to_zarrrecords the matrix'sphasedflag as a store attribute,pg_gpu_phased, in both store layouts.from_zarrnow hasphased=Noneas its default, which takes the recorded flag. This holds on the eager and the streaming path. An explicitTrueorFalsestill wins.call_genotype_phased, the VCZ field for phase. Every call has the same value, so the array has a fill value and no stored chunk (under 600 bytes at any size). An unphased matrix writes no such field: its flag means that phase was not declared, not that each call is known to be unphased.genotype_phasedamong itsfieldskeeps those per-call values in the store.allel_zarr_to_vczcarries the record to the new store.GenotypeMatrix.to_zarrwrites no record.One effect to know
A store written by this version loads as phased where it loaded as unphased before. Under
estimator='auto', the LD statistics then take the haplotype estimator, so values from a saved store can differ from those of an earlier load with the old default. They now agree with the values from the matrix before it was saved.Tests
tests/test_phasing.py::TestZarrKeepsPhase: the round trip for both flag values (VCZ eager, VCZ streaming, scikit-allel); a saved simulation gives noUnphasedDataWarning; the phase field for a phased store and its absence for an unphased one; agenotype_phasedfield among the matrix's fields; a store with the record removed; a genotype store; the layout conversion.Full GPU suite: 3389 passed. Lint and the pipeline-map check pass.
Docs
phasing.rst,quickstart.rst, theHaplotypeMatrixclass docstring, the changelog entry for thephasedflag (which is itself unreleased, so there is no separate bug-fix entry), and the map note forfrom_zarr.