scanpy存儲h5ad報錯

總是被基礎(chǔ)的問題折磨得非常難受,在使用常規(guī)命令adata.write('data.h5ad')時出現(xiàn)報錯:

"*/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不可以為數(shù)值
我的數(shù)據(jù):

修改之前.png

然后把列名改一下就解決問題了sc.var.columns=['Gene']
修改之后

反正都是一些平常很難遇到的bug,偶爾就會出來讓人抓狂一下。解決方法不一定萬能,歡迎討論~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容