沈阳市大东区安妮斯贝闪电泡芙西点店

通过 group.by 定义分组
沈阳市大东区安妮斯贝闪电泡芙西点店
栏目分类
通过 group.by 定义分组
发布日期:2024-06-25 09:19    点击次数:183

通过 group.by 定义分组

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

图片

一 数据输入,处理 

1,载入R包和数据

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

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

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信息 。

#矩阵信息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 labelsunique(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 定义分组。

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) 。

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 analysisCellChatDB.use <- CellChatDB # simply use the default CellChatDB# set the used database in the objectcellchat@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一下。

# subset the expression data of signaling genes for saving computation costcellchat <- subsetData(cellchat) # This step is necessary even if using the whole databasefuture::plan("multisession",
台山市爱达电器厂有限公司 workers = 1) #笔记本可以选1##识别过表达基因cellchat <- identifyOverExpressedGenes(cellchat)#识别过表达配体受体对cellchat <- identifyOverExpressedInteractions(cellchat)

二 推断cell-cell network 

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

1,推断细胞通讯网络

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

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计算细胞类型间整合的细胞通讯结果。

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

图片

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

三 CellChat 可视化

除了和单细胞转录组一致的可视化外,还有一些空转特有的可视化展示。1,celltype之间通讯结果1)根据使用netVisual_circle显示任意两个celltype之间的通讯次数(左)或总通讯强度(右)
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之间的通讯次数(左)或总通讯强度(右)
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图。

cellchat@netP$pathwayspathways.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" 。

# Circle plotpar(mfrow=c(1,1))netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle")# Spatial plotpar(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
# Compute the network centrality scorescellchat <- 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 groupspar(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指定。

#指定受体-配体细胞类型netVisual_bubble(cellchat, sources.use = c(3,5),                  targets.use = c(1,2,4,6), remove.isolate = FALSE)

图片

2)指定受体-配体细胞类型 且 指定通路

同时通过signaling指定展示通路

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 表达
# Take an input of a ligand-receptor pair and show expression in binaryspatialFeaturePlot(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  

◆ ◆ ◆  ◆ ◆

精心整理(含图PLUS版)|R语言生信分析,可视化(R统计,ggplot2绘图,生信图形可视化汇总)

RNAseq纯生信挖掘思路分享?不公司简介,主要是送你代码!(建议收藏)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。