Skip to content

Commit

Permalink
Fixed CEST Interpolation/Extrapolation as an output and OPTIMIZE_KEL
Browse files Browse the repository at this point in the history
- Fixed a logical issue with CEST Interpolation/Extrapolation and TOLD for SD computation
- Fixed an issue with  CEST Interpolation/Extrapolation and TOLD for SS computation
- Fixed an issue with OPTIMIZE_KEL for SS models
- Fixed an issue with preparing the type of data for the output dataframe for all models
  • Loading branch information
opennca committed Nov 12, 2019
1 parent 1fc479c commit a06c1c7
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 88 deletions.
8 changes: 4 additions & 4 deletions openNCA/R/auc_lin.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ auc_lin <- function(conc = NULL, time = NULL, exflag = NULL, interpolate = NULL,
} else {
auc_df <- ""

## 2019-11-07/RD Added for Interpolation to check for triggers for interpolation
## 2019-11-11/RD Added for Interpolation/Extrapolation to check for triggers for interpolation/extrapolation
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
## 2019-11-08/RD Added helper function for Interpolation
##
est_tmp <- estimate_missing_concentration(conc = conc, time = time, auc_method = "LIN", model = model, dosing_type = dosing_type, told = told, orig_conc = orig_conc, orig_time = orig_time)
Expand All @@ -121,9 +121,9 @@ auc_lin <- function(conc = NULL, time = NULL, exflag = NULL, interpolate = NULL,
auc_df <- as.numeric(auc_df)
auc <- sum(auc_df, na.rm = TRUE)
}
## 2019-11-08/RD Returning interpolated data that will be used as an output
## 2019-11-11/RD Returning interpolated/extrapolated data that will be used as an output
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
return(list(auc, est_tmp[[2]]))
} else {
return(auc)
Expand Down
8 changes: 4 additions & 4 deletions openNCA/R/auc_lin_log.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ auc_lin_log <- function(conc = NULL, time = NULL, exflag = NULL, t_max = NULL, i
auc_df <- ""

if(!is.na(t_max)){
## 2019-11-07/RD Added for Interpolation to check for triggers for interpolation
## 2019-11-11/RD Added for Interpolation/Extrapolation to check for triggers for interpolation/extrapolation
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
## 2019-11-08/RD Added helper function for Interpolation
##
est_tmp <- estimate_missing_concentration(conc = conc, time = time, auc_method = "LIN", model = model, dosing_type = dosing_type, told = told, orig_conc = orig_conc, orig_time = orig_time)
Expand All @@ -136,9 +136,9 @@ auc_lin_log <- function(conc = NULL, time = NULL, exflag = NULL, t_max = NULL, i
auc_df <- as.numeric(auc_df)
auc <- sum(auc_df, na.rm = TRUE)
}
## 2019-11-08/RD Returning interpolated data that will be used as an output
## 2019-11-11/RD Returning interpolated/extrapolated data that will be used as an output
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
return(list(auc, est_tmp[[2]]))
} else {
return(auc)
Expand Down
8 changes: 4 additions & 4 deletions openNCA/R/auc_lin_up_log_down.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ auc_lin_up_log_down <- function(conc = NULL, time = NULL, exflag = NULL, interpo
} else {
auc_df <- ""

## 2019-11-07/RD Added for Interpolation to check for triggers for interpolation
## 2019-11-11/RD Added for Interpolation/Extrapolation to check for triggers for interpolation/extrapolation
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
## 2019-11-08/RD Added helper function for Interpolation
##
est_tmp <- estimate_missing_concentration(conc = conc, time = time, auc_method = "LIN", model = model, dosing_type = dosing_type, told = told, orig_conc = orig_conc, orig_time = orig_time)
Expand All @@ -135,9 +135,9 @@ auc_lin_up_log_down <- function(conc = NULL, time = NULL, exflag = NULL, interpo
auc_df <- as.numeric(auc_df)
auc <- sum(auc_df, na.rm = TRUE)
}
## 2019-11-08/RD Returning interpolated data that will be used as an output
## 2019-11-11/RD Returning interpolated/extrapolated data that will be used as an output
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
return(list(auc, est_tmp[[2]]))
} else {
return(auc)
Expand Down
8 changes: 4 additions & 4 deletions openNCA/R/auc_log.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ auc_log <- function(conc = NULL, time = NULL, exflag = NULL, interpolate = NULL,
t_max <- tmax(conc = conc, time = time)
auc_df <- ""

## 2019-11-07/RD Added for Interpolation to check for triggers for interpolation
## 2019-11-11/RD Added for Interpolation/Extrapolation to check for triggers for interpolation/extrapolation
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
## 2019-11-08/RD Added helper function for Interpolation
##
est_tmp <- estimate_missing_concentration(conc = conc, time = time, auc_method = "LIN", model = model, dosing_type = dosing_type, told = told, orig_conc = orig_conc, orig_time = orig_time)
Expand All @@ -132,9 +132,9 @@ auc_log <- function(conc = NULL, time = NULL, exflag = NULL, interpolate = NULL,
auc_df <- as.numeric(auc_df)
auc <- sum(auc_df, na.rm = TRUE)
}
## 2019-11-08/RD Returning interpolated data that will be used as an output
## 2019-11-11/RD Returning interpolated/extrapolated data that will be used as an output
##
if(isTRUE(interpolate)){
if(isTRUE(interpolate) || isTRUE(extrapolate)){
return(list(auc, est_tmp[[2]]))
} else {
return(auc)
Expand Down
26 changes: 12 additions & 14 deletions openNCA/R/run_M1_SD_computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -1123,20 +1123,10 @@ run_M1_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
par_col <- rep(paste0("'", auct1_t2_names[!auct1_t2_names %in% names(map_data)], "'"))
stop(paste0("Dataset provided via 'map' does not contain the required columns for partial areas ", par_col))
}
## 2019-11-08/RD Added for Interpolation to account for error handling
## 2019-11-11/RD Removed Error handling for Interpolation because we agreed dose time is 0 for SD
##
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(opt_list[3] %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (opt_list[3] %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, opt_list[3]] %in% names(tmp_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, opt_list[3]] %in% names(tmp_df))){
tmp_told <- unique(tmp_df[, map_data[, opt_list[3]]])[1]
} else {
tmp_told <- NA
}
} else {
tmp_told <- NA
if((isTRUE(interpolation) || isTRUE(extrapolation))){
tmp_told <- 0
}
for(t in 1:(auc_par_len)){
if(!(is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T1")])) && is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T2")])))){
Expand Down Expand Up @@ -1723,7 +1713,15 @@ run_M1_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
}

for(n in 1:length(regular_int_type)){
suppressWarnings(computation_df[,names(computation_df) == regular_int_type[n]] <- as.numeric(computation_df[,names(computation_df) == regular_int_type[n]]))
tmp_int_type <- computation_df[,names(computation_df) == as.character(regular_int_type[n])]
if(!is.null(ncol(tmp_int_type))){
for(r in 1:length(tmp_int_type)){
print(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r])
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r]))
}
} else {
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])]))
}
}

computation_df <- unit_conversion(data = data_data, map = map_data, result = computation_df, unit_class = "ALL")
Expand Down
28 changes: 18 additions & 10 deletions openNCA/R/run_M1_SS_computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -1908,15 +1908,15 @@ run_M1_SS_computation <- function(data = NULL, map = NULL, method = 1, model_reg
time <- sort(unique(data_data[,map_data$TIME]))
time_di <- sort(tmp_di_df[,map_data$TIME])

## 2019-11-08/RD Added for Interpolation to account for error handling
## 2019-11-11/RD Added for Interpolation to account for error handling
##
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(opt_list[3] %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (opt_list[3] %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, opt_list[3]] %in% names(tmp_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if(isTRUE(interpolation) && (map_data[, opt_list[3]] %in% names(tmp_df))){
tmp_told <- unique(tmp_df[, map_data[, opt_list[3]]])[1]
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(c(paste0("TOLD",d)) %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", paste0("TOLD",d)))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (c(paste0("TOLD",d)) %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, c(paste0("TOLD",d))] %in% names(tmp_di_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", paste0("TOLD",d)))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, c(paste0("TOLD",d))] %in% names(tmp_di_df))){
tmp_told <- tmp_di_df[, as.character(map_data[c(paste0("TOLD",d))])][1]
} else {
tmp_told <- NA
}
Expand Down Expand Up @@ -2614,9 +2614,17 @@ run_M1_SS_computation <- function(data = NULL, map = NULL, method = 1, model_reg
if("FLGEMESIS" %in% names(map_data) && ("TMAXi" %in% parameter_list)){
comutation_df$FLGACCEPTTMAX <- ifelse(computation_df$FLGEMESIS == 1 & computation_df$TMAX1 < 2 * median(computation_df$TMAX1), TRUE, FALSE)
}

for(n in 1:length(regular_int_type)){
suppressWarnings(computation_df[,names(computation_df) == regular_int_type[n]] <- as.numeric(computation_df[,names(computation_df) == regular_int_type[n]]))
tmp_int_type <- computation_df[,names(computation_df) == as.character(regular_int_type[n])]
if(!is.null(ncol(tmp_int_type))){
for(r in 1:length(tmp_int_type)){
print(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r])
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r]))
}
} else {
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])]))
}
}

computation_df <- unit_conversion(data = data_data, map = map_data, result = computation_df, unit_class = "ALL")
Expand Down
26 changes: 12 additions & 14 deletions openNCA/R/run_M2_SD_computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,10 @@ run_M2_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
par_col <- rep(paste0("'", auct1_t2_names[!auct1_t2_names %in% names(map_data)], "'"))
stop(paste0("Dataset provided via 'map' does not contain the required columns for partial areas ", par_col))
}
## 2019-11-08/RD Added for Interpolation to account for error handling
## 2019-11-11/RD Removed Error handling for Interpolation because we agreed dose time is 0 for SD
##
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(opt_list[3] %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (opt_list[3] %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, opt_list[3]] %in% names(tmp_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, opt_list[3]] %in% names(tmp_df))){
tmp_told <- unique(tmp_df[, map_data[, opt_list[3]]])[1]
} else {
tmp_told <- NA
}
} else {
tmp_told <- NA
if((isTRUE(interpolation) || isTRUE(extrapolation))){
tmp_told <- 0
}
for(t in 1:(auc_par_len)){
if(!(is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T1")])) && is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T2")])))){
Expand Down Expand Up @@ -1681,7 +1671,15 @@ run_M2_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
}

for(n in 1:length(regular_int_type)){
computation_df[,names(computation_df) == regular_int_type[n]] <- as.numeric(computation_df[,names(computation_df) == regular_int_type[n]])
tmp_int_type <- computation_df[,names(computation_df) == as.character(regular_int_type[n])]
if(!is.null(ncol(tmp_int_type))){
for(r in 1:length(tmp_int_type)){
print(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r])
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r]))
}
} else {
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])]))
}
}

computation_df <- unit_conversion(data = data_data, map = map_data, result = computation_df, unit_class = "ALL")
Expand Down
27 changes: 18 additions & 9 deletions openNCA/R/run_M2_SS_computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -1727,15 +1727,16 @@ print("in AUCINFOi comp required")
if(comp_required[["AUCT1_T2"]] && auc_pair_check) {
time <- sort(unique(data_data[,map_data$TIME]))
time_di <- sort(tmp_di_df[,map_data$TIME])
## 2019-11-08/RD Added for Interpolation to account for error handling

## 2019-11-11/RD Added for Interpolation to account for error handling
##
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(opt_list[3] %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (opt_list[3] %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, opt_list[3]] %in% names(tmp_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, opt_list[3]] %in% names(tmp_df))){
tmp_told <- unique(tmp_df[, map_data[, opt_list[3]]])[1]
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(c(paste0("TOLD",d)) %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", paste0("TOLD",d)))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (c(paste0("TOLD",d)) %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, c(paste0("TOLD",d))] %in% names(tmp_di_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", paste0("TOLD",d)))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, c(paste0("TOLD",d))] %in% names(tmp_di_df))){
tmp_told <- tmp_di_df[, as.character(map_data[c(paste0("TOLD",d))])][1]
} else {
tmp_told <- NA
}
Expand Down Expand Up @@ -2306,7 +2307,15 @@ print("in AUCINFOi comp required")
}

for(n in 1:length(regular_int_type)){
suppressWarnings(computation_df[,names(computation_df) == regular_int_type[n]] <- as.numeric(computation_df[,names(computation_df) == regular_int_type[n]]))
tmp_int_type <- computation_df[,names(computation_df) == as.character(regular_int_type[n])]
if(!is.null(ncol(tmp_int_type))){
for(r in 1:length(tmp_int_type)){
print(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r])
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r]))
}
} else {
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])]))
}
}

computation_df <- unit_conversion(data = data_data, map = map_data, result = computation_df, unit_class = "ALL")
Expand Down
26 changes: 12 additions & 14 deletions openNCA/R/run_M3_SD_computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,10 @@ run_M3_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
par_col <- rep(paste0("'", auct1_t2_names[!auct1_t2_names %in% names(map_data)], "'"))
stop(paste0("Dataset provided via 'map' does not contain the required columns for partial areas ", par_col))
}
## 2019-11-08/RD Added for Interpolation to account for error handling
## 2019-11-11/RD Removed Error handling for Interpolation because we agreed dose time is 0 for SD
##
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(opt_list[3] %in% names(map_data))){
stop(paste0("Dataset provided via 'map' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (opt_list[3] %in% names(map_data))) {
if((isTRUE(interpolation) || isTRUE(extrapolation)) && !(map_data[, opt_list[3]] %in% names(tmp_df))){
stop(paste0("Dataset provided via 'data' does not contain the required columns for interpolating partial areas ", opt_list[3]))
} else if((isTRUE(interpolation) || isTRUE(extrapolation)) && (map_data[, opt_list[3]] %in% names(tmp_df))){
tmp_told <- unique(tmp_df[, map_data[, opt_list[3]]])[1]
} else {
tmp_told <- NA
}
} else {
tmp_told <- NA
if((isTRUE(interpolation) || isTRUE(extrapolation))){
tmp_told <- 0
}
for(t in 1:(auc_par_len)){
if(!(is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T1")])) && is.numeric(as.numeric(map_data[, paste0("AUC.", t, ".T2")])))){
Expand Down Expand Up @@ -1679,7 +1669,15 @@ run_M3_SD_computation <- function(data = NULL, map = NULL, method = 1, model_reg
}

for(n in 1:length(regular_int_type)){
computation_df[,names(computation_df) == regular_int_type[n]] <- as.numeric(computation_df[,names(computation_df) == regular_int_type[n]])
tmp_int_type <- computation_df[,names(computation_df) == as.character(regular_int_type[n])]
if(!is.null(ncol(tmp_int_type))){
for(r in 1:length(tmp_int_type)){
print(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r])
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])][,r]))
}
} else {
suppressWarnings(computation_df[,names(computation_df) == as.character(regular_int_type[n])] <- as.numeric(computation_df[,names(computation_df) == as.character(regular_int_type[n])]))
}
}
### check units processing
### print(computation_df)
Expand Down

0 comments on commit a06c1c7

Please sign in to comment.