Commit fc14899e authored by Jakob Wirbel's avatar Jakob Wirbel

Add variance explained plot to confounder check.

parent f662cf67
......@@ -6,11 +6,15 @@
#' @title Check for potential confounders in the metadata
#' @description Checks potential confounders in the metadata and produces
#' some visualizations
#' @usage check.confounders(siamcat, fn.plot, meta.in = NULL, verbose = 1)
#' @usage check.confounders(siamcat, fn.plot, meta.in = NULL,
#' feature.type='filtered', verbose = 1)
#' @param siamcat an object of class \link{siamcat-class}
#' @param fn.plot string, filename for the pdf-plot
#' @param meta.in vector, specific metadata variable names to analyze,
#' defaults to NULL (all metadata variables will be analyzed)
#'@param feature.type string, on which type of features should the function
#' work? Can be either \code{c()"original", "filtered", or "normalized")}.
#' Please only change this paramter if you know what you are doing!
#' @param verbose integer, control output: \code{0} for no output at all,
#' \code{1} for only information about progress and success, \code{2} for
#' normal level of information and \code{3} for full debug information,
......@@ -35,13 +39,28 @@
#' # Simple working example
#' check.confounders(siamcat_example, './conf_plot.pdf')
check.confounders <- function(siamcat, fn.plot, meta.in = NULL, verbose = 1) {
check.confounders <- function(siamcat, fn.plot, meta.in = NULL,
feature.type='filtered', verbose = 1) {
if (verbose > 1) message("+ starting check.confounders")
s.time <- proc.time()[3]
label <- label(siamcat)
meta <- meta(siamcat)
# get features
if (feature.type == 'original'){
feat <- get.orig_feat.matrix(siamcat)
} else if (feature.type == 'filtered'){
if (is.null(filt_feat(siamcat, verbose=0))){
stop('Features have not yet been filtered, exiting...\n')
}
feat <- get.filt_feat.matrix(siamcat)
} else if (feature.type == 'normalized'){
if (is.null(norm_feat(siamcat, verbose=0))){
stop('Features have not yet been normalized, exiting...\n')
}
feat <- get.norm_feat.matrix(siamcat)
}
if (is.null(meta)) {
stop('SIAMCAT object does not contain any metadata.\nExiting...')
}
......@@ -115,7 +134,7 @@ check.confounders <- function(siamcat, fn.plot, meta.in = NULL, verbose = 1) {
# FOURTH PLOT(S) - variance explained by label versus variance explained by
# metadata plots
variance.plots(meta, label, get.filt_feat.matrix(siamcat), verbose)
variance.plots(meta, label, feat, verbose)
dev.off()
......@@ -541,11 +560,14 @@ variance.plots <- function(meta, label, feat, verbose){
var.batch[is.infinite(var.batch)] <- NA
}
lim <- round(max(var.label, var.batch, na.rm=TRUE), digits = 2)
plot(var.label, var.batch,
r.mean <- rowMeans(log10(feat+1e-05))
mean.size <- (r.mean + 5) * 8/5 + 1
plot(var.label, var.batch, type='n',
xlab='Variance explained by label',
ylab=paste0('Variance expained by ', variable),
xlim=c(0,lim), ylim=c(0,lim))
abline(0,1, lty=3, col='darkgrey')
symbols(x=var.label, y=var.batch, circles=mean.size, inches=1/9,
bg=alpha("darkgrey", 0.4), fg=alpha('black', 0.7), add=TRUE)
abline(0,1, lty=3, col='black')
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment