Set-up

The object has 32285 genes and 63430 cells before filtering

Add cell QC metrics to the sce

First we need to sort the gene names and gene symbols, because the default ensembl notation is not very handy. And then save the mitochondrial genes as such.

Then we can use the scater package to add the quality per cell. This computes for each cell some useful metrics such as the number of umi counts (library size), the number of detected genes and the percentage of mitochondiral genes.

Then we use the automatic isOutlier function from the same package that determine which values in a numeric vector are outliers based on the median absolute deviation (MAD). When using this function with low number a log transformation is added, that prevents negative thresholds. We also take only in consideration the first three batches, as the last one is lower quality

##                X lib_size_high expression_high lib_size_low expression_low
## 1 Cells filtered       2294.00          74.000       0.0000      3562.0000
## 2      Threshold      18623.92        7087.371     470.3209       453.2256
##        mt_pct total
## 1 13179.00000 17110
## 2    14.04298    NA

This data is saved in outs/fire-mice/autofilter_summary.csv # Plots before QC

Diagnostic plots to visualize the data distribution. The orange cells are marked as outliers by the automatic detection from scater.

Violin plots

We can see how chip 6 has a greater amount of cells with lower umi counts than the other 3. This chip has not been taken in consideration when calculating the overall thresholds.

Histograms

In the x axis we can see the total number of umi (library size) per cell, the number of detected genes per cell and the mitochondrial percentage per cell; with the number of cells for each measure in the y axis.

This object had already been filtrated with the cell-calling algorithm from CellRanger, that is meant to remove empty droplets. Therefore it is expected to see the total sum of umi skewed as in the plot above.

The bimodality present in the number of counts was already visible in the violin plots.

There is a very heavy tail of cells with high mitochondrial genes.

Scatter plots

PCA

Here we run a PCA using the information in the metadata instead of the gene expression. It is useful to visualize the QC parametres.

Ratio between sum and gene counts

This measures the number of detected genes per cell divided by its library size. This will be very useful to delete the cells that have low gene counts but a relatively high umi count (visible in the scatter plots).

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.01078 0.32319 0.39979 0.40960 0.48855 0.87800

The isoutlier function can but used to find the outliers of any distribution, as far as it is roughly normal. Bellow we use it with the ratio between the number of genes expressed and the number of umi. Again, only the first 3 chips are considered to calculate the cut-offs

##      lower     higher 
## 0.04565117 0.72692408

This filters out 1062 cells.

Thresholds for cell filtering

The upper thresholds from the sum of umi counts is 1.8624^{4} and the lower threshold is 470 umi counts.

Also, removing cells with less than 7087 or more than 453 detected genes.

Finally, we will also take in consideration the detected genes/umi counts ratio, that filter out cells with relatively high umi counts but very few detected genes ( lots of copies from the same genes). And any cell with above 14.04 % mitochondrial genes.

Gene QC

It is typically a good idea to remove genes whose expression level is considered “undetectable”. Here we define a gene as detectable if at least two cells contain a transcript from the gene. It is important to keep in mind that genes must be filtered after cell filtering since some genes may only be detected in poor quality cells.

## [1] 9130

This way we deleted 9130 genes and kept 23155 genes

We can look at a plot that shows the top 50 (by default) most-expressed features. Each row in the plot below corresponds to a gene; each bar corresponds to the expression of a gene in a single cell; and the circle indicates the median expression of each gene, with which genes are sorted. We expect to see the “usual suspects”, i.e., mitochondrial genes, actin, ribosomal protein, MALAT1. A large number of pseudo-genes or predicted genes may indicate problems with alignment.

Create new filetered object

The object has 23155 genes and 45936 cells after filtering

Session Info

Click to expand
## R version 4.1.1 (2021-08-10)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19041)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252 
## [2] LC_CTYPE=English_United Kingdom.1252   
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C                           
## [5] LC_TIME=English_United Kingdom.1252    
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] org.Mm.eg.db_3.13.0         AnnotationDbi_1.54.1       
##  [3] scater_1.20.1               ggplot2_3.3.5              
##  [5] scuttle_1.2.1               SingleCellExperiment_1.14.1
##  [7] SummarizedExperiment_1.22.0 Biobase_2.52.0             
##  [9] GenomicRanges_1.44.0        GenomeInfoDb_1.28.1        
## [11] IRanges_2.26.0              S4Vectors_0.30.0           
## [13] BiocGenerics_0.38.0         MatrixGenerics_1.4.2       
## [15] matrixStats_0.60.0          here_1.0.1                 
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-7              bit64_4.0.5              
##  [3] httr_1.4.2                rprojroot_2.0.2          
##  [5] tools_4.1.1               bslib_0.2.5.1            
##  [7] utf8_1.2.2                R6_2.5.0                 
##  [9] irlba_2.3.3               vipor_0.4.5              
## [11] DBI_1.1.1                 colorspace_2.0-2         
## [13] withr_2.4.2               tidyselect_1.1.1         
## [15] gridExtra_2.3             bit_4.0.4                
## [17] compiler_4.1.1            BiocNeighbors_1.10.0     
## [19] DelayedArray_0.18.0       labeling_0.4.2           
## [21] sass_0.4.0                scales_1.1.1             
## [23] stringr_1.4.0             digest_0.6.27            
## [25] rmarkdown_2.10            XVector_0.32.0           
## [27] pkgconfig_2.0.3           htmltools_0.5.1.1        
## [29] sparseMatrixStats_1.4.2   highr_0.9                
## [31] fastmap_1.1.0             rlang_0.4.11             
## [33] RSQLite_2.2.7             DelayedMatrixStats_1.14.2
## [35] farver_2.1.0              jquerylib_0.1.4          
## [37] generics_0.1.0            jsonlite_1.7.2           
## [39] BiocParallel_1.26.1       dplyr_1.0.7              
## [41] RCurl_1.98-1.3            magrittr_2.0.1           
## [43] BiocSingular_1.8.1        GenomeInfoDbData_1.2.6   
## [45] Matrix_1.3-4              Rcpp_1.0.7               
## [47] ggbeeswarm_0.6.0          munsell_0.5.0            
## [49] fansi_0.5.0               viridis_0.6.1            
## [51] lifecycle_1.0.0           stringi_1.7.3            
## [53] yaml_2.2.1                zlibbioc_1.38.0          
## [55] grid_4.1.1                blob_1.2.2               
## [57] crayon_1.4.1              lattice_0.20-44          
## [59] Biostrings_2.60.2         cowplot_1.1.1            
## [61] beachmat_2.8.0            KEGGREST_1.32.0          
## [63] knitr_1.33                pillar_1.6.2             
## [65] ScaledMatrix_1.0.0        glue_1.4.2               
## [67] evaluate_0.14             vctrs_0.3.8              
## [69] png_0.1-7                 gtable_0.3.0             
## [71] purrr_0.3.4               assertthat_0.2.1         
## [73] cachem_1.0.5              xfun_0.25                
## [75] rsvd_1.0.5                viridisLite_0.4.0        
## [77] tibble_3.1.3              beeswarm_0.4.0           
## [79] memoise_2.0.0             ellipsis_0.3.2