Error in ComputeCommunProb
I am running scanpy anndata through CellChat and my code works except for when it gets to computing the communication probability. This is the error I get. ad <- import("anndata", convert = FALSE)
ad_object <- ad$read_h5ad("C:/Users/Sohaib/Downloads/Proliferation_an.h5ad")
access normalized data matrix
data.input <- t(py_to_r(ad_object$X)) rownames(data.input) <- rownames(py_to_r(ad_object$var)) colnames(data.input) <- rownames(py_to_r(ad_object$obs))
access meta data
meta.data <- py_to_r(ad_object$obs) meta <- meta.data
cellchat <- createCellChat(object = data.input,meta = meta, group.by = "library_id") Create a CellChat object from a data matrix Set cell identities for the new CellChat object The cell groups used for CellChat analysis are BcatD3 BcatD4 BcatD5 Cntrl1 Cntrl2 CellChatDB <- CellChatDB.mouse showDatabaseCategory(CellChatDB) dplyr::glimpse(CellChatDB$interaction) Rows: 2,021 Columns: 11 $ interaction_name
"TGFB1_TGFBR1_TGFBR2", "TGFB2_TGFBR1_TGFBR2", "TGFB3_TGFBR1_TGFBR2", "TGFB1_ACVR1B_TGFBR2", "TGFB1_ACVR1C_TGFBR2", "TGFB2_ACVR1B_TGFBR~ $ pathway_name "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "BMP", "BMP", "BMP", "BMP", "BMP", "BM~ $ ligand "Tgfb1", "Tgfb2", "Tgfb3", "Tgfb1", "Tgfb1", "Tgfb2", "Tgfb2", "Tgfb3", "Tgfb3", "Tgfb1", "Tgfb2", "Tgfb3", "Bmp2", "Bmp2", "Bmp2", "B~ $ receptor "TGFbR1_R2", "TGFbR1_R2", "TGFbR1_R2", "ACVR1B_TGFbR2", "ACVR1C_TGFbR2", "ACVR1B_TGFbR2", "ACVR1C_TGFbR2", "ACVR1B_TGFbR2", "ACVR1C_TG~ $ agonist "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb agonist", "TGFb ~ $ antagonist "TGFb antagonist", "TGFb antagonist", "TGFb antagonist", "TGFb antagonist", "TGFb antagonist", "TGFb antagonist", "TGFb antagonist", "~ $ co_A_receptor "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""~ $ co_I_receptor "TGFb inhibition receptor", "TGFb inhibition receptor", "TGFb inhibition receptor", "TGFb inhibition receptor", "TGFb inhibition recep~ $ evidence "KEGG: mmu04350", "KEGG: mmu04350", "KEGG: mmu04350", "PMID: 27449815", "PMID: 27449815", "PMID: 27449815", "PMID: 27449815", "PMID: 2~ $ annotation "Secreted Signaling", "Secreted Signaling", "Secreted Signaling", "Secreted Signaling", "Secreted Signaling", "Secreted Signaling", "S~ $ interaction_name_2 "Tgfb1 - (Tgfbr1+Tgfbr2)", "Tgfb2 - (Tgfbr1+Tgfbr2)", "Tgfb3 - (Tgfbr1+Tgfbr2)", "Tgfb1 - (Acvr1b+Tgfbr2)", "Tgfb1 - (Acvr1c+Tgfbr~ CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") cellchat@DB <- CellChatDB.use subset the expression data of signaling genes for saving computation cost
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database future::plan("multiprocess", workers = 4) # do parallel #> Warning: [ONE-TIME WARNING] Forked processing ('multicore') is disabled #> in future (>= 1.13.0) when running R from RStudio, because it is #> considered unstable. Because of this, plan("multicore") will fall #> back to plan("sequential"), and plan("multiprocess") will fall back to #> plan("multisession") - not plan("multicore") as in the past. For more details, #> how to control forked processing or not, and how to silence this warning in #> future R sessions, see ?future::supportsMulticore cellchat <- identifyOverExpressedGenes(cellchat) cellchat <- identifyOverExpressedInteractions(cellchat)
project gene expression data onto PPI network (optional)
cellchat <- projectData(cellchat, PPI.mouse)
cellchat <- computeCommunProb(cellchat,raw.use = TRUE) | | 0%Error in if (sum(P1) == 0) { : missing value where TRUE/FALSE needed In addition: There were 50 or more warnings (use warnings() to see the first 50)
Does anyone know why this could be happening? My metadata seems fine and my anndata is all normalized.
@sqjin This might be related with the conversion of python object to R. Can you try other methods to convert it?
@sqjin This might be related with the conversion of python object to R. Can you try other methods to convert it? hi! I have the same error (Error in if (sum(P1) == 0) { : missing value where TRUE/FALSE needed) when running computeCommunProb(cellchat,raw.use = TRUE), but I converted a Seurat object into cellchat,I don't know how to fix it, can you help me?
I'm currently having the same issue, did anyone ever come up with a solution here?
I resolved this issue by using my h5 data in a Seurat pipeline rather than Scanpy and then using that data in CellChat. I wasn't ever able to figure out why the Scanpy anndata did not work.