bnprks / BPCells

Scaling Single Cell Analysis to Millions of Cells
https://bnprks.github.io/BPCells
Other
166 stars 17 forks source link

dotplot error #38

Closed jessicaliu70 closed 3 weeks ago

jessicaliu70 commented 1 year ago

can BPCells work with dotplot? I have the following error: dotplot<-DotPlot(object = obj, features = canonical_markers, group.by='seurat_clusters',cols = "Spectral") + theme(axis.text.x = element_text(angle = 45, size = 8), legend.text = element_text(size = 8), legend.title = element_text(size = 8))

Error in .rowNamesDF<-(x, value = value) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names':

bnprks commented 1 year ago

Hi @jessicaliu70, Thanks for the question and sorry for the small delay getting back to you. It's hard to tell whether this specific question is an issue with BPCells or with how Seurat uses BPCells, so I'm hoping you can provide a bit more detail.

I'm able to run DotPlot on an demo project that contains a BPCells matrix just fine, e.g. with this code:

library(BPCells)
library(Seurat)
options(Seurat.object.assay.version = "v5")

pbmc3k_mat <- pbmc3k.SeuratData::pbmc3k@assays$RNA@counts
bpcells_mat <- as(pbmc3k_mat, "IterableMatrix")

proj <- CreateSeuratObject(bpcells_mat)
proj <- AddMetaData(proj, pbmc3k.SeuratData::pbmc3k.final@meta.data$seurat_annotations, "clusts")

DotPlot(proj, features = c("NKG7", "CD3E"), group.by = "clusts" )

Is there some way you might be able to provide a runnable example that reproduces your issue? Ideally you could reproduce it on one of the example datasets from the SeuratData package as I've done in my example above.

If this is not possible, you might try identifying a small subset of your data that can still reproduce the issue (email is OK if you can't post publicly, bparks [at] stanford.edu). I'd recommend using BPCells::write_matrix_memory() to save the data as an in-memory BPCells object, then save the whole Seurat object as an RDS file. It's fine if the data is randomized or subset down to a few dozen cells, just as long as you can provide code that still hits this issue.

jessicaliu70 commented 1 year ago

Hi, Thank you for reply. It worked after I convert the on-disk object to in-memory object.

Then my question is that you can't directly plot dot plot using the on-disk object? Since when I try to call dot plot, it always do: test<-DotPlot(obj, features = c("SNAP25-AS1", "CD3E"), group.by = "cell.type" )

Loading required package: BPCells Warning: Converting to a dense matrix may use excessive memory This message is displayed once every 8 hours.

So if I have a very large object, in-memory object is too big (out of memory), then I can't visualize the dot plot?

bnprks commented 1 year ago

Hi Jessica,

As far as my testing goes, it works fine for me to directly run DotPlot with the on-disk object (see the example code I gave above, slightly updated to add a library(BPCells) call). And despite the warning, in this case there shouldn't be performance worries when running dot plots with on-disk objects even for very large datasets.

I know you're running into errors, but if you don't provide a runnable example for me allows me to also experience the bug I can't help much. What I would need to be able to help is:

immanuelazn commented 3 weeks ago

Closing due to inactivity