aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/checkexperiment.R79
1 files changed, 50 insertions, 29 deletions
diff --git a/R/checkexperiment.R b/R/checkexperiment.R
index b69b81f..8c844e6 100644
--- a/R/checkexperiment.R
+++ b/R/checkexperiment.R
@@ -2,7 +2,7 @@ if(getRversion() >= '2.15.1') utils::globalVariables(c("type", "conc"))
checkexperiment <- function(id, db = "ecotox", endpoint = "%")
{
databases <- data.frame(
- responsename=c("viability","activity","response"),
+ responsename=c("viability","activity","raw_response"),
testtype=c("celltype","enzyme","organism"),
exptype=c("plate","plate","experiment"))
rownames(databases) <- c("cytotox","enzymes","ecotox")
@@ -15,7 +15,6 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%")
stop("For this function, the RODBC package has to be installed and configured.")
}
-
responsename = as.character(databases[db,1])
testtype = as.character(databases[db,2])
exptype = as.character(databases[db,3])
@@ -26,8 +25,8 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%")
commentdata <- RODBC::sqlQuery(channel,commentquery)
comment <- as.character(commentdata[[1]])
- expquery <- paste("SELECT experimentator,substance, ",
- testtype, ",conc,unit,", responsename, ",performed,ok",
+ expquery <- paste("SELECT experimentator, substance, ",
+ testtype, ", conc, unit,", responsename, ", performed, ok",
" FROM ",db," WHERE ",exptype,"=", id,
sep = "")
@@ -50,30 +49,55 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%")
on.exit(par(op))
if (db %in% c("cytotox","enzymes")) {
- blinds <- subset(controldata,type=="blind")
- controls <- subset(controldata,type=="control")
-
- numberOfBlinds <- length(blinds$response)
- meanOfBlinds <- signif(mean(blinds$response),2)
- stdOfBlinds <- signif(sd(blinds$response),2)
+ blinds <- subset(controldata, type == "blind")
+ controls <- subset(controldata, type == "control")
+ QA <- matrix(nrow = 2, ncol = 4,
+ dimnames = list(c("Blind", "Control (conc = 0)"),
+ c("Number", "Mean", "Std. Dev.", "% Std. Dev")))
+
+ QA[1, 1] <- length(blinds$response)
+ QA[1, 2] <- signif(mean(blinds$response), 2)
+ QA[1, 3] <- signif(sd(blinds$response), 2)
+ QA[1, 4] <-signif(QA[1, 3] * 100 / QA[1, 2],2)
} else {
- controls <- subset(expdata,conc == 0)
+ # Use raw response for ecotox
+ expdata$response <- expdata$raw_response
+
+ controls <- subset(expdata, conc == 0)
expdata <- subset(expdata, conc != 0)
- numberOfBlinds <- NA
- meanOfBlinds <- NA
- stdOfBlinds <- NA
+ QA <- matrix(nrow = 1, ncol = 4,
+ dimnames = list(c("Control (conc = 0)"),
+ c("Number", "Mean", "Std. Dev.", "% Std. Dev")))
}
+
numberOfControls <- length(controls$response)
+ QA["Control (conc = 0)", 1] <- numberOfControls
if (numberOfControls > 0) {
- meanOfControls <- signif(mean(controls$response),2)
- stdOfControls <- signif(sd(controls$response),2)
- percentstdOfcontrols <-signif(stdOfControls *100/meanOfControls,2)
- } else {
- meanOfControls <- stdOfControls <- percentstdOfcontrols <- NA
+ QA["Control (conc = 0)", 2] <- signif(mean(controls$response),2)
+ QA["Control (conc = 0)", 3] <- signif(sd(controls$response),2)
+ QA["Control (conc = 0)", 4] <- signif(QA["Control (conc = 0)", 3] * 100 /
+ QA["Control (conc = 0)", 2],2)
}
+ if (db == "ecotox") {
+ if (identical(as.character(levels(expdata$organism)), "Vibrio fischeri")) {
+ positive <- subset(expdata, substance == "Na Cl")
+ if (nrow(positive) > 0) {
+ QA <- rbind(QA,
+ c(nrow(positive),
+ signif(mean(positive$raw_response), 2),
+ signif(sd(positive$raw_response), 2),
+ signif(100 * sd(positive$raw_response) /
+ mean(positive$raw_response), 2)))
+
+ rownames(QA) <- c("Control (conc = 0)",
+ "Positive control (Na Cl)")
+ }
+ expdata <- subset(expdata, substance != "Na Cl", drop = TRUE)
+ }
+ }
if (length(expdata$experimentator) < 1) {
stop("There is no response data for ",exptype," ",
@@ -95,18 +119,15 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%")
"\tSubstance(s):\t\t",levels(expdata$substance),"\n",
"\tConcentration unit(s):\t",levels(expdata$unit),"\n",
"\tComment:\t\t",comment,"\n",
- "\tOK Levels:\t\t\t",levels(expdata$ok),"\n",
- "\t\tNumber \tMean \tStd. Dev. \t% Std. Dev.\n",
- "\tblind\t",numberOfBlinds,"\t",meanOfBlinds,"\t",stdOfBlinds,"\n",
- "\tcontrol\t",numberOfControls,"\t",meanOfControls,"\t",
- stdOfControls,"\t\t",percentstdOfcontrols,"\n")
+ "\tOK Levels:\t\t",levels(expdata$ok),"\n\n")
+ print(QA)
if (db == "ecotox") {
boxplot(controls$response,
names="controls",
ylab="Response",
- ylim=c(0,max(controls$response)),
+ ylim=c(0, max(controls$response, na.rm = TRUE)),
boxwex=0.4,
main=paste("Plate ",id))
} else {
@@ -125,10 +146,10 @@ checkexperiment <- function(id, db = "ecotox", endpoint = "%")
lhd <- log10(max(drdata$conc))
plot(1,type="n",
- xlim=c(lld - 0.5, lhd + 2),
- ylim= c(-0.1, 2),
- xlab=paste("decadic logarithm of the concentration in ",levels(expdata$unit)),
- ylab=responsename)
+ xlim = c(lld - 0.5, lhd + 2),
+ ylim = range(0, max(expdata[responsename])),
+ xlab = paste("decadic logarithm of the concentration in ",levels(expdata$unit)),
+ ylab = responsename)
drdatalist <- split(drdata,drdata$substance)

Contact - Imprint