brief
sceasy is a package that helps easy conversion of different single-cell data formats to each other.
我的主要工作环境是R,现在想将rds文件转换为h5ad文件,h5ad文件作为cellxgene tools的输入。
github地址:https://github.com/cellgeni/sceasy
安装
conda install anndata -c bioconda
# 进入R环境
BiocManager::install("devtools")
devtools::install_github("cellgeni/sceasy")
# 依赖包,感觉不需要装
BiocManager::install(c("LoomExperiment", "SingleCellExperiment"))
install.packages('reticulate')
实例
library(sceasy)
library(reticulate)
use_condaenv('R4') # use_condaenv('EnvironmentName') ,
# 注意我用conda为R做了隔离环境,rbase以及依赖包都在名为R4的conda env下,包括python
# use_condaenv('R4') 就是为了告诉 eticulate 桥接的python为 R4 env 下的python,而不是/usr/bin下的python或者其他地方的python
library(Seurat)
sce <- readRDS("/public/home/djs/huiyu/project/HY0007/PM-XS01KF2023090059/Seurat_object/planB_annotation_combind.rds")
# 因为我的Seurat版本是V5,和当前的sceasy不兼容,需要其他口令
# 报错如下:
# no slot of name "meta.features" for this object of class "Assay"
# 解决如下
sce[["RNA"]] <- as(sce[["RNA"]],"Assay")
# 然后将rds文件转为 h5ad文件
sceasy::convertFormat(sce, from="seurat", to="anndata",outFile='test.h5ad')
# h5ad文件已经写入当前工作目录了!
# h5ad文件转为rds文件
sceasy::convertFormat(h5ad_file, from="anndata", to="seurat",
outFile='filename.rds')