This tutorial provides an example analysis for modelling gene detection pattern as outlined in R.Li et al, 2018. The goal of this tutorial is to provide an overview of the cell type classification and visualization tasks by learning a low dimensional embedding through a class of gene detection models: that is BFA and Binary PCA.
The following workflow summarizes a typical dimensionality reduction procedure performed by BFA or Binary PCA.
Let’s start with the installation
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("scBFA")
next we can load dependent packages
The example dataset is generated from our scRNA-seq pre-DC/cDC dataset sourced from https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE89232 After performing all quality control procedure of genes and cells (as outlined in the paper), we then select 500 most variable genes for illustration purpose. The example dataset consists of 950 cells and 500 genes
For illustration, here we construct a singleCellExperiment class to be the input of BFA and Binary PCA.
Let \(N\) stands for number of cells, \(G\) stands for the number of genes, and \(K\) stands for the number of latent dimensions.
A bfa model object computes the following parameters after fitting the gene detection matrix.
We choose 3 as number of latent dimensions and project the gene detection matrix on the embedding space.
We then visualize the low dimensional embedding of BFA in tSNE space. Points are colored by their corresponding cell types.
set.seed(5)
df = as.data.frame(bfa_model$ZZ)
df$celltype = celltype
p1 <- ggplot(df,aes(x = V1,y = V2,colour = celltype))
p1 <- p1 + geom_jitter(size=2.5,alpha = 0.8)
colorvalue <- c("#43d5f9","#24b71f","#E41A1C", "#ffc935","#3d014c","#39ddb2",
"slateblue2","maroon","#f7df27","palevioletred1","olivedrab3",
"#377EB8","#5043c1","blue","aquamarine2","chartreuse4",
"burlywood2","indianred1","mediumorchid1")
p1 <- p1 + xlab("tsne axis 1") + ylab("tsne axis 2")
p1 <- p1 + scale_color_manual(values = colorvalue)
p1 <- p1 + theme(panel.background = element_blank(),
legend.position = "right",
axis.text=element_blank(),
axis.line.x = element_line(color="black"),
axis.line.y = element_line(color="black"),
plot.title = element_blank()
)
p1
We then visualize the low dimensional embedding of Binary PCA in tSNE space. Points are colored by their corresponding cell types.
df = as.data.frame(bpca$x[,c(1:2)])
colnames(df) = c("V1","V2")
df$celltype = celltype
p1 <- ggplot(df,aes(x = V1,y = V2,colour = celltype))
p1 <- p1 + geom_jitter(size=2.5,alpha = 0.8)
colorvalue <- c("#43d5f9","#24b71f","#E41A1C", "#ffc935","#3d014c","#39ddb2",
"slateblue2","maroon","#f7df27","palevioletred1","olivedrab3",
"#377EB8","#5043c1","blue","aquamarine2","chartreuse4",
"burlywood2","indianred1","mediumorchid1")
p1 <- p1 + xlab("tsne axis 1") + ylab("tsne axis 2")
p1 <- p1 + scale_color_manual(values = colorvalue)
p1 <- p1 + theme(panel.background = element_blank(),
legend.position = "right",
axis.text=element_blank(),
axis.line.x = element_line(color="black"),
axis.line.y = element_line(color="black"),
plot.title = element_blank()
)
p1
sessionInfo()
#> R version 4.1.0 (2021-05-18)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.2 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.13-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.13-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] parallel stats4 stats graphics grDevices utils datasets
#> [8] methods base
#>
#> other attached packages:
#> [1] scBFA_1.6.0 ggplot2_3.3.3
#> [3] zinbwave_1.14.0 SingleCellExperiment_1.14.0
#> [5] SummarizedExperiment_1.22.0 Biobase_2.52.0
#> [7] GenomicRanges_1.44.0 GenomeInfoDb_1.28.0
#> [9] IRanges_2.26.0 S4Vectors_0.30.0
#> [11] BiocGenerics_0.38.0 MatrixGenerics_1.4.0
#> [13] matrixStats_0.58.0
#>
#> loaded via a namespace (and not attached):
#> [1] copula_1.0-1 plyr_1.8.6 igraph_1.2.6
#> [4] lazyeval_0.2.2 splines_4.1.0 pspline_1.0-18
#> [7] BiocParallel_1.26.0 listenv_0.8.0 scattermore_0.7
#> [10] digest_0.6.27 htmltools_0.5.1.1 fansi_0.4.2
#> [13] magrittr_2.0.1 memoise_2.0.0 tensor_1.5
#> [16] cluster_2.1.2 ROCR_1.0-11 limma_3.48.0
#> [19] globals_0.14.0 Biostrings_2.60.0 annotate_1.70.0
#> [22] stabledist_0.7-1 spatstat.sparse_2.0-0 colorspace_2.0-1
#> [25] blob_1.2.1 ggrepel_0.9.1 xfun_0.23
#> [28] dplyr_1.0.6 crayon_1.4.1 RCurl_1.98-1.3
#> [31] jsonlite_1.7.2 genefilter_1.74.0 spatstat.data_2.1-0
#> [34] survival_3.2-11 zoo_1.8-9 glue_1.4.2
#> [37] polyclip_1.10-0 gtable_0.3.0 zlibbioc_1.38.0
#> [40] XVector_0.32.0 leiden_0.3.7 DelayedArray_0.18.0
#> [43] future.apply_1.7.0 abind_1.4-5 scales_1.1.1
#> [46] mvtnorm_1.1-1 DBI_1.1.1 edgeR_3.34.0
#> [49] miniUI_0.1.1.1 Rcpp_1.0.6 viridisLite_0.4.0
#> [52] xtable_1.8-4 reticulate_1.20 spatstat.core_2.1-2
#> [55] bit_4.0.4 htmlwidgets_1.5.3 httr_1.4.2
#> [58] RColorBrewer_1.1-2 ellipsis_0.3.2 Seurat_4.0.1
#> [61] ica_1.0-2 farver_2.1.0 pkgconfig_2.0.3
#> [64] XML_3.99-0.6 uwot_0.1.10 sass_0.4.0
#> [67] deldir_0.2-10 locfit_1.5-9.4 utf8_1.2.1
#> [70] labeling_0.4.2 tidyselect_1.1.1 rlang_0.4.11
#> [73] softImpute_1.4-1 reshape2_1.4.4 later_1.2.0
#> [76] AnnotationDbi_1.54.0 munsell_0.5.0 tools_4.1.0
#> [79] cachem_1.0.5 generics_0.1.0 RSQLite_2.2.7
#> [82] ggridges_0.5.3 evaluate_0.14 stringr_1.4.0
#> [85] fastmap_1.1.0 goftest_1.2-2 yaml_2.2.1
#> [88] knitr_1.33 bit64_4.0.5 fitdistrplus_1.1-3
#> [91] purrr_0.3.4 RANN_2.6.1 KEGGREST_1.32.0
#> [94] nlme_3.1-152 pbapply_1.4-3 future_1.21.0
#> [97] mime_0.10 compiler_4.1.0 plotly_4.9.3
#> [100] png_0.1-7 spatstat.utils_2.1-0 tibble_3.1.2
#> [103] geneplotter_1.70.0 pcaPP_1.9-74 gsl_2.1-6
#> [106] bslib_0.2.5.1 stringi_1.6.2 highr_0.9
#> [109] lattice_0.20-44 Matrix_1.3-3 vctrs_0.3.8
#> [112] pillar_1.6.1 lifecycle_1.0.0 ADGofTest_0.3
#> [115] spatstat.geom_2.1-0 lmtest_0.9-38 jquerylib_0.1.4
#> [118] RcppAnnoy_0.0.18 data.table_1.14.0 cowplot_1.1.1
#> [121] bitops_1.0-7 irlba_2.3.3 httpuv_1.6.1
#> [124] patchwork_1.1.1 R6_2.5.0 promises_1.2.0.1
#> [127] KernSmooth_2.23-20 gridExtra_2.3 parallelly_1.25.0
#> [130] codetools_0.2-18 MASS_7.3-54 assertthat_0.2.1
#> [133] DESeq2_1.32.0 withr_2.4.2 SeuratObject_4.0.1
#> [136] sctransform_0.3.2 GenomeInfoDbData_1.2.6 mgcv_1.8-35
#> [139] rpart_4.1-15 grid_4.1.0 tidyr_1.1.3
#> [142] rmarkdown_2.8 Rtsne_0.15 numDeriv_2016.8-1.1
#> [145] shiny_1.6.0