1 Introduction

In the single cell World, which includes flow cytometry, mass cytometry, single-cell RNA-seq (scRNA-seq), and others, there is a need to improve data visualisation and to bring analysis capabilities to researchers even from non-technical backgrounds. scDataviz (Blighe 2020) attempts to fit into this space, while also catering for advanced users. Additonally, due to the way that scDataviz is designed, which is based on SingleCellExperiment (Lun and Risso 2020), it has a ‘plug and play’ feel, and immediately lends itself as flexibile and compatibile with studies that go beyond scDataviz. Finally, the graphics in scDataviz are generated via the ggplot (Wickham 2016) engine, which means that users can ‘add on’ features to these with ease.

This package just provides some additional functions for dataviz and clustering, and provides another way of identifying cell-types in clusters. It is not strictly intended as a standalone analysis package. For a comprehensive high-dimensional cytometry workflow, it is recommended to check out the work by Nowicka et al. CyTOF workflow: differential discovery in high-throughput high-dimensional cytometry datasets. For a more comprehensive scRNA-seq workflow, please check out OSCA and Analysis of single cell RNA-seq data.

2 Installation

2.2 2. Load the package into R session

3 Tutorial 1: CyTOF FCS data

Here, we will utilise some of the flow cytometry data from Deep phenotyping detects a pathological CD4+ T-cell complosome signature in systemic sclerosis.

This can normally be downloadedd via git clone from your command prompt:

In a practical situation, we would normally read in this data from the raw FCS files and then QC filter, normalise, and transform them. This can be achieved via the processFCS function, which, by default, also removes variables based on low variance and downsamples [randomly] your data to 100000 variables. The user can change these via the downsample and downsampleVar parameters. An example (not run) is given below:

In flow and mass cytometry, getting the correct marker names in the FCS files can be surprisingly difficult. In many cases, from experience, a facility may label the markers by their metals, such as Iridium (Ir), Ruthenium (Ru), Terbium (Tb), et cetera - this is the case for the data used in this tutorial. The true marker names may be held as pData encoded within each FCS, accessible via:

Whatever the case, it is important to sort out marker naming issues prior to the experiment being conducted in order to avoid any confusion.

For this vignette, due to the fact that the raw FCS data is > 500 megabytes, we will work with a smaller pre-prepared dataset that has been downsampled to 10000 cells using the above code. This data comes included with the package.

Load the pre-prepared complosome data.

One can also create a new SingleCellExperiment object manually using any type of data, including any data from scRNA-seq produced elsewhere. Import functions for data deriving from other sources is covered in Tutorials 2 and 3 in this vignette. All functions in scDataviz additionally accept data-frames or matrices on their own, de-necessitating the reliance on the SingleCellExperiment class.

3.2 Perform UMAP

UMAP can be performed on the entire dataset, if your computer’s memory will permit. Currently it’s default is to use the data contained in the ‘scaled’ assay component of your SingleCellExperiment object.

UMAP can also be stratified based on a column in your metadata, e.g., (treated versus untreated samples); however, to do this, I recommend creating separate SingleCellExperiment objects from the very start, i.e., from the the data input stage, and processing the data separately for each group.

Nota bene - advanced users may want to change the default configuration for UMAP. scDataviz currently performs UMAP via the umap package. In order to modify the default configuration, one can pull in the default config separately from the umap package and then modify these config values held in the umap.defaults variable, as per the umap vignette (see ‘Tuning UMAP’ section). For example:

We can also perform UMAP on a select number of PC eigenvectors. PCAtools (Blighe and Lun 2020) can be used to infer ideal number of dimensions to use via the elbow method and Horn’s parallel analysis.

## PC3 
##   3
## [1] 1

For now, let’s just use 5 PCs.

3.3 Create a contour plot of the UMAP layout

This and the remaining sections in this tutorial are about producing great visualisations of the data and attempting to make sense of it, while not fully overlapping with functionalioty provided by other programs that operate in tis space.

With the contour plot, we are essentially looking at celluar density. It can provide for a beautiful viusualisation in a manuscript while also serving as a useful QC tool: if the density is ‘scrunched up’ into a single area in the plot space, then there are likely issues with your input data distribution. We want to see well-separated, high density ‘islands’, or, at least, gradual gradients that blend into one another across high density ‘peaks’.

Create a contour plot of the UMAP layout

Create a contour plot of the UMAP layout

3.5 Shade cells by metadata

Shading cells by metadata can be useful for identifying any batch effects, but also useful for visualising, e.g., differences across treatments.

First, let’s take a look inside the metadata that we have.

##       sample   group treatment
## cell1    P00 Disease    Unstim
## cell2    P00 Disease    Unstim
## cell3    P04 Disease      CD46
## cell4    P03 Disease      CD46
## cell5    P08 Disease    Unstim
## cell6    P00 Disease      CD46
## [1] "Healthy" "Disease"
## [1] "CD46"   "Unstim" "CD3"
Shade cells by metadata

Shade cells by metadata

3.8 Determine enriched markers in each cluster and plot the expression signature

This method also calculates metacluster abundances across a chosen phenotype. The function returns a data-frame, which can then be exported to do other analyses.

3.8.1 Disease vs Healthy metacluster abundances

Cluster nCells TotalCells PercentCells NegMarkers PosMarkers PerCent_HD00 PerCent_HD01 PerCent_HD262 PerCent_P00 PerCent_P02 PerCent_P03 PerCent_P04 PerCent_P08 nCell_Healthy nCell_Disease
0 3311 10000 33.11 NA CD25+ 0.0604047 9.9667774 26.306252 23.5276352 6.4028994 8.2452431 18.2120205 7.2787677 1203 2108
1 1926 10000 19.26 CD25-CD279- CD3+CD45RA+ 0.0000000 0.1038422 62.097612 0.5192108 0.2076843 0.0000000 0.0519211 37.0197300 1198 728
2 1303 10000 13.03 Granzyme B-CD279- CD3+ 15.5794321 7.9815810 2.302379 64.0061397 3.8372985 3.6070606 1.9186493 0.7674597 337 966
3 1229 10000 12.29 NA CD25+ 6.4279902 1.2205045 1.301871 3.0105777 24.0846216 6.8348251 56.9568755 0.1627339 110 1119
4 960 10000 9.60 NA CD3+ 16.5625000 26.0416667 7.500000 28.0208333 3.3333333 10.2083333 6.0416667 2.2916667 481 479
5 500 10000 5.00 CD25- NA 0.4000000 14.6000000 41.000000 11.0000000 0.0000000 0.4000000 0.2000000 32.4000000 280 220
6 301 10000 3.01 CD46-CD279- NA 0.0000000 41.1960133 1.993356 54.4850498 0.3322259 0.3322259 0.6644518 0.9966777 130 171
7 279 10000 2.79 NA Foxp3+CD25+CD3+ 0.3584229 0.0000000 70.609319 1.7921147 0.7168459 0.7168459 0.3584229 25.4480287 198 81
8 109 10000 1.09 CD46- CD25+ 0.9174312 0.0000000 0.000000 0.0000000 67.8899083 27.5229358 3.6697248 0.0000000 1 108
9 61 10000 0.61 CD46- NA 0.0000000 18.0327869 1.639344 0.0000000 1.6393443 78.6885246 0.0000000 0.0000000 12 49
10 21 10000 0.21 CD46-CD279- CD3+ 0.0000000 14.2857143 4.761905 0.0000000 0.0000000 80.9523810 0.0000000 0.0000000 4 17

.

3.8.2 Treatment type metacluster abundances

Cluster nCells TotalCells PercentCells NegMarkers PosMarkers nCell_CD46 nCell_Unstim nCell_CD3
0 3311 10000 33.11 NA CD25+ 3283 3 25
1 1926 10000 19.26 CD25-CD279- CD3+CD45RA+ 3 1919 4
2 1303 10000 13.03 Granzyme B-CD279- CD3+ 5 1176 122
3 1229 10000 12.29 NA CD25+ 18 134 1077
4 960 10000 9.60 NA CD3+ 4 767 189
5 500 10000 5.00 CD25- NA 109 25 366
6 301 10000 3.01 CD46-CD279- NA 289 10 2
7 279 10000 2.79 NA Foxp3+CD25+CD3+ 2 274 3
8 109 10000 1.09 CD46- CD25+ 107 0 2
9 61 10000 0.61 CD46- NA 57 4 0
10 21 10000 0.21 CD46-CD279- CD3+ 20 1 0

.

3.8.3 Expression signature

The expression signature is a quick way to visualise which markers are more or less expressed in each identified cluster of cells.

Determine enriched markers in each cluster and plot the expression signature

Determine enriched markers in each cluster and plot the expression signature

4 Tutorial 2: Import from Seurat

Due to the fact that scDataviz is based on SingleCellExperiment, it has increased interoperability with other packages, including the popular Seurat (Stuart et al. 2018). Taking the data produced from the Seurat Tutorial on Peripheral Blood Mononuclear Cells (PBMCs), we can convert this to a SingleCellExperiment object recognisable by scDataviz via as.SingleCellExperiment().

When deriving from the Seurat route, be sure to manually assign the metadata slot, which is required for some functions. Also be sure to modify the default values for assay, reducedDim, and dimColnames, as these are assigned differently in Seurat.

For markerEnrichment(), a typical command using an ex-Seurat object could be:

5 Tutorial 3: Import any numerical data

scDataviz will work with any numerical data, too. Here, we show a quick example of how one can import a data-matrix of randomly-generated numbers that follow a negative binomial distribution, comprising 2500 cells and 20 markers:

##       group
## cell1     A
## cell2     A
## cell3     A
## cell4     A
## cell5     A
## cell6     A
## class: SingleCellExperiment 
## dim: 20 2500 
## metadata(1): group
## assays(1): normcounts
## rownames(20): CD1 CD2 ... CD19 CD20
## rowData names(0):
## colnames(2500): cell1 cell2 ... cell2499 cell2500
## colData names(0):
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):

This will also work without any assigned metadata; however, having no metadata limits the functionality of the package.

## class: SingleCellExperiment 
## dim: 20 2500 
## metadata(0):
## assays(1): normcounts
## rownames(20): CD1 CD2 ... CD19 CD20
## rowData names(0):
## colnames(2500): cell1 cell2 ... cell2499 cell2500
## colData names(0):
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):

6 Acknowledgments

7 Session info

## R version 4.2.0 RC (2022-04-19 r82224)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.15-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.15-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] PCAtools_2.8.0              ggrepel_0.9.1              
##  [3] ggplot2_3.3.5               scDataviz_1.6.0            
##  [5] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.0
##  [7] Biobase_2.56.0              GenomicRanges_1.48.0       
##  [9] GenomeInfoDb_1.32.0         IRanges_2.30.0             
## [11] MatrixGenerics_1.8.0        matrixStats_0.62.0         
## [13] S4Vectors_0.34.0            BiocGenerics_0.42.0        
## [15] kableExtra_1.3.4            knitr_1.38                 
## 
## loaded via a namespace (and not attached):
##   [1] corrplot_0.92             systemfonts_1.0.4        
##   [3] plyr_1.8.7                igraph_1.3.1             
##   [5] lazyeval_0.2.2            splines_4.2.0            
##   [7] flowCore_2.8.0            BiocParallel_1.30.0      
##   [9] listenv_0.8.0             scattermore_0.8          
##  [11] digest_0.6.29             htmltools_0.5.2          
##  [13] fansi_1.0.3               magrittr_2.0.3           
##  [15] ScaledMatrix_1.4.0        tensor_1.5               
##  [17] cluster_2.1.3             ROCR_1.0-11              
##  [19] globals_0.14.0            RcppParallel_5.1.5       
##  [21] svglite_2.1.0             askpass_1.1              
##  [23] cytolib_2.8.0             spatstat.sparse_2.1-1    
##  [25] colorspace_2.0-3          rvest_1.0.2              
##  [27] xfun_0.30                 dplyr_1.0.8              
##  [29] crayon_1.5.1              RCurl_1.98-1.6           
##  [31] jsonlite_1.8.0            spatstat.data_2.2-0      
##  [33] survival_3.3-1            zoo_1.8-10               
##  [35] glue_1.6.2                polyclip_1.10-0          
##  [37] gtable_0.3.0              zlibbioc_1.42.0          
##  [39] XVector_0.36.0            webshot_0.5.3            
##  [41] leiden_0.3.9              DelayedArray_0.22.0      
##  [43] BiocSingular_1.12.0       future.apply_1.9.0       
##  [45] abind_1.4-5               scales_1.2.0             
##  [47] DBI_1.1.2                 spatstat.random_2.2-0    
##  [49] miniUI_0.1.1.1            Rcpp_1.0.8.3             
##  [51] isoband_0.2.5             viridisLite_0.4.0        
##  [53] xtable_1.8-4              dqrng_0.3.0              
##  [55] reticulate_1.24           spatstat.core_2.4-2      
##  [57] rsvd_1.0.5                umap_0.2.8.0             
##  [59] htmlwidgets_1.5.4         httr_1.4.2               
##  [61] RColorBrewer_1.1-3        ellipsis_0.3.2           
##  [63] Seurat_4.1.0              ica_1.0-2                
##  [65] farver_2.1.0              pkgconfig_2.0.3          
##  [67] sass_0.4.1                uwot_0.1.11              
##  [69] deldir_1.0-6              utf8_1.2.2               
##  [71] labeling_0.4.2            tidyselect_1.1.2         
##  [73] rlang_1.0.2               reshape2_1.4.4           
##  [75] later_1.3.0               munsell_0.5.0            
##  [77] tools_4.2.0               cli_3.3.0                
##  [79] generics_0.1.2            ggridges_0.5.3           
##  [81] evaluate_0.15             stringr_1.4.0            
##  [83] fastmap_1.1.0             yaml_2.3.5               
##  [85] goftest_1.2-3             fitdistrplus_1.1-8       
##  [87] purrr_0.3.4               RANN_2.6.1               
##  [89] sparseMatrixStats_1.8.0   pbapply_1.5-0            
##  [91] future_1.25.0             nlme_3.1-157             
##  [93] mime_0.12                 xml2_1.3.3               
##  [95] compiler_4.2.0            rstudioapi_0.13          
##  [97] plotly_4.10.0             png_0.1-7                
##  [99] spatstat.utils_2.3-0      tibble_3.1.6             
## [101] bslib_0.3.1               stringi_1.7.6            
## [103] highr_0.9                 RSpectra_0.16-1          
## [105] lattice_0.20-45           Matrix_1.4-1             
## [107] vctrs_0.4.1               pillar_1.7.0             
## [109] lifecycle_1.0.1           spatstat.geom_2.4-0      
## [111] lmtest_0.9-40             jquerylib_0.1.4          
## [113] RcppAnnoy_0.0.19          data.table_1.14.2        
## [115] cowplot_1.1.1             bitops_1.0-7             
## [117] irlba_2.3.5               httpuv_1.6.5             
## [119] patchwork_1.1.1           R6_2.5.1                 
## [121] promises_1.2.0.1          RProtoBufLib_2.8.0       
## [123] KernSmooth_2.23-20        gridExtra_2.3            
## [125] parallelly_1.31.1         codetools_0.2-18         
## [127] MASS_7.3-57               assertthat_0.2.1         
## [129] openssl_2.0.0             withr_2.5.0              
## [131] SeuratObject_4.0.4        sctransform_0.3.3        
## [133] GenomeInfoDbData_1.2.8    mgcv_1.8-40              
## [135] parallel_4.2.0            beachmat_2.12.0          
## [137] grid_4.2.0                rpart_4.1.16             
## [139] tidyr_1.2.0               DelayedMatrixStats_1.18.0
## [141] rmarkdown_2.14            Rtsne_0.16               
## [143] shiny_1.7.1

8 References

Blighe (2020)

Blighe and Lun (2020)

Lun and Risso (2020)

Stuart et al. (2018)

Wickham (2016)

Blighe, K. 2020. “scDataviz: single cell dataviz and downstream analyses.” https://github.com/kevinblighe/scDataviz.

Blighe, K, and A Lun. 2020. “PCAtools: everything Principal Component Analysis.” https://github.com/kevinblighe/PCAtools.

Lun, A, and D Risso. 2020. “SingleCellExperiment: S4 Classes for Single Cell Data.” https://bioconductor.org/packages/SingleCellExperiment.

Stuart, Tim, Andrew Butler, Paul Hoffman, Christoph Hafemeister, Efthymia Papalexi, William M Mauck III, Marlon Stoeckius, Peter Smibert, and Rahul Satija. 2018. “Comprehensive Integration of Single Cell Data.” bioRxiv. https://doi.org/10.1101/460147.

Wickham, H. 2016. “ggplot2: Elegant Graphics for Data Analysis.” Springer-Verlag New York, ISBN: 978-3-319-24277-4.