iTALK的文章连接如下:
https://www.biorxiv.org/content/10.1101/507871v1
包的地址:
https://github.com/Coolgenome/iTALK
首先安装包。
if(!require(devtools)) install.packages("devtools");
devtools::install_github("Coolgenome/iTALK", build_vignettes = TRUE)
library(circlize)
library(iTALK)
构建数据、设置细胞及分组,设置颜色,寻找高变基因!
human_data <- readRDS("D:/cellinter-celldb/human_data.rds")
exp <- as.data.frame(t(as.matrix(human_data@assays$RNA@counts)))
exp$cell_type <- human_data@meta.data$celltype
exp$compare_group <- human_data@meta.data$group
length(unique(human_data$celltype))
# [1] 5
highly_exprs_genes<-rawParse(exp,top_genes=25,stats='mean')
comm_list<-c('growth factor','other','cytokine','checkpoint')
cell_col<-structure(c("#B17BA6", "#FF7F00", "#FDB462", "#E7298A", "#E78AC3"),names=unique(exp$cell_type))
接下来进行分析,并对每种类型的互作进行可视化:
par(mfrow=c(1,2))
res<-NULL
for(comm_type in comm_list){
res_cat<-FindLR(highly_exprs_genes,datatype='mean count',comm_type=comm_type)
res_cat<-res_cat[order(res_cat$cell_from_mean_exprs*res_cat$cell_to_mean_exprs,decreasing=T),]
NetView(res_cat,col=cell_col,vertex.label.cex=1,arrow.width=1,edge.max.width=5)
LRPlot(res_cat[1:20,],datatype='mean count',cell_col=cell_col,link.arr.lwd=res_cat$cell_from_mean_exprs[1:20],link.arr.width=res_cat$cell_to_mean_exprs[1:20])
title(comm_type)
res<-rbind(res,res_cat)
}
最后可视化一下整体的互作效果,有互作图和受配体弦图两种形式。
res<-res[order(res$cell_from_mean_exprs*res$cell_to_mean_exprs,decreasing=T),]
NetView(res,col=cell_col,vertex.label.cex=1,arrow.width=1,edge.max.width=5)
iTALK::LRPlot(res[1:20,],
datatype='mean count',
link.arr.lwd=res$cell_from_mean_exprs[1:20],
link.arr.width=res$cell_to_mean_exprs[1:20])
当然了,我们也提到,iTALK可以做组间差异比较,可能是由于我的数据随意构建吧,没有差异,这里就不展示了,感兴趣的可跟着作者的数据学习。
#######------------------两组间显著的配体-受体对---------------------------------
# # randomly assign the compare group to each sample
# data<-data %>% mutate(compare_group=sample(2,nrow(data),replace=TRUE))
# # find DEGenes of regulatory T cells and NK cells between these 2 groups
# deg_t<-DEG(data %>% filter(cell_type=='regulatory_t'),method='Wilcox',contrast=c(2,1))
# deg_nk<-DEG(data %>% filter(cell_type=='cd56_nk'),method='Wilcox',contrast=c(2,1))
# # find significant ligand-receptor pairs and do the plotting
# par(mfrow=c(1,2))
# res<-NULL
# for(comm_type in comm_list){
# res_cat<-FindLR(deg_t,deg_nk,datatype='DEG',comm_type=comm_type)
# res_cat<-res_cat[order(res_cat$cell_from_logFC*res_cat$cell_to_logFC,decreasing=T),]
# #plot by ligand category
# if(nrow(res_cat)==0){
# next
# }else if(nrow(res_cat>=20)){
# LRPlot(res_cat[1:20,],datatype='DEG',cell_col=cell_col,link.arr.lwd=res_cat$cell_from_logFC[1:20],link.arr.width=res_cat$cell_to_logFC[1:20])
# }else{
# LRPlot(res_cat,datatype='DEG',cell_col=cell_col,link.arr.lwd=res_cat$cell_from_logFC,link.arr.width=res_cat$cell_to_logFC)
# }
# NetView(res_cat,col=cell_col,vertex.label.cex=1,arrow.width=1,edge.max.width=5)
# title(comm_type)
# res<-rbind(res,res_cat)
# }
###https://github.com/Coolgenome/iTALK/blob/master/example/example_code.r
到这里还没有结束,我非常看好iTALK种的LRPlot函数,不仅可视化了细胞之间的关系,还展示了具体的受配体,这样的图形一目了然。之间我们在cellchat及cellphonedb种没有这样的可视化,这里我们使用cellchat的数据,也可以利用iTALK这个包的函数做很好的可视化!
setwd("D:/KS项目/公众号文章/iTalk_细胞互作")
A <- read.csv("net_inter.csv", header = T)
A<-A[order(A$cell_from_mean_exprs*A$cell_to_mean_exprs,decreasing=T),]
设置受配体及细胞颜色。
gene_col<-structure(c(rep('#CC3333',length(A[1:40,]$ligand)),
rep("#006699",length(A[1:40,]$receptor))),
names=c(A[1:40,]$ligand,
A[1:40,]$receptor))
cell_col <- structure(c("#DC050C", "#FB8072", "#1965B0", "#7BAFDE", "#882E72",
"#B17BA6", "#FF7F00", "#FDB462", "#E7298A", "#E78AC3",
"#33A02C", "#B2DF8A", "#55A1B1"),
names=unique(A$cell_from))
作图:
iTALK::LRPlot(A[1:40,],
datatype='mean count',
link.arr.lwd=A$cell_from_mean_exprs[1:40],
link.arr.width=0.1,
link.arr.col = 'grey20',#连线颜色设置
print.cell = T,
track.height_1=uh(1, "mm"),
track.height_2 = uh(15, "mm"),
text.vjust = "0.5cm",
gene_col = gene_col,
cell_col = cell_col)
效果还是很好的,用在论文中也是挺吸引人的,对于结果的解读也是更加清晰。
转自:“KS科研分享与服务”微信公众号
如有侵权,请联系本站删除!