omicverse包|这么好看的单细胞umap图快来学习吧
今天就分享一个python包,进行单细胞数据umap图绘制。
·
今天就分享一个python包,进行单细胞数据umap图绘制。非常的好看实用。
原文链接:https://starlitnightly.github.io/omicverse/Tutorialsplotting/t_visualize_single/
话不多说,直接进入数据分析主题。
1、数据下载
原始数据来源:theislab/scvelo_notebooks (github.com)。
准备数据:DentateGyrus\10X43_1.h5ad。
2、初步代码运行
######数据来源,运行环境在python3.9
import omicverse as ov
import scanpy as sc
import matplotlib.pyplot as plt
ov.ov_plot_set()
adata=ov.read(r'data\DentateGyrus\10X43_1.h5ad')
adata
######初步绘图展示
optim_palette=ov.pl.optim_palette(adata,basis='X_umap',colors='clusters')
import matplotlib.pyplot as plt
fig,ax=plt.subplots(figsize = (4,4))
ov.pl.embedding(adata,
basis='X_umap',
color='clusters',
frameon='small',
show=False,
palette=optim_palette,
ax=ax,)
plt.title('Cell Type of DentateGyrus',fontsize=15)
3、将图中细胞名称按照自定义进行排序展示
new_order=[ 'OL', 'OPC','Cck-Tox','nIPC', 'GABA','Radial Glia-like', 'Astrocytes', 'Endothelial','Cajal Retzius',
'Granule immature', 'Granule mature', 'Microglia', 'Mossy', 'Neuroblast',
]
adata.obs['clusters']=adata.obs['clusters'].cat.reorder_categories(new_order)
fig, ax = plt.subplots(figsize=(4,8))
ov.pl.embedding(adata,
basis="X_umap",
color=['clusters'],title='',
show=False,
frameon='small',
size=15,
ax=ax
)
4、指定细胞展示颜色
color_dict={
'OL':ov.pl.blue_color[4],
'OPC':ov.pl.blue_color[5],
'Cck-Tox':ov.pl.purple_color[0],
'nIPC':ov.pl.purple_color[1],
'GABA':ov.pl.green_color[0],
'Radial Glia-like':ov.pl.green_color[1],
'Astrocytes':ov.pl.green_color[2],
'Endothelial':ov.pl.red_color[0],
'Cajal Retzius':ov.pl.red_color[1],
'Granule immature':ov.pl.red_color[2],
'Granule mature':ov.pl.red_color[3],
'Microglia':ov.pl.red_color[4],
'Mossy':ov.pl.red_color[5],
'Neuroblast':ov.pl.red_color[6],
}
fig, ax = plt.subplots(figsize=(4,4))
ov.pl.embedding(adata,
basis="X_umap",
color=['clusters'],title='',
show=False,
frameon='small',
size=10,
palette=color_dict,
ax=ax
)
5、细胞标签可视化
from matplotlib import patheffects
fig, ax = plt.subplots(figsize=(4,4))
ov.pl.embedding(adata,
basis="X_umap",
color=['clusters'],title='',
show=False, legend_loc=None, add_outline=False,
frameon='small',legend_fontoutline=2,ax=ax
)
ov.pl.embedding_adjust(
adata,
basis="X_umap",
groupby='major_celltype',
ax=ax,
adjust_kwargs=dict(arrowprops=dict(arrowstyle='-', color='black')),
text_kwargs=dict(fontsize=12 ,weight='bold',
path_effects=[patheffects.withStroke(linewidth=2, foreground='w')] ),
)
6、同类别细胞轮廓展示
from matplotlib import patheffects
fig, ax = plt.subplots(figsize=(4,4))
ov.pl.embedding(adata,
basis="X_umap",
color=['clusters'],title='',
show=False, legend_loc=None, add_outline=False,
frameon='small',legend_fontoutline=2,ax=ax
)
ov.pl.embedding_adjust(
adata,
basis="X_umap",
groupby='clusters',
ax=ax,
adjust_kwargs=dict(arrowprops=dict(arrowstyle='-', color='black')),
text_kwargs=dict(fontsize=12 ,weight='bold',
path_effects=[patheffects.withStroke(linewidth=2, foreground='w')] ),
)
ov.pl.contour(ax=ax,adata=adata,
basis="X_umap",
groupby='clusters',clusters=['OL','OPC'],
contour_threshold=0.02,colors=ov.pl.red_color[2],linestyles='dashed')
ov.pl.contour(ax=ax,adata=adata,
basis="X_umap",
groupby='clusters',clusters=['Granule immature','Granule mature'],
contour_threshold=0.01,colors=ov.pl.blue_color[6],linestyles='dashed')
ov.pl.contour(ax=ax,adata=adata,
basis="X_umap",
groupby='clusters',clusters=['Radial Glia-like', 'Astrocytes'],
contour_threshold=0.002,colors=ov.pl.orange_color[2],linestyles='dashed')
fig.savefig('umap-ct_major.png',dpi=300,bbox_inches='tight')
fig.savefig('umap-ct_major.pdf',dpi=300,bbox_inches='tight')
7、细胞比例图展示
ov.pl.embedding_celltype(adata,
figsize=(7,4),basis='X_umap',
celltype_key='clusters',
title='Cell type',
celltype_range=(1,10),
embedding_range=(4,10),)
8、细胞分布强度
ov.pl.embedding_density(adata,
basis='X_umap',
groupby='clusters',
target_clusters='Granule mature',
frameon='small',
show=False,cmap='RdBu_r',alpha=0.8)
9、带重叠点的条形图(条形点)图
ov.single.geneset_aucell(adata,
geneset_name='Sox',
geneset=['Sox17', 'Sox4', 'Sox7', 'Sox18', 'Sox5'])
ov.pl.embedding(adata,
basis='X_umap',
color=['Sox4'],
frameon='small',
show=False,)
此次绘图参考优秀的公众号以及官方网站进行,如有疑问,请联系管理员:kriswcyYQ。
更多推荐
所有评论(0)