dviraran / SingleR

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

Still a rownames issue in convertSingleR2Browser #34

Open hfberg opened 5 years ago

hfberg commented 5 years ago

Hi! I'm still trying to combine my different data sets in SingleR.Combine. That part works now, but convertSingleR2Browser is complaining. I updated SingleR since I saw someone post a similar issue here a couple of days ago, but I still got the same error message.

> list_samples<- list(singler_ctrl, singler_stim)
> list_xy <- list(singler_ctrl[["seurat"]]@dr[["tsne"]]@cell.embeddings,singler_stim[["seurat"]]@dr[["tsne"]]@cell.embeddings)
> 
> singler=SingleR.Combine(list_samples)
> saveRDS(singler, file=paste0(ctrl_samp.name,"_singlertemp.rds"))
> singler_ctrl.stim.new = convertSingleR2Browser(singler, use.singler.cluster.annot = F)
Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  invalid 'row.names' length
> #saveRDS(singler_ctrl.stim.new, 'ctrl_stim.rds')
> traceback()
5: stop("invalid 'row.names' length")
4: `row.names<-.data.frame`(`*tmp*`, value = value)
3: `row.names<-`(`*tmp*`, value = value)
2: `rownames<-`(`*tmp*`, value = cell.names)
1: convertSingleR2Browser(singler, use.singler.cluster.annot = F)

I noticed that in my SingleR.Combine object (called singler) some parts does not seem to have been combined properly.(?) For example in the screenshot below there is always 1464 cells, except for in pval where it's 708 values (the same number of cells as in singler_ctrl). "cell names" in SingleR.single.main also has a dodgy number, and so on. In the original singler_ctrl and singler_stim lists, these numbers are the same throughout the list. (708 and 756).

screenshot from 2019-02-19 16-32-17

The full code I use if you need to look at it: SingleR.pdf

dviraran commented 5 years ago

Yeah, seems like SingleR.Combine isn't combining properly with all the different types of usage that I didn't expect... My best suggestion now is to dig into the code of that function to find the inconsistencies.

dviraran commented 5 years ago

Try the following - create a new R file with the code of the function convertSingleR2Browser, and source this file. Now, rerun the procedure. This will allow identifying the exact line where this is failing.

Pval and cell.names are not used in the convertSingleR2Browser, so it is not the reason. I just fixed these issues, but pretty sure there is another issue that is still hidden from us.

hfberg commented 5 years ago

Yes, I know I'm not supposed to use the program this way, but SingleR is VERY useful to us in it's ability to identify the cells. (We have a problem clustering because of very heterogeneous data). Anyway, I found out a way to work around the problem with convertSingleR2Browser, and now I can analyze ctrl and stim samples parallel in your browser. :):) I will have a look at your suggestion and update here, but this works fine for now! :)

drtrix90 commented 5 years ago

What was your work around in covertSingleR2Browser? I'm getting the same rownames error without using SingleR.Combine. It seems to work fine when I use CreateSinglerSeuratObject but it throws me that error when I try to use CreateSinglerObject and pass it clusters from a Seurat object. I haven't figured out a different way to get the clustering I want...

dviraran commented 5 years ago

Yeah, the problem is that SingleR.Combine doesn't rerun the analysis for clusters.

For now just do something like this:

singler$singler[[1]]$SingleR.clusters = NULL
singler$singler[[1]]$SingleR.clusters.main = NULL
singler$singler[[2]]$SingleR.clusters = NULL
singler$singler[[2]]$SingleR.clusters.main = NULL
hfberg commented 5 years ago

Well drtrix90, I had kind of a different problem where I didn't care about the clusters (my data is too heterogenous to create clusters, that's why SingleR is such a good tool for me). Instead I wanted to compare two different samples in SingleRs differential expression function. Try Dvirs solutions, he knows this code waay better, and my solution is a bit tedious, I'm still new, but basically this is what I did:

Guess you can do the same if you only need the cluster annotations for DE. Create an annotations file with UMI and cluster, extract the DGE from your Seurat object and pass it back in to CreateSinglerSeuratObject with the cluster annotations.

Tell me if u need the code and I'll send it to you. Good luck!