sqjin / CellChat

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

cellchat <- computeCommunProb(cellchat) Error in data.use[RsubunitsV, ] : subscript out of bounds bulkRNAseq #303

Open gouxiaojuan opened 2 years ago

gouxiaojuan commented 2 years ago

Thank you very much for providing cellchat. Below are my codes and files. Could you please help me find out where the problem is? I have been checking for several days and browsing all the comments about bulkRNAseq in the question and have not been able to find out what the problem is, I would appreciate your reply

library(CellChat) library(patchwork) options(stringsAsFactors = FALSE) sam_a1 = read.table(paste0('E:/RNAseq/RNAseq_lyy/VPN/count/v350027260_L01_47_clean.count.txt')) sam_b1 = read.table(paste0('E:/RNAseq/RNAseq_lyy/results/E100018798_L01_12_clean.count.txt')) mat = matrix(nrow = 55471,ncol = 2) mat[,1] = sam_a1[1:55471,2] mat[,2] = sam_b1[1:55471,2] rownames(mat)= sam_a1[1:55471,1] colnames(mat)=c('PU1','PU4') database <- mat[,1:2]

type <- factor(c(rep("LC_1",3), rep("LC_2",3)))

database <- round(as.matrix(database)) database <- as.data.frame(database) database$ENSEMBL <- row.names(database) library("clusterProfiler") library(org.Mm.eg.db) gene <- rownames(database) gene.df <- bitr(gene, fromType = "ENSEMBL", #fromType是指你的数据ID类型是属于哪一类的 toType = c( "SYMBOL"), #toType是指你要转换成哪种ID类型,可以写多种,也可以只写一种 OrgDb = org.Mm.eg.db) a <- merge(gene.df,database,by='ENSEMBL') a <- a[,-1] a <- a[!duplicated(a$SYMBOL), ] rownames(a) <- a$SYMBOL a <- a[,-1]

a <- a[which(rowSums(a) > 0),]#去掉两行都为零的值

a <- as(as.matrix(a), "dgCMatrix")

b <- a[1:500,]

b <-as(as.matrix(b), "dgCMatrix")

test<- data.frame(x = c('PU1','PU4'), c('pg1','ag1'),c('pg','ag')) rownames(test) <- test$x test <- test[,-1] colnames(test) <- c('condition','labels')

data.input <- b

data.input <- a data.input=normalizeData(data.input) meta <- test cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels") cellchat <- addMeta(cellchat, meta = meta) cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity levels(cellchat@idents) # show factor levels of the cell labels groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group

CellChatDB <- CellChatDB.mouse # use CellChatDB.mouse if running on mouse data showDatabaseCategory(CellChatDB)

Show the structure of the database

dplyr::glimpse(CellChatDB$interaction)

> Rows: 1,939

> Columns: 11

> $ interaction_name "TGFB1_TGFBR1_TGFBR2", "TGFB2_TGFBR1_TGFBR2", "TGF…

> $ pathway_name "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "T…

> $ ligand "TGFB1", "TGFB2", "TGFB3", "TGFB1", "TGFB1", "TGFB…

> $ receptor "TGFbR1_R2", "TGFbR1_R2", "TGFbR1_R2", "ACVR1B_TGF…

> $ agonist "TGFb agonist", "TGFb agonist", "TGFb agonist", "T…

> $ antagonist "TGFb antagonist", "TGFb antagonist", "TGFb antago…

> $ co_A_receptor "", "", "", "", "", "", "", "", "", "", "", "", ""…

> $ co_I_receptor "TGFb inhibition receptor", "TGFb inhibition recep…

> $ evidence "KEGG: hsa04350", "KEGG: hsa04350", "KEGG: hsa0435…

> $ annotation "Secreted Signaling", "Secreted Signaling", "Secre…

> $ interaction_name_2 "TGFB1 - (TGFBR1+TGFBR2)", "TGFB2 - (TGFBR1+TGFBR2…

use a subset of CellChatDB for cell-cell communication analysis

CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling

use all CellChatDB for cell-cell communication analysis

CellChatDB.use <- CellChatDB # simply use the default CellChatDB

set the used database in the object

cellchat@DB <- CellChatDB.use

subset the expression data of signaling genes for saving computation cost

cellchat <- subsetData(cellchat)

cellchat <- subsetData(cellchat, features = CellChatDB.mouse$geneInfo$Symbol) # 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) E100018798_L01_12_clean.count.txt

gouxiaojuan commented 2 years ago

E100018798_L01_12_clean.count.txt

gouxiaojuan commented 2 years ago

I'll give you cellchat as well gxj.rds.txt

sofiapuvogelvittini commented 1 year ago

Hi gouxiaojuan, Did you solved this issue? I am faceing the same.