Last updated: 2019-07-26

Checks: 4 3

Knit directory: MAGL/

This reproducible R Markdown analysis was created with workflowr (version 1.4.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

The global environment had objects present when the code in the R Markdown file was run. These objects can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment. Use wflow_publish or wflow_build to ensure that the code is always run in an empty environment.

The following objects were defined in the global environment when these results were created:

Name Class Size
data environment 56 bytes
env environment 56 bytes

The command set.seed(20190311) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

The following chunks had caches available:
  • unnamed-chunk-1
  • unnamed-chunk-2
  • unnamed-chunk-3
  • unnamed-chunk-4
  • unnamed-chunk-5
  • violins

To ensure reproducibility of the results, delete the cache directory 4-visualization_cache and re-run the analysis. To have workflowr automatically delete the cache directory prior to building the file, set delete_cache = TRUE when running wflow_build() or wflow_publish().

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    ._.Renviron
    Ignored:    ._.gitignore
    Ignored:    ._README.md
    Ignored:    ._Snakefile
    Ignored:    ._config.yaml
    Ignored:    ._session_info.txt
    Ignored:    .snakemake/
    Ignored:    MAGL/.DS_Store
    Ignored:    MAGL/.RData
    Ignored:    MAGL/.Rhistory
    Ignored:    MAGL/._.DS_Store
    Ignored:    MAGL/._.Rprofile
    Ignored:    MAGL/._.gitignore
    Ignored:    MAGL/._data
    Ignored:    MAGL/analysis/._refs.bib
    Ignored:    MAGL/analysis/0-preprocessing_cache/
    Ignored:    MAGL/analysis/1-clustering_cache/
    Ignored:    MAGL/analysis/3-differential_cache/
    Ignored:    MAGL/analysis/4-visualization_cache/
    Ignored:    MAGL/analysis/5-geneset_cache/
    Ignored:    MAGL/analysis/6-more_cache/
    Ignored:    MAGL/code/._utils.R
    Ignored:    MAGL/data/
    Ignored:    MAGL/output/
    Ignored:    data/
    Ignored:    figures/
    Ignored:    meta/
    Ignored:    results/
    Ignored:    scripts/.DS_Store
    Ignored:    scripts/._.DS_Store
    Ignored:    scripts/._apply_scdd.R
    Ignored:    scripts/._plot_perf_by_expr.R
    Ignored:    scripts/._plot_perf_by_ss.R
    Ignored:    scripts/._plot_runtimes.R
    Ignored:    scripts/._prep_magl.R
    Ignored:    scripts/._prep_sim.R
    Ignored:    scripts/._session_info.R
    Ignored:    scripts/._sim_qc.R
    Ignored:    scripts/._utils.R

Untracked files:
    Untracked:  .RData
    Untracked:  .RDataTmp
    Untracked:  .Rhistory
    Untracked:  MAGL/code/utils.R
    Untracked:  MAGL/current
    Untracked:  figs/

Unstaged changes:
    Modified:   MAGL/.Rprofile
    Modified:   MAGL/analysis/4-visualization.Rmd
    Modified:   MAGL/analysis/5-geneset.Rmd
    Deleted:    scripts/plot_perf_by_lfc.R
    Deleted:    scripts/plot_sim_ex.R
    Deleted:    scripts/prep_data.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
html 033e536 HelenaLC 2019-07-11 update landing page
Rmd 08bf260 HelenaLC 2019-06-17 update
html 08bf260 HelenaLC 2019-06-17 update

library(cowplot)
library(ComplexHeatmap)
library(dplyr)
library(ggplot2)
library(muscat)
library(RColorBrewer)
library(purrr)
library(reshape2)
library(scater)
library(SingleCellExperiment)
library(UpSetR)

Load data & results

sce <- readRDS(file.path("output", "MAGL-SCE.rds"))
res <- readRDS(file.path("output", "MAGL-DS_res.rds"))

For easy accession, we store the character vectors of cluster and sample IDs, as well as the number of clusters and samples:

nk <- length(kids <- set_names(levels(sce$cluster_id)))
ns <- length(sids <- set_names(levels(sce$sample_id)))
ng <- length(gids <- set_names(levels(sce$group_id)))

Results filtering & overview

To get a general overview of the differential testing results, we first filter them to retain hits with \(\text{FDR}<5\%\) and \(~|~logFC~|~>1\), and view the number & percentage of differential findings by cluster. Finally, we extract the top hits (lowest adj. p-value) in each cluster.

tbl <- res$table[[1]] %>% 
    # filter abs(logFC) > 1 & FDR < 0.05
    lapply(dplyr::filter, p_adj.loc < 0.05, abs(logFC) > 1) %>% 
    # sort by FDR
    lapply(dplyr::arrange, p_adj.loc)

# nb. & % of hits by cluster
n_de <- vapply(tbl, nrow, numeric(1))
cbind(n_de, perc = round(n_de / nrow(sce) * 100, 2))
                 n_de perc
Astrocytes        560 5.06
Endothelial       641 5.79
Microglia         319 2.88
Oligodendrocytes  123 1.11
OPC               204 1.84
CPE cells          84 0.76
Excit. Neuron      28 0.25
Inhib. Neuron       9 0.08

Between-cluster concordance

deg_by_k <- lapply(tbl, pull, "gene")
upset(fromList(deg_by_k), sets = rev(kids)[-c(1, 2)],
    mb.ratio = c(0.6, 0.4), nintersects = 30,  
    text.scale = 0.8, point.size = 2, line.size = 0.4)

Version Author Date
08bf260 HelenaLC 2019-06-17

Cell-level visualization

The scater[@McCarthy2017-scater] packages provides a variety of visualizations for single-cell data. Here, we use plotExpression to render violin plots of the top differential genes identified for each cluster. We specify x = "sample_id" to obtain one violin per sample, and colour_by = "group_id" to signify the experimental condition each sample belongs to.

# split cells by cluster
cs_by_k <- split(colnames(sce), sce$cluster_id)
# get top-hits for ea. cluster
n <- 8
top_gs <- lapply(tbl, function(u) {
    n <- ifelse(nrow(u) < n, nrow(u), n)
    u$gene[seq_len(n)]
})
for (k in kids) {
    cat("## ", k, "\n")
    if (length(top_gs[[k]]) != 0)
        print(plotExpression(
            sce[, cs_by_k[[k]]], features = top_gs[[k]], 
            x = "sample_id", colour_by = "group_id") +
        guides(fill = guide_legend(override.aes = list(size = 2, alpha = 1))) +
        theme_classic() + theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)))
    cat("\n\n")
}

Astrocytes

Version Author Date
08bf260 HelenaLC 2019-06-17

Endothelial

Version Author Date
08bf260 HelenaLC 2019-06-17

Microglia

Version Author Date
08bf260 HelenaLC 2019-06-17

Oligodendrocytes

Version Author Date
08bf260 HelenaLC 2019-06-17

OPC

Version Author Date
08bf260 HelenaLC 2019-06-17

CPE cells

Version Author Date
08bf260 HelenaLC 2019-06-17

Excit. Neuron

Version Author Date
08bf260 HelenaLC 2019-06-17

Inhib. Neuron

Version Author Date
08bf260 HelenaLC 2019-06-17

Dimension reduction

for (dr in c("TSNE", "UMAP")) {
    cat("## ", dr, "\n") 
    df <- data.frame(reducedDim(sce, dr), colData(sce))
    labs <- paste(switch(dr, TSNE = "t-SNE", dr), "dim.", 1:2)
    p <- ggplot(df, aes_string(x = colnames(df)[1], y = colnames(df)[2])) + 
        labs(x = labs[1], y = labs[2]) +
        theme_void() + theme(aspect.ratio = 1, 
            legend.key.height = unit(2, "mm"), 
            legend.position = "bottom")
    p1 <-  p + geom_point(size = 0.1, alpha = 0.2, aes(col = cluster_id)) + 
        scale_color_manual(values = CATALYST:::.cluster_cols) +
        guides(color = guide_legend(ncol = 3,
            override.aes = list(size = 2, alpha = 1)))
    p2 <- p + geom_point(size = 0.1, alpha = 0.2, aes(col = group_id)) +
        guides(color = guide_legend(ncol = 1,
            override.aes = list(size = 2, alpha = 1)))
    ps <- plot_grid(
        p1 + theme(legend.position = "none"),
        p2 + theme(legend.position = "none"))
    ls <- plot_grid(get_legend(p1), get_legend(p2), rel_widths = c(4, 1))
    print(plot_grid(ps, ls, ncol = 1, rel_heights = c(3, 1)))
    cat("\n\n")
}

TSNE

Registered S3 methods overwritten by 'car':
  method                          from
  influence.merMod                lme4
  cooks.distance.influence.merMod lme4
  dfbeta.influence.merMod         lme4
  dfbetas.influence.merMod        lme4

Version Author Date
08bf260 HelenaLC 2019-06-17

UMAP

Version Author Date
08bf260 HelenaLC 2019-06-17

sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS:   /usr/local/R/R-3.6.0/lib/libRblas.so
LAPACK: /usr/local/R/R-3.6.0/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
 [1] stats4    parallel  grid      stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
 [1] UpSetR_1.4.0                scater_1.12.2              
 [3] SingleCellExperiment_1.6.0  SummarizedExperiment_1.14.0
 [5] DelayedArray_0.10.0         BiocParallel_1.18.0        
 [7] matrixStats_0.54.0          Biobase_2.44.0             
 [9] GenomicRanges_1.36.0        GenomeInfoDb_1.20.0        
[11] IRanges_2.18.1              S4Vectors_0.22.0           
[13] BiocGenerics_0.30.0         reshape2_1.4.3             
[15] purrr_0.3.2                 RColorBrewer_1.1-2         
[17] muscat_0.99.10              ggplot2_3.2.0              
[19] dplyr_0.8.3                 ComplexHeatmap_2.0.0       
[21] cowplot_1.0.0               BiocStyle_2.12.0           

loaded via a namespace (and not attached):
  [1] tidyr_0.8.3                 acepack_1.4.1              
  [3] bit64_0.9-7                 knitr_1.23                 
  [5] irlba_2.3.3                 multcomp_1.4-10            
  [7] data.table_1.12.2           rpart_4.1-15               
  [9] RCurl_1.95-4.12             doParallel_1.0.14          
 [11] flowCore_1.50.0             TH.data_1.0-10             
 [13] RSQLite_2.1.1               future_1.14.0              
 [15] bit_1.1-14                  httpuv_1.5.1               
 [17] assertthat_0.2.1            viridis_0.5.1              
 [19] xfun_0.8                    hms_0.5.0                  
 [21] evaluate_0.14               promises_1.0.1             
 [23] DEoptimR_1.0-8              progress_1.2.2             
 [25] caTools_1.17.1.2            readxl_1.3.1               
 [27] igraph_1.2.4.1              DBI_1.0.0                  
 [29] geneplotter_1.62.0          CATALYST_1.8.5             
 [31] htmlwidgets_1.3             backports_1.1.4            
 [33] annotate_1.62.0             vctrs_0.2.0                
 [35] abind_1.4-5                 withr_2.1.2                
 [37] grr_0.9.5                   robustbase_0.93-5          
 [39] checkmate_1.9.4             sctransform_0.2.0          
 [41] prettyunits_1.0.2           scran_1.12.1               
 [43] cluster_2.1.0               lazyeval_0.2.2             
 [45] crayon_1.3.4                drc_3.0-1                  
 [47] genefilter_1.66.0           labeling_0.3               
 [49] edgeR_3.26.5                pkgconfig_2.0.2            
 [51] nlme_3.1-140                vipor_0.4.5                
 [53] blme_1.0-4                  nnet_7.3-12                
 [55] rlang_0.4.0                 globals_0.12.4             
 [57] sandwich_2.5-1              rsvd_1.0.1                 
 [59] cellranger_1.1.0            rprojroot_1.3-2            
 [61] graph_1.62.0                Matrix_1.2-17              
 [63] carData_3.0-2               boot_1.3-23                
 [65] zoo_1.8-6                   Matrix.utils_0.9.7         
 [67] base64enc_0.1-3             beeswarm_0.2.3             
 [69] whisker_0.3-2               ggridges_0.5.1             
 [71] GlobalOptions_0.1.0         png_0.1-7                  
 [73] viridisLite_0.3.0           rjson_0.2.20               
 [75] bitops_1.0-6                shinydashboard_0.7.1       
 [77] ConsensusClusterPlus_1.48.0 KernSmooth_2.23-15         
 [79] blob_1.2.0                  DelayedMatrixStats_1.6.0   
 [81] workflowr_1.4.0             shape_1.4.4                
 [83] stringr_1.4.0               scales_1.0.0               
 [85] memoise_1.1.0               magrittr_1.5               
 [87] plyr_1.8.4                  gplots_3.0.1.1             
 [89] gdata_2.18.0                zlibbioc_1.30.0            
 [91] compiler_3.6.0              dqrng_0.2.1                
 [93] plotrix_3.7-6               clue_0.3-57                
 [95] lme4_1.1-21                 DESeq2_1.24.0              
 [97] rrcov_1.4-7                 XVector_0.24.0             
 [99] lmerTest_3.1-0              listenv_0.7.0              
[101] TMB_1.7.15                  htmlTable_1.13.1           
[103] Formula_1.2-3               FlowSOM_1.16.0             
[105] MASS_7.3-51.4               tidyselect_0.2.5           
[107] stringi_1.4.3               forcats_0.4.0              
[109] shinyBS_0.61                highr_0.8                  
[111] yaml_2.2.0                  BiocSingular_1.0.0         
[113] locfit_1.5-9.1              latticeExtra_0.6-28        
[115] ggrepel_0.8.1               tools_3.6.0                
[117] future.apply_1.3.0          rio_0.5.16                 
[119] circlize_0.4.6              rstudioapi_0.10            
[121] foreach_1.4.4               foreign_0.8-71             
[123] git2r_0.26.1                gridExtra_2.3              
[125] Rtsne_0.15                  digest_0.6.20              
[127] BiocManager_1.30.4          shiny_1.3.2                
[129] Rcpp_1.0.1                  car_3.0-3                  
[131] later_0.8.0                 httr_1.4.0                 
[133] AnnotationDbi_1.46.0        colorspace_1.4-1           
[135] XML_3.98-1.20               fs_1.3.1                   
[137] splines_3.6.0               statmod_1.4.32             
[139] plotly_4.9.0                xtable_1.8-4               
[141] jsonlite_1.6                nloptr_1.2.1               
[143] dynamicTreeCut_1.63-1       corpcor_1.6.9              
[145] zeallot_0.1.0               R6_2.4.0                   
[147] Hmisc_4.2-0                 mime_0.7                   
[149] pillar_1.4.2                htmltools_0.3.6            
[151] nnls_1.4                    glue_1.3.1                 
[153] minqa_1.2.4                 DT_0.7                     
[155] BiocNeighbors_1.2.0         codetools_0.2-16           
[157] tsne_0.1-3                  pcaPP_1.9-73               
[159] mvtnorm_1.0-11              lattice_0.20-38            
[161] tibble_2.1.3                numDeriv_2016.8-1.1        
[163] pbkrtest_0.4-7              curl_3.3                   
[165] ggbeeswarm_0.6.0            colorRamps_2.3             
[167] gtools_3.8.1                shinyjs_1.0                
[169] zip_2.0.3                   openxlsx_4.1.0.1           
[171] survival_2.44-1.1           limma_3.40.2               
[173] glmmTMB_0.2.3               rmarkdown_1.14             
[175] munsell_0.5.0               GetoptLong_0.1.7           
[177] GenomeInfoDbData_1.2.1      iterators_1.0.10           
[179] variancePartition_1.14.0    haven_2.1.1                
[181] gtable_0.3.0