❝之前曾老师给我分享了一个sceasy包,这周有时间去看了一下,这个数据格式转换是怎么用的,用起来方便吗?尤其是scanpy和seurat之间的数据转换经常会比较麻烦,而这个包恰恰用一行代码即可搞定。 ❞
github包网址:https://github.com/cellgeni/sceasy
h5ad——seurat obejct 常规格式转换
代码语言:javascript复制remotes::install_github("mojaveazure/seurat-disk")
library(SeuratDisk)
Convert("filename.h5ad", dest="h5seurat",
assay = "RNA",
overwrite=F)
h5_object <- LoadH5Seurat("filename.h5seurat")
所需配置的环境
代码语言:javascript复制conda create -n sceasy
conda activate sceasy
conda install anndata==0.6.19 scipy==1.2.1 -c bioconda
conda install loompy -c bioconda
安装所需的R包
代码语言:javascript复制library(Seurat)
library(hdf5r)
devtools::install_github("cellgeni/sceasy")
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(c("LoomExperiment", "SingleCellExperiment"))
install.packages('reticulate')
reticulate:::find_conda()
library(sceasy)
library(reticulate)
use_condaenv('sceasy')
loompy <- reticulate::import('loompy')
不同格式单细胞数据转换
代码语言:javascript复制#导入数据
seurat_object=readRDS("sce.all_int.rds")
#Seurat to AnnData
sceasy::convertFormat(seurat_object, from="seurat", to="anndata",
outFile='filename.h5ad')
#Seurat to SingleCellExperiment
sceasy::convertFormat(seurat_object, from="seurat", to="sce",
outFile='filename.rds')
其他数据格式
可以用自己的数据来试一下。
代码语言:javascript复制#AnnData to Seurat
sceasy::convertFormat(h5ad_file, from="anndata", to="seurat",
outFile='filename.rds')
#SingleCellExperiment to AnnData
sceasy::convertFormat(sce_object, from="sce", to="anndata",
outFile='filename.h5ad')
#SingleCellExperiment to Loom
sceasy::convertFormat(sce_object, from="sce", to="loom",
outFile='filename.loom')
#Loom to AnnData
sceasy::convertFormat('filename.loom', from="loom", to="anndata",
outFile='filename.h5ad')
#Loom to SingleCellExperiment
sceasy::convertFormat('filename.loom', from="loom", to="sce",
outFile='filename.rds')
❝我一开始的时候忘了没有配置好环境,而直接安装sceasy,因此在use_condaenv('sceasy')这步就出现了报错,【Error: Unable to find conda binary. Is Anaconda installed?】 所以一定要配置好环境才能用!这个包还是挺方便实用的。 ❞