总是被基础的问题折磨得非常难受,在使用常规命令adata.write('data.h5ad')
时出现报错:
"*/lib/python3.9/site-packages/anndata/_io/utils.py", line 109, in check_key
raise TypeError(f"{key} of type {typ} is an invalid key. Should be str.")
TypeError: 0 of type <class 'int'> is an invalid key. Should be str.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
"*/lib/python3.9/site-packages/anndata/_io/h5ad.py", line 99, in write_h5ad
write_elem(f, "var", adata.var, dataset_kwargs=dataset_kwargs)
File "*/envs/Spateo2/lib/python3.9/site-packages/anndata/_io/utils.py", line 220, in func_wrapper
raise type(e)(
TypeError: 0 of type <class 'int'> is an invalid key. Should be str.
Above error raised while writing key 'var' of <class 'h5py._hl.group.Group'> to /
Github上面其实由类似的问题讨论:https://github.com/scverse/anndata/issues/628
大概看了一下,问题出在h5文件存储时,var和obs的columns不可以为数值
我的数据:
然后把列名改一下就解决问题了
sc.var.columns=['Gene']
修改之后
反正都是一些平常很难遇到的bug,偶尔就会出来让人抓狂一下。解决方法不一定万能,欢迎讨论~
网友评论