首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >🤩 Cellchat | 空间转录组也可以做细胞通讯啦!~(一)(单个数据集篇)

🤩 Cellchat | 空间转录组也可以做细胞通讯啦!~(一)(单个数据集篇)

作者头像
生信漫卷
发布2024-11-23 09:12:35
发布2024-11-23 09:12:35
84000
代码可运行
举报
运行总次数:0
代码可运行

写在前面

CellChat 2 现在支持多种数据类型,除了单细胞转录组数据(scRNA-seq),还扩展支持 空间转录组数据spatial transcriptomics)。😘

可以将空间信息与细胞间通信分析结合起来,更加精确地探索细胞与细胞之间的关系。🧐

用到的包

代码语言:javascript
代码运行次数:0
运行
复制
rm(list = ls())
library(tidyverse)
library(CellChat)
library(Seurat)

示例数据

代码语言:javascript
代码运行次数:0
运行
复制
load("./visium_mouse_cortex_annotated.RData")
# show the image and annotated spots
color.use <- scPalette(nlevels(visium.brain)); names(color.use) <- levels(visium.brain)

准备数据

代码语言:javascript
代码运行次数:0
运行
复制
# Prepare input data for CelChat analysis
data.input = Seurat::GetAssayData(visium.brain, slot = "data", assay = "SCT") # normalized data matrix

代码语言:javascript
代码运行次数:0
运行
复制
meta = data.frame(labels = Seurat::Idents(visium.brain), samples = "sample1", row.names = names(Seurat::Idents(visium.brain))) # manually create a dataframe consisting of the cell labels
meta$samples <- factor(meta$samples)
unique(meta$labels) # check the cell labels

代码语言:javascript
代码运行次数:0
运行
复制
unique(meta$samples) # check the sample labels

代码语言:javascript
代码运行次数:0
运行
复制
spatial.locs = Seurat::GetTissueCoordinates(visium.brain, scale = NULL, cols = c("imagerow", "imagecol"))

代码语言:javascript
代码运行次数:0
运行
复制
scalefactors = jsonlite::fromJSON(txt = file.path("./spatial_imaging_data_visium-brain", 'scalefactors_json.json'))
spot.size = 65 # the theoretical spot size (um) in 10X Visium
conversion.factor = spot.size/scalefactors$spot_diameter_fullres
spatial.factors = data.frame(ratio = conversion.factor, tol = spot.size/2)

d.spatial <- computeCellDistance(coordinates = spatial.locs, ratio = spatial.factors$ratio, tol = spatial.factors$tol)
min(d.spatial[d.spatial!=0]) # this value should approximately equal 100um for 10X Visium data

创建 CellChat 对象

代码语言:javascript
代码运行次数:0
运行
复制
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels",
                           datatype = "spatial", coordinates = spatial.locs, spatial.factors = spatial.factors)
cellchat

设置配体-受体相互作用数据库

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

showDatabaseCategory(CellChatDB)

代码语言:javascript
代码运行次数:0
运行
复制
dplyr::glimpse(CellChatDB$interaction)

用部分数据做互作分析!~🧐

代码语言:javascript
代码运行次数:0
运行
复制
# use a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling", key = "annotation") # use Secreted Signaling

# Only uses the Secreted Signaling from CellChatDB v1
#  CellChatDB.use <- subsetDB(CellChatDB, search = list(c("Secreted Signaling"), c("CellChatDB v1")), key = c("annotation", "version"))

# use all CellChatDB except for "Non-protein Signaling" for cell-cell communication analysis
# CellChatDB.use <- subsetDB(CellChatDB)


# use all CellChatDB for cell-cell communication analysis
# CellChatDB.use <- CellChatDB # simply use the default CellChatDB. We do not suggest to use it in this way because CellChatDB v2 includes "Non-protein Signaling" (i.e., metabolic and synaptic signaling) that can be only estimated from gene expression data. 

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

预处理表达数据以进行细胞间通信分析

代码语言:javascript
代码运行次数:0
运行
复制
# 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 = 4) 
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat, variable.both = F)

# cellchat <- projectData(cellchat, PPI.mouse)

细胞间通信网络的推理

代码语言:javascript
代码运行次数:0
运行
复制
cellchat <- computeCommunProb(cellchat, 
                              type = "truncatedMean", 
                              trim = 0.1,
                              distance.use = TRUE, 
                              interaction.range = 250, 
                              scale.distance = 0.01,
                              contact.dependent = TRUE, 
                              contact.range = 100,
                              nboot = 50
                              )

代码语言:javascript
代码运行次数:0
运行
复制
cellchat <- filterCommunication(cellchat, min.cells = 10)

提取推断出的通信网络

代码语言:javascript
代码运行次数:0
运行
复制
df.net <- subsetCommunication(cellchat)

在信号通路水平上推断细胞间通信

代码语言:javascript
代码运行次数:0
运行
复制
cellchat <- computeCommunProbPathway(cellchat)

计算aggregated细胞间通信网络

代码语言:javascript
代码运行次数:0
运行
复制
cellchat <- aggregateNet(cellchat)

可视化一下!~😘

代码语言:javascript
代码运行次数:0
运行
复制
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")

代码语言:javascript
代码运行次数:0
运行
复制
netVisual_heatmap(cellchat, measure = "count", color.heatmap = "Blues")

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

细胞间通信网络的可视化

代码语言:javascript
代码运行次数:0
运行
复制
pathways.show <- c("IGF") 
# Circle plot
par(mfrow=c(1,1), xpd = TRUE) # `xpd = TRUE` should be added to show the title
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle")

代码语言:javascript
代码运行次数:0
运行
复制
# 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)

计算和可视化网络中心性分数!~😘

代码语言:javascript
代码运行次数:0
运行
复制
# 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)

代码语言:javascript
代码运行次数:0
运行
复制
# USER can show this information on the spatial transcriptomics when visualizing a signaling network, e.g., bigger circle indicates larger incoming signaling
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "spatial", edge.width.max = 2, alpha.image = 0.2, vertex.weight = "incoming", vertex.size.max = 4, vertex.label.cex = 3.5)

可视化组织上的基因表达分布~!🧐

代码语言:javascript
代码运行次数:0
运行
复制
# Take an input of a few genes
spatialFeaturePlot(cellchat, features = c("Igf1","Igf1r"), point.size = 0.8, color.heatmap = "Reds", direction = 1)

代码语言:javascript
代码运行次数:0
运行
复制
# Take an input of a ligand-receptor pair
spatialFeaturePlot(cellchat, pairLR.use = "IGF1_IGF1R", point.size = 0.5, do.binary = FALSE, cutoff = 0.05, enriched.only = F, color.heatmap = "Reds", direction = 1)

代码语言:javascript
代码运行次数:0
运行
复制
# Take an input of a ligand-receptor pair and show expression in binary
spatialFeaturePlot(cellchat, pairLR.use = "IGF1_IGF1R", point.size = 1, do.binary = TRUE, cutoff = 0.05, enriched.only = F, color.heatmap = "Reds", direction = 1)

最后祝大家早日不卷!~

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

本文分享自 生信漫卷 微信公众号,前往查看

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 写在前面
  • 用到的包
  • 示例数据
  • 准备数据
  • 创建 CellChat 对象
  • 设置配体-受体相互作用数据库
  • 预处理表达数据以进行细胞间通信分析
  • 细胞间通信网络的推理
  • 提取推断出的通信网络
  • 在信号通路水平上推断细胞间通信
  • 计算aggregated细胞间通信网络
  • 细胞间通信网络的可视化
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档