saezlab / liana

LIANA: a LIgand-receptor ANalysis frAmework
https://saezlab.github.io/liana/
GNU General Public License v3.0
169 stars 30 forks source link

Error in coercing to CsparseMatrix when running with SingleCellExperiment #31

Closed alejoaa closed 2 years ago

alejoaa commented 2 years ago

Hi, thanks for the Liana package!

I'm running into an error that I haven't been able to solve. When running liana_wrap with a SingleCellExperiment I get the following error:

Error in as(from, "CsparseMatrix"): no method or default for coercing "data.frame" to "CsparseMatrix"
Traceback:

1. liana_wrap(all.sce[[1]])
2. liana_prep(sce, idents_col = idents_col, assay = assay, verbose = verbose)
3. liana_prep.SingleCellExperiment(sce, idents_col = idents_col, 
 .     assay = assay, verbose = verbose)
4. .filter_sce(sce)
5. as(counts(sce), "sparseMatrix")
6. asMethod(object)
7. as(from, "CsparseMatrix")
8. stop(gettextf("no method or default for coercing %s to %s", dQuote(thisClass), 
 .     dQuote(Class)), domain = NA)

Do you know how I may be able to solve it? Thanks

dbdimitrov commented 2 years ago

Hi @alejoaa,

It seems that you have a data.frame in either your counts or logcounts slot. This should be a matrix. So it would be worth to double check this.

If this is not the case, you could share a subset of your object with me and I can check myself.

Best, Daniel

alejoaa commented 2 years ago

Hi @dbdimitrov,

Thanks, your solution worked. Seems that in all my analyses the SingleCellExperment stores counts and logcounts as data.frame. I had tried to directly coerce the data.frame to a sparse matrix and it didn't work. But running assay(sce, "counts") <- as.matrix(assay(sce, "counts")) fixed it.

Best, Alejandro