Error with DefaultAssay in R when Integrating Data Using scvi-tools


I am encountering an issue while trying to integrate data using scvi-tools in R. Here is the code I am using:


latent <- as.matrix(latent)
rownames(latent) = colnames(adata)
adata[["scvi"]] <- CreateDimReducObject(embeddings = latent, key = "scvi_", assay = DefaultAssay(adata))

However, this results in the following error:
Error in UseMethod(generic = “DefaultAssay”, object = object): no applicable method for ‘DefaultAssay’ applied to an object of class “c(‘anndata._core.anndata.AnnData’, ‘python.builtin.object’)”

  1. CreateDimReducObject(embeddings = latent, key = “scvi_”, assay = DefaultAssay(adata))
  2. DefaultAssay(adata)

t seems that the DefaultAssay function is not recognizing the adata object as expected. I have confirmed that adata is an AnnData object.

r-seurat 4.4.0
scvi-tools 1.1.2

Could you please help me understand what might be causing this error and how to resolve it?

Thank you!

I’m not really an expert for Seurat. However, from the error latent contains an AnnData object and not a matrix. Can you provide the data type of latent?

Thank you very much for your reply, and I apologize for the delay in getting back to you. You were correct, I checked the format of latent and adata, and the issue was indeed there. The error has been resolved, thank you so much.

However, I have encountered a new problem. When running

ifnb <- RunUMAP(ifnb, dims = 1:10, reduction = "scvi", n.components = 2),

I get the error Error in irlba::irlba(L, nv = n, nu = 0, maxit = iters): function 'sexp_as_cholmod_sparse' not provided by package 'Matrix'.
My Matrix version is [1] ‘’. Do you know which version of Matrix provides sexp_as_cholmod_sparse?
Thank you again for your reply!

This is more a question to the Seurat (or matrix) developers and I wouldn’t expect a response her, unfortunately.

ok, I’ll try to solve it focusing on Seurat and Matrix, thanks a lot!