This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ReporteR.scRNAseq/inst/content/03-normalization-C-scnorm.Rmd
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
90 lines (73 sloc)
5.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r parameters-and-defaults, include = FALSE} | |
module <- "scRNAseq" | |
section <- "normalization" | |
``` | |
```{r parameter-merge, include = FALSE} | |
local_params <- module %>% | |
options() %>% | |
magrittr::extract2(module) %>% | |
magrittr::extract2(section) %>% | |
ReporteR.base::validate_params(parameters_and_defaults) | |
``` | |
```{r scRNAseq-normalization-C-scnorm-checks, include = FALSE, echo = FALSE} | |
num_figure_rows <- 3 | |
assertive.sets::assert_is_subset(local_params$features, colnames(SummarizedExperiment::colData(object_filtered))) | |
if (assertive.properties::is_empty(local_params$features)) { | |
local_params$features <- c(NULL) | |
num_figure_rows <- 2 | |
} | |
if (assertive.properties::is_non_empty(local_params$batch)) { | |
assertive.sets::assert_is_subset(local_params$batch, colnames(SummarizedExperiment::colData(object_filtered))) | |
batch = droplevels(as.factor(SummarizedExperiment::colData(object_filtered)[, local_params$batch])) | |
cellcount <- table(batch) | |
} else { | |
batch = NULL | |
cellcount <- dim(object_filtered)[2] | |
} | |
assertive.numbers::assert_all_are_greater_than(min(cellcount), 15) | |
``` | |
### Normalization by SCnorm | |
```{r scRNAseq-normalization-C-scnorm-processing, include = FALSE, echo = FALSE} | |
scnorm <- SCnorm::SCnorm(object_filtered, Conditions = batch, reportSF = FALSE, NCores = parallel::detectCores() - 1) | |
assay(object_filtered, "norm_scnorm") <- assay(scnorm, "normcounts") | |
``` | |
Global scaling factors, like *sizefactors*, are based on the assumption that the count-depth relationship is common across individual genes. When this relationship is not common across genes, normalization via global scale factors leads to overcorrection for weakly and moderately expressed genes and, in some cases, undernormalization of highly expressed genes. | |
Here, we apply a method [@bacher_scnorm_2017] that tries to overcome this by using quantile regression to estimate the dependence of transcript expression on sequencing depth for every gene. Genes with similar dependence are then grouped, and a second quantile regression is used to estimate scale factors within each group. Within-group adjustment for sequencing depth is then performed using the estimated scale factors to provide normalized estimates of expression. Figure \@ref(fig:scRNAseq-normalization-C-scnorm-figure) depicts effects of the normalization strategy. | |
```{r scRNAseq-normalization-C-scnorm-figure-params, include = FALSE, echo = FALSE} | |
fig_height <- ReporteR.base::estimate_figure_height( | |
height_in_panels = num_figure_rows, | |
panel_height_in_in = params$formatting_defaults$figures$panel_height_in, | |
axis_space_in_in = params$formatting_defaults$figures$axis_space_in, | |
mpf_row_space = as.numeric(grid::convertUnit(grid::unit(5, 'mm'), 'in')), | |
max_height_in_in = params$formatting_defaults$figures$max_height_in) | |
``` | |
```{r scRNAseq-normalization-C-scnorm-figure, echo = FALSE, message=FALSE, warning=FALSE, fig.height = fig_height$global, fig.cap = paste("Results of normalization by SCnorm [@bacher_scnorm_2017].", caption_norm_pca, ifelse(num_figure_rows == 3, caption_norm_pca_extra, ""))} | |
figure_normalization_scnorm <- multipanelfigure::multi_panel_figure(height = fig_height$sub, columns = 3, rows = num_figure_rows, unit = "in") | |
# Based on raw counts | |
figure_normalization_scnorm <- multipanelfigure::fill_panel(figure_normalization_scnorm, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "logcounts", colour_by = local_params$features[1], add_ticks = FALSE) + | |
theme_norm_pca) | |
figure_normalization_scnorm <- multipanelfigure::fill_panel(figure_normalization_scnorm, | |
scater::plotExplanatoryVariables(object_filtered, exprs_values = "logcounts", variables = local_params$features) + | |
theme_norm_pca, | |
column = 2:3) | |
# Based on normalized values | |
figure_normalization_scnorm <- multipanelfigure::fill_panel(figure_normalization_scnorm, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "norm_scnorm", colour_by = local_params$features[1], add_ticks = FALSE) + | |
ggplot2::guides(colour = FALSE) + | |
theme_norm_pca) | |
figure_normalization_scnorm <- multipanelfigure::fill_panel(figure_normalization_scnorm, | |
scater::plotExplanatoryVariables(object_filtered, exprs_values = "norm_scnorm", variables = local_params$features) + | |
theme_norm_pca, | |
column = 2:3) | |
# Additional panels for first three variables | |
if(num_figure_rows == 3) { | |
for(i in 1:min(3, length(local_params$features))) { | |
figure_normalization_scnorm <- multipanelfigure::fill_panel(figure_normalization_scnorm, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "norm_scnorm", colour_by = local_params$features[i], add_ticks = FALSE) + | |
ggplot2::guides(colour = FALSE) + | |
theme_norm_pca) | |
} | |
} | |
figure_normalization_scnorm | |
``` |