Seurat4.0系列教程20:单细胞对象的格式转换
分享是一种态度
在此教程中,我们演示了在 Seurat 对象、SingleCellExperiment对象和anndata对象之间转换的方法。
# install scater https://bioconductor.org/packages/release/bioc/html/scater.html
library(scater)
library(Seurat)
# install SeuratDisk from GitHub using the remotes package remotes::install_github(repo =
# 'mojaveazure/seurat-disk', ref = 'develop')
library(SeuratDisk)
library(patchwork)
SingleCellExperiment的转换
SingleCellExperiment[1]是一类存储的单细胞实验数据,由 Davide Risso, Aaron Lun, and Keegan Korthauer创建,并被许多 Bioconductor 包使用。在这里,我们演示将PBMC 3k 教程中产生的 Seurat 对象转换为SingleCellExperiment,需要使用Davis McCarthy’s scater
包。。
# download from satija lab https://www.dropbox.com/s/kwd3kcxkmpzqg6w/pbmc3k_final.rds?dl=0
pbmc <- readRDS(file = "../data/pbmc3k_final.rds")
pbmc.sce <- as.SingleCellExperiment(pbmc)
p1 <- plotExpression(pbmc.sce, features = "MS4A1", x = "ident") + theme(axis.text.x = element_text(angle = 45,
hjust = 1))
p2 <- plotPCA(pbmc.sce, colour_by = "ident")
p1 + p2
Seurat还允许从SingleCellExperiment
对象转换为Seurat对象:
# download from hemberg lab
# https://scrnaseq-public-datasets.s3.amazonaws.com/scater-objects/manno_human.rds
manno <- readRDS(file = "../data/manno_human.rds")
manno <- runPCA(manno)
manno.seurat <- as.Seurat(manno, counts = "counts", data = "logcounts")
# gives the same results; but omits defaults provided in the last line
manno.seurat <- as.Seurat(manno)
Idents(manno.seurat) <- "cell_type1"
p1 <- DimPlot(manno.seurat, reduction = "PCA", group.by = "Source") + NoLegend()
p2 <- RidgePlot(manno.seurat, features = "ACTB", group.by = "Source")
p1 + p2
loom文件转换
loom[2]格式是 Sten Linnarsson’s[3]团队设计的HDF5文件[4]上的文件结构。它旨在有效地存储大型单细胞基因组学数据集。保存 Seurat 对象为 loom文件是通过 SeuratDisk[5]中实现的。有关loom
格式的更多详细信息,可参阅loom file format specification[6].
pbmc.loom <- as.loom(pbmc, filename = "../output/pbmc3k.loom", verbose = FALSE)
pbmc.loom
## Class: loom
## Filename: /__w/2/s/output/pbmc3k.loom
## Access type: H5F_ACC_RDWR
## Listing:
## name obj_type dataset.dims dataset.type_class
## attrs H5I_GROUP <NA> <NA>
## col_attrs H5I_GROUP <NA> <NA>
## col_graphs H5I_GROUP <NA> <NA>
## layers H5I_GROUP <NA> <NA>
## matrix H5I_DATASET 2638 x 13714 H5T_FLOAT
## row_attrs H5I_GROUP <NA> <NA>
## row_graphs H5I_GROUP <NA> <NA>
# Always remember to close loom files when done
pbmc.loom$close_all()
Seurat 还可以通过SeuratDisk[7]读取loom
文件转换成Seurat 对象:我们在Linnarsson 实验室创建的小鼠脑数据集[8]上展示了这一点。
# download from linnarsson lab
# https://storage.googleapis.com/linnarsson-lab-loom/l6_r1_immune_cells.loom
l6.immune <- Connect(filename = "../data/l6_r1_immune_cells.loom", mode = "r")
l6.immune
## Class: loom
## Filename: /__w/2/s/data/l6_r1_immune_cells.loom
## Access type: H5F_ACC_RDONLY
## Attributes: CreationDate, last_modified
## Listing:
## name obj_type dataset.dims dataset.type_class
## col_attrs H5I_GROUP <NA> <NA>
## col_graphs H5I_GROUP <NA> <NA>
## layers H5I_GROUP <NA> <NA>
## matrix H5I_DATASET 14908 x 27998 H5T_FLOAT
## row_attrs H5I_GROUP <NA> <NA>
## row_graphs H5I_GROUP <NA> <NA>
l6.seurat <- as.Seurat(l6.immune)
Idents(l6.seurat) <- "ClusterName"
VlnPlot(l6.seurat, features = c("Sparc", "Ftl1", "Junb", "Ccl4"), ncol = 2)
# Always remember to close loom files when done
l6.immune$close_all()
有关在 R 和 Seurat 中Loom文件交互的更多详细信息,请参阅loomR on GitHub[9]. 。
AnnData转换
AnnData[10]是由Alex Wolf and Philipp Angerer创建的 Python 类型,用于存储单细胞数据。此数据格式还用于存储Scanpy
包的结果,现在支持与seurat交互操作,通过SeuratDisk
包从文件中读取数据并将数据保存到AnnData
文件中,
查看更多AnnData文件转换可参考convert-anndata[11]。
参考资料
SingleCellExperiment: https://bioconductor.org/packages/release/bioc/html/SingleCellExperiment.html
[2]loom: http://loompy.org/
[3]Sten Linnarsson’s: http://linnarssonlab.org/
[4]HDF5文件: http://portal.hdfgroup.org/display/support
[5]SeuratDisk: https://mojaveazure.github.io/seurat-disk
[6]loom file format specification: http://linnarssonlab.org/loompy/format/index.html
[7]SeuratDisk: https://github.com/mojaveazure/seurat-disk
[8]小鼠脑数据集: http://mousebrain.org/
[9]loomR on GitHub: https://github.com/mojaveazure/loomR
[10]AnnData: https://anndata.readthedocs.io/en/latest/
[11]convert-anndata: https://mojaveazure.github.io/seurat-disk/articles/convert-anndata.html
Rethinking batch effect removing methods—LIGER
如果你对单细胞转录组研究感兴趣,但又不知道如何入门,也许你可以关注一下下面的课程
看完记得顺手点个“在看”哦!
长按扫码可关注