From c4236c0f742201b375402b8bd0f01817f2c42277 Mon Sep 17 00:00:00 2001 From: jeffersonfparil Date: Thu, 19 Dec 2024 08:52:25 +1100 Subject: [PATCH] updated error catching in gp --- R/cross_validation.R | 73 ++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/R/cross_validation.R b/R/cross_validation.R index 15b6a6e..82dd5b7 100644 --- a/R/cross_validation.R +++ b/R/cross_validation.R @@ -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) } @@ -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 @@ -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 @@ -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) } @@ -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 @@ -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) }