美文网首页
scanpy | 实现细胞类型umap图按样本分面

scanpy | 实现细胞类型umap图按样本分面

作者: 生信云笔记 | 来源:发表于2024-06-01 11:02 被阅读0次
import scanpy as sc
import matplotlib.pyplot as plt

adata = sc.read_h5ad('human_heart.h5ad')
adata.obs.head()
                               n_counts  n_genes  percent_mito  percent_ribo sample gender     celltype
AAACCCAAGCAAGGAA-1-H0026_apex     590.0      426      0.003390      0.005085  ctrl2   Male  Endothelial
AAACCCAAGCGTGCCT-1-H0026_apex    1866.0     1052      0.001072      0.000536  ctrl2   Male    Pericytes
AAACCCAAGGTAAGAG-1-H0026_apex    1991.0     1216      0.002511      0.001005  ctrl2   Male    Pericytes
AAACCCACAAATTGCC-1-H0026_apex     664.0      521      0.013554      0.003012  ctrl2   Male  Endothelial
AAACCCAGTCAAAGTA-1-H0026_apex    1664.0      900      0.004808      0.000000  ctrl2   Male    Pericytes

split = adata.obs['sample'].unique().tolist()
n_split = len(split)
fig, ax = plt.subplots(nrows=1, ncols=n_split, squeeze=False, figsize=(7 * n_split, 5))

for i in range(n_split):
     tmp = adata[adata.obs['sample'] == split[i], :]
     sc.pl.umap(tmp, color='celltype', ax=ax[0, i], show=False)
     ax[0, i].set_title(f"{split[i]}: celltype")

plt.subplots_adjust(wspace=0.6)
fig.show()

相关文章

网友评论

      本文标题:scanpy | 实现细胞类型umap图按样本分面

      本文链接:https://www.haomeiwen.com/subject/dsrpfjtx.html