https://www.bilibili.com/read/cv7751387
https://www.bilibili.com/read/cv7760100
https://www.bilibili.com/read/cv7764833
https://www.jianshu.com/p/1e7acde1a318
第一步 导入模块 1 2 3 4 5 6 7 import scvelo as scvimport scanpy as scimport numpy as npimport pandas as pdimport seaborn as sns scv.settings.verbosity = 3 scv.settings.set_figure_params('scvelo' )
第二步 读取数据(loom文件读取时间很长) 1 2 3 4 loomf = '/home/jovyan/upload/zl_liu/data/data/res/hPB003/velocyto/hPB003.loom' adata = scv.read(loomf, cache=False ) metadataf = '/home/jovyan/upload/zl_liu/data/data/res/hPB003/velocyto/metadata.csv' meta = pd.read_csv(metadataf, index_col=0 )
第三步 取交集并合并数据 1 2 3 4 5 6 7 8 9 10 11 12 13 tmp = [x for x in (x[7 :23 ] for x in adata.obs.index) if x in meta.index] meta = meta.loc[tmp] adata = adata[[f'hPB003:{x} x' for x in tmp]] test = meta['cell_type_fig3' ] test.index = adata.obs.index adata.obs['cell_type_fig3' ] = test adata.obsm['X_pca' ] = np.asarray(meta.iloc[:, 4 :]) adata.obsm['X_umap' ] = np.asarray(meta.iloc[:, 2 :4 ]) sc.pl.pca(adata, color='cell_type_fig3' ) sc.pl.umap(adata, color='cell_type_fig3' )