cellchat analysis from from a Scanpy h5ad file
0
0
Entering edit mode
10 months ago
cgp09741 ▴ 10

I am currently trying to generate a cellchat analysis created from a Scanpy h5ad file but I am encountering an error when it comes to the computeCommunProb below is the code that i am running along with the error. If anyone has insight as to where I am going wrong in the transfer of my h5ad file to a cellchat onject it would be greatly appreciated.

ad <- import("anndata", convert = FALSE)

ad_object <- ad$read_h5ad("/adata.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)
colnames(meta.data) <- c("doublet_scores", "predicted_doublets", "mito_fraction", "n_counts", "n_genes", "total_counts", "sample", "batch", "leiden", "cell_type")
meta.data <- select(meta.data, cell_type)
meta.data <- meta.data %>% rename(group = cell_type)

meta <- meta.data

cellchat <- createCellChat(object = data.input, meta = meta, group.by = "group")
cellchat <- addMeta(cellchat, meta = meta, meta.name = "group")
cellchat <- setIdent(cellchat, ident.use = "group")
levels(cellchat@idents)


CellChatDB.human <- CellChatDB.human # Load the human database 
showDatabaseCategory(CellChatDB.human)
# Set all CellChatDB for cell-cell communication analysis
CellChatDB.use <- CellChatDB.human
cellchat@DB <- CellChatDB.use

cellchat <- subsetData(cellchat)

# Pre-processing the expression data
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)

# Optional: project gene expression data onto protein-protein interaction (PPI)
cellchat <- projectData(cellchat, PPI.human)

# 4. Compute the communication probability and infer cellular communication network
cellchat <- computeCommunProb(cellchat)
cellchat <- computeCommunProb(cellchat, raw.use = FALSE) # use the projected data

0%Error in if (sum(P1_Pspatial) == 0) { : missing value where TRUE/FALSE needed

scanpy r h5ad CellChat cellchat • 431 views
ADD COMMENT

Login before adding your answer.

Traffic: 1531 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6