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-A-sumfactors.Rmd
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
104 lines (84 sloc)
6.02 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-A-sumfactors-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) | |
``` | |
### Sumfactor normalization | |
```{r scRNAseq-normalization-A-sumfactors-processing, include = FALSE, echo = FALSE} | |
# Calculate senseful sizes for normalization | |
max_size <- max(ceiling( 2 * sqrt(min(cellcount))), 150) | |
step <- floor( 1/2 * sqrt(min(cellcount))) | |
if (min(cellcount) < 50) { | |
sizes <- 5:max_size * step | |
} else { | |
sizes <- 4:max_size * step | |
} | |
object_filtered <- scran::computeSumFactors(object_filtered, clusters = batch, sizes = sizes) | |
assertive.numbers::assert_all_are_non_negative(SingleCellExperiment::sizeFactors(object_filtered)) | |
object_filtered <- scater::normalize(object_filtered) | |
SummarizedExperiment::assay(object_filtered, "norm_sumfactor") <- SummarizedExperiment::assay(object_filtered, "logcounts") | |
# Reset logcounts | |
SummarizedExperiment::assay(object_filtered, "logcounts") <- log2(SummarizedExperiment::assay(object_filtered, "counts") + 1) | |
``` | |
Here, we apply a novel approach [@lun_pooling_2016] where normalization is performed on pooled counts for multiple cells, where the incidence of problematic zeroes is reduced by summing across cells. Expression values are summed across pools of cells of different sizes, and the summed values are used for normalization. The pool-based size factors are then deconvolved to infer the size factors for the individual cells without the need of spike-ins. The deconvolution approach was shown to outperform existing methods for accurate normalization of cell-specific biases in simulated data. Similar behavior is observed in real data, where deconvolution improves the relevance of results of downstream analyses [@lun_pooling_2016]. Figure \@ref(fig:scRNAseq-normalization-A-sumfactors-figure) depicts effects of the normalization strategy. | |
```{r scRNAseq-normalization-A-sumfactors-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-A-sumfactors-figure, echo = FALSE, message=FALSE, warning=FALSE, fig.height = fig_height$global, fig.cap = paste("Results of sumfactor normalization.", caption_norm_pca, ifelse(num_figure_rows == 3, caption_norm_pca_extra, ""))} | |
figure_normalization_sumfactors <- multipanelfigure::multi_panel_figure(height = fig_height$sub, columns = 3, rows = num_figure_rows, unit = "in") | |
# Based on raw counts | |
figure_normalization_sumfactors <- multipanelfigure::fill_panel(figure_normalization_sumfactors, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "logcounts", colour_by = local_params$features[1], add_ticks = FALSE) + | |
theme_norm_pca) | |
figure_normalization_sumfactors <- multipanelfigure::fill_panel(figure_normalization_sumfactors, | |
scater::plotExplanatoryVariables(object_filtered, exprs_values = "logcounts", variables = local_params$features) + | |
theme_norm_pca, | |
column = 2:3) | |
# Based on normalized values | |
figure_normalization_sumfactors <- multipanelfigure::fill_panel(figure_normalization_sumfactors, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "norm_sumfactor", colour_by = local_params$features[1], add_ticks = FALSE) + | |
ggplot2::guides(colour = FALSE) + | |
theme_norm_pca) | |
figure_normalization_sumfactors <- multipanelfigure::fill_panel(figure_normalization_sumfactors, | |
scater::plotExplanatoryVariables(object_filtered, exprs_values = "norm_sumfactor", 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_sumfactors <- multipanelfigure::fill_panel(figure_normalization_sumfactors, | |
scater::plotPCASCE(object_filtered, ntop = 10, exprs_values = "norm_sumfactor", colour_by = local_params$features[i], add_ticks = FALSE) + | |
ggplot2::guides(colour = FALSE) + | |
theme_norm_pca) | |
} | |
} | |
figure_normalization_sumfactors | |
``` |