Single Cells with edgeR

This vignette demonstrates usage of Glimma on a single cell dataset. The data here comes from brain cells from the Zeisel A et al. (2015) study on mouse brain single cells. We will use the MDS plot to perform unsupervised clustering of the cells. A pseudo-bulk single cell aggregation approach with edgeR will be used to test for differential expression, and two styles of MA plots will be used to investigate the results.

This is a simplified workflow not intended to represent best practice, but to produce reasonable looking plots in the minimal amount of code. Please refer to a resource such Orchestrating Single-Cell Analysis with Bioconductor (OSCA) for appropriate workflows for analysis.

We start by loading in the data using the scRNAseq package.

library(scRNAseq)
library(scater)
library(scran)
library(Glimma)
library(edgeR)

sce <- ZeiselBrainData(ensembl=TRUE)
#> see ?scRNAseq and browseVignettes('scRNAseq') for documentation
#> loading from cache
#> see ?scRNAseq and browseVignettes('scRNAseq') for documentation
#> loading from cache
#> see ?scRNAseq and browseVignettes('scRNAseq') for documentation
#> loading from cache
#> see ?scRNAseq and browseVignettes('scRNAseq') for documentation
#> loading from cache
#> loading from cache
#> require("ensembldb")
#> Warning: Unable to map 1565 of 20006 requested IDs.

Once the data is loaded in we follow the OSCA procedure for identifying highly variable genes for creating a multi-dimensional scaling (MDS) plot. We use the functions provided by scran to identify the most highly variable genes rather than the algorithm within glimmaMDS, as scran is tailored towards single cells.

sce <- logNormCounts(sce)

var_mod <- modelGeneVar(sce)
hvg_genes <- getTopHVGs(var_mod, n=500)
hvg_sce <- sce[hvg_genes, ]

hvg_sce <- logNormCounts(hvg_sce)

Choosing to colour the MDS plot using level1class reveals separation between cell types.

glimmaMDS(
    exprs(hvg_sce),
    groups = colData(hvg_sce)
)

To demonstrate the MA plot we will perform a differential expression analysis using the pseudo-bulk approach. This involves creating pseudo-bulk samples by aggregating single cells as an analogue of biological replicates. Here the pseudo-bulk samples will be generated from combinations of level1class and level2class, the cells belonging to unique combinations of the two factors will be aggregated into samples.

colData(sce)$pb_group <-
    paste0(colData(sce)$level1class,
           "_",
           colData(sce)$level2class)

sce_counts <- counts(sce)
pb_counts <- t(rowsum(t(sce_counts), colData(sce)$pb_group))

pb_samples <- colnames(pb_counts)
pb_samples <- gsub("astrocytes_ependymal", "astrocytes-ependymal", pb_samples)
pb_split <- do.call(rbind, strsplit(pb_samples, "_"))
pb_sample_anno <- data.frame(
    sample = pb_samples,
    cell_type = pb_split[, 1],
    sample_group = pb_split[, 2]
)

With the pseudo-bulk annotations and counts we can construct a DGEList object.

pb_dge <- DGEList(
    counts = pb_counts,
    samples = pb_sample_anno,
    group = pb_sample_anno$cell_type
)

pb_dge <- calcNormFactors(pb_dge)

With this we perform differential expression analysis between “pyramidal SS” and “pyramidal CA1” samples using edgeR’s generalised linear models.

design <- model.matrix(~0 + cell_type, data = pb_dge$samples)
colnames(design) <- make.names(gsub("cell_type", "", colnames(design)))

pb_dge <- estimateDisp(pb_dge, design)

contr <- makeContrasts("pyramidal.SS - pyramidal.CA1", levels = design)

pb_fit <- glmFit(pb_dge, design)
pb_lrt <- glmLRT(pb_fit, contrast = contr)

The results of this analysis can be visualised using glimmaMA() as it would be for bulk RNA-seq.

glimmaMA(pb_lrt, dge = pb_dge)

An alternative view of the data can be constructed using the single cells in the expression plot rather than the pseudo-bulk samples. Since the MA plot is related to the expressions by only the genes in the rows, another expression matrix containing the same genes can be substituted in as below.

We construct a new DGE list from the raw single cell counts, then filter it down to just the cells used in our comparison and further down-sampled to 100 cells. This is done because Glimma does not handle a large number of cells well, the limit being a few hundred for most computers. Sampling still provides an approximate representation of the data without computation strain.

The code is not evaluated here to keep the vignette compact.

sc_dge <- DGEList(
    counts = sce_counts,
    group = colData(sce)$level1class
)

sc_dge <- sc_dge[, colData(sce)$level1class %in% c("pyramidal CA1", "pyramidal SS")]

glimmaMA(
    pb_lrt,
    dge = sc_dge[, sample(1:ncol(sc_dge), 100)]
)

Session Info

sessionInfo()
#> R version 4.3.1 (2023-06-16)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.18-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#> 
#> 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       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] ensembldb_2.26.0            AnnotationFilter_1.26.0    
#>  [3] GenomicFeatures_1.54.0      AnnotationDbi_1.64.0       
#>  [5] AnnotationHub_3.10.0        BiocFileCache_2.10.0       
#>  [7] dbplyr_2.3.4                scran_1.30.0               
#>  [9] scater_1.30.0               ggplot2_3.4.4              
#> [11] scuttle_1.12.0              scRNAseq_2.15.0            
#> [13] SingleCellExperiment_1.24.0 DESeq2_1.42.0              
#> [15] SummarizedExperiment_1.32.0 Biobase_2.62.0             
#> [17] MatrixGenerics_1.14.0       matrixStats_1.0.0          
#> [19] GenomicRanges_1.54.0        GenomeInfoDb_1.38.0        
#> [21] IRanges_2.36.0              S4Vectors_0.40.0           
#> [23] BiocGenerics_0.48.0         edgeR_4.0.0                
#> [25] limma_3.58.0                Glimma_2.12.0              
#> 
#> loaded via a namespace (and not attached):
#>   [1] jsonlite_1.8.7                magrittr_2.0.3               
#>   [3] ggbeeswarm_0.7.2              rmarkdown_2.25               
#>   [5] BiocIO_1.12.0                 zlibbioc_1.48.0              
#>   [7] vctrs_0.6.4                   memoise_2.0.1                
#>   [9] Rsamtools_2.18.0              DelayedMatrixStats_1.24.0    
#>  [11] RCurl_1.98-1.12               htmltools_0.5.6.1            
#>  [13] S4Arrays_1.2.0                progress_1.2.2               
#>  [15] curl_5.1.0                    BiocNeighbors_1.20.0         
#>  [17] SparseArray_1.2.0             sass_0.4.7                   
#>  [19] bslib_0.5.1                   htmlwidgets_1.6.2            
#>  [21] cachem_1.0.8                  GenomicAlignments_1.38.0     
#>  [23] igraph_1.5.1                  mime_0.12                    
#>  [25] lifecycle_1.0.3               pkgconfig_2.0.3              
#>  [27] rsvd_1.0.5                    Matrix_1.6-1.1               
#>  [29] R6_2.5.1                      fastmap_1.1.1                
#>  [31] GenomeInfoDbData_1.2.11       shiny_1.7.5.1                
#>  [33] digest_0.6.33                 colorspace_2.1-0             
#>  [35] dqrng_0.3.1                   irlba_2.3.5.1                
#>  [37] ExperimentHub_2.10.0          RSQLite_2.3.1                
#>  [39] beachmat_2.18.0               filelock_1.0.2               
#>  [41] fansi_1.0.5                   httr_1.4.7                   
#>  [43] abind_1.4-5                   compiler_4.3.1               
#>  [45] bit64_4.0.5                   withr_2.5.1                  
#>  [47] BiocParallel_1.36.0           viridis_0.6.4                
#>  [49] DBI_1.1.3                     biomaRt_2.58.0               
#>  [51] rappdirs_0.3.3                DelayedArray_0.28.0          
#>  [53] bluster_1.12.0                rjson_0.2.21                 
#>  [55] tools_4.3.1                   vipor_0.4.5                  
#>  [57] beeswarm_0.4.0                interactiveDisplayBase_1.40.0
#>  [59] httpuv_1.6.12                 glue_1.6.2                   
#>  [61] restfulr_0.0.15               promises_1.2.1               
#>  [63] grid_4.3.1                    cluster_2.1.4                
#>  [65] generics_0.1.3                gtable_0.3.4                 
#>  [67] hms_1.1.3                     metapod_1.10.0               
#>  [69] ScaledMatrix_1.10.0           BiocSingular_1.18.0          
#>  [71] xml2_1.3.5                    utf8_1.2.4                   
#>  [73] XVector_0.42.0                ggrepel_0.9.4                
#>  [75] BiocVersion_3.18.0            pillar_1.9.0                 
#>  [77] stringr_1.5.0                 later_1.3.1                  
#>  [79] splines_4.3.1                 dplyr_1.1.3                  
#>  [81] lattice_0.22-5                rtracklayer_1.62.0           
#>  [83] bit_4.0.5                     tidyselect_1.2.0             
#>  [85] locfit_1.5-9.8                Biostrings_2.70.0            
#>  [87] knitr_1.44                    gridExtra_2.3                
#>  [89] ProtGenerics_1.34.0           xfun_0.40                    
#>  [91] statmod_1.5.0                 stringi_1.7.12               
#>  [93] lazyeval_0.2.2                yaml_2.3.7                   
#>  [95] evaluate_0.22                 codetools_0.2-19             
#>  [97] tibble_3.2.1                  BiocManager_1.30.22          
#>  [99] cli_3.6.1                     xtable_1.8-4                 
#> [101] munsell_0.5.0                 jquerylib_0.1.4              
#> [103] Rcpp_1.0.11                   png_0.1-8                    
#> [105] XML_3.99-0.14                 parallel_4.3.1               
#> [107] ellipsis_0.3.2                blob_1.2.4                   
#> [109] prettyunits_1.2.0             sparseMatrixStats_1.14.0     
#> [111] bitops_1.0-7                  viridisLite_0.4.2            
#> [113] scales_1.2.1                  purrr_1.0.2                  
#> [115] crayon_1.5.2                  rlang_1.1.1                  
#> [117] KEGGREST_1.42.0