From b88bdbd8b4a06eb86cde7ef3e6ff2086605e9773 Mon Sep 17 00:00:00 2001 From: andzajan Date: Fri, 6 Sep 2019 14:31:55 +0100 Subject: [PATCH] Allow different labels for QC samples --- DESCRIPTION | 2 +- R/sbc_main.R | 15 +++++++++------ R/sbcmsPlot.R | 5 +++-- man/QCRSC.Rd | 5 ++++- man/sbcmsPlot.Rd | 4 +++- tests/testthat/test-sbcmsPlot.R | 20 ++++++++++++++++++++ 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 96574b4..6a4f7e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: sbcms Type: Package Title: Signal batch correction for (LC)-MS data -Version: 0.99.0 +Version: 0.99.1 Author: Andris Jankevics Maintainer: Andris Jankevics Description: This signal batch correction package for LC-MS data. This version supports missing vallues in your data (at least 4 data point for QC are needed) and has moduler desing to add different fitting/correction functions. diff --git a/R/sbc_main.R b/R/sbc_main.R index 0bf9b1f..1a93d49 100644 --- a/R/sbc_main.R +++ b/R/sbc_main.R @@ -24,6 +24,7 @@ NULL ##' @param log TRUE or FALSE to perform the signal correction fit on the log ##'scaled data. Default is TRUE. ##' @param minQC Minimum number of QC samples required for signal correction. +##' @param qc_label Class label for QC sample. ##' ##' @return A data frame of corrected values. ##' @@ -37,19 +38,21 @@ NULL ##' ##' @export -QCRSC <- function(df, order, batch, classes, spar = 0, log = TRUE, minQC = 5) { +QCRSC <- function(df, order, batch, classes, spar = 0, log = TRUE, + minQC = 5, qc_label="QC") { - if (length(which(classes == "QC")) <= 0) { - message("QC samples are not defined! Class label has to be QC.") + if (length(which(classes == qc_label)) <= 0) { + message("QC samples are not defined! Please see help page for + parameter qc_label.") stop() } message("The number of NA and <= 0 values in peaksData before QC-RSC: ", sum(is.na(df) | df <= 0)) - qcData <- df[, classes == "QC"] - qc_batch <- batch[classes == "QC"] - qc_order <- order[classes == "QC"] + qcData <- df[, classes == qc_label] + qc_batch <- batch[classes == qc_label] + qc_order <- order[classes == qc_label] QC_fit <- lapply(seq_len(nrow(df)), sbcWrapper, qcData = qcData, order = order, qcBatch = qc_batch, qcOrder = qc_order, log = log, spar = spar, batch = batch, minQC = minQC) diff --git a/R/sbcmsPlot.R b/R/sbcmsPlot.R index 3e082b1..2a5385e 100644 --- a/R/sbcmsPlot.R +++ b/R/sbcmsPlot.R @@ -18,6 +18,7 @@ NULL ##'plot. If set to NULL will plot the first 100. ##' @param output Filename of the output pdf file. Can include the path. ##'If set to NULL output will be list object containing ggplot2 plots. +##' @param qc_label Class label for QC sample. ##' ##' @return Pdf file or list object showing data before and after ##'signal correction @@ -35,10 +36,10 @@ NULL ##' @export sbcmsPlot <- function(df, corrected_df, classes, batch, indexes = NULL, - output = "sbcms_plots.pdf") { + qc_label="QC", output = "sbcms_plots.pdf") { shapes <- rep(19, length(classes)) - shapes[classes == "QC"] <- 3 + shapes[classes == qc_label] <- 3 manual_color <- c("#386cb0", "#ef3b2c", "#7fc97f", "#fdb462", "#984ea3", "#a6cee3", "#778899", "#fb9a99", "#ffff33") gg_THEME <- theme(panel.background = element_blank(), diff --git a/man/QCRSC.Rd b/man/QCRSC.Rd index 7be2700..95e8529 100644 --- a/man/QCRSC.Rd +++ b/man/QCRSC.Rd @@ -4,7 +4,8 @@ \alias{QCRSC} \title{Quality Control-Robust Spline Correction (QC-RSC)} \usage{ -QCRSC(df, order, batch, classes, spar = 0, log = TRUE, minQC = 5) +QCRSC(df, order, batch, classes, spar = 0, log = TRUE, minQC = 5, + qc_label = "QC") } \arguments{ \item{df}{A data frame of values to be corrected (samples in columns and @@ -26,6 +27,8 @@ If set to 0 it will be estimated using leave-one-out cross-validation.} scaled data. Default is TRUE.} \item{minQC}{Minimum number of QC samples required for signal correction.} + +\item{qc_label}{Class label for QC sample.} } \value{ A data frame of corrected values. diff --git a/man/sbcmsPlot.Rd b/man/sbcmsPlot.Rd index 2e1ce71..29b44bd 100644 --- a/man/sbcmsPlot.Rd +++ b/man/sbcmsPlot.Rd @@ -6,7 +6,7 @@ the first 100 features} \usage{ sbcmsPlot(df, corrected_df, classes, batch, indexes = NULL, - output = "sbcms_plots.pdf") + qc_label = "QC", output = "sbcms_plots.pdf") } \arguments{ \item{df}{A data frame containing the original data before correction @@ -24,6 +24,8 @@ If only one batch was measured then all values should be set to 1} \item{indexes}{Numeric vector defining whihc features from data frame to plot. If set to NULL will plot the first 100.} +\item{qc_label}{Class label for QC sample.} + \item{output}{Filename of the output pdf file. Can include the path. If set to NULL output will be list object containing ggplot2 plots.} } diff --git a/tests/testthat/test-sbcmsPlot.R b/tests/testthat/test-sbcmsPlot.R index 3ee38b2..23890c4 100644 --- a/tests/testthat/test-sbcmsPlot.R +++ b/tests/testthat/test-sbcmsPlot.R @@ -51,3 +51,23 @@ test_that ("sbcmsPlot returns output for the first 100 features if testthat::expect_true(length(plots) == 100) }) + +test_that ("sbcmsPlot returns ggplot output, with different QC sample label", { + + classes <- sbcdata$class + classes[classes == "QC"] <- "Quality" + batch <- sbcdata$batch + order <- c(1:nrow(sbcdata$data)) + data <- t(sbcdata$data[, 1:10]) + + out <- QCRSC(df = data, order = order, batch = batch, classes = classes, + spar = 0, minQC = 4, qc_label="Quality") + + plots <- sbcmsPlot(df = data, corrected_df = out, + classes, batch, output=NULL, indexes=c(1,5,7), qc_label="Quality") + + testthat::expect_s3_class(plots[[1]], "ggplot") + # Empty plots are getting removed from the list object + testthat::expect_true(length(plots) == 3) + +})