Skip to content

Commit

Permalink
added check for bmd and ac50 in bmd.high flagging (#41)
Browse files Browse the repository at this point in the history
* added check for bmd and ac50 in bmd.high flagging

* added check for modl = 'none' and return warning if all results are modl = 'none'
  • Loading branch information
brown-jason authored Apr 25, 2023
1 parent 020b214 commit e0188d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions R/mc6.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,29 @@ 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) {
warning("No level 5 data for AEID", ae, ". Level 6 processing incomplete;",
" 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"
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/mc6_mthds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit e0188d1

Please sign in to comment.