dviraran / SingleR

SingleR: Single-cell RNA-seq cell types Recognition (legacy version)
GNU General Public License v3.0
266 stars 98 forks source link

SingleR.Subset returns error #36

Closed RyanSchubert closed 5 years ago

RyanSchubert commented 5 years ago

Hi Dvir,

I had this working previously, but now when I run SingleR.Subset it thinks for a minute then I get:

Error in s$singler[[i]]$SingleR.single$labels[subsetdata, ] : incorrect number of dimensions

I've checked and I have the same number of cells in the SingleR and Seurat objects. Could this have to do with the way singleR stores list information for the labels?

Thanks for your attention!

Best,

Ryan

dviraran commented 5 years ago

What version of Seurat are you using?

RyanSchubert commented 5 years ago

Seurat_2.3.4

dviraran commented 5 years ago

I can't reproduce this. Can you try running the code line by line:

s = singler
s$seurat = SubsetData(s$seurat,colnames(s$seurat@data)[subsetdata])
subsetdata = unlist(lapply(s$seurat@cell.names,FUN=function(x) 
        which(singler$singler[[1]]$SingleR.single$cell.names==x)))
for (i in 1:length(s$singler)) {
    s$singler[[i]]$SingleR.single$labels = 
      as.matrix(s$singler[[i]]$SingleR.single$labels[subsetdata,])

    }
RyanSchubert commented 5 years ago

Hmm, same error Error in s$singler[[i]]$SingleR.single$labels[subsetdata, ] : incorrect number of dimensions

Could it be the number of cells we are analyzing? >100,000 cells?

dviraran commented 5 years ago

Ok. I have a guess, though not sure where is the mistake in the code. Your object was created using SingleR.Combine, right? I'm guessing that for some reason singler$singler[[i]]$SingleR.single$labels is not a matrix [n.cells X 1]. Try this:

 for (i in 1:length(singler$singler)) {
    singler$singler[[i]]$SingleR.single$labels = as.matrix(singler$singler[[i]]$SingleR.single$labels)
}

and run the SingleR.Subset function again. Does this solve the issue? (might fail in another place)

RyanSchubert commented 5 years ago

You got it! I ended up iterating this over all the rest of the labels matrices:

for (i in 1:length(singler$singler)) { singler$singler[[i]]$SingleR.single$labels = as.matrix(singler$singler[[i]]$SingleR.single$labels) }

for (i in 1:length(singler$singler)) { singler$singler[[i]]$SingleR.single$labels1 = as.matrix(singler$singler[[i]]$SingleR.single$labels1) }

for (i in 1:length(singler$singler)) { singler$singler[[i]]$SingleR.single.main$labels = as.matrix(singler$singler[[i]]$SingleR.single.main$labels) }

for (i in 1:length(singler$singler)) { singler$singler[[i]]$SingleR.single.main$labels1 = as.matrix(singler$singler[[i]]$SingleR.single.main$labels1) }

kupadhya2 commented 5 years ago

Hi Dvir,

While running SingleR.Subset, I am getting below error. I am using Seurat_3.

Error in is.data.frame(x) : no slot of name "data" for this object of class "Seurat".

Initially was getting same error as Ryan but resolved that with your previous comments.

Thanks, Kinnari

dviraran commented 5 years ago

Yes, sorry. I need to make some adjustments to that function to work with Seurat 3. The problem is that I didn't upgrade Seurat yet on my computer, so its a bit hard to test...

kupadhya2 commented 5 years ago

I will try to work around by using your SingleR.Subset function.

dviraran commented 5 years ago

Until I make the change, don't send the function the seurat object (singler$seurat = NULL) and subset it independently.

kupadhya2 commented 5 years ago

Yup sure. Thanks for quick response. It's great tool