❝1、《KS科研分享与服务》公众号有QQ交流群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!
2、《KS科研分享与服务》微信VIP群只针对购买打包代码的小伙伴(公众号所有付费内容合集)!微信群不是单独的,是对于打包的人答疑解惑和交流的平台、群成员专享视频教程,帖子提前发布,以及其他更多福利!
点击:→ 加入微信vip群:2024-2025《KS科研分享与服务》付费内容打包集合
3、需进QQ群或者打包代码入微信VIP的小伙伴请添加作者微信了解,请备注目的,除此之外请勿添加,谢谢!
详情请联系作者:
❞
❝2、10X-Visum空间转录组(2)---下游分析数据基本处理-降维聚类-可视化
3、10X-Visum空间转录组(3)---细胞注释|基因集评分
❞
# cellchat version:2.1.2
# Seurat version:4.3.0
#本次演示数据为10X visum空转
#部分内容系个人理解,如果有偏差,欢迎指正交流!
#安装R包
devtools::install_github("jinworks/CellChat")
library(Seurat)
library(CellChat)
library(patchwork)
setwd("/home/tq_ziv/data_analysis/10X空间转录组/spatial_cellchat/")
load("~/data_analysis/10X空间转录组/Spatial_integrated_5_8.RData")
#我们是整合样本,所以提取一个样本做演示一下单样本的空转互作分析即可
names(Spatial_integrated )
# [1] "Early1" "Early2" "Mid1" "Mid2" "Old1" "Old2"
Early1_sp <- subset(Spatial_integrated, orig.ident=="Early1")
Early1_spin% "Early1")] <- NULL [-which(names(Early1_sp ) %
data.input = GetAssayData(Early1_sp, slot = "data", assay = "SCT")
meta = Early1_sp@meta.data[,c("orig.ident","clusterLevel")]#取注释的celltype
colnames(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 Visium
conversion.factor = spot.size/scalefactors$spot_diameter_fullres
spatial.factors = data.frame(ratio = conversion.factor, tol = spot.size/2)#构建为一个dataframe
cellchat_E1 <- createCellChat(object = data.input, meta = meta, group.by = "labels",
datatype = "spatial", coordinates = spatial.locs, spatial.factors = spatial.factors)
#我的是小鼠数据,用小鼠数据库
CellChatDB <- CellChatDB.mouse
cellchat_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_E1, min.cells = 10)
cellchat_E1 <- computeCommunProbPathway(cellchat_E1)
#互作网络整合,可以设置soure和target,我们这里默认了,就是全部的
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 plot
par(mfrow=c(1,1), xpd = TRUE) # `xpd = TRUE` should be added to show the title
netVisual_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 scores
cellchat_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 groups
par(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)