1 Introduction

A fundamental problem in biomedical research is the low number of observations, mostly due to a lack of available biosamples, prohibitive costs, or ethical reasons. By augmenting a few real observations with artificially generated samples, their analysis could lead to more robust and higher reproducibility. One possible solution to the problem is the use of generative models, which are statistical models of data that attempt to capture the entire probability distribution from the observations. Using the variational autoencoder (VAE), a well-known deep generative model, this package is aimed to generate samples with gene expression data, especially for single-cell RNA-seq data. Furthermore, the VAE can use conditioning to produce specific cell types or subpopulations. The conditional VAE (CVAE) allows us to create targeted samples rather than completely random ones.

Autoencoders are an unsupervised neural networks that perform data compression from multidimensional to a preferred dimensionality. They reconstruct input data using the hidden layer weights calculated by encoding. The basic idea of an autoencoder is to have an output layer with the same dimensionality as the inputs. The idea is to try to reconstruct each dimension exactly by passing it through the network. It is common but not necessary for an autoencoder to have a symmetric architecture between the input and output. The number of units in the middle layer is typically fewer than that in the input or output. After training an autoencoder, it is not necessary to use both the encoder and decoder portions. For example, when using the approach for dimensionality reduction, one can use the encoder portion in order to create the reduced representations of the data. The reconstructions of the decoder might not be required at all. As a result, an autoencoder is capable of performing dimension reduction. The objective function of this neural network encompasses reconstruction loss. The loss function uses the sum of squared differences between the input and the output in order to force the output to be as similar as possible to the input. Also, the cross-entropy can used as a loss function for quantifying the difference between two probability distributions.

Another interesting application of the autoencoder is one in which we use only the decoder portion of the network. Variational autoencoders are based on Bayesian inference in which the compressed representation follows probability distribution. This constraint differentiates the VAE from standard autoencoder. The VAE can generate new data while conventional autoencoders fail. For example, one might add a term to the loss function to enforce the fact that the hidden variables are drawn from a Gaussian distribution. Then, one might repeatedly draw samples from this Gaussian distribution and use only the decoder portion of the network in order to generate samples of the original data. In this autoencoder, bottleneck vector (latent vector) is replaced by two vectors, namely, mean vector and standard deviation vector. The overall loss function \(J = L + \lambda R\) of the VAE is expressed as a weighted sum of the reconstruction loss \(L\) and the regularization loss \(R\), where \(\lambda > 0\) is the regularization parameter. The term “variational” comes from the close relationship between the regularization and the variational inference method in statistics. One can use a variety of choices for the reconstruction error, and we will use the binary cross-entropy loss between the input and output. The regularization loss is simply the Kullback-Leibler divergence measure of the conditional distributions of the hidden representations of particular points with respect to the standard multivariate Gaussian distribution. Small values of \(\lambda\) will favor exact reconstruction, and the approach will behave like a traditional autoencoder.

One can apply conditioning to variational autoencoders in order to obtain some interesting results. The basic idea in the conditional variational autoencoder is to add an additional conditional input. From an implementation perspective, we can encode category information as a one-hot representation, indicating to the model which class is at the input. One can use an autoencoder for embedding multimodal data in a joint latent space. Multimodal data is essentially data in which the input features are heterogeneous. In addition, by separating the samples into different classes, the data points within the same category become more similar, enhancing the modeling capacity and sample quality of the CVAE.



2 Example

2.1 VAE

Consider artificial data. The data consist of 1000 genes and three groups of 100 samples. Each group has 100 differentially expressed genes.

## Loading required package: keras
## Loading required package: mclust
## Package 'mclust' version 6.0.0
## Type 'citation("mclust")' for citing this R package in publications.

The VAE model can be built by using the function “fit_vae” with gene expression data and the cell annotation from the object “sce”. The overall loss function of the VAE is expressed as a weighted sum of the reconstruction loss and the regularization loss. The reconstruction loss is the binary cross-entropy loss between the input and output and the regularization loss is simply the Kullback-Leibler divergence measure. Note that the same dataset is used for training and validation.

## Loaded Tensorflow version 2.4.1
## normalizing...
## training...

The function “plot_vae” draws the plot for model architecture.

The function “gen_exprs” can generate samples with expression data by using the trained model.

## generating...
## post-processing...

The function “plot_aug” uses reduced dimension plots for augmented data visualization.



2.2 CVAE

The “yan” data set is single-cell RNA sequencing data with 20214 genes and 90 cells from human preimplantation embryos and embryonic stem cells at different passages. The rows in the dataset correspond to genes and columns correspond to cells. The “SingleCellExperiment” class can be used to store and manipulate single-cell genomics data. It extends the “RangedSummarizedExperiment” class and follows similar conventions. The object “sce” can be created by the data “yan” with cell type annotation “ann”.

## Loading required package: SummarizedExperiment
## Loading required package: MatrixGenerics
## Loading required package: matrixStats
## 
## Attaching package: 'MatrixGenerics'
## The following objects are masked from 'package:matrixStats':
## 
##     colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
##     colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
##     colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
##     colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
##     colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
##     colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
##     colWeightedMeans, colWeightedMedians, colWeightedSds,
##     colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
##     rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
##     rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
##     rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
##     rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
##     rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
##     rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
##     rowWeightedSds, rowWeightedVars
## Loading required package: GenomicRanges
## Loading required package: stats4
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## The following object is masked from 'package:keras':
## 
##     normalize
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
##     as.data.frame, basename, cbind, colnames, dirname, do.call,
##     duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
##     lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
##     pmin.int, rank, rbind, rownames, sapply, setdiff, sort, table,
##     tapply, union, unique, unsplit, which.max, which.min
## Loading required package: S4Vectors
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:base':
## 
##     I, expand.grid, unname
## Loading required package: IRanges
## Loading required package: GenomeInfoDb
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## 
## Attaching package: 'Biobase'
## The following object is masked from 'package:MatrixGenerics':
## 
##     rowMedians
## The following objects are masked from 'package:matrixStats':
## 
##     anyMissing, rowMedians
## pre-processing...
## normalizing...
## training...
## generating...
## post-processing...



3 Session information

## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-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] SingleCellExperiment_1.20.0 SummarizedExperiment_1.28.0
##  [3] Biobase_2.58.0              GenomicRanges_1.50.0       
##  [5] GenomeInfoDb_1.34.0         IRanges_2.32.0             
##  [7] S4Vectors_0.36.0            BiocGenerics_0.44.0        
##  [9] MatrixGenerics_1.10.0       matrixStats_0.62.0         
## [11] SC3_1.26.0                  VAExprs_1.4.0              
## [13] mclust_6.0.0                keras_2.9.0                
## 
## loaded via a namespace (and not attached):
##   [1] DeepPINCS_1.6.0           BiocParallel_1.32.0      
##   [3] tfruns_1.5.1              SnowballC_0.7.0          
##   [5] ggplot2_3.3.6             scater_1.26.0            
##   [7] digest_0.6.30             foreach_1.5.2            
##   [9] htmltools_0.5.3           viridis_0.6.2            
##  [11] float_0.3-0               fansi_1.0.3              
##  [13] magrittr_2.0.3            ScaledMatrix_1.6.0       
##  [15] tm_0.7-9                  cluster_2.1.4            
##  [17] doParallel_1.0.17         ROCR_1.0-11              
##  [19] colorspace_2.0-3          rrcov_1.7-2              
##  [21] rvest_1.0.3               ggrepel_0.9.1            
##  [23] sylly_0.1-6               WriteXLS_6.4.0           
##  [25] xfun_0.34                 dplyr_1.0.10             
##  [27] crayon_1.5.2              RCurl_1.98-1.9           
##  [29] CatEncoders_0.1.1         jsonlite_1.8.3           
##  [31] zeallot_0.1.0             iterators_1.0.14         
##  [33] glue_1.6.2                stopwords_2.3            
##  [35] gtable_0.3.1              zlibbioc_1.44.0          
##  [37] XVector_0.38.0            DelayedArray_0.24.0      
##  [39] webchem_1.1.3             BiocSingular_1.14.0      
##  [41] DEoptimR_1.0-11           mlapi_0.1.1              
##  [43] scales_1.2.1              mvtnorm_1.1-3            
##  [45] pheatmap_1.0.12           DBI_1.1.3                
##  [47] rngtools_1.5.2            data.tree_1.0.0          
##  [49] Rcpp_1.0.9                xtable_1.8-4             
##  [51] viridisLite_0.4.1         reticulate_1.26          
##  [53] text2vec_0.6.2            rsvd_1.0.5               
##  [55] matlab_1.0.4              proxy_0.4-27             
##  [57] htmlwidgets_1.5.4         httr_1.4.4               
##  [59] DiagrammeR_1.0.9          RColorBrewer_1.1-3       
##  [61] ellipsis_0.3.2            pkgconfig_2.0.3          
##  [63] farver_2.1.1              scuttle_1.8.0            
##  [65] sass_0.4.2                utf8_1.2.2               
##  [67] later_1.3.0               tidyselect_1.2.0         
##  [69] labeling_0.4.2            rlang_1.0.6              
##  [71] PRROC_1.3.1               munsell_0.5.0            
##  [73] tools_4.2.1               visNetwork_2.1.2         
##  [75] cachem_1.0.6              cli_3.4.1                
##  [77] generics_0.1.3            rsparse_0.5.1            
##  [79] evaluate_0.17             stringr_1.4.1            
##  [81] fastmap_1.1.0             yaml_2.3.6               
##  [83] textstem_0.1.4            RhpcBLASctl_0.21-247.1   
##  [85] knitr_1.40                robustbase_0.95-0        
##  [87] lgr_0.4.4                 purrr_0.3.5              
##  [89] doRNG_1.8.2               sparseMatrixStats_1.10.0 
##  [91] mime_0.12                 koRpus_0.13-8            
##  [93] whisker_0.4               slam_0.1-50              
##  [95] xml2_1.3.3                tokenizers_0.2.3         
##  [97] compiler_4.2.1            rstudioapi_0.14          
##  [99] beeswarm_0.4.0            png_0.1-7                
## [101] koRpus.lang.en_0.1-4      e1071_1.7-12             
## [103] tibble_3.1.8              pcaPP_2.0-3              
## [105] bslib_0.4.0               stringi_1.7.8            
## [107] highr_0.9                 lattice_0.20-45          
## [109] Matrix_1.5-1              tensorflow_2.9.0         
## [111] vctrs_0.5.0               stringdist_0.9.9         
## [113] pillar_1.8.1              lifecycle_1.0.3          
## [115] jquerylib_0.1.4           BiocNeighbors_1.16.0     
## [117] data.table_1.14.4         cowplot_1.1.1            
## [119] bitops_1.0-7              irlba_2.3.5.1            
## [121] httpuv_1.6.6              sylly.en_0.1-3           
## [123] ttgsea_1.6.0              R6_2.5.1                 
## [125] promises_1.2.0.1          gridExtra_2.3            
## [127] vipor_0.4.5               codetools_0.2-18         
## [129] assertthat_0.2.1          GenomeInfoDbData_1.2.9   
## [131] parallel_4.2.1            grid_4.2.1               
## [133] beachmat_2.14.0           class_7.3-20             
## [135] rmarkdown_2.17            DelayedMatrixStats_1.20.0
## [137] shiny_1.7.3               NLP_0.2-1                
## [139] base64enc_0.1-3           ggbeeswarm_0.6.0



4 References

Aggarwal, C. C. (2018). Neural Networks and Deep Learning. Springer.

Al-Jabery, K., Obafemi-Ajayi, T., Olbricht, G., & Wunsch, D. (2019). Computational Learning Approaches to Data Analytics in Biomedical Applications. Academic Press.

Cinelli, L. P., Marins, M. A., da Silva, E. A. B., & Netto, S. L. (2021). Variational Methods for Machine Learning with Applications to Deep Networks. Springer.

Das, H., Pradhan, C., & Dey, N. (2020). Deep Learning for Data Analytics: Foundations, Biomedical Applications, and Challenges. Academic Press.

Marouf, M., Machart, P., Bansal, V., Kilian, C., Magruder, D. S., Krebs, C. F., & Bonn, S. (2020). Realistic in silico generation and augmentation of single-cell RNA-seq data using generative adversarial networks. Nature communications, 11(1), 1-12.

Pedrycz, W., & Chen, S. M. (Eds.). (2020). Deep Learning: Concepts and Architectures. Springer.

Yan, W. Q. (2020). Computational Methods for Deep Learning: Theoretic, Practice and Applications. Springer.