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/02-quality-control-E-genefiltering.Rmd
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (47 sloc)
2.7 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 <- "quality_control" | |
``` | |
```{r parameter-merge, include = FALSE} | |
local_params <- module %>% | |
options() %>% | |
magrittr::extract2(module) %>% | |
magrittr::extract2(section) %>% | |
ReporteR.base::validate_params(parameters_and_defaults) | |
``` | |
```{r scRNAseq-quality-control-E-genefiltering-checks, include = FALSE, echo = FALSE} | |
assertive.files::assert_all_are_readable_files(local_params$gene_filter_yml) | |
gene_filter <- yaml::read_yaml(local_params$gene_filter_yml) | |
# Check filter names | |
assertive.properties::assert_has_names(gene_filter) | |
# Assemble gene filter | |
filter_functions <- lapply(names(gene_filter), function(f) { | |
fn <- strsplit(f, "::")[[1]] | |
what <- if(length(fn)==1) { | |
get(fn[[1]], envir=parent.frame(), mode="function") | |
} else { | |
get(fn[[2]], envir=asNamespace(fn[[1]]), mode="function") | |
} | |
do.call(what = what, args = gene_filter[[f]]) | |
}) | |
``` | |
### Gene filtering | |
Gene filtering strives for the identification of features that should be excluded from downstream analysis, e.g. because they are lowly expressed and therefore do not allow a statistically robust quantification. Gene filtering is accomplished by applying so-called **filter functions** to the raw data, excluding low quality samples identified above. | |
```{r scRNAseq-quality-control-E-genefiltering-processing, include = FALSE, echo = FALSE} | |
keep_genes <- genefilter::genefilter(SummarizedExperiment::assay(object[, SummarizedExperiment::colData(object)$qc_status == "pass"], local_params$assay), genefilter::filterfun(filter_functions)) | |
keep_genes <- ifelse(keep_genes, "pass", "fail") | |
SummarizedExperiment::rowData(object)$qc_status <- keep_genes | |
``` | |
In total, **`r sum(keep_genes == "fail")`** features (`r round(sum(keep_genes == "fail")/length(keep_genes) * 100)`%) are excluded from downstream analysis (Table \@ref(tab:scRNAseq-quality-control-E-genefiltering-table)). | |
```{r scRNAseq-quality-control-E-genefiltering-table, results = "asis"} | |
if(assertive.properties::is_non_empty(local_params$tabulate_features)) { | |
Feature <- gsub("_", "-", SummarizedExperiment::rowData(object)[, local_params$tabulate_features]) | |
tbl <- stats::ftable(SummarizedExperiment::rowData(object)$qc_status, Feature, row.vars = 2) | |
extra_caption <- paste0("by ", gsub("_", "-", local_params$tabulate_features)) | |
} else { | |
tbl <- stats::ftable(SummarizedExperiment::rowData(object)$qc_status) | |
extra_caption <- "" | |
} | |
xftbl <- xtable::xtableFtable(tbl, method = "compact", caption = paste("(\\#tab:scRNAseq-quality-control-E-genefiltering-table)Number of features passing/failing quality control", extra_caption)) | |
xtable::print.xtableFtable(xftbl, booktabs = TRUE, comment = FALSE, timestamp = NULL) | |
``` |