scanpy文件读取h5ad的一个BUG

BUG

当正常使用anndata或者scanpy读入数据的时候,如下

data=anndata.read('data.h5ad')
# or
data=sc.read_h5ad('data.h5ad')

常规操作,数据可能也是自己用anndata储存的,但是读入马上会出现一段非常长的error提示:

KeyError                                  Traceback (most recent call last)
File /usr/local/lib/python3.8/site-packages/anndata/_io/utils.py:156, in report_read_key_on_error..func_wrapper(elem, *args, **kwargs)
    155 try:
--> 156     return func(elem, *args, **kwargs)
    157 except Exception as e:

File /usr/local/lib/python3.8/site-packages/anndata/_io/h5ad.py:532, in read_group(group)
    531 if encoding_type:
--> 532     EncodingVersions[encoding_type].check(
    533         group.name, group.attrs["encoding-version"]
    534     )
    535 if encoding_type in {None, "raw"}:

File /usr/local/lib/python3.8/enum.py:387, in EnumMeta.__getitem__(cls, name)
    386 def __getitem__(cls, name):
--> 387     return cls._member_map_[name]

KeyError: 'dict'

During handling of the above exception, another exception occurred:

AnnDataReadError                          Traceback (most recent call last)
Cell In[2], line 1
----> 1 data=sc.read_h5ad('/data/users/liaopingfang/online/turtle/figures/final_result.h5ad')

File /usr/local/lib/python3.8/site-packages/anndata/_io/h5ad.py:426, in read_h5ad(filename, backed, as_sparse, as_sparse_fmt, chunk_size)
    424         d[k] = read_dataframe(f[k])
    425     else:  # Base case
--> 426         d[k] = read_attribute(f[k])
    428 d["raw"] = _read_raw(f, as_sparse, rdasp)
    430 X_dset = f.get("X", None)

File /usr/local/lib/python3.8/functools.py:875, in singledispatch..wrapper(*args, **kw)
    871 if not args:
    872     raise TypeError(f'{funcname} requires at least '
    873                     '1 positional argument')
--> 875 return dispatch(args[0].__class__)(*args, **kw)

File /usr/local/lib/python3.8/site-packages/anndata/_io/utils.py:162, in report_read_key_on_error..func_wrapper(elem, *args, **kwargs)
    160 else:
    161     parent = _get_parent(elem)
--> 162     raise AnnDataReadError(
    163         f"Above error raised while reading key {elem.name!r} of "
    164         f"type {type(elem)} from {parent}."
    165     )

AnnDataReadError: Above error raised while reading key '/layers' of type  from /.

反正结果就是一句话AnnDataReadError,读入出问题了

Reason and resolution

但这个数据本身其实没有错误,是anndata版本的问题。这个数据是用更新版本的anndata生成的,所以需要anndata>=0.8.0以上的版本才能正常处理和读入,因此升级最新的anndata解决问题。
(python对版本的要求非常严格,不像Seurat,V4.0也能读V2.0写出的对象)

你可能感兴趣的:(scanpy文件读取h5ad的一个BUG)