前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >空转 | CellChat-V2,揭秘空间转录组数据的细胞通讯分析

空转 | CellChat-V2,揭秘空间转录组数据的细胞通讯分析

作者头像
生信补给站
发布2023-11-09 14:02:33
1.7K0
发布2023-11-09 14:02:33
举报
文章被收录于专栏:生信补给站生信补给站

这里介绍下空间转录组的CellChat分析 以及 和单细胞转录组的一些区别。

一 数据输入,处理

1,载入R包和数据

仍然使用空转 | 结合scRNA完成空转spot注释(Seurat Mapping) & 彩蛋(封面的空转主图代码)推文中的空转数据进行示例展示。

注:CellChat分析中 Cell labels cannot contain `0`! ,因为未作细胞注释,因此将cluster前面加C

代码语言:javascript
复制
options(stringsAsFactors = FALSE)
library(CellChat)
library(Seurat)
library(tidyverse)
library(viridis)
library(RColorBrewer)
#载入数据
load("Brain_ST_scRNA.sBio.Rdata")
#查看数据情况
Brain_ST@meta.data$celltype <- paste("C",Brain_ST$seurat_clusters,sep = "")
Idents(Brain_ST) <- "celltype"
head(Brain_ST)
#可定义颜色
color.use <- scPalette(nlevels(Brain_ST))
names(color.use) <- levels(Brain_ST)
SpatialDimPlot(Brain_ST, label = TRUE, label.size = 3, cols = color.use)

2,准备输入文件

和单细胞区别之一:空间转录组除矩阵和meta外,还需要额外输入空间图像信息 以及 Scale factor信息 。

代码语言:javascript
复制
#矩阵信息
data.input = Seurat::GetAssayData(Brain_ST, slot = "data", assay = "SCT") 
#meta信息
meta = data.frame(labels = Idents(Brain_ST), #名字自定义
                  row.names = names(Idents(Brain_ST))) # manually create a dataframe consisting of the cell labels
unique(meta$labels)

# 空间图像信息
spatial.locs = Seurat::GetTissueCoordinates(Brain_ST, scale = NULL, 
                                            cols = c("imagerow", "imagecol")) 
# Scale factors and spot diameters 信息 
scale.factors = jsonlite::fromJSON(txt = 
                                   file.path("E:/bioinformation/sc_ST/data/Brain_35707680/spatial", 'scalefactors_json.json'))
scale.factors = list(spot.diameter = 65, spot = scale.factors$spot_diameter_fullres, # these two information are required
                     fiducial = scale.factors$fiducial_diameter_fullres, hires = scale.factors$tissue_hires_scalef, lowres = scale.factors$tissue_lowres_scalef # these three information are not required
)

scalefactors_json.json在构建空转Object时候用到的, 查找一下路径即可。

3,创建CellChat对象

使用上述准备好的矩阵数据、meta信息,图像信息和scale factor信息构建CellChat对象,通过 group.by 定义分组。

代码语言:javascript
复制
cellchat <- createCellChat(object = data.input, 
                           meta = meta, 
                           group.by = "labels", #前面的meta ,定义的名字是labels
                           datatype = "spatial", ###
                           coordinates = spatial.locs, 
                           scale.factors = scale.factors)

注意datatype 要选择 "spatial" 。

4,设置参考数据库

因为空转数据是人的,这里直接选择CellChatDB.human(鼠的话选择 CellChatDB.mouse) 。

代码语言:javascript
复制
CellChatDB <- CellChatDB.human # use CellChatDB.mouse if running on mouse data

# use a subset of CellChatDB for cell-cell communication analysis
#CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling", key = "annotation") # use Secreted Signaling
# use all CellChatDB for cell-cell communication analysis
CellChatDB.use <- CellChatDB # simply use the default CellChatDB

# set the used database in the object
cellchat@DB <- CellChatDB.use

注1:使用全部的用于cellchat分析,也可以不进行subsetDB,直接指定cellchat@DB <- CellChatDB 即可

注2:如果你有关心的配受体对 且 不在该数据库中,也可以自行添加上。大概步骤就是下载对应的csv(数据库),在对应的列上添加上你的配受体对信息,保存后重新读取新的csv即可,详细见https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/tutorial/Update-CellChatDB.html。

5,CellChat预处理

可以使用subsetData选择进行cellchat的子集,注意使用全集的话也要subsetData一下

代码语言:javascript
复制
# subset the expression data of signaling genes for saving computation cost
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
future::plan("multisession", workers = 1) #笔记本可以选1
##识别过表达基因
cellchat <- identifyOverExpressedGenes(cellchat)
#识别过表达配体受体对
cellchat <- identifyOverExpressedInteractions(cellchat)

二 推断cell-cell network

前面数据和配体受体库准备好之后,就可以根据表达值推断细胞类型之间的互作了。

1,推断细胞通讯网络

使用表达值推测细胞互作的概率

代码语言:javascript
复制
cellchat <- computeCommunProb(cellchat, 
                              type = "truncatedMean", trim = 0.1, 
                              distance.use = TRUE, 
                              scale.distance = 0.01)
cellchat <- filterCommunication(cellchat, min.cells = 10)

注1:type 默认为triMean,producing fewer but stronger interactions; 当设置‘type = "truncatedMean"', 需要跟 'trim'参数 , producing more interactions.

注2:distance.use = FALSE 会过滤掉较远空间距离之间的交互

注3:空转默认的是truncatedMean 和 trim组合,根据经验进行适当的调整。

2,计算cell-cell communication

使用computeCommunProbPathway计算每个信号通路的所有配体-受体相互作用的通信结果,结存存放在net 和 netP中 。

然后使用aggregateNet计算细胞类型间整合的细胞通讯结果。

代码语言:javascript
复制
#计算每个信号通路相关的所有配体-受体相互作用的通信结果
cellchat <- computeCommunProbPathway(cellchat)
#计算整合的细胞类型之间通信结果
cellchat <- aggregateNet(cellchat)

与单细胞转录组一样,得到的net中也会有count 和 weight 两个维度,可以选择性可视化。

三 CellChat 可视化

除了和单细胞转录组一致的可视化外,还有一些空转特有的可视化展示。

1,celltype之间通讯结果

1)根据使用netVisual_circle显示任意两个celltype之间的通讯次数(左)或总通讯强度(右)
代码语言:javascript
复制
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd=TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = rowSums(cellchat@net$count), 
                 weight.scale = T, label.edge= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = rowSums(cellchat@net$weight), 
                 weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
2)根据使用netVisual_heatmap显示任意两个celltype之间的通讯次数(左)或总通讯强度(右)
代码语言:javascript
复制
p1 <- netVisual_heatmap(cellchat, measure = "count", color.heatmap = "Blues")

p2 <- netVisual_heatmap(cellchat, measure = "weight", color.heatmap = "Blues")

p1 + p2

2,单个信号通路可视化

首先根据cellchat@netP$pathways展示当前有哪些通路结果,选择感兴趣的进行展示,此处示例展示SPP1通路。

levels(cellchat@idents) 查看当前的celltype顺序,然后可以通过vertex.receiver指定target 的细胞类型。

1)层级图

绘制层级图的话 ,需要指定layout为hierarchy ,当前版本默认下出来的是circle图。

代码语言:javascript
复制
cellchat@netP$pathways
pathways.show <- c("SPP1")levels(cellchat@idents)   
#[1] "C9" "C3" "C5" "C4" "C0" "C7" "C6" "C8" "C1" "C2"     
vertex.receiver = c(1,2,4,5)  #选择的是levels(cellchat@idents) 中的
netVisual_aggregate(cellchat, signaling = pathways.show,                      
vertex.receiver = vertex.receiver,layout = "hierarchy")

左图中间的Target是vertex.receiver选定的细胞类型,右图是除vertex.receiver选中之外的另外的细胞类型。

注意vertex.receiver = c(1,2,4,5) 选择的是levels(cellchat@idents) 中的第1 2 4 5 个celltype 而不是C1 C2 C4 C5。

2)和弦图

可以额外绘制空间转录组版本的和弦图,添加layout = "spatial" 。

代码语言:javascript
复制
# Circle plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle")

# Spatial plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "spatial", 
                    edge.width.max = 2, vertex.size.max = 1, 
                    alpha.image = 0.2, vertex.label.cex = 3.5)
3) network centrality scores
代码语言:javascript
复制
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
par(mfrow=c(1,1))
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, 
                                  width = 8, height = 2.5, font.size = 10)

3,绘制配体受体气泡图

1)指定受体-配体细胞类型

绘制指定受体-配体细胞类型中的全部配体受体结果的气泡图,通过sources.use 和 targets.use指定。

代码语言:javascript
复制
#指定受体-配体细胞类型
netVisual_bubble(cellchat, sources.use = c(3,5), 
                 targets.use = c(1,2,4,6), remove.isolate = FALSE)
2)指定受体-配体细胞类型 且 指定通路

同时通过signaling指定展示通路

代码语言:javascript
复制
netVisual_bubble(cellchat, sources.use = c(3,5), targets.use = c(1,2,4,6),                  
                 signaling = c("TGFb","SPP1"), remove.isolate = FALSE)
3)ligand-receptor pair 表达
代码语言:javascript
复制
# Take an input of a ligand-receptor pair and show expression in binary
spatialFeaturePlot(cellchat, pairLR.use = "IGF1_IGF1R", point.size = 1.5, 
                   do.binary = TRUE, cutoff = 0.05, enriched.only = F, 
                   color.heatmap = "Reds", direction = 1)

以上就完成了CellChat 在空转数据中的应用。

四 参考资料

更多的可视化展示方式详见官网:

[1]https://github.com/jinworks/CellChat

[2]https://htmlpreview.github.io/?https://github.com/jinworks/CellChat/blob/master/tutorial/CellChat_analysis_of_spatial_imaging_data.html

[3]CellChat for systematic analysis of cell-cell communication from single-cell and spatially resolved transcriptomics

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2023-11-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信补给站 微信公众号,前往查看

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

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2,准备输入文件
  • 3,创建CellChat对象
  • 4,设置参考数据库
  • 5,CellChat预处理
  • 1,推断细胞通讯网络
  • 2,计算cell-cell communication
  • 除了和单细胞转录组一致的可视化外,还有一些空转特有的可视化展示。
  • 1,celltype之间通讯结果
    • 1)根据使用netVisual_circle显示任意两个celltype之间的通讯次数(左)或总通讯强度(右)
      • 2)根据使用netVisual_heatmap显示任意两个celltype之间的通讯次数(左)或总通讯强度(右)
      • 2,单个信号通路可视化
        • 1)层级图
          • 2)和弦图
            • 3) network centrality scores
            • 3,绘制配体受体气泡图
              • 1)指定受体-配体细胞类型
                • 2)指定受体-配体细胞类型 且 指定通路
                  • 3)ligand-receptor pair 表达
                  • 四 参考资料
                    • 更多的可视化展示方式详见官网:
                    相关产品与服务
                    数据库
                    云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
                    领券
                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档