dviraran / SingleR

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

Error with 'replacement has 1378 rows, data has 1345' #16

Open biansr opened 5 years ago

biansr commented 5 years ago

Hello, I've been recently tried to use singleR but it failed after the step creating a singleR object. My seurat object contains 14793 genes and 1378 cells. I use:

singler = CreateSinglerObject(syno@data, annot = NULL, syno, min.genes = 500, technology = "10X", species = "Human", citation = "", ref.list = list(), normalize.gene.length = F, variable.genes = "de", fine.tune = T, do.signatures = F, clusters = NULL, do.main.types = T, reduce.file.size = T, numCores = SingleR.numCores) singler$seurat <- syno singler$meta.data$xy <- ra.control@dr$tsne@cell.embeddings singler$meta.data$clusters <- ra.control@ident

to create the singleR object, and:

SingleR.DrawHeatmap(singler$singler[[1]]$SingleR.single.main,top.n=Inf, clusters = singler$meta.data$clusters) out = SingleR.PlotTsne(singler$singler[[1]]$SingleR.single.main, singler$meta.data$xy,do.label=FALSE, do.letters =T,labels=singler$singler[[1]]$SingleR.single.main$labels, dot.size = 2, font.size = 12) out$p

for analysis. However, it returns with an error saying 'replacement has 1378 rows, data has 1345'. Do you know what might cause the data read 33 less rows? Thank you very much.

Best, Shurui.

dviraran commented 5 years ago

Hi, Its probably because of using a different threshold for min.genes. When using an already available Seurat object you don't want any filtering of the genes. Just use mig.genes = 0.

I'll change it in the example as well.

Best, Dvir

biansr commented 5 years ago

Hi, Its probably because of using a different threshold for min.genes. When using an already available Seurat object you don't want any filtering of the genes. Just use mig.genes = 0.

I'll change it in the example as well.

Best, Dvir

Thank you very much! It solves the issue. Now I have another issue. When I tried:

out = SingleR.PlotTsne(singler$singler[[1]]$SingleR.single.main, singler$meta.data$xy,do.label=FALSE, do.letters =T,labels=singler$singler[[1]]$SingleR.single.main$labels, dot.size = 2, font.size = 12) out$p

to plot tSNE plot, it returns an error of 'Error in FUN(X[[i]], ...) : object 'x' not found'. Do you have any idea why that would happen?

dviraran commented 5 years ago

Great.

Its hard to guess... looking back at your code singler$meta.data$xy seems to be taken from a different object than the seurat object. Is it set properly?

Can you print out the traceback() output?

biansr commented 5 years ago

What do you mean by saying "taken from a different object than the seurat object"? Actually I'm a bit confused too, because singler$meta.data seems to only have two components: project.name, and orig.ident. singler$meta.data$xy returns NULL. Maybe that's something that I need to change from the sample code? However both using project.name and orig.ident return errors.

traceback()

11: FUN(X[[i]], ...) 10: lapply(aesthetics[new_aesthetics], rlang::eval_tidy, data = data) 9: scales_add_defaults(plot$scales, data, aesthetics, plot$plot_env) 8: f(..., self = self) 7: l$compute_aesthetics(d, plot) 6: f(l = layers[[i]], d = data[[i]]) 5: by_layer(function(l, d) l$compute_aesthetics(d, plot)) 4: ggplot_build.ggplot(x) 3: ggplot_build(x) 2: print.ggplot(x) 1: function (x, ...) UseMethod("print")(x)

dviraran commented 5 years ago

I guessed right... :)

You have the seurat object called syno, but to copy those you are a different object (ra.control).

singler$meta.data$xy <- ra.control@dr$tsne@cell.embeddings singler$meta.data$clusters <- ra.control@ident

those lines just copy the tSNE coordinates and the cluster identities from Seurat. You need to figure out that you are doing it correctly...

biansr commented 5 years ago

I guessed right... :)

You have the seurat object called syno, but to copy those you are a different object (ra.control).

singler$meta.data$xy <- ra.control@dr$tsne@cell.embeddings singler$meta.data$clusters <- ra.control@ident

those lines just copy the tSNE coordinates and the cluster identities from Seurat. You need to figure out that you are doing it correctly...

What a terrible mistake I've made. Thank you very much!