centered_pca result cannot be saved in h5ad
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Python
- Stars
- 159
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
Description of feature
---------------------------------------------------------------------------
IORegistryError Traceback (most recent call last)
Cell In[138], line 3
1 import os
----> 3 adata_train_1.write(os.path.join(output_dir, "adata_train_1.h5ad"))
4 adata_test_1.write(os.path.join(output_dir, "adata_test_1.h5ad"))
5 adata_ood_1.write(os.path.join(output_dir, "adata_ood_1.h5ad"))
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_core/anndata.py:1929, in AnnData.write_h5ad(self, filename, compression, compression_opts, as_dense)
1926 if filename is None:
1927 filename = self.filename
-> 1929 write_h5ad(
1930 Path(filename),
1931 self,
1932 compression=compression,
1933 compression_opts=compression_opts,
1934 as_dense=as_dense,
1935 )
1937 if self.isbacked:
1938 self.file.filename = filename
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/h5ad.py:107, in write_h5ad(filepath, adata, as_dense, dataset_kwargs, **kwargs)
105 write_elem(f, "var", adata.var, dataset_kwargs=dataset_kwargs)
106 write_elem(f, "obsm", dict(adata.obsm), dataset_kwargs=dataset_kwargs)
--> 107 write_elem(f, "varm", dict(adata.varm), dataset_kwargs=dataset_kwargs)
108 write_elem(f, "obsp", dict(adata.obsp), dataset_kwargs=dataset_kwargs)
109 write_elem(f, "varp", dict(adata.varp), dataset_kwargs=dataset_kwargs)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:359, in write_elem(store, k, elem, dataset_kwargs)
335 def write_elem(
336 store: GroupStorageType,
337 k: str,
(...)
340 dataset_kwargs: Mapping[str, Any] = MappingProxyType({}),
341 ) -> None:
342 """
343 Write an element to a storage group using anndata encoding.
344
(...)
357 E.g. for zarr this would be `chunks`, `compressor`.
358 """
--> 359 Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/utils.py:243, in report_write_key_on_error.<locals>.func_wrapper(*args, **kwargs)
241 raise ValueError("No element found in args.")
242 try:
--> 243 return func(*args, **kwargs)
244 except Exception as e:
245 path = _get_display_path(store)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:309, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers)
303 write_func = partial(
304 self.find_writer(dest_type, elem, modifiers),
305 _writer=self,
306 )
308 if self.callback is None:
--> 309 return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)
310 return self.callback(
311 write_func,
312 store,
(...)
316 iospec=self.registry.get_spec(elem),
317 )
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:57, in write_spec.<locals>.decorator.<locals>.wrapper(g, k, *args, **kwargs)
55 @wraps(func)
56 def wrapper(g: GroupStorageType, k: str, *args, **kwargs):
---> 57 result = func(g, k, *args, **kwargs)
58 g[k].attrs.setdefault("encoding-type", spec.encoding_type)
59 g[k].attrs.setdefault("encoding-version", spec.encoding_version)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/methods.py:312, in write_mapping(f, k, v, _writer, dataset_kwargs)
310 g = f.require_group(k)
311 for sub_k, sub_v in v.items():
--> 312 _writer.write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/utils.py:243, in report_write_key_on_error.<locals>.func_wrapper(*args, **kwargs)
241 raise ValueError("No element found in args.")
242 try:
--> 243 return func(*args, **kwargs)
244 except Exception as e:
245 path = _get_display_path(store)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:304, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers)
300 elif k in store:
301 del store[k]
303 write_func = partial(
--> 304 self.find_writer(dest_type, elem, modifiers),
305 _writer=self,
306 )
308 if self.callback is None:
309 return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:269, in Writer.find_writer(self, dest_type, elem, modifiers)
267 return self.registry.get_writer(dest_type, pattern, modifiers)
268 # Raises IORegistryError
--> 269 return self.registry.get_writer(dest_type, type(elem), modifiers)
File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:117, in IORegistry.get_writer(self, dest_type, src_type, modifiers)
115 return self.write[(dest_type, src_type, modifiers)]
116 else:
--> 117 raise IORegistryError._from_write_parts(dest_type, src_type, modifiers)
IORegistryError: No method registered for writing <class 'numpy.matrix'> into <class 'h5py._hl.group.Group'>
Error raised while writing key 'X_mean' of <class 'h5py._hl.group.Group'> to /varm
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the adata_train_1.write(..."adata_train_1.h5ad") call and inspect the centered_pca result under varm, especially the X_mean entry named in the traceback. The work is done when the generated AnnData object saves to h5ad without the IORegistryError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- bioinformatics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100