simonwm / tacco

TACCO: Transfer of Annotations to Cells and their COmbinations
BSD 3-Clause "New" or "Revised" License
42 stars 1 forks source link

Tacco key in adata.uns causes issues when saving h5ad #14

Closed pakiessling closed 6 months ago

pakiessling commented 6 months ago

Hi,

I am on tacco 0.3.0 and anndata 0.10.5.post1.

When I try to save a h5ad after tacco I receive the error:

 merged.write_h5ad("merged_4heart_counts.h5ad")
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_core/anndata.py", line 2017, in write_h5ad
    write_h5ad(
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/h5ad.py", line 111, in write_h5ad
    write_elem(f, "uns", dict(adata.uns), dataset_kwargs=dataset_kwargs)
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 359, in write_elem
    Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/utils.py", line 243, in func_wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 309, in write_elem
    return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 57, in wrapper
    result = func(g, k, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/methods.py", line 312, in write_mapping
    _writer.write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/utils.py", line 243, in func_wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 304, in write_elem
    self.find_writer(dest_type, elem, modifiers),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 269, in find_writer
    return self.registry.get_writer(dest_type, type(elem), modifiers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/rwth1209/enviroments/spatial_analysis/lib/python3.11/site-packages/anndata/_io/specs/registry.py", line 117, in get_writer
    raise IORegistryError._from_write_parts(dest_type, src_type, modifiers)
anndata._io.specs.registry.IORegistryError: No method registered for writing <class 'pandas.core.series.Series'> into <class 'h5py._hl.group.Group'>
Error raised while writing key 'tacco_mc8' of <class 'h5py._hl.group.Group'> to /uns

Deleting the key fixes the issue. Any idea what is going wrong?

JWatter commented 6 months ago

Hi,

thanks for letting us know about this error and sorry for the late reply. It seems this bug is caused upstream by anndata. I opened an issue on the anndata github, regarding this behavior here.
For now, you could continue just deleting the .uns key in question. In case you need it for downstream analysis, you could convert the series to a dictionary. This way you would keep all information.

adata.uns[<key>] = adata.uns[<key>].to_dict()
adata.write_h5ad('adata.h5ad')

Hope this helps!

pakiessling commented 6 months ago

Perfect, thank you!