CellChat icon indicating copy to clipboard operation
CellChat copied to clipboard

Error at computeCommunProbPathway

Open tkapello opened this issue 1 year ago • 2 comments

Hi,

thank you for this nice package. I am encountering an issue which has been archived in the old github repository. I expanded the CellChat database with the Omnipath resource and I ran CellChat on a seurat object. When I run computeCommunProbPathway(cellchat), I get the following error:

Error in prob.pathways[, , pathways.sig] : subscript out of bounds

I attach below the code I have run and I am happy to share the object if needed.

cellchat<-createCellChat(object=seurat@assays$RNA@data, [email protected], group.by='annotation')

# Load Cellchat database
cellchatdb<-CellChatDB.human

# Assemble Omnipath databases
intercell<-import_intercell_network(organism=9606)
intercell<-intercell[intercell$entity_type_intercell_target=='protein' & intercell$entity_type_intercell_source=='protein',]
ptm<-import_omnipath_enzsub(organism=9606)

intercell<-intercell[,c(8,7)]
colnames(intercell)<-c('ligand', 'receptor')
ptm<-ptm[,c(3,4)]
colnames(ptm)<-c('ligand', 'receptor')

interactions<-rbind(intercell, ptm)
interactions$interaction_name<-paste(interactions$ligand, sep='_', interactions$receptor)
interactions<-interactions[!duplicated(interactions$interaction_name),]
interactions<-as.data.frame(interactions)
rownames(interactions)<-interactions$interaction_name
interactions$interaction_name_2<-gsub('_', ' - ', interactions$interaction_name)
interactions[, c("agonist", "antagonist", "co_A_receptor", "co_I_receptor", "evidence", "annotation", "pathway_name")] <- NA
interactions<-interactions[,c(3, 11, 1, 2, 5:10, 4)]
interactions[]<-lapply(interactions, function(x) ifelse(is.na(x), "", x))
interactions<-rbind(interactions, cellchatdb$interaction)
interactions<-interactions[!duplicated(interactions$interaction_name),]

complex<-import_intercell_network(organism=9606)
complex<-complex[complex$entity_type_intercell_source=='complex' | complex$entity_type_intercell_target=='complex',]
complex<-complex %>% distinct(source_genesymbol, .keep_all=TRUE)
complex<-separate(complex, source_genesymbol, into = c("subunit_1", "subunit_2", "subunit_3", "subunit_4"), sep = "_")
complex<-as.data.frame(complex)

for(i in complex$genesymbol_intercell_source){
  if(grepl(':', i)==TRUE) {
    complex[complex$genesymbol_intercell_source==i, "genesymbol_intercell_source"]<-sapply(strsplit(split=':', i), '[', 2)
  } else {
    complex[complex$genesymbol_intercell_source==i, "genesymbol_intercell_source"]<-i
    }
}
  
rownames(complex)<-complex$genesymbol_intercell_source
complex<-complex[,8:11]
complex[]<-lapply(complex, function(x) ifelse(is.na(x), "", x))
complex<-rbind(complex, cellchatdb$complex)

gene_symbols<-unique(c(interactions$ligand, interactions$receptor, 
                       complex$subunit_1, complex$subunit_2, complex$subunit_3, complex$subunit_4,
                       cellchatdb$cofactor$cofactor1, cellchatdb$cofactor$cofactor2, cellchatdb$cofactor$cofactor3, cellchatdb$cofactor$cofactor4, cellchatdb$cofactor$cofactor5, 
                       cellchatdb$cofactor$cofactor6, cellchatdb$cofactor$cofactor7, cellchatdb$cofactor$cofactor8, cellchatdb$cofactor$cofactor9, cellchatdb$cofactor$cofactor10,
                       cellchatdb$cofactor$cofactor11, cellchatdb$cofactor$cofactor12, cellchatdb$cofactor$cofactor13, cellchatdb$cofactor$cofactor14, cellchatdb$cofactor$cofactor15,
                       cellchatdb$cofactor$cofactor16))
gene_symbols<-gene_symbols[!is.na(gene_symbols)]

gene_info<-select(org.Hs.eg.db, keys=gene_symbols, keytype="SYMBOL", column=c("GENENAME", "ENTREZID", "ENSEMBL"))
colnames(gene_info)<-c('Symbol', 'Name', 'EntrezGene.ID', 'Ensembl.Gene.ID')

omnipath<-list(interactions=interactions, complex=complex, cofactor=cellchatdb$cofactor, geneInfo=gene_info)

# Add Omnipath database to CellChat object
cellchat@DB<-omnipath

# Pre-process datasets
cellchat<-subsetData(cellchat)
cellchat<-identifyOverExpressedGenes(cellchat)
cellchat<-identifyOverExpressedInteractions(cellchat)

# Compute cell-cell communication probability
cellchat<-computeCommunProb(cellchat, population.size=T)
cellchat<-filterCommunication(cellchat, min.cells=50)

# Compute signaling pathway probability
cellchat<-computeCommunProbPathway(cellchat)

I would appreciate any help!

tkapello avatar May 15 '24 18:05 tkapello

@tkapello This issue is clear. You have to provide the pathway information for each L-R pair when running computeCommunProbPathway

sqjin avatar May 23 '24 08:05 sqjin

Thank you @sqjin for the reply. May I ask how you annotated the pathways when you were building the tool? It seems to me that you name each pathway by the ligand. Did you have any rules?

tkapello avatar May 24 '24 14:05 tkapello