Chapter 3 A introduction to Single Cell Sequening
Based on singleron02.html
3.1 data format of Seurat
- Bioconductor主导的SingleCellExperiment数据格式:例如scran、scater、monocle(尽管它的对象不直接使用SingleCellExperiment,但灵感来源于SingleCellExperiment,并且操作也是类似的)
- Seurat:SeuratObject格式
- scanpy:AnnData格式
ref:
3.2 Data Access
Summary information about Seurat objects can be had quickly and easily using standard R functions. Object shape/dimensions can be found using the dim
, ncol
, and nrow
functions; cell and feature names can be found using the colnames
and rownames
functions, respectively, or the dimnames
function. A vector of names of Assay, DimReduc, and Graph objects contained in a Seurat object can be had by using names
.
Pulling specific Assay, DimReduc, or Graph objects can be done with the double [[
extract operator. Adding new objects to a Seurat object is also done with the double [[
extract operator; Seurat will figure out where in the Seurat object a new associated object belongs.
Accessing data from an Seurat object is done with the GetAssayData
function. Adding expression data to either the counts, data, or scale.data slots can be done with SetAssayData
. New data must have the same cells in the same order as the current expression data. Data added to counts or data must have the same features as the current expression data.
Cell-level meta data can be accessed with the single [[
extract operator or using the $
sigil. Pulling with the $
sigil means only one bit of meta data can be pulled at a time, though tab-autocompletion has been enabled for it, making it ideal for interactive use. Adding cell-level meta data can be set using the single [[
extract operator as well, or by using AddMetaData.
The HVFInfo
function pulls feature mean and dispersion from an Assay object. The vector of variable features can be pulled with the VariableFeatures
function. VariableFeatures
can also set the vector of variable features.
A vector of standard deviations for a DimReduc stored within the Seurat object can be found with Stdev
.
3.3 Methods
library(Seurat)
::methods(class = 'Seurat') utils
## [1] [ [[
## [3] [[<- $
## [5] $<- AddMetaData
## [7] as.CellDataSet as.SingleCellExperiment
## [9] colMeans colSums
## [11] Command DefaultAssay
## [13] DefaultAssay<- dim
## [15] dimnames droplevels
## [17] Embeddings FindClusters
## [19] FindMarkers FindNeighbors
## [21] FindSpatiallyVariableFeatures FindVariableFeatures
## [23] FoldChange GetAssay
## [25] GetAssayData GetImage
## [27] GetTissueCoordinates HVFInfo
## [29] Idents Idents<-
## [31] Key levels
## [33] levels<- Loadings
## [35] merge Misc
## [37] Misc<- names
## [39] NormalizeData Project
## [41] Project<- ProjectUMAP
## [43] RenameCells RenameIdents
## [45] ReorderIdent rowMeans
## [47] rowSums RunCCA
## [49] RunICA RunLDA
## [51] RunPCA RunSPCA
## [53] RunTSNE RunUMAP
## [55] ScaleData ScoreJackStraw
## [57] SCTResults SetAssayData
## [59] SetIdent show
## [61] SpatiallyVariableFeatures StashIdent
## [63] Stdev subset
## [65] SVFInfo Tool
## [67] Tool<- VariableFeatures
## [69] VariableFeatures<- WhichCells
## see '?methods' for accessing help and source code
3.4 test read h5 file.
library("Seurat")
<- Read10X_h5("../covid_balf/GSM4339769_C141_filtered_feature_bc_matrix.h5") tmp
## Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
## counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
3.5 reproduce UMAP fig 1a
paper “Single-cell landscape of bronchoalveolar immune cells in patients with COVID-19”
<- readRDS("../covid_balf/nCoV.rds")
bm
<- DimPlot(bm, reduction="umap", label = TRUE, repel = TRUE, label.size = 2.5) + NoLegend()
p1 <- DimPlot(bm, group.by = 'group', label = TRUE, repel = TRUE, label.size = 2.5)
p2 + p2 p1
3.6 sessionInfo
sessionInfo()
## R version 4.0.4 (2021-02-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.10
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] forcats_0.5.1 stringr_1.4.0 dplyr_1.0.5
## [4] purrr_0.3.4 readr_1.4.0 tidyr_1.1.3
## [7] tibble_3.1.1 ggplot2_3.3.3 tidyverse_1.3.1
## [10] pbmc3k.SeuratData_3.1.4 SeuratData_0.2.1 SeuratObject_4.0.0
## [13] Seurat_4.0.1
##
## loaded via a namespace (and not attached):
## [1] readxl_1.3.1 backports_1.2.1 plyr_1.8.6
## [4] igraph_1.2.6 lazyeval_0.2.2 splines_4.0.4
## [7] listenv_0.8.0 scattermore_0.7 digest_0.6.27
## [10] htmltools_0.5.1.1 fansi_0.4.2 magrittr_2.0.1
## [13] tensor_1.5 cluster_2.1.2 ROCR_1.0-11
## [16] globals_0.14.0 modelr_0.1.8 matrixStats_0.58.0
## [19] spatstat.sparse_2.0-0 colorspace_2.0-0 rvest_1.0.0
## [22] rappdirs_0.3.3 ggrepel_0.9.1 haven_2.4.0
## [25] xfun_0.22 crayon_1.4.1 jsonlite_1.7.2
## [28] spatstat.data_2.1-0 survival_3.2-10 zoo_1.8-9
## [31] glue_1.4.2 polyclip_1.10-0 gtable_0.3.0
## [34] leiden_0.3.7 future.apply_1.7.0 abind_1.4-5
## [37] scales_1.1.1 DBI_1.1.1 miniUI_0.1.1.1
## [40] Rcpp_1.0.6 viridisLite_0.4.0 xtable_1.8-4
## [43] reticulate_1.18 spatstat.core_2.1-2 bit_4.0.4
## [46] htmlwidgets_1.5.3 httr_1.4.2 RColorBrewer_1.1-2
## [49] ellipsis_0.3.1 ica_1.0-2 pkgconfig_2.0.3
## [52] farver_2.1.0 sass_0.3.1 uwot_0.1.10
## [55] dbplyr_2.1.1 deldir_0.2-10 utf8_1.2.1
## [58] tidyselect_1.1.0 labeling_0.4.2 rlang_0.4.10
## [61] reshape2_1.4.4 later_1.1.0.1 munsell_0.5.0
## [64] cellranger_1.1.0 tools_4.0.4 cli_2.4.0
## [67] generics_0.1.0 broom_0.7.6 ggridges_0.5.3
## [70] evaluate_0.14 fastmap_1.1.0 yaml_2.2.1
## [73] goftest_1.2-2 bit64_4.0.5 knitr_1.32
## [76] fs_1.5.0 fitdistrplus_1.1-3 RANN_2.6.1
## [79] pbapply_1.4-3 future_1.21.0 nlme_3.1-152
## [82] mime_0.10 xml2_1.3.2 hdf5r_1.3.3
## [85] compiler_4.0.4 rstudioapi_0.13 plotly_4.9.3
## [88] png_0.1-7 spatstat.utils_2.1-0 reprex_2.0.0
## [91] bslib_0.2.4 stringi_1.5.3 highr_0.9
## [94] lattice_0.20-41 Matrix_1.3-2 vctrs_0.3.7
## [97] pillar_1.6.0 lifecycle_1.0.0 spatstat.geom_2.1-0
## [100] lmtest_0.9-38 jquerylib_0.1.3 RcppAnnoy_0.0.18
## [103] data.table_1.14.0 cowplot_1.1.1 irlba_2.3.3
## [106] httpuv_1.5.5 patchwork_1.1.1 R6_2.5.0
## [109] bookdown_0.21 promises_1.2.0.1 KernSmooth_2.23-18
## [112] gridExtra_2.3 parallelly_1.24.0 codetools_0.2-18
## [115] MASS_7.3-53.1 assertthat_0.2.1 withr_2.4.2
## [118] sctransform_0.3.2 mgcv_1.8-35 parallel_4.0.4
## [121] hms_1.0.0 grid_4.0.4 rpart_4.1-15
## [124] rmarkdown_2.7 Rtsne_0.15 shiny_1.6.0
## [127] lubridate_1.7.10