dgrun / StemID

Algorithm for the inference of cell types and lineage trees from single-cell RNA-seq data.
39 stars 19 forks source link

Error when Seurat object is used for StemID score evaluation #4

Closed raveancic closed 4 years ago

raveancic commented 4 years ago

Dear all,

I am trying to run StemID on my Seurat object on which I have done both the QC needed and the clustering analysis. I am following both the answer here and the tutorial here.

Unfortunately I meet the following error when I perform the comppvalue step.

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
  'data' must be of a vector type, was 'NULL'

Here is all the code I am running:


# Create the sc object
seurat_integrated <- readRDS("file.rds")

ndata <- seurat_integrated@assays$RNA@counts[,]

sc <- SCseq(ndata)

# Filter for this
sc <- filterdata(sc, mintotal = 2000)

# Re-initialize raceID
part <- as.numeric(seurat_integrated@meta.data$seurat_clusters)
d <- as.matrix(dist(seurat_integrated@reductions$pca@cell.embeddings))
umap <- as.data.frame(seurat_integrated@reductions$UMAP@cell.embeddings)
names(part) <- colnames(d)

n <- colnames(sc@ndata)
part <- part[n]

# partition
sc@cpart <- sc@cluster$kpart <- part
# distances
sc@distances <- d[n,n]
# umap
sc@umap <- umap[n,]
# expression data (optional)
sc@counts <- sc@counts * 0 + 1
sc@ndata  <- ndata[,n]
# cluster medoids
sc@medoids <- compmedoids(sc, sc@cpart)

col_cluster <- colorRampPalette(brewer.pal(12,"Set3"))(length(unique(seurat_integrated@meta.data$seurat_clusters)))
names(col_cluster) <- as.character(unique(seurat_integrated@meta.data$seurat_clusters))

set.seed(12345)
sc@fcol <- col_cluster[order(as.numeric(names(col_cluster)))]

# Run StemID

ltr <- Ltree(sc)

ltr <- compentropy(ltr)
ltr <- projcells(ltr,cthr=5,nmode=TRUE,fr=TRUE, um=T, knn=3)

ltr <- lineagegraph(ltr)

ltr <- comppvalue(ltr,pthr=0.05)
# Here I get the error

plotgraph(ltr,showCells=FALSE,showMap=TRUE)

x <- compscore(ltr)

Can anyone help me on this? I really thank you in advance for this, Have a great day, Alessandro

dgrun commented 4 years ago

Never had this error. Could you provide sample data to reproduce it?

raveancic commented 4 years ago

Hello,

thank you for answering me and sorry for my late reply, I pointed out the wrong error, that was the one of the compscore step, instead I get this one with comppvalue using the "StemID: nearest-neighbour mode."

Error in binom.test(x[1], N, min(1, x[2]), alternative = "g") : 
  'n' must be a positive integer >= 'x'

I get this with any Seurat file I am using on the pipeline above, you can download from herethe original Seurat example file I used; perhaps there is something wrong on the step I am doing. I really thank you in advance for helping me on this, I would like to get thru this since it is fundamental to me infer the cluster with most staminality in order to start the Slingshot analysis downstream.
The package version of RaceID used is the 0.1.8.

Have a great day, Alessandro

dgrun commented 4 years ago

Ok, I found the error.

Please replace

ltr <- projcells(ltr,cthr=5,nmode=TRUE,fr=TRUE, um=T, knn=3)

by

ltr <- projcells(ltr,cthr=5,nmode=TRUE, um=TRUE, knn=3)

in your code.

Don't use the fr=TRUE parameter, since you haven't calculated a Fruchterman-Rheingold force-directed layout, and you would also like to use the UMAP for the layout.

I tested the code and with this change it works for me.

raveancic commented 4 years ago

Thank you Dominic, I just followed the vignette and under the "StemID: nearest-neighbour mode" section there was the fr parameter as T, so I thought it was necessary for this.

I will re-run everything without it, with the example it works. Have a nice day!