单细胞格式转换哪家强?2025最全盘点来了

· 5 min read · Analysis Notes

单细胞格式转换哪家强?2025最全盘点来了

单细胞格式转换哪家强?2025最全盘点来了

随着单细胞技术的爆发式发展,R和Python两大生态系统各自繁荣,但数据格式的互通性成了横亘在研究者面前的一座大山。在数据结构日新月异、测序技术五花八门的2025年,格式转换,特别是Seurat对象和Anndata/Mudata对象之间的转换变得更加复杂。但好消息是,我们有了更多成熟的解决方案。今天带大家盘点几个稳定、维护完善、社区比较活跃的包(以R包为主),希望对大家的分析有所帮助。

1. anndataR

是由scverse团队开发的包,目标使得在R中也可以自由操作Anndata,不需要额外的转译层。当然,也支持Anndata向Seurat对象或者SingleCellExperiment的转换。

优势: 原生R实现,无需Python环境;支持自定义slot映射

source: anndataR documentationsource: anndataR documentation

安装

if (!requireNamespace("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}
BiocManager::install("anndataR")

Seurat ➡️ Anndata

library(anndataR)
# 一步到位:
write_h5ad(seurat_obj, tempfile(fileext = ".h5ad"))

# 分两步:
adata <- as_AnnData(seurat_obj)
adata$write_h5ad(tempfile(fileext = ".h5ad"))

Anndata ➡️ Seurat

# 一步到位:
seurat_obj <- read_h5ad(h5ad_file, as = "Seurat")

# 分两步:
adata <- read_h5ad(h5ad_file)
seurat_obj <- adata$as_Seurat()

参考资料

  1. Github:https://github.com/scverse/anndataR
  2. 官方文档:https://anndatar.data-intuitive.com/

2. zellkonverter

生信大牛组Theis Lab(也是Single-cell Best Practices书的作者)开发的转换包。同属scverse系列,以后大概率会被anndataR代替,但是就目前来讲zellkonverter还在活跃维护。该包通过R内部的Python环境转译,实现Anndata和SingleCellExperiment的互相转换。

优势: 内存效率高,支持DelayedArray后端

安装

if (!requireNamespace("BiocManager", quietly=TRUE)) {
    install.packages("BiocManager")
}
BiocManager::install("zellkonverter")

Anndata ➡️ SCE

library(zellkonverter)
sce <- readH5AD(example_h5ad)

# or
sce <- AnnData2SCE(adata)

SCE ➡️ Anndata

out_path <- tempfile(pattern = ".h5ad")
writeH5AD(sce, file = out_path)

# or
adata <- SCE2AnnData(sce)

关于下一步的SingleCellExperiment和Seurat的转换,可以依靠Seurat自带的as.SingleCellExperiment() 和as.Seurat()。

参考资料

  1. 官方文档:https://theislab.github.io/zellkonverter/index.html
  2. GitHub: https://github.com/theislab/zellkonverter/

3. schard

Sanger Institute cellgeni团队开发的无Python依赖转换工具,使用rhdf5直接读写h5ad文件。(但目前似乎不支持将Seurat对象写入h5ad)

优势: 依赖包少,不依赖Python环境,支持空间转录组(Visium)转换

安装

remotes::install_github("cellgeni/schard")

h5ad ➡️ Seurat

library(schard)
# 直接读取h5ad为Seurat
seurat <- schard::h5ad2seurat('input.h5ad')

# 支持空间数据(自动识别Visium数据)
seurat_spatial <- schard::h5ad2seurat_spatial('visium.h5ad')
# 可以按slide分别读取
visum_list <- schard::h5ad2seurat_spatial('visium.h5ad', simplify = FALSE)

# 读取raw counts(从adata.raw.X)
seurat_raw <- schard::h5ad2seurat('input.h5ad', use.raw = TRUE)

h5ad ➡️ SingleCellExperiment

# 也支持转为SCE
sce <- schard::h5ad2sce('input.h5ad')

直接读取h5ad中的特定数据

# 查看h5ad文件结构
ls <- rhdf5::h5ls('input.h5ad')

# 读取特定的obsm(如UMAP坐标)
umap <- t(schard::h5ad2Matrix('input.h5ad', '/obsm/X_umap'))

# 读取metadata
obs <- schard::h5ad2df('input.h5ad', '/obs')

参考资料

  1. GitHub:https://github.com/cellgeni/schard

4. easySCF

由Zhang et al.  于2024年11月发表在Bioinformatics的工具,专门解决R和Python之间单细胞数据交换效率问题。该包使用统一的HDF5格式作为中间层,支持Seurat v5的所有新特性。

优势: 速度极快,内存占用低;完美支持Seurat v5;支持大规模数据集(>100万细胞自动启用BPCells);支持Visium HD空间数据

安装

# 从GitHub安装(注意:需要指定r子目录)
install.packages("devtools")
devtools::install_github("xleizi/easySCF/r")

# Python端
pip install easySCFpy

R端使用

library(easySCFr)
# 保存Seurat对象为h5格式
saveH5(seurat_obj,
       FileName = "data.h5",
       assay = "RNA",
       SeuratVersion = 5,  # 支持v5
       split_save = TRUE,  # 大数据集分块保存
       max_cells_per_subset = 5000)

# 读取h5格式
seurat_obj <- loadH5(FileName = "data.h5",
                     assay = "RNA",
                     useBPcells = FALSE,  # >100万细胞时自动启用
                     readType = "Seurat")

Python 端使用

from easySCFpy import saveH5, loadH5
# 读取h5文件为scanpy对象
adata = loadH5("data.h5", datatype="scanpy")
# 保存为h5格式
saveH5(adata, "output.h5",
       split_save=True,
       compression="gzip")

参考资料

  1. 论文:Zhang H, et al. easySCF: a tool for enhancing interoperability between R and Python for efficient single-cell data analysis. Bioinformatics 2024;40(12):btae710
  2. GitHub:https://github.com/xleizi/easySCF

5. MuDataSeurat

专为多模态数据设计的转换包,是MuData(多模态AnnData)生态系统的R接口。如果你的数据包含CITE-seq、ATAC-seq、空间转录组等多个模态,这是最佳选择。

优势: 原生多模态支持;保留模态间关系;与muon (Python)完美对接

安装

remotes::install_github("PMBio/MuDataSeurat")

Seurat (多模态) ➡️ MuData

library(MuDataSeurat)
# 支持多个assay的Seurat对象
# 例如包含RNA和ADT的CITE-seq数据
WriteH5MU(seurat_multi, "multimodal.h5mu")

MuData ➡️ Seurat

# 读取h5mu文件,自动创建多assay的Seurat对象
seurat_multi <- ReadH5MU("multimodal.h5mu")
# 各模态自动分配到不同assay
names(seurat_multi@assays)  # 例如: "RNA", "ADT", "ATAC"

参考资料

  1. GitHub:https://github.com/PMBio/MuDataSeurat

6. convert2anndata

由Setty Lab开发,提供了最完整的转换功能,特别擅长保留复杂的metadata和alternative experiments。支持命令行和R内两种使用方式。

优势: 信息保留最完整;支持alternative experiments;递归转换嵌套结构;CLI工具方便批处理

安装

# 需要先安装依赖
BiocManager::install(c("SingleCellExperiment",
                       "SummarizedExperiment",
                       "S4Vectors"))
# 安装主包
remotes::install_github("settylab/convert2anndata")

命令行

# 设置别名后
c2a -i seurat_v5.rds -o converted.h5ad
# 带参数
c2a -i input.rds -o output.h5ad -a counts --disable-recursive-altExp

R

library(convert2anndata)
# 先转为SCE(如果是Seurat)
sce <- convert_seurat_to_sce(seurat_obj)
# 再转为AnnData
ad <- convert_to_anndata(sce,
                         assayName = "counts",
                         useAltExp = TRUE)  # 保留altExp
write_h5ad(ad, "output.h5ad")

参考资料

  1. GitHub:https://github.com/settylab/convert2anndata

7. srtdisk

原SeuratDisk的社区fork版本,专门解决了Seurat v5兼容性问题和空间转录组(Visium)的转换问题,使用h5Seurat作为统一中间格式,不需要python转译。

⚠️该fork由小编个人维护,可能还存在部分bug,但基本功能已经测试过。如遇到问题欢迎提GitHub issue!

优势: 支持Seurat v5,Visium;无需Python环境;保留command logs和完整元数据

安装

# 从GitHub安装fork版本
remotes::install_github("mianaz/seuratdisk-v5")

Seurat v5 ➡️ Anndata

library(srtdisk)  # 注意:包名已改为srtdisk
# 两步转换:先保存为h5Seurat
SaveH5Seurat(seurat_v5, filename = "data.h5Seurat")
# 再转换为h5ad
Convert("data.h5Seurat", dest = "h5ad")

Anndata ➡️ Seurat v5

# 支持直接转换,包括空间数据
Convert("spatial.h5ad", dest = "h5seurat")
seurat_spatial <- LoadH5Seurat("spatial.h5seurat")
# 空间图像重建(测试中)
Images(seurat_spatial)

参考资料

  1. GitHub:https://github.com/mianaz/seuratdisk-V5

大家还知道哪些好用的格式转换包?欢迎在评论区交流分享。

Single Cell Seurat Downstream