Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
Allow different labels for QC samples
Browse files Browse the repository at this point in the history
  • Loading branch information
andzajan committed Sep 6, 2019
1 parent dd82a42 commit b88bdbd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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.
Expand Down
15 changes: 9 additions & 6 deletions R/sbc_main.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##'
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions R/sbcmsPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion man/QCRSC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/sbcmsPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/test-sbcmsPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})

0 comments on commit b88bdbd

Please sign in to comment.