前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >空间细胞类型密度分布图

空间细胞类型密度分布图

原创
作者头像
追风少年i
发布2023-07-19 09:20:27
3210
发布2023-07-19 09:20:27
举报
作者,Evil Genius
今天我们的目标是实现单细胞空间如下分析图谱

如果要实现以上图谱,需要如下几步:
第一步,空间区域识别,这已经成了空间数据分析的必备技能了,需要空间聚类结果和形态学结合起来。

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

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

拿到这个结果之后,我们就需要绘制空间细胞类型密度分布图,需要示例数据的请留言:
代码语言:javascript
复制
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()

然后根据需求绘制即可。

生活很好,有你更好

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 作者,Evil Genius
  • 今天我们的目标是实现单细胞空间如下分析图谱
  • 如果要实现以上图谱,需要如下几步:
    • 第一步,空间区域识别,这已经成了空间数据分析的必备技能了,需要空间聚类结果和形态学结合起来。
      • 空间区域识别之后,第二步需要单细胞空间的联合分析,这部分R版本就是Seurat或者RCTD,python版本的就用cell2location,下面展示一张示例图,直接可以放在文章中:
      • 拿到这个结果之后,我们就需要绘制空间细胞类型密度分布图,需要示例数据的请留言:
        • 然后根据需求绘制即可。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档