Last updated: 2020-08-07

Checks: 7 0

Knit directory: neural_scRNAseq/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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.

Great job! The global environment was empty. Objects defined in the global environment 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.

The command set.seed(20200522) 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 results in this page were generated with repository version 7562682. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    ._.DS_Store
    Ignored:    ._Rplots.pdf
    Ignored:    .__workflowr.yml
    Ignored:    ._neural_scRNAseq.Rproj
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    analysis/._.DS_Store
    Ignored:    analysis/._01-preprocessing.Rmd
    Ignored:    analysis/._01-preprocessing.html
    Ignored:    analysis/._02.1-SampleQC.Rmd
    Ignored:    analysis/._03-filtering.Rmd
    Ignored:    analysis/._04-clustering.Rmd
    Ignored:    analysis/._04-clustering.knit.md
    Ignored:    analysis/._04.1-cell_cycle.Rmd
    Ignored:    analysis/._05-annotation.Rmd
    Ignored:    analysis/._Lam-0-NSC_no_integration.Rmd
    Ignored:    analysis/._Lam-01-NSC_integration.Rmd
    Ignored:    analysis/._Lam-02-NSC_annotation.Rmd
    Ignored:    analysis/._NSC-1-clustering.Rmd
    Ignored:    analysis/._NSC-2-annotation.Rmd
    Ignored:    analysis/.__site.yml
    Ignored:    analysis/._additional_filtering.Rmd
    Ignored:    analysis/._additional_filtering_clustering.Rmd
    Ignored:    analysis/._index.Rmd
    Ignored:    analysis/01-preprocessing_cache/
    Ignored:    analysis/02-1-SampleQC_cache/
    Ignored:    analysis/02-quality_control_cache/
    Ignored:    analysis/02.1-SampleQC_cache/
    Ignored:    analysis/03-filtering_cache/
    Ignored:    analysis/04-clustering_cache/
    Ignored:    analysis/04.1-cell_cycle_cache/
    Ignored:    analysis/05-annotation_cache/
    Ignored:    analysis/Lam-01-NSC_integration_cache/
    Ignored:    analysis/NSC-1-clustering_cache/
    Ignored:    analysis/NSC-2-annotation_cache/
    Ignored:    analysis/additional_filtering_cache/
    Ignored:    analysis/additional_filtering_clustering_cache/
    Ignored:    analysis/sample5_QC_cache/
    Ignored:    data/.DS_Store
    Ignored:    data/._.DS_Store
    Ignored:    data/._.smbdeleteAAA17ed8b4b
    Ignored:    data/._Lam_figure2_markers.R
    Ignored:    data/._known_NSC_markers.R
    Ignored:    data/._known_cell_type_markers.R
    Ignored:    data/._metadata.csv
    Ignored:    data/data_sushi/
    Ignored:    data/filtered_feature_matrices/
    Ignored:    output/.DS_Store
    Ignored:    output/._.DS_Store
    Ignored:    output/Lam-01-clustering.rds
    Ignored:    output/NSC_1_clustering.rds
    Ignored:    output/additional_filtering.rds
    Ignored:    output/figures/
    Ignored:    output/sce_01_preprocessing.rds
    Ignored:    output/sce_02_quality_control.rds
    Ignored:    output/sce_03_filtering.rds
    Ignored:    output/sce_preprocessing.rds
    Ignored:    output/so_04_1_cell_cycle.rds
    Ignored:    output/so_04_clustering.rds
    Ignored:    output/so_additional_filtering_clustering.rds

Untracked files:
    Untracked:  Rplots.pdf
    Untracked:  analysis/Lam-0-NSC_no_integration.Rmd
    Untracked:  analysis/additional_filtering.Rmd
    Untracked:  analysis/additional_filtering_clustering.Rmd
    Untracked:  analysis/sample5_QC.Rmd
    Untracked:  data/Homo_sapiens.GRCh38.98.sorted.gtf
    Untracked:  data/Lam_et_al/
    Untracked:  scripts/

Unstaged changes:
    Modified:   analysis/_site.yml

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 repository in which changes were made to the R Markdown (analysis/Lam-02-NSC_annotation.Rmd) and HTML (docs/Lam-02-NSC_annotation.html) files. If you've configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 7562682 khembach 2020-08-07 adjust fig sizes
html 875e3c5 khembach 2020-07-10 Build site.
Rmd 15a0ad2 khembach 2020-07-10 compare cell cluster membership before and after NES integration; merge
html a1ebb78 khembach 2020-07-08 Build site.
Rmd d8bd339 khembach 2020-07-08 NSC integration with NES from Lam et al.

Load packages

library(ComplexHeatmap)
library(cowplot)
library(ggplot2)
library(dplyr)
library(muscat)
library(purrr)
library(RColorBrewer)
library(viridis)
library(scran)
library(Seurat)
library(SingleCellExperiment)
library(stringr)
library(RCurl)
library(BiocParallel)

Load data & convert to SCE

so <- readRDS(file.path("output", "Lam-01-clustering.rds"))
sce <- as.SingleCellExperiment(so, assay = "RNA")
colData(sce) <- as.data.frame(colData(sce)) %>% 
    mutate_if(is.character, as.factor) %>% 
    DataFrame(row.names = colnames(sce))

Number of clusters by resolution

cluster_cols <- grep("res.[0-9]", colnames(colData(sce)), value = TRUE)
sapply(colData(sce)[cluster_cols], nlevels)
       SCT_snn_res.0.8        RNA_snn_res.0.4 integrated_snn_res.0.1 
                     0                      7                      5 
integrated_snn_res.0.2 integrated_snn_res.0.4 integrated_snn_res.0.8 
                     6                      7                     12 
  integrated_snn_res.1 integrated_snn_res.1.2   integrated_snn_res.2 
                    14                     17                     24 

Cluster-sample counts

# set cluster IDs to resolution 0.4 clustering
so <- SetIdent(so, value = "integrated_snn_res.0.4")
so@meta.data$cluster_id <- Idents(so)
sce$cluster_id <- Idents(so)
(n_cells <- table(sce$cluster_id, sce$sample_id))
   
    1NSC 2NSC  NES
  0 2896 3024  215
  1 1770 1725  206
  2 1669 1582  188
  3  983 1042   88
  4  564  600   19
  5  412  401   22
  6   37   34   30

Relative cluster-abundances

fqs <- prop.table(n_cells, margin = 2)
mat <- as.matrix(unclass(fqs))
Heatmap(mat,
    col = rev(brewer.pal(11, "RdGy")[-6]),
    name = "Frequency",
    cluster_rows = FALSE,
    cluster_columns = FALSE,
    row_names_side = "left",
    row_title = "cluster_id",
    column_title = "sample_id",
    column_title_side = "bottom",
    rect_gp = gpar(col = "white"),
    cell_fun = function(i, j, x, y, width, height, fill)
        grid.text(round(mat[j, i] * 100, 2), x = x, y = y, 
            gp = gpar(col = "white", fontsize = 10)))

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

Distribution of NES subtypes per cluster

In the paper, they identified clusters that were specific for different cell types. For our analysis, we merge identical cell subtypes from the different cell lines.

levels(sce$cell_subtype_nes) 
[1] "Glia_progenitor"                "Neural_prog_Proliferating_SAi2"
[3] "Neural_progenitor"              "Neural_progenitor_Ctrl7"       
[5] "Neural_progenitor_SAi2"         "Neuroblast_Ctrl7"              
[7] "Radial_Glia_progenitor"        
## merge identical cell subtypes
levels(sce$cell_subtype_nes)  <- 
  c("Glia_progenitor", "Neural_prog_Proliferating", "Neural_progenitor", 
    "Neural_progenitor", "Neural_progenitor", "Neuroblast", 
    "Radial_Glia_progenitor")
levels(sce$cell_subtype_nes) 
[1] "Glia_progenitor"           "Neural_prog_Proliferating"
[3] "Neural_progenitor"         "Neuroblast"               
[5] "Radial_Glia_progenitor"   
(n_types <- table(sce$cluster_id, sce$cell_subtype_nes))
   
    Glia_progenitor Neural_prog_Proliferating Neural_progenitor Neuroblast
  0              44                        13               121          2
  1              26                        62               103          0
  2              33                        20               113          2
  3              43                         7                38          0
  4              15                         1                 3          0
  5               7                         4                11          0
  6               0                         2                 8         18
   
    Radial_Glia_progenitor
  0                     35
  1                     15
  2                     20
  3                      0
  4                      0
  5                      0
  6                      2
fqs <- prop.table(n_types, margin = 2)
mat <- as.matrix(unclass(fqs))
Heatmap(mat,
    col = rev(brewer.pal(11, "RdGy")[-6]),
    name = "Frequency",
    cluster_rows = FALSE,
    cluster_columns = FALSE,
    row_names_side = "left",
    row_title = "cluster_id",
    column_title = "sample_id",
    column_title_side = "bottom",
    rect_gp = gpar(col = "white"),
    cell_fun = function(i, j, x, y, width, height, fill)
        grid.text(round(mat[j, i] * 100, 2), x = x, y = y, 
            gp = gpar(col = "white", fontsize = 10)))

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

DR colored by cluster ID

.plot_dr <- function(so, dr, id)
    DimPlot(so, group.by = id, reduction = dr, pt.size = 0.4) +
        guides(col = guide_legend(nrow = 11, 
            override.aes = list(size = 3, alpha = 1))) +
        theme_void() + theme(aspect.ratio = 1)
ids <- c("cluster_id", "group_id", "sample_id")
for (id in ids) {
    cat("## ", id, "\n")
    p1 <- .plot_dr(so, "tsne", id)
    lgd <- get_legend(p1)
    p1 <- p1 + theme(legend.position = "none")
    p2 <- .plot_dr(so, "umap", id) + theme(legend.position = "none")
    ps <- plot_grid(plotlist = list(p1, p2), nrow = 1)
    p <- plot_grid(ps, lgd, nrow = 1, rel_widths = c(1, 0.2))
    print(p)
    cat("\n\n")
}

cluster_id

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

group_id

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

sample_id

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

Cluster markers from Lam et al.

Similar to figure 2f in paper.

## source file with list of known marker genes
source(file.path("data", "Lam_figure2_markers.R"))

fs <- lapply(fs, sapply, function(g)
    grep(pattern = paste0("\\.", g, "$"), rownames(sce), value = TRUE)
  )

fs <- lapply(fs, function(x) unlist(x[lengths(x) !=0]) )

gs <- gsub(".*\\.", "", unlist(fs))
ns <- vapply(fs, length, numeric(1))
ks <- rep.int(names(fs), ns)
labs <- lapply(fs, function(x) gsub(".*\\.", "",x))

Heatmap of mean marker-exprs. by cluster

# split cells by cluster
cs_by_k <- split(colnames(sce), sce$cluster_id)
# compute cluster-marker means
ms_by_cluster <- lapply(fs, function(gs) vapply(cs_by_k, function(i)
        Matrix::rowMeans(logcounts(sce)[gs, i, drop = FALSE]), 
        numeric(length(gs))))
# prep. for plotting & scale b/w 0 and 1
mat <- do.call("rbind", ms_by_cluster)
mat <- muscat:::.scale(mat)
rownames(mat) <- gs
cols <- muscat:::.cluster_colors[seq_along(fs)]
cols <- setNames(cols, names(fs))
row_anno <- rowAnnotation(
    df = data.frame(label = factor(ks, levels = names(fs))),
    col = list(label = cols), gp = gpar(col = "white"))
# percentage of cells from each of the samples per cluster
sample_props <- prop.table(n_cells, margin = 1)
col_mat <- as.matrix(unclass(sample_props))
sample_cols <- c("#882255", "#CC6677", "#11588A")
sample_cols <- setNames(sample_cols, colnames(col_mat))
col_anno <- HeatmapAnnotation(
    perc_sample = anno_barplot(col_mat, gp = gpar(fill = sample_cols), 
                               height = unit(2, "cm"),
                               border = FALSE),
    annotation_label = "fraction of sample\nin cluster",
    gap = unit(10, "points"))
col_lgd <- Legend(labels = names(sample_cols),
       title = "sample",
       legend_gp = gpar(fill = sample_cols))

hm <- Heatmap(mat,
    name = "scaled avg.\nexpression",
    col = viridis(10),
    cluster_rows = FALSE,
    cluster_columns = FALSE,
    row_names_side = "left",
    column_title = "cluster_id",
    column_title_side = "bottom",
    column_names_side = "bottom",
    column_names_rot = 0, 
    column_names_centered = TRUE,
    rect_gp = gpar(col = "white"),
    left_annotation = row_anno,
    top_annotation = col_anno)
draw(hm, annotation_legend_list = list(col_lgd))

Version Author Date
875e3c5 khembach 2020-07-10
a1ebb78 khembach 2020-07-08

sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

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

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       

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

other attached packages:
 [1] BiocParallel_1.22.0         RCurl_1.98-1.2             
 [3] stringr_1.4.0               Seurat_3.1.5               
 [5] scran_1.16.0                SingleCellExperiment_1.10.1
 [7] SummarizedExperiment_1.18.1 DelayedArray_0.14.0        
 [9] matrixStats_0.56.0          Biobase_2.48.0             
[11] GenomicRanges_1.40.0        GenomeInfoDb_1.24.2        
[13] IRanges_2.22.2              S4Vectors_0.26.1           
[15] BiocGenerics_0.34.0         viridis_0.5.1              
[17] viridisLite_0.3.0           RColorBrewer_1.1-2         
[19] purrr_0.3.4                 muscat_1.2.1               
[21] dplyr_1.0.0                 ggplot2_3.3.2              
[23] cowplot_1.0.0               ComplexHeatmap_2.4.2       
[25] workflowr_1.6.2            

loaded via a namespace (and not attached):
  [1] backports_1.1.8           circlize_0.4.10          
  [3] blme_1.0-4                igraph_1.2.5             
  [5] plyr_1.8.6                lazyeval_0.2.2           
  [7] TMB_1.7.16                splines_4.0.0            
  [9] listenv_0.8.0             scater_1.16.2            
 [11] digest_0.6.25             foreach_1.5.0            
 [13] htmltools_0.5.0           gdata_2.18.0             
 [15] lmerTest_3.1-2            magrittr_1.5             
 [17] memoise_1.1.0             cluster_2.1.0            
 [19] doParallel_1.0.15         ROCR_1.0-11              
 [21] limma_3.44.3              globals_0.12.5           
 [23] annotate_1.66.0           prettyunits_1.1.1        
 [25] colorspace_1.4-1          rappdirs_0.3.1           
 [27] ggrepel_0.8.2             blob_1.2.1               
 [29] xfun_0.15                 jsonlite_1.7.0           
 [31] crayon_1.3.4              genefilter_1.70.0        
 [33] lme4_1.1-23               zoo_1.8-8                
 [35] ape_5.4                   survival_3.2-3           
 [37] iterators_1.0.12          glue_1.4.1               
 [39] gtable_0.3.0              zlibbioc_1.34.0          
 [41] XVector_0.28.0            leiden_0.3.3             
 [43] GetoptLong_1.0.1          BiocSingular_1.4.0       
 [45] future.apply_1.6.0        shape_1.4.4              
 [47] scales_1.1.1              DBI_1.1.0                
 [49] edgeR_3.30.3              Rcpp_1.0.4.6             
 [51] xtable_1.8-4              progress_1.2.2           
 [53] clue_0.3-57               reticulate_1.16          
 [55] dqrng_0.2.1               bit_1.1-15.2             
 [57] rsvd_1.0.3                tsne_0.1-3               
 [59] htmlwidgets_1.5.1         httr_1.4.1               
 [61] gplots_3.0.4              ellipsis_0.3.1           
 [63] ica_1.0-2                 farver_2.0.3             
 [65] pkgconfig_2.0.3           XML_3.99-0.4             
 [67] uwot_0.1.8                locfit_1.5-9.4           
 [69] labeling_0.3              tidyselect_1.1.0         
 [71] rlang_0.4.6               reshape2_1.4.4           
 [73] later_1.1.0.1             AnnotationDbi_1.50.1     
 [75] munsell_0.5.0             tools_4.0.0              
 [77] generics_0.0.2            RSQLite_2.2.0            
 [79] ggridges_0.5.2            evaluate_0.14            
 [81] yaml_2.2.1                knitr_1.29               
 [83] bit64_0.9-7               fs_1.4.2                 
 [85] fitdistrplus_1.1-1        caTools_1.18.0           
 [87] RANN_2.6.1                pbapply_1.4-2            
 [89] future_1.17.0             nlme_3.1-148             
 [91] whisker_0.4               pbkrtest_0.4-8.6         
 [93] compiler_4.0.0            plotly_4.9.2.1           
 [95] beeswarm_0.2.3            png_0.1-7                
 [97] variancePartition_1.18.2  tibble_3.0.1             
 [99] statmod_1.4.34            geneplotter_1.66.0       
[101] stringi_1.4.6             lattice_0.20-41          
[103] Matrix_1.2-18             nloptr_1.2.2.2           
[105] vctrs_0.3.1               pillar_1.4.4             
[107] lifecycle_0.2.0           lmtest_0.9-37            
[109] GlobalOptions_0.1.2       RcppAnnoy_0.0.16         
[111] BiocNeighbors_1.6.0       data.table_1.12.8        
[113] bitops_1.0-6              irlba_2.3.3              
[115] patchwork_1.0.1           httpuv_1.5.4             
[117] colorRamps_2.3            R6_2.4.1                 
[119] promises_1.1.1            KernSmooth_2.23-17       
[121] gridExtra_2.3             vipor_0.4.5              
[123] codetools_0.2-16          boot_1.3-25              
[125] MASS_7.3-51.6             gtools_3.8.2             
[127] DESeq2_1.28.1             rprojroot_1.3-2          
[129] rjson_0.2.20              withr_2.2.0              
[131] sctransform_0.2.1         GenomeInfoDbData_1.2.3   
[133] hms_0.5.3                 tidyr_1.1.0              
[135] glmmTMB_1.0.2.1           minqa_1.2.4              
[137] rmarkdown_2.3             DelayedMatrixStats_1.10.1
[139] Rtsne_0.15                git2r_0.27.1             
[141] numDeriv_2016.8-1.1       ggbeeswarm_0.6.0