Repository navigation
fix: keep trees of a TreeData modality through MuData IO - #103
Conversation
mudata writes only the AnnData elements of each modality and reads it back as AnnData, so a TreeData modality loses obst, vart, label, allow_overlap and alignment on write_h5mu/write_zarr/write_h5ad + read. Factor the writing and reading of those elements out of _write_tdata and _read_tdata into group-relative _write_tree_elems/_read_tree_elems, and expose them as the _write_mudata_extras/_read_mudata_extras hooks that a mudata with AnnData subclass modality support calls. With a mudata that does not call the hooks nothing changes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
@pedrocr83 thanks for the PR. Resolving this will depend on scverse/mudata#210 |
…ooks Replace the private _write_mudata_extras/_read_mudata_extras methods with public functions that store and restore the tree elements (obst, vart, label, allow_overlap, alignment) in an existing AnnData group. mudata calls them for TreeData modalities and marks the group with encoding-subtype = "treedata". On-disk output of .h5td and zarr is unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #103 +/- ##
==========================================
+ Coverage 92.91% 93.05% +0.13%
==========================================
Files 7 7
Lines 762 777 +15
==========================================
+ Hits 708 723 +15
Misses 54 54
🚀 New features to boost your workflow:
|
|
Thanks for the PR and the report. I pushed two commits on top of this branch that change the approach, so the description above no longer matches the code. Why In the discussion on scverse/mudata#210, the mudata maintainers did not want a duck-typed hook that any What changed
How mudata uses it The companion mudata change (still in my fork for review: colganwi/mudata#1) writes Testing With that mudata branch installed, the suite gives 62 passed, including The fix only takes effect once mudata ships the matching change. |
Closes #102.
What
_write_tree_elems(group, tdata, kwargs)/_read_tree_elems(group): the writing and reading oflabel,allow_overlap,alignment,obstandvart, factored out of_write_tdata/_read_tdataand made group-relative._write_tdata/_read_tdatacall them, so.h5tdand zarr output is unchanged.TreeData._write_mudata_extras(group, *, dataset_kwargs)and the classmethodTreeData._read_mudata_extras(group, adata): the hooks proposed in AnnData subclass modalities (e.g. TreeData) lose their extra elements and type on write_h5mu/write_zarr + read scverse/mudata#210, so a TreeData modality of a MuData keeps its trees,label,allow_overlapandalignmentthroughmudata.write_h5mu/write_zarr/write_h5adand read (in memory and backed).Why
mudata writes only AnnData elements per modality and reads modalities back as AnnData, so the trees are lost (#102). treedata's writer only works on a file root, so there was nothing mudata could call.
Tests
In
tests/test_readwrite.py:test_mudata_hooks[h5|zarr]: writes a TreeData (non-defaultlabel,allow_overlap=False,alignment="subset") as an AnnData group, calls the two hooks, and checks the restored TreeData. No mudata needed.test_mudata_readwrite[h5mu|zarr]: end-to-end MuData round trip. It is skipped when mudata is not installed (it is not a test dependency) or when the installed mudata does not call the hooks.Full suite (Python 3.13, anndata 0.13.4, zarr 3.4.1):
main: 58 passed.prek run --all-filespasses.Dependency
This PR is safe to merge on its own: with released mudata the hooks are never called and behavior is unchanged. The fix only takes effect once scverse/mudata#211 (or whatever form of the hook the mudata maintainers accept) is released; if they choose a different protocol I will adapt this PR. You may want to add
mudatato thetestdependency group so the end-to-end test runs in CI once that release exists.Found while building biotapy, a microbiome toolkit on TreeData/MuData.
🤖 Generated with Claude Code