sc.read_10x_mtx 报错 KeyError: 2
2023-08-29 本文已影响0人
Yayamia
原因:
So the problem is actually from GEO. When people submitted the files processed by Cellranger version 2, they gzip-ed the files. However when Scanpy sees .gz file it recognized the version as Cellranger version 3 by default, which is a little bit different from the version 2 format.
All you need to do is just to gunzip the matrix.mtx.gz, barcodes.tsv.gz, and genes.tsv.gz files. You can tell whether the data was processed using version 2 or 3 from the description in GEO, or by the name of the uploaded gene files: genes.tsv (version 2, could be genes.tsv.gz) or features.tsv.gz (version 3)
是因为数据是从GEO下载下来的,是用cellranger V2处理
解决方法:gunzip解压文件之后:
adata = sc.read_mtx('./matrix.mtx')
adata_bc=pd.read_csv('./barcodes.tsv',header=None)
adata_features=pd.read_csv('./features.tsv',header=None)
adata= adata.T
adata.obs['cell_id']= adata_bc
adata.var['gene_name']= adata_features[0].tolist()
adata.var.index= adata.var['gene_name']