diff options
-rw-r--r-- | DESCRIPTION | 4 | ||||
-rw-r--r-- | R/checkexperiment.R | 41 | ||||
-rw-r--r-- | R/checkplate.R | 4 | ||||
-rw-r--r-- | R/checksubstance.R | 86 | ||||
-rw-r--r-- | R/drplot.R | 36 | ||||
-rw-r--r-- | man/checkexperiment.Rd | 13 | ||||
-rw-r--r-- | man/checksubstance.Rd | 13 | ||||
-rw-r--r-- | man/drplot.Rd | 13 |
8 files changed, 141 insertions, 69 deletions
diff --git a/DESCRIPTION b/DESCRIPTION index ee6d4ff..8f8b1e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: drfit -Version: 0.05-80 -Date: 2006-05-22 +Version: 0.05-83 +Date: 2006-08-14 Title: Dose-response data evaluation Author: Johannes Ranke <jranke@uni-bremen.de> Maintainer: Johannes Ranke <jranke@uni-bremen.de> diff --git a/R/checkexperiment.R b/R/checkexperiment.R index 3078ca5..941856b 100644 --- a/R/checkexperiment.R +++ b/R/checkexperiment.R @@ -1,23 +1,29 @@ -checkexperiment <- function(id,db="ecotox") +checkexperiment <- function(id, db = "ecotox", endpoint = "%") { databases <- data.frame( - responsetype=c("viability","activity","response"), + responsename=c("viability","activity","response"), testtype=c("celltype","enzyme","organism"), exptype=c("plate","plate","experiment")) rownames(databases) <- c("cytotox","enzymes","ecotox") - if (!(db %in% rownames(databases))) stop("Database does not exist") + if (!(db %in% rownames(databases))) stop("Database is not supported") library(RODBC) channel <- odbcConnect(db,uid="cytotox",pwd="cytotox",case="tolower") - responsetype = as.character(databases[db,1]) + responsename = as.character(databases[db,1]) testtype = as.character(databases[db,2]) exptype = as.character(databases[db,3]) - expquery <- paste("SELECT experimentator,substance,", - testtype,",conc,unit,",responsetype,",performed,ok", - "FROM ",db," WHERE ",exptype,"=", id) + expquery <- paste("SELECT experimentator,substance, ", + testtype, ",conc,unit,", responsename, ",performed,ok", + " FROM ",db," WHERE ",exptype,"=", id, + sep = "") + + if (db == "ecotox") { + expquery <- paste(expquery, " AND type LIKE '", + endpoint, "'", sep = "") + } expdata <- sqlQuery(channel,expquery) @@ -57,10 +63,13 @@ checkexperiment <- function(id,db="ecotox") meanOfControls <- stdOfControls <- percentstdOfcontrols <- NA } + if (length(expdata$experimentator) < 1) { stop("There is no response data for ",exptype," ", id," in database ",db,"\n") } + exptypestring <- paste(toupper(substring(exptype,1,1)), + substring(exptype,2),sep="") expdata$experimentator <- factor(expdata$experimentator) expdata$type <- factor(expdata[[testtype]]) expdata$performed <- factor(as.character(expdata$performed)) @@ -68,13 +77,13 @@ checkexperiment <- function(id,db="ecotox") expdata$unit <- factor(expdata$unit) expdata$ok <- factor(expdata$ok) - cat("\n",exptype," ",id," from database ",db,"\n", - "\tExperimentator(s): ",levels(expdata$experimentator),"\n", - "\tType(s): ",levels(expdata$type),"\n", - "\tPerformed on: ",levels(expdata$performed),"\n", - "\tSubstance(s): ",levels(expdata$substance),"\n", - "\tConcentration unit(s): ",levels(expdata$unit),"\n", - "\tOK: ",levels(expdata$ok),"\n", + cat("\n",exptypestring,id,"from database",db,":\n\n", + "\tExperimentator(s):\t",levels(expdata$experimentator),"\n", + "\tType(s):\t\t",levels(expdata$type),"\n", + "\tPerformed on:\t\t",levels(expdata$performed),"\n", + "\tSubstance(s):\t\t",levels(expdata$substance),"\n", + "\tConcentration unit(s):\t",levels(expdata$unit),"\n", + "\tOK:\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", @@ -107,12 +116,12 @@ checkexperiment <- function(id,db="ecotox") xlim=c(lld - 0.5, lhd + 2), ylim= c(-0.1, 2), xlab=paste("decadic logarithm of the concentration in ",levels(expdata$unit)), - ylab=responsetype) + ylab=responsename) drdatalist <- split(drdata,drdata$substance) for (i in 1:length(drdatalist)) { - points(log10(drdatalist[[i]]$conc),drdatalist[[i]][[responsetype]],col=i); + points(log10(drdatalist[[i]]$conc),drdatalist[[i]][[responsename]],col=i); } legend("topright",substances, pch=1, col=1:length(substances), inset=0.05) diff --git a/R/checkplate.R b/R/checkplate.R index e03be70..0a56e44 100644 --- a/R/checkplate.R +++ b/R/checkplate.R @@ -1,4 +1,4 @@ -checkplate <- function(id,db="cytotox") +checkplate <- function(id, db = "cytotox") { - checkexperiment(id,db=db) + checkexperiment(id, db = db) } diff --git a/R/checksubstance.R b/R/checksubstance.R index 986edda..96be999 100644 --- a/R/checksubstance.R +++ b/R/checksubstance.R @@ -1,60 +1,94 @@ -checksubstance <- function(substance,db="cytotox",experimentator="%",celltype="%",enzymetype="%",whereClause="1",ok="%") +checksubstance <- function(substance, db = "cytotox", experimentator = "%", + celltype = "%", enzymetype = "%", organism = "%", + endpoint = "%", + whereClause = "1", ok= "%") { + databases <- data.frame( + responsename=c("viability","activity","response"), + testtype=c("celltype","enzyme","organism"), + exptype=c("plate","plate","experiment")) + rownames(databases) <- c("cytotox","enzymes","ecotox") + + if (!(db %in% rownames(databases))) stop("Database is not supported") + library(RODBC) channel <- odbcConnect(db,uid="cytotox",pwd="cytotox",case="tolower") + responsename = as.character(databases[db,1]) + testtype = as.character(databases[db,2]) + exptype = as.character(databases[db,3]) + if (db == "cytotox") { - responsetype <- "viability" - testtype <- "celltype" type <- celltype - } else { - responsetype <- "activity" - testtype <- "enzyme" + } + if (db == "enzymes") { type <- enzymetype - } - query <- paste("SELECT experimentator,substance,",testtype,",plate,conc,unit,",responsetype,",ok", + } + if (db == "ecotox") { + type <- organism + } + + query <- paste("SELECT experimentator,substance,", + testtype, ",", exptype, ",conc,unit,",responsename,",ok", " FROM ",db," WHERE substance LIKE '", substance,"' AND experimentator LIKE '", experimentator,"' AND ",testtype," LIKE '", type,"' AND ", - whereClause," AND ok LIKE '",ok,"'",sep="") + whereClause," AND ok LIKE '",ok,"'", + sep = "") + + if (db == "ecotox") { + query <- paste(query, " AND type LIKE '", + endpoint, "'", sep = "") + } data <- sqlQuery(channel,query) odbcClose(channel) + + if (length(data$experimentator) < 1) { + stop(paste("\nNo response data for",substance,"in database", + db,"found with these parameters\n")) + } data$experimentator <- factor(data$experimentator) data$substance <- factor(data$substance) substances <- levels(data$substance) data$type <- factor(data[[testtype]]) - data$plate <- factor(data$plate) - plates <- levels(data$plate) + data[[exptype]] <- factor(data[[exptype]]) + experiments <- levels(data[[exptype]]) concentrations <- split(data$conc,data$conc) concentrations <- as.numeric(names(concentrations)) data$unit <- factor(data$unit) data$ok <- factor(data$ok) - - if (length(plates)>6) { - palette(rainbow(length(plates))) + + if (length(experiments)>6) { + palette(rainbow(length(experiments))) } - plot(log10(data$conc),data[[responsetype]], + plot(log10(data$conc),data[[responsename]], xlim=c(-2.5, 4.5), ylim= c(-0.1, 2), xlab=paste("decadic logarithm of the concentration in ",levels(data$unit)), - ylab=responsetype) + ylab=responsename) - platelist <- split(data,data$plate) + explist <- split(data,data[[exptype]]) - for (i in 1:length(platelist)) { - points(log10(platelist[[i]]$conc),platelist[[i]][[responsetype]],col=i); + for (i in 1:length(explist)) { + points(log10(explist[[i]]$conc),explist[[i]][[responsename]],col=i); } - legend("topleft", plates, pch=1, col=1:length(plates), inset=0.05) + legend("topleft", experiments, pch=1, col=1:length(experiments), inset=0.05) title(main=paste(substance," - ",levels(data$experimentator)," - ",levels(data$type))) - - cat("Substanz ",substance,"\n", - "\tExperimentator(s):",levels(data$experimentator),"\n", - "\tType(s):\t",levels(data$type),"\n", - "\tSubstance(s):\t",levels(data$substance),"\n", - "\tPlate(s):\t",plates,"\n\n") + + exptypename <- paste(toupper(substring(exptype,1,1)), + substring(exptype,2), sep = "") + experimentators <- paste(levels(data$experimentator), collapse = " ") + types <- paste(levels(data$type), collapse = " ") + experiments <- paste(levels(data[[exptype]]), collapse = " ") + class(experiments) + cat("\n\tSubstanz:\t\t",substance,"\n", + "\tExperimentator(s):\t", experimentators,"\n", + "\tType(s): \t\t",types,"\n", + "\tEndpoint: \t\t",endpoint,"\n", + "\t", exptypename, "(s):\t\t",experiments,"\n\n", sep = "") } @@ -2,10 +2,12 @@ drplot <- function(drresults, data, dtype = "std", alpha = 0.95, ctype = "none", path = "./", fileprefix = "drplot", overlay = FALSE, xlim = c("auto","auto"), ylim = c("auto","auto"), + xlab = paste("Decadic Logarithm of the dose in ", unit), + ylab = "Normalized response", postscript = FALSE, pdf = FALSE, png = FALSE, bw = TRUE, pointsize = 12, - colors = 1:8, devoff=T, lpos="topright") + colors = 1:8, ltys = 1:8, devoff=T, lpos="topright") { # Check if all data have the same unit unitlevels <- levels(as.factor(drresults$unit)) @@ -81,8 +83,8 @@ drplot <- function(drresults, data, plot(0,type="n", xlim = xlim, ylim = ylim, - xlab = paste("Decadic Logarithm of the dose in ", unit), - ylab = "Normalized response") + xlab = xlab, + ylab = ylab) } else { # If overlay plot is not requested, ask before showing multiple plots on the screen if (!postscript && !png && !pdf && length(dsubstances) > 1) { @@ -90,6 +92,8 @@ drplot <- function(drresults, data, on.exit(par(op)) } } + # nl is the overall number of fits to draw by different line types + nl <- 0 # Plot the data either as raw data or as error bars if(is.data.frame(data)) { @@ -97,7 +101,7 @@ drplot <- function(drresults, data, # n is the index for the dose-response curves n <- 0 if (bw) colors <- rep("black",length(dsubstances)) - # Loop over the substances in the data + # Loop over the substances in the data (index n) for (i in dsubstances) { n <- n + 1 tmp <- splitted[[i]] @@ -128,10 +132,10 @@ drplot <- function(drresults, data, plot(0,type="n", xlim = xlim, ylim = ylim, - xlab = paste("Decadic Logarithm of the dose in ", unit), - ylab = "Normalized response") + xlab = xlab, + ylab = ylab) } - if (!overlay) legend(lpos, i,lty = 1, col = color, inset=0.05) + if (!overlay) legend(lpos, i, lty = 1, col = color, inset=0.05) tmp$dosefactor <- factor(tmp$dose) # necessary because the old # factor has all levels, not # only the ones tested with @@ -180,31 +184,35 @@ drplot <- function(drresults, data, } } - # Plot the fits, if there are any + # Plot the fits for this substance, if there are any fits <- subset(drresults,Substance == i) - nf <- length(fits$Substance) # number of fits to plot + nf <- length(fits$Substance) # number of fits to plot for this substance if (nf > 0) { for (j in 1:nf) { logED50 <- fits[j,"logED50"] mtype <- as.character(fits[j, "mtype"]) if (mtype == "probit") { + lty <- ltys[nl <- nl + 1] scale <- fits[j,"b"] - plot(function(x) pnorm(-x,-logED50,scale),lld - 0.5, lhd + 2, add=TRUE,col=color) + plot(function(x) pnorm(-x,-logED50,scale),lld - 0.5, lhd + 2, add=TRUE, col=color, lty=lty) } if (mtype == "logit") { + lty <- ltys[nl <- nl + 1] scale <- fits[j,"b"] - plot(function(x) plogis(-x,-logED50,scale),lld - 0.5, lhd + 2, add=TRUE,col=color) + plot(function(x) plogis(-x,-logED50,scale),lld - 0.5, lhd + 2, add=TRUE, col=color, lty=lty) } if (mtype == "weibull") { + lty <- ltys[nl <- nl + 1] location <- fits[j,"a"] shape <- fits[j,"b"] - plot(function(x) pweibull(-x+location,shape),lld - 0.5, lhd + 2, add=TRUE,col=color) + plot(function(x) pweibull(-x+location,shape),lld - 0.5, lhd + 2, add=TRUE, col=color, lty=lty) } if (mtype == "linlogit") { + lty <- ltys[nl <- nl + 1] plot(function(x) linlogitf(10^x,1,fits[j,"c"],fits[j,"logED50"],fits[j,"b"]), lld - 0.5, lhd + 2, - add=TRUE,col=color) + add=TRUE, col=color, lty=lty) } } } @@ -214,7 +222,7 @@ drplot <- function(drresults, data, } } } - if (overlay) legend(lpos, dsubstances,lty = 1, col = colors, inset=0.05) + if (overlay) legend(lpos, dsubstances, col = colors, lty = ltys, inset=0.05) if (overlay && (postscript || png || pdf)) { if (devoff) { dev.off() diff --git a/man/checkexperiment.Rd b/man/checkexperiment.Rd index 56db90c..1162d1b 100644 --- a/man/checkexperiment.Rd +++ b/man/checkexperiment.Rd @@ -7,16 +7,19 @@ specified database, box plot controls, and plot the dose-response data. } \usage{ - checkplate(id,db="cytotox") - checkexperiment(id,db="ecotox") + checkplate(id, db = "cytotox") + checkexperiment(id, db = "ecotox", endpoint = "\%") } \arguments{ \item{id}{ The id of the experiment or the plate identifying it within the database.} \item{db}{ - The database to be used. Currently, the microtiter plate databases - "cytotox", "enzymes" of the UFT Department of Bioorganic Chemistry are - supported, as well as the database of ecotoxicity experiments "ecotox".} + The database to be used. Currently, the microtiter plate databases + "cytotox", "enzymes" of the UFT Department of Bioorganic Chemistry are + supported, as well as the database of ecotoxicity experiments "ecotox".} + \item{endpoint}{ + The endpoint that should be used for selecting the data. Only important if + the database "ecotox" is used. Defaults to "\%".} } \value{ The function lists a report and shows two graphs side by side. diff --git a/man/checksubstance.Rd b/man/checksubstance.Rd index f5340fe..387785f 100644 --- a/man/checksubstance.Rd +++ b/man/checksubstance.Rd @@ -6,7 +6,10 @@ the data. } \usage{ - checksubstance(substance,db="cytotox",experimentator="\%",celltype="\%",enzymetype="\%",whereClause="1",ok="\%") + checksubstance(substance, db = "cytotox", experimentator = "\%", + celltype = "\%", enzymetype = "\%", organism = "\%", + endpoint = "\%", + whereClause = "1", ok = "\%") } \arguments{ \item{substance}{ @@ -25,9 +28,15 @@ \item{enzymetype}{ Currently, only data for AChE, GR and GST are supported. The default value is "\%", i.e. data for any enzyme type will be displayed.} + \item{organism}{ + The latin name of the tested organism, if the ecotox db was selected. The + default value is "\%", i.e. data for any organism will be displayed.} + \item{endpoint}{ + The endpoint that should be used for selecting the data. Only important if + the database "ecotox" is used. Defaults to "\%".} \item{whereClause}{ With this argument, additional conditions for the SQL query can be set, - e.g. "where plate != 710". The default is 1 (in SQL syntax this means TRUE).} + e.g. "plate != 710". The default is 1 (in SQL syntax this means TRUE).} \item{ok}{ With the default value "\%", all data in the database is retrieved for the specified substance.} diff --git a/man/drplot.Rd b/man/drplot.Rd index bff2388..7924be2 100644 --- a/man/drplot.Rd +++ b/man/drplot.Rd @@ -7,8 +7,8 @@ } \usage{ drplot(drresults, data, dtype, alpha, ctype, path, - fileprefix, overlay, xlim, ylim, postscript, pdf, png, bw, - pointsize, colors, devoff, lpos) + fileprefix, overlay, xlim, ylim, xlab, ylab, postscript, pdf, png, bw, + pointsize, colors, ltys, devoff, lpos) } \arguments{ \item{drresults}{ @@ -57,6 +57,12 @@ \item{ylim}{ The plot limits (min,max) on the response axis. } + \item{xlab}{ + The axis title for the x axis. Defaults to "Concentration in" \code{unit}. + } + \item{ylab}{ + The axis title for the y axis. Defaults to "Normalized response". + } \item{postscript}{ If TRUE, (a) postscript graph(s) will be created. Otherwise, and if the pdf and png arguments are also FALSE, graphics will be @@ -82,6 +88,9 @@ \item{colors}{ This is a vector of colors, defaulting to 1:8, used for plotting the data. } + \item{ltys}{ + This is a vector of line types for the dose-response models, defaulting to 1:8. + } \item{lpos}{ An optional argument defaulting to "topright" specifying the position of the legend by being passed to the legend function. See the help for the |