本節(jié),我們演示了在Seurat對(duì)象套么、singlecellexper對(duì)象和anndata對(duì)象之間進(jìn)行轉(zhuǎn)換的能力医寿。以建立Seurat與其他單細(xì)胞數(shù)據(jù)分析工具之間的鏈接巡揍。
# install scater https://bioconductor.org/packages/release/bioc/html/scater.html
library(scater)
# install loomR from GitHub using the remotes package remotes::install_github(repo =
# 'mojaveazure/loomR', ref = 'develop')
library(loomR)
library(Seurat)
library(monocle)
Seurat to monocle
用 Seurat 3 的Seurat::as.CellDataSet()函數(shù)可以直接將Seurat對(duì)象轉(zhuǎn)化為monocle2的對(duì)象,進(jìn)行monocle2的擬時(shí)分析油够。
?Seurat::as.CellDataSet()
monocle to Seurat
那蚁袭,monocle分析之后又想用seurat的功能怎么辦呢?monocle的對(duì)象也是可以轉(zhuǎn)化為Seurat的石咬。在這之前揩悄,讓我們來(lái)看看monocle的數(shù)據(jù)格式:
一般monocle構(gòu)建CDS需要3個(gè)矩陣:expr.matrix、pd鬼悠、fd
- expr.matrix :基因-細(xì)胞表達(dá)矩陣
- pd :細(xì)胞-細(xì)胞特征注釋矩陣
- fd :基因-基因特征注釋矩陣
而創(chuàng)建這個(gè)seurat對(duì)象需要什么呢删性?
?Seurat::CreateSeuratObject
CreateSeuratObject(
counts, # 一個(gè)基因-細(xì)胞表達(dá)矩陣 (對(duì)應(yīng)monocle的expr.matrix)
project = "SeuratProject", # 項(xiàng)目名稱可以以您的心情寫(xiě)
assay = "RNA", # 一般count矩陣說(shuō)就是RNA
min.cells = 0, # cells 過(guò)濾條件
min.features = 0, # 基因過(guò)濾條件
names.field = 1, # 細(xì)胞名稱格式(一般不用亏娜,geo下載的數(shù)據(jù)需要注意了)
names.delim = "_", # 細(xì)胞名稱分隔符(一般不用)
meta.data = NULL #細(xì)胞-細(xì)胞特征注釋矩陣
)
所以我們可以用monocle的 expr.matrix 和pd 來(lái)構(gòu)建seurat的對(duì)象。
converting-tofrom-singlecellexperiment
SingleCellExperiment是由Davide Risso蹬挺、Aaron Lun和Keegan Korthauer創(chuàng)建的用于存儲(chǔ)單細(xì)胞實(shí)驗(yàn)數(shù)據(jù)的類维贺,并被許多生物導(dǎo)體分析包使用。在這里巴帮,我們演示了將3k PBMC教程中生成的Seurat對(duì)象轉(zhuǎn)換為與Davis McCarthy的scater包一起使用的SingleCellExperiment對(duì)象幸缕。
# 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")
CombinePlots(plots = list(p1, p2))
?pheatmap
head(pbmc@meta.data)
plotHeatmap(pbmc.sce,features = VariableFeatures(object = pbmc) ,show_colnames=F,colour_columns_by='seurat_clusters')#,cluster_cols=F
pbmc.sce <- calculateQCMetrics(pbmc.sce)
fontsize <- theme(axis.text=element_text(size=12), axis.title=element_text(size=16))
plotHighestExprs(pbmc.sce, n=20) + fontsize
Seurat還允許從SingleCellExperiment對(duì)象轉(zhuǎn)換為Seurat對(duì)象;我們通過(guò)從Martin Hemberg的團(tuán)隊(duì)維護(hù)的存儲(chǔ)庫(kù)下載的一些公共數(shù)據(jù)來(lái)演示這一點(diǎn)。
# download from hemberg lab
# https://scrnaseq-public-datasets.s3.amazonaws.com/scater-objects/manno_human.rds
manno <- readRDS(file = "D:\\Users\\Administrator\\Desktop\\Novo周運(yùn)來(lái)\\SingleCell\\scrna_tools/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")
CombinePlots(plots = list(p1, p2))
converting-tofrom-loom
loom
是一個(gè)文件結(jié)構(gòu)強(qiáng)加于HDF5文件,由斯坦林納森的小組設(shè)計(jì)晰韵。它的設(shè)計(jì)是為了有效地描述大型單細(xì)胞基因組數(shù)據(jù)集发乔。loop格式的詳細(xì)信息,請(qǐng)參閱http://linnarssonlab.org/loompy/format/index.html
pbmc.loom <- as.loom(pbmc, filename = "pbmc3k.loom", verbose = FALSE)
Transposing input data: loom file will show input columns (cells) as rows and input rows (features) as columns
This is to maintain compatibility with other loom tools
Adding: CellID
Adding: Gene
Adding: vst_mean
Adding: vst_variance
Adding: vst_variance_expected
Adding: vst_variance_standardized
Adding: vst_variable
Adding: Selected
Adding: orig_ident
Adding: nCount_RNA
Adding: nFeature_RNA
Adding: percent_mt
Adding: RNA_snn_res_0_5
Adding: seurat_clusters
Adding: S_Score
Adding: G2M_Score
Adding: Phase
Adding: ClusterID
Adding: ClusterName
> pbmc.loom
Class: loom
Filename: D:\Documents\pbmc3k.loom
Access type: H5F_ACC_RDWR
Attributes: version, chunks, LOOM_SPEC_VERSION, assay, 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 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()
當(dāng)然了雪猪,Seurat也支持loom格式到seurat的轉(zhuǎn)化栏尚。我們?cè)贚innarson實(shí)驗(yàn)室制作的小鼠大腦圖譜Mouse Brain Atlas
的一個(gè)子集中進(jìn)行演示。(我還是用Seurat生成的pbmc3k.loom來(lái)做演示吧……)
> pbmc <- connect(filename = "pbmc3k.loom", mode = "r")
> pbmc
Class: loom
Filename: D:\Documents\pbmc3k.loom
Access type: H5F_ACC_RDONLY
Attributes: version, chunks, LOOM_SPEC_VERSION, assay, 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 2638 x 13714 H5T_FLOAT
row_attrs H5I_GROUP <NA> <NA>
row_graphs H5I_GROUP <NA> <NA>
pbmc <- as.Seurat(pbmc)
VlnPlot(pbmc, features ="ACTB" , ncol = 2, pt.size = 0.1)
# Always remember to close loom files when done
l6.immune$close_all()
converting-tofrom-anndata
AnnData提供了一個(gè)由Alex Wolf和Philipp Angerer創(chuàng)建的Python類只恨,它可以用來(lái)存儲(chǔ)單細(xì)胞數(shù)據(jù)译仗。這種數(shù)據(jù)格式也用于存儲(chǔ)在他們的Scanpy包中,我們現(xiàn)在支持互操作性官觅。Seurat有一個(gè)新的函數(shù)ReadH5AD纵菌,用于從AnnData使用的H5AD文件中讀取數(shù)據(jù)。
# download from satija lab https://www.dropbox.com/s/ngs3p8n2i8y33hj/pbmc3k.h5ad?dl=0
pbmc3k <- ReadH5AD(file = "../data/pbmc3k.h5ad")
Idents(pbmc3k) <- "louvain"
p1 <- DimPlot(pbmc3k, label = TRUE) + NoLegend()
p2 <- VlnPlot(pbmc3k, features = c("CST3", "NKG7", "PPBP"), combine = FALSE)
CombinePlots(plots = c(list(p1), p2), ncol = 2, legend = "none")
We currently do not support direct Seurat → AnnData conversion. We do have a work around by allowing users to write out to a loom file with as.loom, then reading the loom file in Python with Scanpy/AnnData