sqjin / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell data
GNU General Public License v3.0
623 stars 142 forks source link

Subscript out of bounds error #19

Closed LooLipin closed 4 years ago

LooLipin commented 4 years ago

Hi there, thanks for making this great tool. It's quite easy to use and I can see it getting adopted widely in the field.

I have managed to run my individual seurat objects without any issues.

When I switched to comparing 2 datasets, WT vs mutant, I managed to create individual cellchat objects and merged them together. However, I ran into an error at the next computeNetSimilarity step (following this https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/vignettes/Joint_analysis_of_multiple_datasets.html).

WT <- readRDS("WT.rds")
DefaultAssay(WT)<-"RNA"
WT<-NormalizeData(WT)
WT<-ScaleData(WT)

data.input <- GetAssayData(WT, assay = "RNA", slot = "data") # normalized data matrix
labels <- Idents(WT)
identity <- data.frame(group = labels, row.names = names(labels))
unique(identity$group)

WT <- createCellChat(data = data.input)
WT <- addMeta(WT, meta = identity, meta.name = "labels")
WT <- setIdent(WT, ident.use = "labels") # set "labels" as default cell identity
levels(WT@idents) # show factor levels of the cell labels
groupSize <- as.numeric(table(WT@idents))

mutant <- readRDS("mutant.rds")
DefaultAssay(mutant)<-"RNA"
mutant<-NormalizeData(mutant)
mutant<-ScaleData(mutant)

data.input <- GetAssayData(mutant, assay = "RNA", slot = "data") # normalized data matrix
labels <- Idents(mutant)
identity <- data.frame(group = labels, row.names = names(labels))
unique(identity$group)

mutant <- createCellChat(data = data.input)
mutant <- addMeta(mutant, meta = identity, meta.name = "labels")
mutant <- setIdent(mutant, ident.use = "labels") # set "labels" as default cell identity
levels(mutant@idents) # show factor levels of the cell labels

cellchat <- mergeCellChat(list(WT, mutant), add.names = c("WT","mutant"))
cellchat <- computeNetSimilarityPairwise(cellchat, type = "structural")
Error in net[[i]] : subscript out of bounds

Please advise.

Thanks, Lipin

LooLipin commented 4 years ago

Sorry I noticed the slot was empty for NetP so I proceeded to preprocess the data and got a different subscript out of bounds error instead

cellchat <- identifyOverExpressedGenes(cellchat)
Error in data.use[, cell.use2, drop = FALSE] : subscript out of bounds

Should I run my objects separately before merging to computeNetSimilarityPairwise?

sqjin commented 4 years ago

Hi @LooLipin , yes, you need to run the objects separately before merging the two objects.