Last updated: 2020-05-28

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 a7ced59. 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:    .__workflowr.yml
    Ignored:    ._neural_scRNAseq.Rproj
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/._.DS_Store
    Ignored:    analysis/._01-preprocessing.Rmd
    Ignored:    analysis/._01-preprocessing.html
    Ignored:    analysis/._02.1-SampleQC.Rmd
    Ignored:    analysis/.__site.yml
    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:    data/.DS_Store
    Ignored:    data/._.DS_Store
    Ignored:    data/._metadata.csv
    Ignored:    data/._metadata.xlsx
    Ignored:    data/.smbdeleteAAA17ed8b4b
    Ignored:    data/data_sushi/
    Ignored:    data/metadata.csv
    Ignored:    data/metadata.xlsx
    Ignored:    output/sce_01_preprocessing.rds
    Ignored:    output/sce_02_quality_control.rds
    Ignored:    output/sce_preprocessing.rds

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/03-filtering.Rmd) and HTML (docs/03-filtering.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 a7ced59 khembach 2020-05-28 cell and gene filtering

Load packages

library(scater)
library(LSD)

Load data

sce <- readRDS(file.path("output", "sce_02_quality_control.rds"))

Identification of outlier cells

Based on the QC metrics, we now identify outlier cells:

cols <- c("sum", "detected", "subsets_Mt_percent")
log <- c(TRUE, TRUE, FALSE)
type <- c("both", "both", "higher")

drop_cols <- paste0(cols, "_drop")
for (i in seq_along(cols))
    colData(sce)[[drop_cols[i]]] <- isOutlier(sce[[cols[i]]], 
        nmads = 3, type = type[i], log = log[i], batch = sce$sample_id)

# Overlap of outlier cells from two metrics
sapply(drop_cols, function(i) 
    sapply(drop_cols, function(j)
        sum(sce[[i]] & sce[[j]])))
                        sum_drop detected_drop subsets_Mt_percent_drop
sum_drop                    3484          2770                     786
detected_drop               2770          3337                    1038
subsets_Mt_percent_drop      786          1038                    2907
colData(sce)$discard <- rowSums(data.frame(colData(sce)[,drop_cols])) > 0
table(colData(sce)$discard)

FALSE  TRUE 
54104  5903 
## Plot the metrics and highlight the discarded cells
plotColData(sce, x = "sample_id", y = "sum", colour_by = "discard") + 
  scale_y_log10()

plotColData(sce, x = "sample_id", y = "detected", colour_by = "discard") + 
  scale_y_log10()

plotColData(sce, x = "sample_id", y = "subsets_Mt_percent", 
            colour_by = "discard")

Plot the library size against the number of detected genes before and after filtering.

cd <- colData(sce)
layout(matrix(1:12, nrow = 3, byrow = TRUE))
for (i in levels(sce$sample_id)) {
  tmp <- cd[cd$sample_id == i,]
  heatscatter(tmp$sum, tmp$detected, log = "xy", 
              main = paste0(i, "-unfiltered"), xlab = "total counts", 
              ylab = "detected genes")
  heatscatter(tmp$sum[!tmp$discard], tmp$detected[!tmp$discard], 
              log = "xy", main = paste0(i, "-filtered"), xlab = "total counts", 
              ylab = "detected genes")    
}

We remove the outlier cells and filter the genes:

## summary of the kept cells
nr <- table(cd$sample_id)
nr_fil <- table(cd$sample_id[!cd$discard])
print(rbind(
    unfiltered = nr, filtered = nr_fil, 
    "%" = round(nr_fil / nr * 100, digits = 0)))
           1NSC 2NSC 3NC52 4NC52 5NC96 6NC96
unfiltered 8904 8863 10899  8873 16181  6287
filtered   8354 8416  9924  7446 15172  4792
%            94   95    91    84    94    76
## discard the outlier cells
dim(sce)
[1] 19415 60007
sce <- sce[,!cd$discard]
dim(sce)
[1] 19415 54104
## we filter genes and require > 1 count in at least 20 cells
sce <- sce[rowSums(counts(sce) > 1) >= 20, ]
dim(sce)
[1] 13133 54104

Save data to RDS

saveRDS(sce, file.path("output", "sce_03_filtering.rds"))

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

other attached packages:
 [1] HDF5Array_1.16.0            rhdf5_2.32.0               
 [3] LSD_4.0-0                   scater_1.16.0              
 [5] ggplot2_3.3.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.0        
[13] IRanges_2.22.2              S4Vectors_0.26.1           
[15] BiocGenerics_0.34.0         workflowr_1.6.2            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6              rsvd_1.0.3               
 [3] lattice_0.20-41           assertthat_0.2.1         
 [5] rprojroot_1.3-2           digest_0.6.25            
 [7] R6_2.4.1                  backports_1.1.7          
 [9] evaluate_0.14             pillar_1.4.4             
[11] zlibbioc_1.34.0           rlang_0.4.6              
[13] irlba_2.3.3               whisker_0.4              
[15] Matrix_1.2-18             rmarkdown_2.1            
[17] labeling_0.3              BiocNeighbors_1.6.0      
[19] BiocParallel_1.22.0       stringr_1.4.0            
[21] RCurl_1.98-1.2            munsell_0.5.0            
[23] compiler_4.0.0            httpuv_1.5.2             
[25] vipor_0.4.5               BiocSingular_1.4.0       
[27] xfun_0.14                 pkgconfig_2.0.3          
[29] ggbeeswarm_0.6.0          htmltools_0.4.0          
[31] tidyselect_1.1.0          gridExtra_2.3            
[33] tibble_3.0.1              GenomeInfoDbData_1.2.3   
[35] codetools_0.2-16          viridisLite_0.3.0        
[37] crayon_1.3.4              dplyr_0.8.5              
[39] withr_2.2.0               later_1.0.0              
[41] bitops_1.0-6              grid_4.0.0               
[43] gtable_0.3.0              lifecycle_0.2.0          
[45] git2r_0.27.1              magrittr_1.5             
[47] scales_1.1.1              stringi_1.4.6            
[49] farver_2.0.3              XVector_0.28.0           
[51] viridis_0.5.1             fs_1.4.1                 
[53] promises_1.1.0            DelayedMatrixStats_1.10.0
[55] ellipsis_0.3.1            vctrs_0.3.0              
[57] Rhdf5lib_1.10.0           tools_4.0.0              
[59] glue_1.4.1                beeswarm_0.2.3           
[61] purrr_0.3.4               yaml_2.2.1               
[63] colorspace_1.4-1          knitr_1.28