Last updated: 2019-12-06

Checks: 6 1

Knit directory: bentsen-rausch-2019/

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.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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(20191021) 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.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

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:    .Rproj.user/
    Ignored:    test_files/

Untracked files:
    Untracked:  analysis/figure_6.Rmd
    Untracked:  analysis/figure_7.Rmd
    Untracked:  analysis/olig_ttest_padj.csv
    Untracked:  code/sc_functions.R
    Untracked:  data/bulk/
    Untracked:  data/fgf_filtered_nuclei.RDS
    Untracked:  data/figures/
    Untracked:  data/filtglia.RDS
    Untracked:  data/glia/
    Untracked:  data/lps1.txt
    Untracked:  data/mcao1.txt
    Untracked:  data/mcao_d3.txt
    Untracked:  data/mcaod7.txt
    Untracked:  data/mouse_data/
    Untracked:  data/neur_astro_induce.xlsx
    Untracked:  data/neuron/
    Untracked:  data/synaptic_activity_induced.xlsx
    Untracked:  olig_ttest_padj.csv
    Untracked:  output/agrp_pcgenes.csv
    Untracked:  output/all_wc_markers.csv
    Untracked:  output/allglia_wgcna_genemodules.csv
    Untracked:  output/bulk/
    Untracked:  output/fig.RData
    Untracked:  output/fig4_part2.RData
    Untracked:  output/glia/
    Untracked:  output/glial_markergenes.csv
    Untracked:  output/integrated_all_markergenes.csv
    Untracked:  output/integrated_neuronmarkers.csv
    Untracked:  output/neuron/
    Untracked:  suppglia.Rmd
    Untracked:  wc_de.pdf

Unstaged changes:
    Modified:   analysis/9_wc_processing.Rmd
    Modified:   analysis/figure_1.Rmd
    Modified:   analysis/index.Rmd

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 d1c9939 Full Name 2019-12-06 wflow_publish(“analysis/supp1.Rmd”)

#Load Libraries

library(Seurat)
library(tidyverse)
library(DESeq2)
library(here)
library(future)
library(cluster)
library(parallelDist)
library(ggplot2)
library(cowplot)
library(ggrepel)
library(future.apply)
library(reshape2)
library(gProfileR)
library(ggsignif)
plan("multiprocess", workers = 40)
options(future.globals.maxSize = 4000 * 1024^2)

Load data

knitr::opts_chunk$set(message = FALSE, warnings = FALSE)
source(here("code/sc_functions.R"))
fgf.neur <- readRDS(here("data/neuron/fgf_neur_mappingscores.RDS"))

Filter and recluster unmapped data

fgf.neur.unmap <- subset(fgf.neur, ref == "unmap")
fgf.neur.unmap <- reprocess_subset(obj = fgf.neur.unmap, dims = 30, resolution = 0.3)
Warning in FindVariableFeatures.Assay(object = assay.data, selection.method
= selection.method, : selection.method set to 'vst' but count slot is
empty; will use data slot instead
Warning in eval(predvars, data, env): NaNs produced
Warning in hvf.info$variance.expected[not.const] <- 10^fit$fitted: number
of items to replace is not a multiple of replacement length
Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
This message will be shown once per session
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck

Number of nodes: 11986
Number of edges: 612849

Running Louvain algorithm...
Maximum modularity in 10 random starts: 0.8920
Number of communities: 14
Elapsed time: 1 seconds
DefaultAssay(fgf.neur.unmap) <- "SCT"
lab.mark <- FindAllMarkers(fgf.neur.unmap, only.pos = T, logfc.threshold = 0.5)
write_csv(x = lab.mark, here("output/neuron/neuron_clusters_unmapped.csv"))

Plot unmapped neurons

data.frame(Embeddings(fgf.neur.unmap, reduction = "umap")) %>% 
  mutate(group = fgf.neur.unmap$group) %>%
  mutate(celltype = Idents(fgf.neur.unmap)) %>%
  sample_frac(1L) -> umap_embed
colnames(umap_embed)[1:2] <- c("UMAP 1", "UMAP 2")

label.df <- data.frame(cluster=levels(umap_embed$celltype),label=levels(umap_embed$celltype))
label.df_2 <- umap_embed %>% 
  group_by(celltype) %>% 
  dplyr::summarize(x = median(`UMAP 1`), y = median(`UMAP 2`)) 

prop_neur_byclus <- ggplot(umap_embed, aes(x=`UMAP 1`, y=`UMAP 2`, color=celltype)) + 
  geom_point(size=0.5, alpha=0.5)  + 
  geom_text_repel(data = label.df_2, aes(label = celltype, x=x, y=y), 
                  size=2, 
                  inherit.aes = F, bg.colour="white", fontface="bold",
                  force=1, min.segment.length = unit(0, 'lines')) +
  xlab("UMAP1") + ylab("UMAP2") +
  ggpubr::theme_pubr(legend="none") + ggsci::scale_color_igv() + theme_figure 
prop_neur_byclus

ggsave("data/figures/supp/umap_plot.pdf")

Extract color scheme

g <- ggplot_build(prop_neur_byclus)
cols<-data.frame(colours = as.character(unique(g$data[[1]]$colour)), 
             label = as.character(unique(g$plot$data[, g$plot$labels$colour])))
colvec<-as.character(cols$colours)
names(colvec)<-as.character(cols$label)

Resampling DEG

#Generate matrices
split_mats <- splitbysamp(fgf.neur.unmap, split_by="sample")
names(split_mats) <- unique(Idents(fgf.neur.unmap))
pb<-replicate(100, gen_pseudo_counts(split_mats, ncells=10)) 
names(pb) <- paste0(rep(names(split_mats)),"_",rep(1:100, each=length(names(split_mats))))
# Generate DESeq2 Objects
res<-rundeseq(pb)

Boxplot

degenes<-lapply(res, function(x) {
  tryCatch({
    y<-x[[2]]
    y<-na.omit(y)
    data.frame(y)%>%filter(padj<0.1)%>%nrow()}, 
    error=function(err) {NA})
})

boxplot<-lapply(unique(Idents(fgf.neur.unmap)), function(x) {
  z<-unlist(degenes[grep(paste0("^",x,"_"), names(degenes))])
})

names(boxplot)<-unique(Idents(fgf.neur.unmap))
boxplot<-t(as.data.frame(do.call("rbind", boxplot)))
rownames(boxplot)<-1:100
genenum<-melt(boxplot)
write_csv(genenum, path = here("output/neuron/genenum_supplemental.csv"))

resampling results

deboxplot<-ggplot(genenum,aes(x=reorder(Var2, -value), y=value, fill=factor(Var2))) + 
  geom_boxplot(notch = T, alpha=0.75) + 
  scale_fill_manual(values = colvec) +
  ggpubr::theme_pubr() +
  theme(axis.text.x = element_text(angle=45, hjust=1), legend.position = "none") + 
  ylab("Number DEG") + xlab(NULL) + theme_figure
deboxplot

ggsave(here("data/figures/supp/deboxplot.pdf"))

sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Storage

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.3.so

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

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

other attached packages:
 [1] ggsignif_0.5.0              gProfileR_0.6.7            
 [3] reshape2_1.4.3              future.apply_1.3.0         
 [5] ggrepel_0.8.0.9000          cowplot_1.0.0              
 [7] parallelDist_0.2.4          cluster_2.1.0              
 [9] future_1.14.0               here_0.1                   
[11] DESeq2_1.22.2               SummarizedExperiment_1.12.0
[13] DelayedArray_0.8.0          BiocParallel_1.16.6        
[15] matrixStats_0.54.0          Biobase_2.42.0             
[17] GenomicRanges_1.34.0        GenomeInfoDb_1.18.2        
[19] IRanges_2.16.0              S4Vectors_0.20.1           
[21] BiocGenerics_0.28.0         forcats_0.4.0              
[23] stringr_1.4.0               dplyr_0.8.3                
[25] purrr_0.3.2                 readr_1.3.1.9000           
[27] tidyr_0.8.3                 tibble_2.1.3               
[29] ggplot2_3.2.1               tidyverse_1.2.1            
[31] Seurat_3.0.3.9036          

loaded via a namespace (and not attached):
  [1] reticulate_1.13        R.utils_2.9.0          tidyselect_0.2.5      
  [4] RSQLite_2.1.1          AnnotationDbi_1.44.0   htmlwidgets_1.3       
  [7] grid_3.5.3             Rtsne_0.15             munsell_0.5.0         
 [10] codetools_0.2-16       ica_1.0-2              withr_2.1.2           
 [13] colorspace_1.4-1       highr_0.8              knitr_1.23            
 [16] rstudioapi_0.10        ROCR_1.0-7             gbRd_0.4-11           
 [19] listenv_0.7.0          labeling_0.3           Rdpack_0.11-0         
 [22] git2r_0.25.2           GenomeInfoDbData_1.2.0 bit64_0.9-7           
 [25] rprojroot_1.3-2        vctrs_0.2.0            generics_0.0.2        
 [28] xfun_0.8               R6_2.4.0               rsvd_1.0.2            
 [31] locfit_1.5-9.1         bitops_1.0-6           assertthat_0.2.1      
 [34] SDMTools_1.1-221.1     scales_1.0.0           nnet_7.3-12           
 [37] gtable_0.3.0           npsurv_0.4-0           globals_0.12.4        
 [40] workflowr_1.4.0        rlang_0.4.0            zeallot_0.1.0         
 [43] genefilter_1.64.0      splines_3.5.3          lazyeval_0.2.2        
 [46] acepack_1.4.1          broom_0.5.2            checkmate_1.9.4       
 [49] yaml_2.2.0             modelr_0.1.4           backports_1.1.4       
 [52] Hmisc_4.2-0            tools_3.5.3            gplots_3.0.1.1        
 [55] RColorBrewer_1.1-2     ggridges_0.5.1         Rcpp_1.0.2            
 [58] plyr_1.8.4             base64enc_0.1-3        zlibbioc_1.28.0       
 [61] RCurl_1.95-4.12        ggpubr_0.2.1           rpart_4.1-15          
 [64] pbapply_1.4-1          zoo_1.8-6              haven_2.1.0           
 [67] fs_1.3.1               magrittr_1.5           RSpectra_0.15-0       
 [70] data.table_1.12.2      lmtest_0.9-37          RANN_2.6.1            
 [73] whisker_0.3-2          fitdistrplus_1.0-14    hms_0.5.0             
 [76] lsei_1.2-0             evaluate_0.14          xtable_1.8-4          
 [79] XML_3.98-1.20          readxl_1.3.1           gridExtra_2.3         
 [82] compiler_3.5.3         KernSmooth_2.23-15     crayon_1.3.4          
 [85] R.oo_1.22.0            htmltools_0.3.6        Formula_1.2-3         
 [88] geneplotter_1.60.0     RcppParallel_4.4.3     lubridate_1.7.4       
 [91] DBI_1.0.0              MASS_7.3-51.4          Matrix_1.2-17         
 [94] cli_1.1.0              R.methodsS3_1.7.1      gdata_2.18.0          
 [97] metap_1.1              igraph_1.2.4.1         pkgconfig_2.0.2       
[100] foreign_0.8-71         plotly_4.9.0           xml2_1.2.0            
[103] annotate_1.60.1        XVector_0.22.0         bibtex_0.4.2          
[106] rvest_0.3.4            digest_0.6.20          sctransform_0.2.0     
[109] RcppAnnoy_0.0.12       tsne_0.1-3             rmarkdown_1.13        
[112] cellranger_1.1.0       leiden_0.3.1           htmlTable_1.13.1      
[115] uwot_0.1.3             gtools_3.8.1           nlme_3.1-140          
[118] jsonlite_1.6           viridisLite_0.3.0      pillar_1.4.2          
[121] ggsci_2.9              lattice_0.20-38        httr_1.4.1            
[124] survival_2.44-1.1      glue_1.3.1             png_0.1-7             
[127] bit_1.1-14             stringi_1.4.3          blob_1.1.1            
[130] latticeExtra_0.6-28    caTools_1.17.1.2       memoise_1.1.0         
[133] irlba_2.3.3            ape_5.3