首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >方法分享----高精度空间组学数据中识别和表征细胞生态位

方法分享----高精度空间组学数据中识别和表征细胞生态位

原创
作者头像
追风少年i
发布2025-02-18 14:37:13
发布2025-02-18 14:37:13
2640
举报

作者,Evil Genius

今日目标

参考文献,浙大的文章。

解决的核心问题----细胞niche,有一篇NC在手,真的是非常好。

至于聚类,目前没有定论,符合生物学意义即可。

细胞生态位,也称为细胞微环境或空间域,被定义为细胞周围的局部环境或群落,在决定各种生物过程中起着至关重要的作用,例如维持组织稳态和塑造疾病进展。

scNiche的设计理念

分析需要的信息----分子矩阵、分子邻域矩阵和其邻域的细胞组成

高精度平台表现

低精度平台表现

最后看看示例代码,在https://github.com/ZJUFanLab/scNiche

首先高精度

代码语言:javascript
复制
import scniche as sn
import numpy as np
import scanpy as sc
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scniche.pl import *
import warnings
warnings.filterwarnings('ignore')

adata = sc.read_h5ad('tnbc.h5ad.gz')
adata

AnnData object with n_obs × n_vars = 173205 × 36
    obs: 'SampleID', 'cellLabelInImage', 'cellSize', 'C', 'Na', 'Si', 'P', 'Ca', 'Fe', 'Background', 'B7H3', 'OX40', 'CD163', 'CSF.1R', 'Ta', 'Au', 'tumorYN', 'tumorCluster', 'Group', 'immuneCluster', 'immuneGroup', 'group_name', 'immuneGroup_name', 'all_group_name', 'leiden', 'x', 'y', 'scNiche', 'subtype', 'all_group_name2'
    obsm: 'X_cn', 'X_cn_norm', 'X_data', 'X_data_nbr', 'X_pca', 'X_scniche', 'spatial'

kwargs = {'figsize': (5, 3)}
sn.pl.stacked_barplot(adata, x_axis='scNiche', y_axis='all_group_name', mode='proportion', palette=palettes.default_20, kwargs=kwargs)
sn.pl.stacked_barplot(adata, x_axis='scNiche', y_axis='all_group_name2', mode='proportion', palette=['#426cb5', '#bababa', '#ff7700']
代码语言:javascript
复制
##Enrichment analysis framework
# cell type enrichment
sn.al.enrichment(adata, id_key='all_group_name', val_key='scNiche', library_key='SampleID')

# plot
kwargs = {'figsize': (8, 8), 'vmax': 4, 'cmap': 'YlOrBr', 'linewidths': 0, 'linecolor': 'white', }
col_order = ['CD4 T', 'CD8 T', 'DC/Mono', 'NK', 'B', 'DC', 'Tregs', 'Macrophages', 'CD3 T', 'Endothelial', 'Other immune', 'Mono/Neu', 'Neutrophils', 'Mesenchymal like', 'Tumor', 'Keratin+ tumor', ]
row_order = ['Niche11', 'Niche5', 'Niche3', 'Niche9', 'Niche2', 'Niche10', 'Niche1', 'Niche12', 'Niche8', 'Niche0', 'Niche4', 'Niche6', 'Niche7', ]
adata.uns['scNiche_colors'] = palettes.default_57
colors1 = adata.uns['scNiche_colors']
categories1 = adata.obs['scNiche'].cat.categories
palette_use = [colors1[list(categories1).index(cat)] for cat in row_order]

sn.pl.enrichment_heatmap(adata=adata, id_key='all_group_name', val_key='scNiche', binarized=False, show_pval=True,
                         col_order=col_order, row_order=row_order, anno_key=None, anno_palette=palette_use, kwargs=kwargs)
代码语言:javascript
复制
# sample enrichment
sn.al.enrichment(adata, id_key='scNiche', val_key='SampleID', library_key=None)

# plot
kwargs = {'figsize': (6.2, 10), 'vmax': 4, 'cmap': 'magma'}
col_order = ['Niche2', 'Niche9', 'Niche4', 'Niche6', 'Niche7', 'Niche11', 'Niche12', 'Niche0', 'Niche5', 'Niche10', 'Niche1', 'Niche8', 'Niche3', ]
row_order = [37, 29, 13, 39, 11, 12, 32, 16, 4, 9, 17, 5, 35, 18, 20,14, 2, 10,  34,  23, 38, 31,6, 27,7, 1, 8,28, 21,36, 41, 33, 40, 3, ]
palette_use = ['#2166AC', '#B2182B', ]
sn.pl.enrichment_heatmap(adata=adata, id_key='scNiche', val_key='SampleID', binarized=False, col_order=col_order, row_order=row_order, 
                         anno_key='subtype', anno_palette=palette_use, kwargs=kwargs)
代码语言:javascript
复制
# tumor niches: cell type enrichmant
tumor_list = ['Niche1', 'Niche10', 'Niche2', 'Niche9', 'Niche3', 'Niche5', 'Niche11']
adata_tumor = adata[adata.obs['scNiche'].isin(tumor_list)].copy()
sn.al.enrichment(adata_tumor, id_key='all_group_name', val_key='scNiche', library_key='SampleID')

# plot
kwargs = {'figsize': (9, 6), 'vmax': 4, 'cmap': 'YlOrBr', 'linewidths': 0, 'linecolor': 'white', }
row_order = ['Niche9', 'Niche3', 'Niche10', 'Niche2', 'Niche1', 'Niche5', 'Niche11']
col_order = ['CD4 T', 'CD8 T', 'DC/Mono', 'NK', 'B', 'DC', 'Tregs', 'Macrophages', 'CD3 T', 'Endothelial', 'Other immune', 'Mono/Neu', 'Neutrophils', 'Mesenchymal like', 'Tumor', 'Keratin+ tumor',]
palette_use = [palettes.default_57[i] for i in [9, 3, 10, 2, 1, 5, 11]]
sn.pl.enrichment_heatmap(adata=adata_tumor, id_key='all_group_name', val_key='scNiche', binarized=False, col_order=col_order, row_order=row_order, 
                         anno_key=None, anno_palette=palette_use, show_pval=True, kwargs=kwargs)

低精度也差不多

代码语言:javascript
复制
import scniche as sn
import numpy as np
import scanpy as sc
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scniche.pl import *
import warnings
warnings.filterwarnings('ignore')

print("Last run with scNiche version:", sn.__version__)

# set seed
sn.pp.set_seed()

adata = sc.read_h5ad('liver.h5ad.gz')

# normalize first
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata

AnnData object with n_obs × n_vars = 37505 × 20423
    obs: 'tile', 'x', 'y', 'condition', 'celltype', 'cell', 'scNiche', 'group'
    uns: 'log1p'
    obsm: 'X_cn', 'X_cn_norm', 'X_data', 'X_data_nbr', 'X_scVI', 'X_scniche', 'spatial'

kwargs = {'figsize': (5, 3)}
sn.pl.stacked_barplot(adata, x_axis='scNiche', y_axis='celltype', mode='proportion', palette=palettes.default_20, kwargs=kwargs)
palette_use = ["#1e40af", "#1d4ed8", "#2563eb", "#3b82f6", "#60a5fa", "#93c5fd", "#fdba74", "#fb923c", "#f97316", "#ea580c"]
sn.pl.stacked_barplot(adata, x_axis='scNiche', y_axis='tile', mode='proportion', palette=palette_use, kwargs=kwargs)
代码语言:javascript
复制
# cell type enrichment
sn.al.enrichment(adata, id_key='celltype', val_key='scNiche', library_key='tile')

# plot
kwargs = {'figsize': (8, 8), 'vmax': 4, 'cmap': 'YlOrBr', 'linewidths': 0, 'linecolor': 'white', }
row_order =[ 'Niche0', 'Niche3', 'Niche12', 'Niche5', 'Niche14', 'Niche11', 'Niche1', 'Niche10',  'Niche2', 'Niche6', 'Niche8', 'Niche13', 'Niche7', 'Niche9', 'Niche4', ]
col_order = ['Macrophage_Inflamed', 'HPC', 'HSC-A', 'Hep_Injured', 'RBC', 'Macrophage_Kupffer', 'HSC-N', 'ENDO', 'Hep_MT', 'Hep_Nuc', 'Hep_PP', 'Hep_Mup10','Hep_Gstp', 'Hep_Eef1a1', 'Hep_PC', ]
adata.uns['scNiche_colors'] = palettes.default_57
colors1 = adata.uns['scNiche_colors']
categories1 = adata.obs['scNiche'].cat.categories
palette_use = [colors1[list(categories1).index(cat)] for cat in row_order]
sn.pl.enrichment_heatmap(adata=adata, id_key='celltype', val_key='scNiche', binarized=False, show_pval=True, col_order=col_order, row_order=row_order, 
                         anno_key=None, anno_palette=palette_use, kwargs=kwargs)
代码语言:javascript
复制
# sample enrichment
sn.al.enrichment(adata, id_key='scNiche', val_key='tile', library_key=None)

# plot
kwargs = {'figsize': (5, 5), 'vmax': 3, 'cmap': 'magma'}
col_order = [ 'Niche0', 'Niche3', 'Niche12', 'Niche5', 'Niche14', 'Niche11', 'Niche1', 'Niche10',  'Niche2', 'Niche6', 'Niche8', 'Niche13', 'Niche7', 'Niche9', 'Niche4', ]
palette_use = ['#2166AC', '#B2182B', ]
sn.pl.enrichment_heatmap(adata=adata, id_key='scNiche', val_key='tile', binarized=False, col_order=col_order, row_order=None, 
                         anno_key='group', anno_palette=palette_use, kwargs=kwargs)

生活很好,有你更好

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 作者,Evil Genius
  • 今日目标
  • 参考文献,浙大的文章。
  • 解决的核心问题----细胞niche,有一篇NC在手,真的是非常好。
  • 至于聚类,目前没有定论,符合生物学意义即可。
  • 细胞生态位,也称为细胞微环境或空间域,被定义为细胞周围的局部环境或群落,在决定各种生物过程中起着至关重要的作用,例如维持组织稳态和塑造疾病进展。
  • scNiche的设计理念
  • 分析需要的信息----分子矩阵、分子邻域矩阵和其邻域的细胞组成
  • 高精度平台表现
  • 低精度平台表现
  • 最后看看示例代码,在https://github.com/ZJUFanLab/scNiche
  • 首先高精度
  • 低精度也差不多
  • 生活很好,有你更好
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档