SCA-IRCM / SingleCellSignalR

R package for Bioconductor submission
29 stars 12 forks source link

Error in cell_signalling and inter_network #21

Open pcr08 opened 1 year ago

pcr08 commented 1 year ago

I am a student in the last year of my master's in bioinformatics and I am using this tool for my thesis, but I am getting errors in the function "cell-signalling" and "inter_network" each time it can not find significant interactions from one of the sides. It always gives the same error, "Error in tmp[, 1] : incorrect number of dimensions", when trying to access that variable you created (tmp). I would like to know if this is possible to fix because I have been trying it, but as I am not the owner of the code, some of the details are out of bounds for me. Thank you, Best regards,

Paula Camargo Screenshot_1

SCA-IRCM commented 1 year ago

Hi,

Sorry for the delay. It seems that you only have one cell in one of your clusters, is it the case? SingleCellSignalR is ment to be used on scRNAseq data containing several (at least 2) cells per cluster.

Hope this helps.

Keep me posted anyway.

SCA

pcr08 commented 1 year ago

Hi, no, I do have 25000 cells for each cluster (columns of the matrix). What could it be then?

SCA-IRCM commented 1 year ago

Hi,

I think I have been able to reproduce your error. It seems to come from the visualize function. If you can share some of your script I could tell you what changes can be tested.

pcr08 commented 1 year ago

Sure, my script goes like this:

load packages

library(Seurat) library(SingleCellSignalR) require(Matrix) require(stringr)

load matrix

setwd('/proj/snic2022-22-1049/Paula/GBmap/ourdata') dataset1 <- read.table(file = "table_paula.txt", header = TRUE, row.names = NULL) rownames(dataset1) <- make.names(dataset1[,1], unique = T) dataset1[,1] <- NULL first_column <- colnames(dataset1) second_column <- rep(c("neoplastic"),each=length(colnames(dataset1))) metadata1 <- data.frame(first_column, second_column) colnames(metadata1) <- c('sample','cell_type') rownames(metadata1) <- make.names(metadata1[,1], unique = T) se_neo <- CreateSeuratObject(counts = dataset1, meta.data = metadata1) #create Seurat object for lab data (tumour) se_neo <- NormalizeData(se_neo, normalization.method = "LogNormalize" )

setwd('/proj/snic2022-22-1049/Paula/GBmap') data_newexp <- readRDS('data_newexp.rds') setwd('/proj/snic2022-22-1049/Paula/GBmap/ourdata') dataset2 <- data_newexp@meta.data[data_newexp@meta.data$cell_type == "microglial cell",] # healthy microglial cell types se_m <- subset(data_newexp, cells = row.names(dataset2))

QC for each dataset

our data -- neoplastic cells

nGenes <- se_neo$nFeature_RNA nMol <- se_neo$nCount_RNA sparse.exprMat <- GetAssayData(se_neo, slot = "counts") gene.counts_neo <- Matrix::rowSums(sparse.exprMat) set5 <- gene.counts_neo > 1000 keep.genes_neo <- rownames(se_neo)[set5] se_neo.subset <- subset(se_neo, features = keep.genes_neo)

GBmap data -- microglial cells

nGenes <- se_m$nFeature_RNA nMol <- se_m$nCount_RNA set1 <- se_m$nCount_RNA >= 5000 set4 <- se_m$nCount_RNA <= 30500 set2 <- se_m$nFeature_RNA >= 200 set3 <- se_m$nFeature_RNA <= 7000 keep.cells <- colnames(se_m)[(set1 & set2 & set3 & set4)] se_m.subset <- subset(se_m, cells = keep.cells) sparse.exprMat <- GetAssayData(se_m, slot = "data") gene.counts <- Matrix::rowSums(sparse.exprMat) set5 <- gene.counts > 1000 head(set5) keep.genes <- rownames(se_m)[set5] se_m.subset <- subset(se_m.subset, features = keep.genes)

combine datasets

se_combined.subset <- merge(se_m.subset, y = se_neo.subset, add.cell.ids = c("microglial_cell", "neoplastic"))

normalization

library(glmGamPoi) se_combined.subset <- SCTransform(object = se_combined.subset, vars.to.regress = "cell_type", method="glmGamPoi", conserve.memory = TRUE) #includes scaling and transformation in one step

variable feature identification

se_combined.subset <- FindVariableFeatures(se_combined.subset, selection.method = "vst", nfeatures = 2000, verbose = FALSE)

dimensionality reduction

se_combined.subset <- ScaleData(se_combined.subset, vars.to.regress = "cell_type") se_combined.subset <- RunPCA(se_combined.subset, features = VariableFeatures(object = se_combined.subset), verbose = FALSE)

translate Ensembl symbols to HUGO

library("EnsDb.Hsapiens.v86") mmatrix <- GetAssayData(object = se_combined.subset, assay= "SCT", slot = "data") #get the normalized UMI counts for both GBM and microglial cells m1 <- row.names(mmatrix[1:8997,]) #microglial, ENSEMBL m2 <- rownames(mmatrix[8998:24489,]) #lab, HUGO m1 <- mapIds(EnsDb.Hsapiens.v86,keys = m1, keytype = "GENEID",column = "SYMBOL", multiVals="first") which(is.na(rownames(m1))) m3 <- c(m1,m2) row.names(mmatrix) <- m3 which(is.na(rownames(mmatrix)))

singlecellsignalR

library(SCOPfunctions) data <- utils_big_as.matrix(mmatrix) clust <- se_combined.subset$cell_type clust[clust == "neoplastic"] = 1 #glioblastoma clust[clust == "microglial cell"] = 2 #microglial cell clust <- as.numeric(clust) clust.ana <- cluster_analysis(data = data, c.names = c("glioblastoma","microglial cells"), genes = rownames(data), cluster = clust) signal <- cell_signaling(data = data, c.names = c("glioblastoma","microglial cells"),s.score=0, genes = rownames(data), cluster = clust) library(igraph) inter.net <- inter_network(data = data, c.names = c("glioblastoma","microglial cells"), signal = signal, genes = rownames(data), cluster = clust) SingleCellSignalR::visualize_interactions(signal, write.out = TRUE)

As I commented before, the error should appear in both, cell_signaling() and inter_network().

SCA-IRCM commented 1 year ago

The error comes when you execute the _cellsignaling and the _internetwork functions only? It is a bit surprising because there isn't any variables called tmp that is called on the first column in these functions. What is the shape of signal?

pcr08 commented 1 year ago

Hi, I did run it again to get the shape of signal. It is 1 when there is only one side prediction (and I would guess it is 2 if there is both sides?). I did remove all the visualize() from the script and it did run ok. Is there any posibility to get the visualization? Thank you so much!