❝3、付费文章集合有打包价哦! 详情请联系作者: ❞ 针对cellchat更新的问题我们之前说过一期了:Cellchat和Cellphonedb细胞互作一些问题的解决(error和可视化)。但是小伙伴反应还是出问题,cellchat和igraph报的版本都对,主要是做贝壳图那里循环的时候出错。微信VIP群里尝试无果后,我们决定来一次头脑风暴,其实实质就是利用循环作图,可是怎么总是出错,思考一下改写一下。 顺便近期小伙伴问道cellchat部分的可视化,这里就补充上了。因为cellchat可视化内容实在太多,很多我没有兴趣,也不知道怎么解释应用到自己的分析,还是建议看看原文作者的解释,选适合自己的可视化。 详细分析间:Cellchat(代码详细注释版):单细胞转录组(人、小鼠)细胞互作分析及可视化。这里仅仅是部分可视化。 一、贝壳图 #----------------------------------一、贝壳图----------------------------------- # #展示每个亚群作为source的信号传递 # mat <- group1_cellchat@net$weight # par(mfrow = c(5,4), xpd=TRUE,mar=c(1,1,1,1)) # for (i in 1:nrow(mat)) { # mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat)) # mat2[i, ] <- mat[i, ] # netVisual_circle(mat2, # vertex.weight = groupSize, # weight.scale = T, # edge.weight.max = max(mat), # title.name = rownames(mat)[i]) # } # Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, : # Length of new attribute value must be 1 or 7, the number of target edges, not 2
#多少种细胞就设置多少个颜色 cell_color <- c("#20B2AA","#FFA500","#9370DB", "#98FB98","#F08080","#1E90FF","#7CFC00") color_data <- data.frame(cell_color) for (i in 1:length(cell_color)){ color1 <- c(cell_color[i], setdiff(cell_color, cell_color[i])) color1 <- as.data.frame(color1) color_data <- cbind(color_data, color1) }
color_data <- color_data[, -1]
#展示每个亚群作为source的信号传递 mat <- mycellchat@net$weight par(mfrow = c(2,4), xpd=TRUE,mar=c(2,2,2,2)) for (i in 1:nrow(mat)) { mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat)) mat2[i, ] <- mat[i, ] mat2 <- as.data.frame(mat2) data <- data.frame(mat2[i,]) data <- select(data,i,everything()) data1 <- data.frame(mat2[-i, ]) data1 <- select(data1,i,everything()) data2 <- rbind(data, data1) data2 <- as.matrix(data2) netVisual_circle(data2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(data2)[1], color.use = color_data[, i]) }
二、可视化通路基因表达
#----------------------------------二、通路基因表达----------------------------- pathway.show <- unique(group1.net$pathway_name) #TGFb p1 <- plotGeneExpression(mycellchat, signaling = 'TGFb') # color.use = NULL, # group.by = NULL,
三、河流图
#----------------------------------三、河流图------------------------------------- library(NMF) library(ggalluvial) #选择合适的nPatterns mycellchat <- netAnalysis_computeCentrality(mycellchat) selectK(mycellchat, pattern = "outgoing")
#outgoing nPatterns = 4#选择第一次下降的拐点数字 mycellchat <- identifyCommunicationPatterns(object = mycellchat, pattern = "outgoing", k = nPatterns)
netAnalysis_river(mycellchat, pattern = "outgoing",do.order=T)
#incoming selectK(mycellchat, pattern = "incoming") nPatterns = 4 mycellchat <- identifyCommunicationPatterns(object = mycellchat, pattern = "incoming", k = nPatterns) netAnalysis_river(mycellchat, pattern = "incoming")
好了,这就是所有内容了。对了,小伙伴在解决第一个报错上有好的办法希望分享。觉得这个帖子对你有帮助的话,点个赞再走呗!
|