aboutsummaryrefslogtreecommitdiff
path: root/R/checkexperiment.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2017-07-18 11:25:23 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2017-07-18 14:40:50 +0200
commitabebba715cf2a317acc04cc0d229c2a605a005a2 (patch)
treebbc8820a52bb69692969dfc9766da544678b8ede /R/checkexperiment.R
parent52bb819dac45d1d8ddfba2e88c0e476014c28774 (diff)
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).
Diffstat (limited to 'R/checkexperiment.R')
-rw-r--r--R/checkexperiment.R37
1 files 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)

Contact - Imprint