CellChat 报错"Error in `levels<-`(`*tmp*`, value = as.character(levels)) : factor level [2] is d...

今天在跑CellChat的时候,出现了一个问题"Error in levels<-(*tmp*, value = as.character(levels)) : factor level [2] is duplicated", 写个教程记录下解决办法。

1. 问题

问题

我看了下在跑到LT通路的时候,发现报错了,看了下跑出来的结果,发现LT通路中显著的配体受体对是重复的。这个重复的话只能是zebrafish的配体受体对库中有重复了


LT通路中显著的配体受体对是重复的

2.解决

(1) check zebrafish 配体受体对库

CellChatDB <- CellChatDB.zebrafish # use CellChatDB.mouse if running on mouse data
showDatabaseCategory(CellChatDB)

dplyr::glimpse(CellChatDB$interaction)

# use a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling

同一通路中重复的配体受体对

(2) 删除配体受体库中其他重复的配体受体对

new_interaction <- NULL
all_pathway_name <- unique(CellChatDB.use$interaction$pathway_name)

lrnum <- matrix(0, length(all_pathway_name), 4)
for (i in seq_along(all_pathway_name)){
    print(all_pathway_name[i])
    temp <- dplyr::filter(CellChatDB.use$interaction, pathway_name == all_pathway_name[i])
    lrnum[i, c(1, 2)] <- dim(temp)
    temp <- temp %>% distinct(interaction_name_2, .keep_all = TRUE)
  lrnum[i, c(3, 4)] <- dim(temp)
    new_interaction <- rbind(new_interaction, temp)
}
rownames(lrnum) <- all_pathway_name
发现insulin中也是有重复的

Insulin重复

开心!!!!!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容