空间细胞类型密度分布图

作者,Evil Genius

今天我们的目标是实现单细胞空间如下分析图谱

如果要实现以上图谱,需要如下几步:

第一步,空间区域识别,这已经成了空间数据分析的必备技能了,需要空间聚类结果和形态学结合起来。


同时展示几个其他文章的例子
皮肤


空间区域识别之后,第二步需要单细胞空间的联合分析,这部分R版本就是Seurat或者RCTD,python版本的就用cell2location,下面展示一张示例图,直接可以放在文章中,脚本放在了最后:

拿到这个结果之后,我们就需要绘制空间细胞类型密度分布图,需要示例数据的请留言:

import sys
import scanpy as sc
import anndata
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
import matplotlib as mpl

import cell2location
#import scvi

from matplotlib import rcParams
rcParams['pdf.fonttype'] = 42 # enables correct plotting of text
import seaborn as sns

####读取数据
adata_vis = sc.read_h5ad('./sp.h5ad')

####提取单细胞空间联合分析的结果
adata_vis.obs[adata_vis.uns['mod']['factor_names']] = adata_vis.obsm['q05_cell_abundance_w_sf']

###创建空矩阵
annot_abundance_df = pd.DataFrame(index=adata_vis.uns['mod']['factor_names'],
                                  columns=annot_)

####根据区域绘图
annot_ = ['Tissue', 'Perichondrium', 'Cartilage', 'Glands',
       'Multilayer_epithelium', 'Airway_Smooth_Muscle', 'Weird_morphology',
       'Nerve', 'Venous_vessel', 'Arterial_vessel', 'Parenchyma',
       'Mesothelium', 'Pulmonary_vessel', 'Small_airway', 'iBALT']

for a in annot_:
    ind = adata_vis.obs[a] == True
    annot_abundance_df.loc[:,a] = list(adata_vis.obsm['q05_cell_abundance_w_sf'].loc[ind,:].mean(0))

####均一化
annot_abundance_norm = (annot_abundance_df.T / annot_abundance_df.sum(1)).T

mpl.rc_file_defaults()
mpl.rcParams['pdf.fonttype'] = 42 # enables correct plotting of text
with mpl.rc_context({'font.size': 8, 'axes.facecolor': "white"}):
    from cell2location.plt.plot_heatmap import clustermap
    clustermap(annot_abundance_norm, figure_size=(5, 11), 
               cmap='RdPu', log=True, fun_type='dotplot',
               cluster_rows=True, cluster_cols=True)
    plt.savefig("./histology_annotation_dotplot.pdf",
                    bbox_inches='tight')
    plt.show()

然后根据需求绘制即可。

你可能感兴趣的:(空间细胞类型密度分布图)