From abebba715cf2a317acc04cc0d229c2a605a005a2 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 18 Jul 2017 11:25:23 +0200 Subject: Mean control growth rate, y axis labels Also warn if there is more than one endpoint in the data, and restrict the data to the first endpoint (e.g. frond area if there is also frond number data). --- R/checkexperiment.R | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/R/checkexperiment.R b/R/checkexperiment.R index 02ed706..58868da 100644 --- a/R/checkexperiment.R +++ b/R/checkexperiment.R @@ -26,13 +26,12 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") comment <- as.character(commentdata[[1]]) expquery <- paste("SELECT experimentator, substance, ", - testtype, ", conc, unit,", responsename, ", performed, ok", + testtype, ", conc, unit,", responsename, ", type, raw_0, duration, performed, ok", " FROM ",db," WHERE ",exptype,"=", id, sep = "") if (db == "ecotox") { - expquery <- paste(expquery, " AND type LIKE '", - endpoint, "'", sep = "") + expquery <- paste0(expquery, " AND type LIKE '", endpoint, "'") } expdata <- RODBC::sqlQuery(channel,expquery) @@ -62,6 +61,16 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") } else { # Use raw response for ecotox expdata$response <- expdata$raw_response + + if (nlevels(expdata$type) > 1) { + message("There are data for more than one type of raw response in your data.\n", + "The types are ", paste(levels(expdata$type), collapse = " and "), ".\n", + "You should choose one of these types using 'endpoint = \"$type\"'", + "in your call to checkexperiment\n", + "For now, we are continuing with the data for ", levels(expdata$type)[1]) + } + endpoint <- expdata$type[1] + expdata <- subset(expdata, type == endpoint) controls <- subset(expdata, conc == 0) expdata <- subset(expdata, conc != 0) @@ -112,6 +121,7 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") expdata$unit <- factor(expdata$unit) expdata$ok <- factor(expdata$ok) + # Info on the experiment cat("\n",exptypestring,id,"from database",db,":\n\n", "\tExperimentator(s):\t",levels(expdata$experimentator),"\n", "\tType(s):\t\t",levels(expdata$type),"\n", @@ -123,10 +133,23 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") print(QA) + # Control growth rate for Lemna and algae + if (endpoint %in% c("cell count", "frond area", "frond number")) { + duration <- unique(expdata$duration) # in hours + if (length(duration) > 1) stop("More than one duration in the data") + response_0 <- unique(expdata$raw_0) + if (length(response_0) > 1) stop("More than one mean response at time 0 in the data") + t_days <- duration / 24 + control_growth_rates <- log(controls$response) - log(response_0) / t_days + cat("\nMean growth rate in controls:\t", round(mean(control_growth_rates), 3), "per day\n") + } + + + # Box plot of control data if (db == "ecotox") { boxplot(controls$response, names="controls", - ylab="Response", + ylab=endpoint, ylim=range(controls$response, na.rm = TRUE), boxwex=0.4, main=paste("Plate ",id)) @@ -138,6 +161,7 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") main=paste("Plate ",id)) } + # Plot of dose response data drdata <- expdata[c(2,4,6)] drdata$substance <- factor(drdata$substance) substances <- levels(drdata$substance) @@ -145,11 +169,14 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%") lld <- log10(min(subset(drdata,conc!=0)$conc)) lhd <- log10(max(drdata$conc)) + ylab <- if (db == "ecotox") endpoint + else responsename + plot(1,type="n", xlim = c(lld - 0.5, lhd + 2), ylim = range(expdata[responsename], na.rm = TRUE), xlab = paste("decadic logarithm of the concentration in ",levels(expdata$unit)), - ylab = responsename) + ylab = ylab) drdatalist <- split(drdata,drdata$substance) -- cgit v1.2.1