I am trying to convert rds file (or Seurat object) to h5ad files using the following command in R:
library(scater)
library(Seurat)
library(cowplot)
pbmc_ad <- Convert(from = pbmc, to = "anndata", filename = "results/pbmc3k.h5ad")
in which pbmc is a Seurat object. but keep getting the following error:
Error in Convert(from = pbmc, to = "anndata", filename = "results/pbmc3k.h5ad") :
could not find function "Convert"
I made sure that all the libraries are installed completely. do you know what the problem could be?
2 answers
You need to do following-
library(Seurat)
library(SeuratData)
library(SeuratDisk)
SaveH5Seurat(pbmc_ad, filename = "pbmc_ad.h5Seurat")
Convert("pbmc_ad.h5Seurat", dest = "h5ad")
OR, alternatively you can use sceasy package for this-
library(sceasy)
sceasy::convertFormat(pbmc_ad, from="seurat", to="anndata",
outFile='pbmc_ad.h5ad')
You're one step away from solving this problem yourself - that's awesome. Here's the step and piece of info that would have helped you solve it yourself:
Knowledge: Your error says that the function "Convert" could not be found, but you show us that you've loaded Seurat without problems. So obviously, Convert is not part of Seurat. From what I know of Seurat, there are a few additional Seurat supporter packages out there, so this could be from one of them.
Step I took: I googled "Seurat convert" and this was the first page that popped up: https://mojaveazure.github.io/seurat-disk/articles/convert-anndata.html. It looks like there are 2 libraries loaded over there that you probably have not loaded: SeuratData and SeuratDisk. You could try loading them both and checking again, or you could go one step further: check their manuals to find which one has this function. I went with SeuratDisk first and found this: https://mojaveazure.github.io/seurat-disk/reference/index.html
It looks like SeuratDisk is the package you need to load to fix this error.
Log in to answer this question.