Cellchat分析受配体数据库更新(自定义)

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

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


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


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


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


详情请联系作者:

Cellchat单细胞通讯分析大家都很熟悉了(单细胞通讯CellChat V2详细版(视频教程))。我们在做V2更新教程的时候也说过,其实更新最重要的是受配体数据库的更新,这涉及到我们分析结果。最近有小伙伴也提到,cellchat分析的数据库怎么修改或者自定义呢?这个问题官网给出了详细的示例。自定义数据库适用于两种情况,cellchat默认提供了小鼠、人、斑马鱼的分析受配体数据库,需要其他物种分析的那么就需要自行构建了,当然可以进行同源转化利用人的数据库分析,但是我们也知道,人同源基因在其他物种中发挥的作用,以及受配体形式是否一样,这个是存疑的。第二种情况则是我们需要添加新的受配体对进入原有的数据库,例如cellchatDB目前是V2,但是我们在数据库中没有某些感兴趣的受配体,那么就可以自定义添加。

题外话:某些老师觉得自定义数据库了这个分析的逼格就上去了!!!本文完整注释代码已发布在微信VIP群,请自行下载。我们这里是按照教程将cellphonedb的数据库添加到cellchatDB。注意Cellchat安装最新版!
devtools::install_github("jinworks/CellChat")library(CellChat)#version 2.1.2setwd("D:\\KS项目\\公众号文章\\cellchat受配体数据库更新及自定义")
需要自定义数据库呢,其实也很简单,只不过从头整理工作量比较大,只要准备好相关的数据,按照cellchat数据的格式整理储存即可。cellphonedb数据库中人的数据已经是整理过的,下载cellphonedb数据库,修改相关文件即可:
#Step 1: 加载数据库文件interaction_input <- read.csv(file = './cpdb数据库文件/interaction_input.csv')complex_input <- read.csv(file = './cpdb数据库文件/complex_input.csv', row.names = 1)geneInfo <- read.csv(file = './cpdb数据库文件/gene_input.csv')
#Step 2: 修改文件,以期让其适用于cellchat
#gene information---需要有一列列名是“Symbol”geneInfo$Symbol <- geneInfo$hgnc_symbol#将基因名那一列命名为SymbolgeneInfo <- select(geneInfo, -c("ensembl"))geneInfo <- unique(geneInfo)#去除重复行
#interaction_input---获取受配体信息(选择有用的,去除冗余的信息)# get the ligand information---添加一列ligand,并将其转化为symbol(大家熟悉的形式,cpdb这里写的是protein uniprot)idx_partnerA <- match(interaction_input$partner_a, geneInfo$uniprot)idx.use <- !is.na(idx_partnerA)interaction_input$ligand <- interaction_input$partner_ainteraction_input$ligand[idx.use] <- geneInfo$hgnc_symbol[idx_partnerA[idx.use]]# get the receptor information---添加一列receptoridx_partnerB <- match(interaction_input$partner_b, geneInfo$uniprot)idx.use <- !is.na(idx_partnerB)interaction_input$receptor <- interaction_input$partner_binteraction_input$receptor[idx.use] <- geneInfo$hgnc_symbol[idx_partnerB[idx.use]]
# get other informationinteraction_input$interaction_name <- interaction_input$interactorsinteraction_input$interaction_name_2 <- interaction_input$interaction_nameinteraction_input$pathway_name <- interaction_input$classificationinteraction_input$pathway_name <- gsub(".*by ", "", interaction_input$pathway_name)interaction_input$annotation <- interaction_input$directionalityinteraction_input <- select(interaction_input, -c("partner_a","partner_b","protein_name_a","protein_name_b","interactors","classification","directionality"))


##other_info---prepare complex_input filecomplexsubunits <- dplyr::select(complex_input, starts_with("uniprot"))for (i in 1:ncol(complexsubunits)) { idx_complex <- match(complex_input[,paste0("uniprot_",i)], geneInfo$uniprot) idx.use <- !is.na(idx_complex) complex_input[idx.use,paste0("uniprot_",i)] <- geneInfo$hgnc_symbol[idx_complex[idx.use]]}colnames(complex_input)[1:ncol(complexsubunits)] <- paste0("subunit_",seq_len(ncol(complexsubunits)))complex_input <- dplyr::select(complex_input, starts_with("subunit"))
## prepare other information other_info <- list(complex = complex_input)

#Step 3: 更新数据库#这里为什么trim.pathway选择T,一定要让interactions有pathways注释,这是因为:#Warning: If no pathway information of each L-R pair is provided, all pathway-level analysis from CellChat cannot be used, such as computeCommunProb!

#仅仅只有cpdb数据库db.new.cpdb <- updateCellChatDB(db = interaction_input, gene_info = geneInfo, other_info = other_info, trim.pathway = T,species_target = "human",merged = F)#将cpdb数据库和cellchat合并db.new.cpdb_ccdb <- updateCellChatDB(db = interaction_input, gene_info = geneInfo, other_info = other_info, trim.pathway = T,species_target = "human",merged = T)
#保存文件,后续分析直接使用save(db.new.cpdb, file = 'db_new_cpdb.RData')save(db.new.cpdb_ccdb, file = 'db.new.cpdb_ccdb.RData')
修改好的文件,在后续进行cellchat分析选择数据库的时候,就可以直接使用。如果需要自行添加某些受配体,那么只需要下载之前的数据库文件,在Excel中对应的地方修改,然后存储即可!
CellChatDB <- CellChatDB.mouseclass(CellChatDB)#它是一个list,里面包含4个文件,即4个dataframe# [1] "list"
interaction_input <- CellChatDB$interactioncomplex_input <- CellChatDB$complexcofactor_input <- CellChatDB$cofactorgeneInfo <- CellChatDB$geneInfowrite.csv(interaction_input, file = "interaction_input_CellChatDB.csv")write.csv(complex_input, file = "complex_input_CellChatDB.csv")write.csv(cofactor_input, file = "cofactor_input_CellChatDB.csv")write.csv(geneInfo, file = "geneInfo_input_CellChatDB.csv")

#Excel中打开,就能具体查看到底有什么信息#然后直接修改即可#文件按照要求修改之后,读入对应的文件
interaction_input <- read.csv(file = 'interaction_input_CellChatDB.csv', row.names = 1)complex_input <- read.csv(file = 'complex_input_CellChatDB.csv', row.names = 1)cofactor_input <- read.csv(file = 'cofactor_input_CellChatDB.csv', row.names = 1)geneInfo <- read.csv(file = ' geneInfo_input_CellChatDB.csv', row.names = 1)

#cellchat数据库是list形式,所以将修改好的文件(4个dataframe)以list形式储存即可

CellChatDB <- list()CellChatDB$interaction <- interaction_inputCellChatDB$complex <- complex_inputCellChatDB$cofactor <- cofactor_inputCellChatDB$geneInfo <- geneInfo
总之,学会了自定义数据库,提高了我们分析的可操作性。更多详细内容请阅读官网教程。觉得分享有用的点个赞再走呗。

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