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:
  • barcode
  • camera
  • session-info-chunk-inserted-by-workflowr
  • unnamed-chunk-2
  • unnamed-chunk-3
  • unnamed-chunk-4
  • unnamed-chunk-5
  • unnamed-chunk-6

To ensure reproducibility of the results, delete the cache directory 5-geneset_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
Rmd 08bf260 HelenaLC 2019-06-17 update
html 08bf260 HelenaLC 2019-06-17 update

library(limma)
library(magrittr)
library(msigdbr)
library(dplyr)
library(reshape2)
library(SingleCellExperiment)
library(pheatmap)

Load data

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

Organize genesets & names

m_df <- msigdbr(
    species = "Mus musculus") %>%
    dplyr::filter(gs_cat %in% c("H", "C5", "C7"))

dat <- lapply(res$data, function(u) {
  ss <- strsplit(rownames(u), ".", fixed=TRUE)
  u$genes <- data.frame(
      ensembl_id = sapply(ss, .subset, 1), 
      symbol = sapply(ss, .subset, 2))
  return(u)
})
Loading required package: edgeR

Attaching package: 'edgeR'
The following object is masked from 'package:SingleCellExperiment':

    cpm
sapply(dat, function(u) 
    table(u$genes$symbol %in% m_df$gene_symbol))
      Astrocytes Endothelial Microglia Oligodendrocytes  OPC CPE cells
FALSE       1082        1085      1077             1081 1070      1078
TRUE        9960        9964      9919             9942 9934      9922
      Excit. Neuron Inhib. Neuron
FALSE          1091          1090
TRUE           9972          9972
sets <- split(m_df$gene_symbol, m_df$gs_name)
n <- vapply(sets, length, numeric(1))
sets <- sets[n >= 20 & n <= 1000]
length(sets)
[1] 8978

Run camera on ea. cluster

gs_dat <- mapply(function(uu, vv) {
    inds <- ids2indices(sets, uu$genes$symbol, remove.empty = TRUE)
    mm <- uu$design[colnames(uu),]
    v <- voom(uu, mm)
    f <- lmFit(v, mm)
    f <- eBayes(f)
    cf <- contrasts.fit(f, coefficients = 2)
    cf <- eBayes(cf)
    list(indices = inds, voom = v, design = mm, 
        cluster_id = vv, contrasts.fit = cf)
}, dat, names(dat), SIMPLIFY = FALSE)

gs_df <- lapply(gs_dat, function(u)
    camera(u$voom, u$indices, u$design) %>% 
        rownames_to_column("geneset")) %>% 
    bind_rows(.id = "cluster_id")

Heatmap summary

cats <- gs_df %>% 
    dplyr::filter(FDR < 1e-20) %>%
    pull(geneset) %>% unique
length(cats)
[1] 68
gs_df %>% 
    dplyr::filter(geneset %in% cats) %>%
    dplyr::mutate(neg_log10_fdr = -log10(FDR)) %>% 
    acast(cluster_id ~ geneset, value.var = "neg_log10_fdr") %>% 
    set_colnames(gsub("/*([^_]*)_(.*)", "\\2", colnames(.))) %>% 
    set_colnames(strtrim(colnames(.), 30)) %>%
    pheatmap(fontsize = 8, border_color = NA, color = colorRampPalette(
        c("aliceblue", "cornflowerblue", "violet", "red"))(50))

Version Author Date
08bf260 HelenaLC 2019-06-17

Barcode plots

cats_by_cluster <- gs_df %>% 
    group_by(cluster_id) %>% 
    top_n(10, dplyr::desc(FDR)) %>% 
    group_split %>% 
    lapply(pull, geneset) %>% 
    set_names(names(res$data))

lapply(names(res$data), function(k) {
    cat("## ", k, "\n")
    lapply(cats_by_cluster[[k]], function(c)
        barcodeplot(
            statistics = gs_dat[[k]]$contrasts.fit$t[, 1],
            index = gs_dat[[k]]$indices[[c]],
            quantiles=c(-1, 1) * qt(0.95, df = 14),
            main = c, cex.main = 0.8))
    cat("\n\n")
})

Astrocytes

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Endothelial

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Microglia

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Oligodendrocytes

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

OPC

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

CPE cells

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Excit. Neuron

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Inhib. Neuron

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

Version Author Date
08bf260 HelenaLC 2019-06-17

[[1]] NULL

[[2]] NULL

[[3]] NULL

[[4]] NULL

[[5]] NULL

[[6]] NULL

[[7]] NULL

[[8]] NULL

Write results to .rds & .csv

saveRDS(gs_dat, file.path("output", "MAGL-geneset_data.rds")) 
saveRDS(gs_df, file.path("output", "MAGL-geneset_df.rds")) 
write.csv(dplyr::filter(gs_df, FDR < 0.05),
    file.path("output", "MAGL-geneset_res.csv"),
    quote = FALSE, row.names = FALSE)

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  stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] edgeR_3.26.5                pheatmap_1.0.12            
 [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] msigdbr_6.2.1               tibble_2.1.3               
[17] dplyr_0.8.3                 magrittr_1.5               
[19] limma_3.40.2               

loaded via a namespace (and not attached):
 [1] locfit_1.5-9.1         tidyselect_0.2.5       xfun_0.8              
 [4] purrr_0.3.2            lattice_0.20-38        colorspace_1.4-1      
 [7] htmltools_0.3.6        yaml_2.2.0             rlang_0.4.0           
[10] pillar_1.4.2           glue_1.3.1             RColorBrewer_1.1-2    
[13] GenomeInfoDbData_1.2.1 plyr_1.8.4             stringr_1.4.0         
[16] zlibbioc_1.30.0        munsell_0.5.0          gtable_0.3.0          
[19] workflowr_1.4.0        codetools_0.2-16       evaluate_0.14         
[22] knitr_1.23             highr_0.8              Rcpp_1.0.1            
[25] backports_1.1.4        scales_1.0.0           XVector_0.24.0        
[28] fs_1.3.1               digest_0.6.20          stringi_1.4.3         
[31] rprojroot_1.3-2        grid_3.6.0             tools_3.6.0           
[34] bitops_1.0-6           RCurl_1.95-4.12        crayon_1.3.4          
[37] whisker_0.3-2          pkgconfig_2.0.2        Matrix_1.2-17         
[40] assertthat_0.2.1       rmarkdown_1.14         rstudioapi_0.10       
[43] R6_2.4.0               git2r_0.26.1           compiler_3.6.0