Repository navigation
Conversation
ilan-gold
left a comment
There was a problem hiding this comment.
Removing the hacks would require making anndata's write_use more flexible: Adding a boolean argument to disable encoding type/version checking and adding arguments to pass in obs_names and var_names to check against (or, even better, pass in an AdAcc instance and do something like adata[getattr(A, dim)].index).
If we do this, I'd want to think through EHRData and TreeData as well as potential consumers
| have_mods and mdata.mod.keys() != set(disk_mods.keys()) or any(mod not in disk_mods for mod in have_mod) | ||
| ): | ||
| warn( | ||
| "Modalities given in 'use' do not correspond to those already on disk and no global metadata is being written. " |
There was a problem hiding this comment.
Why not write the global metadata?
There was a problem hiding this comment.
Because it may not work.
If the MuData object has axis=-1, then it is possible that obs_names and var_names do match what's on disk after an update(), but it gets really complicated for axis=0 and axis=1. Suppose you have a MuData with axis=0 on disk with 2 modalities, and you add a third. Then there are two possibilities:
- You haven't run
mdata.update()yet, in which case the global metadata has not changed and writing it won't do anything. - You have run
mdata.update(). Then thevar_names(and potentially theobs_names) no longer correspond to what's on disk, and the entire write will fail (at least according to current logic).
mudata runs update() in its constructor, which is called when reading from disk, so the read itself should succeed, but the ordering of modalities or global obs_names may or may not change. Hence suprising results.
Running update() in the _write_use() function is not a solution either: The user may have added multiple modalities, but is only writing one of those to disk. After update() the global metadata will reflect all the modalities.
There was a problem hiding this comment.
or global obs_names may or may not change.
Ok, so the disk storage of global obs_names is more of a suggestion than a ground truth? Why store it then? Just curious since it sounds like it's reconstructable from the constituent mods...
How could the obs_names "change" also? Maybe be more specific - it seems more of a mismatch issue than a change issue.
There was a problem hiding this comment.
Ok, so the disk storage of global obs_names is more of a suggestion than a ground truth? Why store it then? Just curious since it sounds like it's reconstructable from the constituent mods...
Suppose you have three modalities, let's call them mod1, mod2, and mod3, where each has a different ordering of observations. When the MuData object is first constructed, update() goes through the modalities in order and determines the global obs_names as a union of all modality obs_names, which means that the global obs_names start with the obs_names of the mod1 in the order that they are in mod1, followed by the obs_names from mod2 that are not in mod1 in the order that they are present in mod2, and so on. Now say you delete mod1 and run update() again. If we were reconstructing obs_names from scratch, their ordering will change. So update() looks at the existing obs_names and obsmap and tries to preserve their order. This can happen here if someone is writing the entire A.mod, for example.
How could the obs_names "change" also? Maybe be more specific - it seems more of a mismatch issue than a change issue.
Again, depends on the exact usecase. The worst case that I can think of right now is: The user renames one or multiple modalities (mdata.mod["mod1"].obs_names = ...) and does not run update(). He then does write(use=A.mod). Since there was no update(), the global names still match with what's on disk, so that check will succeed. But when reading back the file, update() will run, and so the global names will actually change.
I suppose I can add another check when I write an entire modality to verify that also that modality's names match what's on disk, but I'm not sure if that's too restrictive, and it won't help with the scenario above (deleted modality).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #222 +/- ##
==========================================
- Coverage 90.40% 81.58% -8.83%
==========================================
Files 12 14 +2
Lines 1939 2118 +179
==========================================
- Hits 1753 1728 -25
- Misses 186 390 +204
🚀 New features to boost your workflow:
|
ilan-gold
left a comment
There was a problem hiding this comment.
Nice! Just a few q's for my own learning
| have_mods and mdata.mod.keys() != set(disk_mods.keys()) or any(mod not in disk_mods for mod in have_mod) | ||
| ): | ||
| warn( | ||
| "Modalities given in 'use' do not correspond to those already on disk and no global metadata is being written. " |
There was a problem hiding this comment.
or global obs_names may or may not change.
Ok, so the disk storage of global obs_names is more of a suggestion than a ground truth? Why store it then? Just curious since it sounds like it's reconstructable from the constituent mods...
How could the obs_names "change" also? Maybe be more specific - it seems more of a mismatch issue than a change issue.
Same as scverse/anndata#2707, but for MuData.
There are several hacks to bypass the sanity checks in anndata's implementation:
attrswith something returning anndata's encoding type and version. This is necessary to be able to pass in a MuData object to anndata's write_use, which happens when writing e.g.MuData.obs,MuData.varetc.obs_names/var_namesof the passed in object, which would be aMuDataobject if using a MuData accessor, so the names don't match what's on disk for the individual modality.Removing the hacks would require making anndata's
write_usemore flexible: Adding a boolean argument to disable encoding type/version checking and adding arguments to pass inobs_namesandvar_namesto check against (or, even better, pass in anAdAccinstance and do something likeadata[getattr(A, dim)].index).The CI is failing due to warnings related to Pandas 3.1. The warnings will disappear with anndata 0.13.5. Everything else is passing (though the new code is not tested in CI yet becase there is no pre-release of anndata 0.14, but the tests pass locally).