keep getting error while trying to convert Seurat object into a H5ad file
2
0
Entering edit mode
12 months ago
Sara ▴ 260

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?

scRNA-seq Seurat • 3.3k views
ADD COMMENT
2
Entering edit mode
12 months ago
bk11 ★ 3.0k

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')
ADD COMMENT
2
Entering edit mode
12 months ago
Ram 44k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2593 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6