Skip to content

Commit

Permalink
updated error catching in gp
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonfparil committed Dec 18, 2024
1 parent f780060 commit c4236c0
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions R/cross_validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,11 @@ fn_cross_validation_within_population = function(list_merged, n_folds=10, n_reps
)))
cat(error@message); return(error)
}
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
df_metrics = rbind(df_metrics, list_perf$df_metrics)
df_y_validation = rbind(df_y_validation, list_perf$df_y_validation)
}
Expand Down Expand Up @@ -822,12 +822,14 @@ fn_cross_validation_within_population = function(list_merged, n_folds=10, n_reps
for (fname_within_Rds in vec_fname_within_Rds) {
# fname_within_Rds = vec_fname_within_Rds[1]
list_tmp = readRDS(fname_within_Rds)
if (is.null(METRICS_WITHIN_POP) & is.null(YPRED_WITHIN_POP)) {
METRICS_WITHIN_POP = list_tmp$df_metrics
YPRED_WITHIN_POP = list_tmp$df_y_validation
} else {
METRICS_WITHIN_POP = rbind(METRICS_WITHIN_POP, list_tmp$df_metrics)
YPRED_WITHIN_POP = rbind(YPRED_WITHIN_POP, list_tmp$df_y_validation)
if (!is.na(utils::head(list_tmp$df_metrics, n=1)[1]) & !is.na(utils::head(list_tmp$df_y_validation, n=1)[1])) {
if (is.null(METRICS_WITHIN_POP) & is.null(YPRED_WITHIN_POP)) {
METRICS_WITHIN_POP = list_tmp$df_metrics
YPRED_WITHIN_POP = list_tmp$df_y_validation
} else {
METRICS_WITHIN_POP = rbind(METRICS_WITHIN_POP, list_tmp$df_metrics)
YPRED_WITHIN_POP = rbind(YPRED_WITHIN_POP, list_tmp$df_y_validation)
}
}
}
### Save the concatenated output data frames across populations and clean-up
Expand Down Expand Up @@ -1091,12 +1093,15 @@ fn_cross_validation_across_populations_bulk = function(list_merged, n_folds=10,
YPRED_ACROSS_POP_BULK = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.null(METRICS_ACROSS_POP_BULK) & is.null(YPRED_ACROSS_POP_BULK)) {
METRICS_ACROSS_POP_BULK = list_perf$df_metrics
YPRED_ACROSS_POP_BULK = list_perf$df_y_validation
} else {
METRICS_ACROSS_POP_BULK = rbind(METRICS_ACROSS_POP_BULK, list_perf$df_metrics)
YPRED_ACROSS_POP_BULK = rbind(YPRED_ACROSS_POP_BULK, list_perf$df_y_validation)
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (is.null(METRICS_ACROSS_POP_BULK) & is.null(YPRED_ACROSS_POP_BULK)) {
METRICS_ACROSS_POP_BULK = list_perf$df_metrics
YPRED_ACROSS_POP_BULK = list_perf$df_y_validation
} else {

METRICS_ACROSS_POP_BULK = rbind(METRICS_ACROSS_POP_BULK, list_perf$df_metrics)
YPRED_ACROSS_POP_BULK = rbind(YPRED_ACROSS_POP_BULK, list_perf$df_y_validation)
}
}
}
### Save the concatenated output data frames across populations and clean-up
Expand Down Expand Up @@ -1378,11 +1383,11 @@ fn_cross_validation_across_populations_pairwise = function(list_merged,
df_y_validation = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
df_metrics = rbind(df_metrics, list_perf$df_metrics)
df_y_validation = rbind(df_y_validation, list_perf$df_y_validation)
}
Expand Down Expand Up @@ -1415,12 +1420,14 @@ fn_cross_validation_across_populations_pairwise = function(list_merged,
for (fname_across_pairwise_Rds in vec_fname_across_pairwise_Rds) {
# fname_across_pairwise_Rds = vec_fname_across_pairwise_Rds[1]
list_tmp = readRDS(fname_across_pairwise_Rds)
if (is.null(METRICS_ACROSS_POP_PAIRWISE) & is.null(YPRED_ACROSS_POP_PAIRWISE)) {
METRICS_ACROSS_POP_PAIRWISE = list_tmp$df_metrics
YPRED_ACROSS_POP_PAIRWISE = list_tmp$df_y_validation
} else {
METRICS_ACROSS_POP_PAIRWISE = rbind(METRICS_ACROSS_POP_PAIRWISE, list_tmp$df_metrics)
YPRED_ACROSS_POP_PAIRWISE = rbind(YPRED_ACROSS_POP_PAIRWISE, list_tmp$df_y_validation)
if (!is.na(utils::head(list_tmp$df_metrics, n=1)[1]) & !is.na(utils::head(list_tmp$df_y_validation, n=1)[1])) {
if (is.null(METRICS_ACROSS_POP_PAIRWISE) & is.null(YPRED_ACROSS_POP_PAIRWISE)) {
METRICS_ACROSS_POP_PAIRWISE = list_tmp$df_metrics
YPRED_ACROSS_POP_PAIRWISE = list_tmp$df_y_validation
} else {
METRICS_ACROSS_POP_PAIRWISE = rbind(METRICS_ACROSS_POP_PAIRWISE, list_tmp$df_metrics)
YPRED_ACROSS_POP_PAIRWISE = rbind(YPRED_ACROSS_POP_PAIRWISE, list_tmp$df_y_validation)
}
}
}
### Save the concatenated output data frames across populations and clean-up
Expand Down Expand Up @@ -1661,11 +1668,11 @@ fn_cross_validation_across_populations_lopo = function(list_merged,
df_y_validation = NULL
for (list_perf in list_list_perf) {
# list_perf = list_list_perf[[1]]
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (!is.na(utils::head(list_perf$df_metrics, n=1)[1]) & !is.na(utils::head(list_perf$df_y_validation, n=1)[1])) {
if (is.null(df_metrics) & is.null(df_y_validation)) {
df_metrics = list_perf$df_metrics
df_y_validation = list_perf$df_y_validation
} else {
df_metrics = rbind(df_metrics, list_perf$df_metrics)
df_y_validation = rbind(df_y_validation, list_perf$df_y_validation)
}
Expand Down

0 comments on commit c4236c0

Please sign in to comment.