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)
#> 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)
#> Warning in edgeR::decideTestsDGE(x): 'decideTestsDGE' is deprecated.
#> Use 'decideTests' instead.
#> See help("Deprecated")

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.4.0 beta (2024-04-15 r86425)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.19-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_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [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.28.0            AnnotationFilter_1.28.0    
#>  [3] GenomicFeatures_1.56.0      AnnotationDbi_1.66.0       
#>  [5] AnnotationHub_3.12.0        BiocFileCache_2.12.0       
#>  [7] dbplyr_2.5.0                scran_1.32.0               
#>  [9] scater_1.32.0               ggplot2_3.5.1              
#> [11] scuttle_1.14.0              scRNAseq_2.17.10           
#> [13] SingleCellExperiment_1.26.0 DESeq2_1.44.0              
#> [15] SummarizedExperiment_1.34.0 Biobase_2.64.0             
#> [17] MatrixGenerics_1.16.0       matrixStats_1.3.0          
#> [19] GenomicRanges_1.56.0        GenomeInfoDb_1.40.0        
#> [21] IRanges_2.38.0              S4Vectors_0.42.0           
#> [23] BiocGenerics_0.50.0         edgeR_4.2.0                
#> [25] limma_3.60.0                Glimma_2.14.0              
#> 
#> loaded via a namespace (and not attached):
#>   [1] jsonlite_1.8.8            magrittr_2.0.3           
#>   [3] ggbeeswarm_0.7.2          gypsum_1.0.0             
#>   [5] rmarkdown_2.26            BiocIO_1.14.0            
#>   [7] zlibbioc_1.50.0           vctrs_0.6.5              
#>   [9] memoise_2.0.1             Rsamtools_2.20.0         
#>  [11] DelayedMatrixStats_1.26.0 RCurl_1.98-1.14          
#>  [13] htmltools_0.5.8.1         S4Arrays_1.4.0           
#>  [15] curl_5.2.1                BiocNeighbors_1.22.0     
#>  [17] Rhdf5lib_1.26.0           SparseArray_1.4.0        
#>  [19] rhdf5_2.48.0              sass_0.4.9               
#>  [21] alabaster.base_1.4.0      bslib_0.7.0              
#>  [23] htmlwidgets_1.6.4         alabaster.sce_1.4.0      
#>  [25] httr2_1.0.1               cachem_1.0.8             
#>  [27] GenomicAlignments_1.40.0  igraph_2.0.3             
#>  [29] mime_0.12                 lifecycle_1.0.4          
#>  [31] pkgconfig_2.0.3           rsvd_1.0.5               
#>  [33] Matrix_1.7-0              R6_2.5.1                 
#>  [35] fastmap_1.1.1             GenomeInfoDbData_1.2.12  
#>  [37] digest_0.6.35             colorspace_2.1-0         
#>  [39] paws.storage_0.5.0        dqrng_0.3.2              
#>  [41] irlba_2.3.5.1             ExperimentHub_2.12.0     
#>  [43] RSQLite_2.3.6             beachmat_2.20.0          
#>  [45] filelock_1.0.3            fansi_1.0.6              
#>  [47] httr_1.4.7                abind_1.4-5              
#>  [49] compiler_4.4.0            bit64_4.0.5              
#>  [51] withr_3.0.0               BiocParallel_1.38.0      
#>  [53] viridis_0.6.5             DBI_1.2.2                
#>  [55] HDF5Array_1.32.0          alabaster.ranges_1.4.0   
#>  [57] alabaster.schemas_1.4.0   rappdirs_0.3.3           
#>  [59] DelayedArray_0.30.0       bluster_1.14.0           
#>  [61] rjson_0.2.21              tools_4.4.0              
#>  [63] vipor_0.4.7               beeswarm_0.4.0           
#>  [65] glue_1.7.0                restfulr_0.0.15          
#>  [67] rhdf5filters_1.16.0       grid_4.4.0               
#>  [69] cluster_2.1.6             generics_0.1.3           
#>  [71] gtable_0.3.5              metapod_1.12.0           
#>  [73] ScaledMatrix_1.12.0       BiocSingular_1.20.0      
#>  [75] utf8_1.2.4                XVector_0.44.0           
#>  [77] ggrepel_0.9.5             BiocVersion_3.19.1       
#>  [79] pillar_1.9.0              splines_4.4.0            
#>  [81] dplyr_1.1.4               lattice_0.22-6           
#>  [83] rtracklayer_1.64.0        bit_4.0.5                
#>  [85] tidyselect_1.2.1          paws.common_0.7.2        
#>  [87] locfit_1.5-9.9            Biostrings_2.72.0        
#>  [89] knitr_1.46                gridExtra_2.3            
#>  [91] ProtGenerics_1.36.0       xfun_0.43                
#>  [93] statmod_1.5.0             UCSC.utils_1.0.0         
#>  [95] lazyeval_0.2.2            yaml_2.3.8               
#>  [97] evaluate_0.23             codetools_0.2-20         
#>  [99] tibble_3.2.1              alabaster.matrix_1.4.0   
#> [101] BiocManager_1.30.22       cli_3.6.2                
#> [103] munsell_0.5.1             jquerylib_0.1.4          
#> [105] Rcpp_1.0.12               png_0.1-8                
#> [107] XML_3.99-0.16.1           parallel_4.4.0           
#> [109] blob_1.2.4                sparseMatrixStats_1.16.0 
#> [111] bitops_1.0-7              viridisLite_0.4.2        
#> [113] alabaster.se_1.4.0        scales_1.3.0             
#> [115] purrr_1.0.2               crayon_1.5.2             
#> [117] rlang_1.1.3               KEGGREST_1.44.0