diff --git a/R/mc6.R b/R/mc6.R index 918fd7bb..09cb6262 100644 --- a/R/mc6.R +++ b/R/mc6.R @@ -49,13 +49,6 @@ mc6 <- function(ae, wr = FALSE) { ## Load level 5 and, if needed, level 3 data ft <- tcplLoadData(lvl = 5L, type = "mc", fld = "aeid", val = ae, add.fld = TRUE) - setkey(ft, m4id) - if (any(ms$nddr)) { - dr <- .load6DR(ae) - setkey(dr, m4id, aeid, spid) - setkey(ft, m4id, aeid, spid) - dr <- dr[ft] - } ## Check if any level 5 data was loaded if (nrow(ft) == 0) { @@ -63,6 +56,22 @@ mc6 <- function(ae, wr = FALSE) { " no updates\n made to the mc6 table for AEID", ae, ".") if(wr) return(FALSE) else return(list(FALSE, NULL)) } + + ## Remove modl == none and check if any data remains + ft <- ft[modl != "none",] + if (nrow(ft) == 0) { + warning("All level 5 data for AEID", ae, " have winning model of 'none'. Level 6 processing incomplete;", + " no updates\n made to the mc6 table for AEID", ae, ".") + if(wr) return(FALSE) else return(list(FALSE, NULL)) + } + + setkey(ft, m4id) + if (any(ms$nddr)) { + dr <- .load6DR(ae) + setkey(dr, m4id, aeid, spid) + setkey(ft, m4id, aeid, spid) + dr <- dr[ft] + } ## Load assay information to check for cell viability. Fill with 0 if unavailable. tbl <- "assay_component_endpoint" @@ -90,7 +99,7 @@ mc6 <- function(ae, wr = FALSE) { ## Initialize f, the list of data.tables containing the flag information f <- vector(mode = "list", length = max(ms$mthd_id)) - + ## Generate and evaluate flag expressions mthd_funcs <- mc6_mthds() exprs <- lapply(ms$mthd_id, function(x) mthd_funcs[[ms[J(x), mthd]]](x)) # XXX this breaks if functions appear more than once in mc6_mthds() diff --git a/R/mc6_mthds.R b/R/mc6_mthds.R index a7dce018..b5baffa4 100644 --- a/R/mc6_mthds.R +++ b/R/mc6_mthds.R @@ -173,7 +173,7 @@ mc6_mthds <- function() { "flag", "fval", "fval_unit") init <- bquote(list(.(mthd), .(flag), NA_real_, NA_character_, FALSE)) e1 <- bquote(ft[ , .(c(out[4:7], "test")) := .(init)]) - e2 <- bquote(ft[ , test := bmd > ac50]) + e2 <- bquote(ifelse(all(c("ac50","bmd") %in% names(ft)),ft[ , test := bmd > ac50],ft)) e3 <- bquote(f[[.(mthd)]] <- ft[which(test), .SD, .SDcols = .(out)]) cr <- c("mc6_mthd_id", "flag", "fval", "fval_unit", "test") e4 <- bquote(ft[ , .(cr) := NULL])