美文网首页
Seurat V5更新了啥?(上)

Seurat V5更新了啥?(上)

作者: Cherrieg | 来源:发表于2024-11-05 09:10 被阅读0次

Satijia实验室在2023年11月发布了Seurat软件的V5版本,作为目前使用最广泛的单细胞组学数据分析工具的一次重大版本更新,Seurat V5(以下简称V5)版本新增了许多新功能。根据官方的更新说明,V5版本在以下方面与之前版本有所区别:

  1. Seurat对象和assay类:为了兼容更多的数据类型,V5对assay进行了更新,并对占用磁盘存储进行了优化。V5将数据存储在assay的layer中(之前版本为slot)。layer中可以存储不同类型的数据,例如:原始计数(layer='counts')、标准化后的数据(layer='data')、经过z-score标准化或方差稳定化处理的数据(layer='scale.data')。用户可以使用$访问layer中的数据,如obj[["RNA"]]$counts,或者使用LayerData函数,如LayerData(obj, assay="RNA", layer='counts')
  2. 整合流程:V5引入了简化的数据整合流程,整合过程变得更加高效和简洁。
  3. 差异表达:V5引入presto包来加速差异表达分析,并在计算log-FC时改变了伪计数的应用水平。
  4. SCTransform v2:V5将SCTransform包更新至v2版本。
  5. 伪Bulk分析:当单细胞数据集被注释为细胞亚群,伪Bulk分析(即在给定的亚群和样本中将细胞聚集在一起)可以减少噪声、提高低表达基因的定量、并减少数据矩阵的大小。在Seurat V5中,推荐使用AggregateExpression函数来进行伪Bulk分析。

为了更加清晰的理解Seurat V5的更新,我们使用公开的单细胞组学数据来对比一下Seurat V4(以下简称V4)与V5的差异。
我们选用一个10x Chromium的小鼠神经元单细胞RNA数据,并分别使用V4和V5以相同方式读入。

###Seurat V4
> library(Seurat)

> data <- Read10X(data.dir = "SC3_v3_NextGem_SI_Neuron_10K/filtered_feature_bc_matrix/")
> obj4 <- CreateSeuratObject(counts = data, 
                           project = "neuron_v4", 
                           min.cells = 3, min.features = 200)
###Seurat V5
> library(Seurat)

> data <- Read10X(data.dir = "SC3_v3_NextGem_SI_Neuron_10K/filtered_feature_bc_matrix/")
> obj5 <- CreateSeuratObject(counts = data, 
                           project = "neuron_v5", 
                           min.cells = 3, min.features = 200)

首先来看一下两个seurat object的概况:

> obj4
An object of class Seurat
20574 features across 11311 samples within 1 assay
Active assay: RNA (20574 features, 0 variable features)
> obj5
An object of class Seurat
20574 features across 11311 samples within 1 assay
Active assay: RNA (20574 features, 0 variable features)
 1 layer present: counts

可以看到V5对象中加入了layer,然后我们进一步查看RNA assay的结构:

### V4
> str(obj4@assays$RNA)
Formal class 'Assay' [package "SeuratObject"] with 8 slots
  ..@ counts       :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:37176145] 5 7 8 10 24 28 31 32 33 38 ...
  .. .. ..@ p       : int [1:11312] 0 3886 7528 7914 10641 14692 18593 24724 25838 30534 ...
  .. .. ..@ Dim     : int [1:2] 20574 11311
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:20574] "Xkr4" "Gm19938" "Rp1" "Sox17" ...
  .. .. .. ..$ : chr [1:11311] "AAACCCACAAGAATAC-1" "AAACCCACAATAAGGT-1" "AAACCCACACCATAAC-1" "AAACCCACAGCCCACA-1" ...
  .. .. ..@ x       : num [1:37176145] 2 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..@ data         :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. ..@ i       : int [1:37176145] 5 7 8 10 24 28 31 32 33 38 ...
  .. .. ..@ p       : int [1:11312] 0 3886 7528 7914 10641 14692 18593 24724 25838 30534 ...
  .. .. ..@ Dim     : int [1:2] 20574 11311
  .. .. ..@ Dimnames:List of 2
  .. .. .. ..$ : chr [1:20574] "Xkr4" "Gm19938" "Rp1" "Sox17" ...
  .. .. .. ..$ : chr [1:11311] "AAACCCACAAGAATAC-1" "AAACCCACAATAAGGT-1" "AAACCCACACCATAAC-1" "AAACCCACAGCCCACA-1" ...
  .. .. ..@ x       : num [1:37176145] 2 1 1 1 1 1 1 1 1 1 ...
  .. .. ..@ factors : list()
  ..@ scale.data   : num[0 , 0 ]
  ..@ key          : chr "rna_"
  ..@ assay.orig   : NULL
  ..@ var.features : logi(0)
  ..@ meta.features:'data.frame':       20574 obs. of  0 variables
  ..@ misc         : list()

### V5
> str(obj5@assays$RNA)
Formal class 'Assay5' [package "SeuratObject"] with 8 slots
  ..@ layers    :List of 1
  .. ..$ counts:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. ..@ i       : int [1:37176145] 5 7 8 10 24 28 31 32 33 38 ...
  .. .. .. ..@ p       : int [1:11312] 0 3886 7528 7914 10641 14692 18593 24724 25838 30534 ...
  .. .. .. ..@ Dim     : int [1:2] 20574 11311
  .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. ..$ : NULL
  .. .. .. .. ..$ : NULL
  .. .. .. ..@ x       : num [1:37176145] 2 1 1 1 1 1 1 1 1 1 ...
  .. .. .. ..@ factors : list()
  ..@ cells     :Formal class 'LogMap' [package "SeuratObject"] with 1 slot
  .. .. ..@ .Data: logi [1:11311, 1] TRUE TRUE TRUE TRUE TRUE TRUE ...
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:11311] "AAACCCACAAGAATAC-1" "AAACCCACAATAAGGT-1" "AAACCCACACCATAAC-1" "AAACCCACAGCCCACA-1" ...
  .. .. .. .. ..$ : chr "counts"
  .. .. ..$ dim     : int [1:2] 11311 1
  .. .. ..$ dimnames:List of 2
  .. .. .. ..$ : chr [1:11311] "AAACCCACAAGAATAC-1" "AAACCCACAATAAGGT-1" "AAACCCACACCATAAC-1" "AAACCCACAGCCCACA-1" ...
  .. .. .. ..$ : chr "counts"
  ..@ features  :Formal class 'LogMap' [package "SeuratObject"] with 1 slot
  .. .. ..@ .Data: logi [1:20574, 1] TRUE TRUE TRUE TRUE TRUE TRUE ...
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:20574] "Xkr4" "Gm19938" "Rp1" "Sox17" ...
  .. .. .. .. ..$ : chr "counts"
  .. .. ..$ dim     : int [1:2] 20574 1
  .. .. ..$ dimnames:List of 2
  .. .. .. ..$ : chr [1:20574] "Xkr4" "Gm19938" "Rp1" "Sox17" ...
  .. .. .. ..$ : chr "counts"
  ..@ default   : int 1
  ..@ assay.orig: chr(0) 
  ..@ meta.data :'data.frame':  20574 obs. of  0 variables
  ..@ misc      :List of 1
  .. ..$ calcN: logi TRUE
  ..@ key       : chr "rna_"

V5相较于V4的数据结构发生了明显的改变,在数据矩阵的上层新增了layer层以便在下游分析中更加灵活的处理数据。因此,如果我们想获取原始计数的矩阵,我们也需要使用不同的方式:

### V4
> obj4@assays$RNA@counts[1:5, 1:5]
5 x 5 sparse Matrix of class "dgCMatrix"
        AAACCCACAAGAATAC-1 AAACCCACAATAAGGT-1 AAACCCACACCATAAC-1
Xkr4                     .                  .                  .
Gm19938                  .                  1                  .
Rp1                      .                  .                  .
Sox17                    .                  .                  .
Gm37587                  .                  .                  .
        AAACCCACAGCCCACA-1 AAACCCACAGTAACGG-1
Xkr4                     .                  .
Gm19938                  .                  1
Rp1                      .                  .
Sox17                    .                  .
Gm37587                  .                  .

### V5
> LayerData(obj5, layer='counts')[1:5, 1:5]
5 x 5 sparse Matrix of class "dgCMatrix"
        AAACCCACAAGAATAC-1 AAACCCACAATAAGGT-1 AAACCCACACCATAAC-1
Xkr4                     .                  .                  .
Gm19938                  .                  1                  .
Rp1                      .                  .                  .
Sox17                    .                  .                  .
Gm37587                  .                  .                  .
        AAACCCACAGCCCACA-1 AAACCCACAGTAACGG-1
Xkr4                     .                  .
Gm19938                  .                  1
Rp1                      .                  .
Sox17                    .                  .
Gm37587                  .                  .
### OR
> obj5[['RNA']]$counts[1:5, 1:5]
5 x 5 sparse Matrix of class "dgCMatrix"
        AAACCCACAAGAATAC-1 AAACCCACAATAAGGT-1 AAACCCACACCATAAC-1
Xkr4                     .                  .                  .
Gm19938                  .                  1                  .
Rp1                      .                  .                  .
Sox17                    .                  .                  .
Gm37587                  .                  .                  .
        AAACCCACAGCCCACA-1 AAACCCACAGTAACGG-1
Xkr4                     .                  .
Gm19938                  .                  1
Rp1                      .                  .
Sox17                    .                  .
Gm37587                  .                  .

值得注意的是,GetAssayData函数对V4和V5都是兼容的。
将两个版本的seurat object分别进行保存:

> saveRDS(obj4, 'seurat_v4.rds')
> saveRDS(obj5, 'seurat_v5.rds')

V5版本保存后的RDS大小小于V4,节省了磁盘空间使用。

  85M seurat_v5.rds
 169M seurat_v4.rds

相关文章

网友评论

      本文标题:Seurat V5更新了啥?(上)

      本文链接:https://www.haomeiwen.com/subject/pmvadjtx.html