今天在跑CellChat的时候,出现了一个问题"Error in
levels<-
(*tmp*
, value = as.character(levels)) : factor level [2] is duplicated", 写个教程记录下解决办法。
1. 问题
我看了下在跑到LT通路的时候,发现报错了,看了下跑出来的结果,发现LT通路中显著的配体受体对是重复的。这个重复的话只能是zebrafish的配体受体对库中有重复了
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
开心!!!!!