muon: Can't save MuData object to h5mu file
I created a MuData object that contains the AnnData for 2 modalities, did some basic filtering of the datasets and then tried to save it with: joint.write("joint_data.h5mu")
but this throws the following error:
TypeError Traceback (most recent call last)
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
213 try:
--> 214 return func(elem, key, val, *args, **kwargs)
215 except Exception as e:
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/anndata/_io/specs/registry.py in write_elem(f, k, elem, modifiers, *args, **kwargs)
174 else:
--> 175 _REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
176
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/anndata/_io/specs/registry.py in get_writer(self, dest_type, typ, modifiers)
63 if (dest_type, typ, modifiers) not in self.write:
---> 64 raise TypeError(
65 f"No method has been defined for writing {typ} elements to {dest_type}"
TypeError: No method has been defined for writing <class 'mudata._core.mudata.MuAxisArrays'> elements to <class 'h5py._hl.group.Group'>
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
/tmp/efec76988f/ipykernel_20272/4022115007.py in <module>
----> 1 joint.write("../Merged/929_cancer/929_cancer_joint_data.h5mu")
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/mudata/_core/mudata.py in write_h5mu(self, filename, **kwargs)
1084 raise ValueError("Provide a filename!")
1085 else:
-> 1086 write_h5mu(filename, self, **kwargs)
1087 if self.isbacked:
1088 self.file.filename = filename
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/mudata/_core/io.py in write_h5mu(filename, mdata, **kwargs)
207
208 with h5py.File(filename, "w", userblock_size=512) as f:
--> 209 _write_h5mu(f, mdata, **kwargs)
210 with open(filename, "br+") as f:
211 nbytes = f.write(
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/mudata/_core/io.py in _write_h5mu(file, mdata, write_data, **kwargs)
44 dataset_kwargs=kwargs,
45 )
---> 46 write_attribute(file, "obsm", mdata.obsm, dataset_kwargs=kwargs)
47 write_attribute(file, "varm", mdata.varm, dataset_kwargs=kwargs)
48 write_attribute(file, "obsp", mdata.obsp, dataset_kwargs=kwargs)
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/anndata/_io/utils.py in write_attribute(*args, **kwargs)
132 DeprecationWarning,
133 )
--> 134 return write_elem(*args, **kwargs)
135
136
/data/leuven/miniconda3/envs/pytorch2/lib/python3.8/site-packages/anndata/_io/utils.py in func_wrapper(elem, key, val, *args, **kwargs)
218 else:
219 parent = _get_parent(elem)
--> 220 raise type(e)(
221 f"{e}\n\n"
222 f"Above error raised while writing key {key!r} of {type(elem)} "
TypeError: No method has been defined for writing <class 'mudata._core.mudata.MuAxisArrays'> elements to <class 'h5py._hl.group.Group'>
Above error raised while writing key 'obsm' of <class 'h5py._hl.files.File'> to /
I also tried to save only a MuData object with just the raw matrices (no more metadata), but it throws the same error, also when trying to save each of the modalities alone (in a MuData object with only 1 modality).
I am using python ‘3.8.12’, scanpy ‘1.9.1’ and muon ‘0.1.2’
Thank you for your help, this is a very useful tool.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15
Hmm okay, some folks on our team are still hitting this issue, I need to go check what versions they’re using
Hey @dburkhardt,
Thanks for making it very easy to run your use case for me! It works, and I get this output after running your code on your files with the current
mudata
master branch:There’s still a possibility I misunderstand your message but AnnData v0.8 brought forward incompatibility, which means that with
anndata < 0.8
one can’t read the files written with the new serialisation. Asmudata
is lean and reusesanndata
I/O internals, its older versions can’t useanndata >= 0.8
as the internals for serialisation were changed. That means thatmudata >= 0.2
fixes the dependency asanndata >= 0.8
. Meaning that upon installingmudata >= 0.2
(PyPI release will be there soon), a package manager should make sure thatanndata
is>= 0.8
. Ifanndata
is upgraded to a forward-incompatible version aftermudata
has been installed, there’s not much we can do I think:mudata 0.1.2
specifiesanndata < 0.8
as its dependency.Can we reopen this an pin the current version of mudata to an older version of anndata? This isn’t resolved:
Files to reproduce 👇 data.zip
outputs