10X-Visum空间转录组(4)---cellchat V2空转互作分析及可视化

学术   2024-08-01 09:30   重庆  
觉得小编内容有用的、有意思的,点赞、分享、关注一下呗!

1、《KS科研分享与服务》公众号有QQ交流群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!


2、《KS科研分享与服务》微信VIP群只针对购买打包代码的小伙伴(公众号所有付费内容合集)!微信群不是单独的,是对于打包的人答疑解惑和交流的平台、群成员专享视频教程,帖子提前发布,以及其他更多福利!


点击:→ 加入微信vip群:2024-2025《KS科研分享与服务》付费内容打包集合


3、需进QQ群或者打包代码入微信VIP的小伙伴请添加作者微信了解,请备注目的,除此之外请勿添加,谢谢!


详情请联系作者:

10X Visum空间转录组往期内容:

1、10X-Visum空间转录组(1)---上游分析

2、10X-Visum空间转录组(2)---下游分析数据基本处理-降维聚类-可视化

3、10X-Visum空间转录组(3)---细胞注释|基因集评分

Cellchat V2支持单细胞空转的互作分析,假设您的数据已经完成了基本的分析和注释,那么进行互作分析也是一种手段,这里简单介绍一下(请注意,数据无实际意义)。我们在写的过程中发现,其实这个步骤和scRNA的cellchat差不多(单细胞通讯CellChat V2详细版(视频教程))。重复写没有意思,所以我们直接介绍了cellchat(Cellchat分析受配体数据库更新(自定义))和cellphonedb(Cellphonedb单细胞互作分析数据库更新及自定义)数据库的更新,感兴趣的学习一下。Cellchat v2安装最新版哦!
# cellchat version:2.1.2# Seurat version:4.3.0#本次演示数据为10X visum空转#部分内容系个人理解,如果有偏差,欢迎指正交流!#安装R包devtools::install_github("jinworks/CellChat")library(Seurat)library(CellChat)library(patchwork)
首先还是准备input文件,我们以一个样本演示:
setwd("/home/tq_ziv/data_analysis/10X空间转录组/spatial_cellchat/")load("~/data_analysis/10X空间转录组/Spatial_integrated_5_8.RData")#我们是整合样本,所以提取一个样本做演示一下单样本的空转互作分析即可names(Spatial_integrated@images)# [1] "Early1" "Early2" "Mid1"   "Mid2"   "Old1"   "Old2" 
Early1_sp <- subset(Spatial_integrated, orig.ident=="Early1")Early1_sp@images[-which(names(Early1_sp@images) %in% "Early1")] <- NULL
data.input = GetAssayData(Early1_sp, slot = "data", assay = "SCT") 
meta = Early1_sp@meta.data[,c("orig.ident","clusterLevel")]#取注释的celltypecolnames(meta) <- c("group","labels")
spatial.locs = GetTissueCoordinates(Early1_sp, scale = NULL, cols = c("imagerow", "imagecol")) #空间坐标
scalefactors = jsonlite::fromJSON(txt = file.path("/home/tq_ziv/data_analysis/10X空间转录组/sptial/Early_R01_S1_spatial/", 'scalefactors_json.json'))spot.size = 65 # the theoretical spot size (um) in 10X Visiumconversion.factor = spot.size/scalefactors$spot_diameter_fullresspatial.factors = data.frame(ratio = conversion.factor, tol = spot.size/2)#构建为一个dataframe
构建cellchat object,之后就和scRNA没什么大的区别了;关于Cellchat能否做其他物种这里说明一下,首先cellchat自带了小鼠、人、斑马鱼的受配体数据库,要做其他的物种,在代码上没有区别,只不过有两种形式,一种同源转化你的数据,然后用模式生物的数据库;另一种就是按照cellchat需要的形式,自定义数据库即可!
cellchat_E1 <- createCellChat(object = data.input, meta = meta, group.by = "labels",                           datatype = "spatial", coordinates = spatial.locs, spatial.factors = spatial.factors)
#我的是小鼠数据,用小鼠数据库CellChatDB <- CellChatDB.mousecellchat_E1 <- subsetData(cellchat_E1)#目的是选择在CellChatDB.use中的信号基因future::plan("multisession", workers = 5) #可以设置多线程cellchat_E1 <- identifyOverExpressedGenes(cellchat_E1)cellchat_E1 <- identifyOverExpressedInteractions(cellchat_E1, variable.both = F)#推断通讯网络cellchat_E1 <- computeCommunProb(cellchat_E1, type = "triMean", trim = 0.1, distance.use = TRUE, interaction.range = 250, scale.distance = 0.01, contact.dependent = TRUE, contact.range = 100) cellchat_E1 <- filterCommunication(cellchat_E1min.cells = 10)cellchat_E1 <- computeCommunProbPathway(cellchat_E1)
#互作网络整合,可以设置souretarget,我们这里默认了,就是全部的cellchat_E1 <- aggregateNet(cellchat_E1)                                         
至此,分析就结束了!然后就是可视化了:
#figure1-互作数目
groupSize <- as.numeric(table(cellchat_E1@idents))par(mfrow = c(1,2), xpd=TRUE)netVisual_circle(cellchat_E1@net$count, vertex.weight = rowSums(cellchat_E1@net$count), weight.scale = T, label.edge= F, title.name = "Number of interactions")netVisual_circle(cellchat_E1@net$weight, vertex.weight = rowSums(cellchat_E1@net$weight), weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")

#figure2-heatmap展示netVisual_heatmap(cellchat_E1, measure = "count", color.heatmap = "Blues")

#展示互作关系#figure3-通路水平-弦图
pathways.show <- c("IGF") # Circle plotpar(mfrow=c(1,1), xpd = TRUE) # `xpd = TRUE` should be added to show the titlenetVisual_aggregate(cellchat_E1, signaling = pathways.show, layout = "circle")

#figure4-Spatial plot-空间展示par(mfrow=c(1,1))netVisual_aggregate(cellchat_E1, signaling = pathways.show,                     layout = "spatial", edge.width.max = 2,                     vertex.size.max = 1, alpha.image = 0.2, vertex.label.cex = 3.5)

#figure5-信号# Compute the network centrality scorescellchat_E1 <- netAnalysis_computeCentrality(cellchat_E1, 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_E1, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)

#figure8-可以直接输入受配体对spatialFeaturePlot(cellchat_E1, pairLR.use = "VEGFA_VEGFR1",                    point.size = 0.5, do.binary = FALSE, cutoff = 0.05,                    enriched.only = F, color.heatmap = "Blues", direction = 1)

这就是所有内容了,其实如果你熟悉了scRNA的cellchat分析,那么空转的也不是什么大问题,很简单的了。希望我的分析对您有用,单个赞再走呗!

KS科研分享与服务
科研学习交流于分享,生信学习笔记,科研经历和生活!
 最新文章