在此教程中,我们演示了在 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是一类存储的单细胞实验数据,由 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格式是 Sten Linnarsson’s团队设计的HDF5文件上的文件结构。它旨在有效地存储大型单细胞基因组学数据集。保存 Seurat 对象为 loom文件是通过 SeuratDisk
中实现的。 有关loom
格式的更多详细信息,可参阅loom file format specification.
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读取loom
文件转换成Seurat 对象:我们在Linnarsson 实验室创建的小鼠脑数据集上展示了这一点。
# 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.
。
AnnData转换
AnnData是由Alex Wolf and Philipp Angerer创建的 Python 类型,用于存储单细胞数据。此数据格式还用于存储Scanpy包的结果,现在支持与seurat交互操作,通过SeuratDisk包从文件中读取数据并将数据保存到AnnData
文件中,
查看更多AnnData文件转换可参考convert-anndata。