Skip to content

Commit

Permalink
fixing empty plots
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonfparil committed Dec 16, 2024
1 parent d6c75f9 commit a8d327c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion R/metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn_prediction_performance_metrics = function(y_true, y_pred, verbose=FALSE) {
print("Scatter plot of the observed and predicted phenotypes")
tryCatch(
txtplot::txtplot(x=y_true, y=y_pred),
error=function(e){print(e)})
error=function(e){print("Empty plot")})
} else {
print("All pairs of phenotype values have missing data.")
}
Expand Down
42 changes: 21 additions & 21 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn_ols = function(list_merged, vec_idx_training, vec_idx_validation, other_param
n_non_zero = sum(abs(b_hat) > .Machine$double.eps)
if (verbose) {
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*p/n_non_zero), "%)"))
}
### Predict and assess prediction accuracy
Expand Down Expand Up @@ -310,9 +310,9 @@ fn_ridge = function(list_merged, vec_idx_training, vec_idx_validation, other_par
if (verbose) {
p = ncol(X_training)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -454,9 +454,9 @@ fn_lasso = function(list_merged, vec_idx_training, vec_idx_validation, other_par
if (verbose) {
p = ncol(X_training)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -598,9 +598,9 @@ fn_elastic_net = function(list_merged, vec_idx_training, vec_idx_validation, oth
if (verbose) {
p = ncol(X_training)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -739,9 +739,9 @@ fn_Bayes_A = function(list_merged, vec_idx_training, vec_idx_validation,
if (verbose) {
p = ncol(list_merged$G)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -886,9 +886,9 @@ fn_Bayes_B = function(list_merged, vec_idx_training, vec_idx_validation,
if (verbose) {
p = ncol(list_merged$G)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -1033,9 +1033,9 @@ fn_Bayes_C = function(list_merged, vec_idx_training, vec_idx_validation,
if (verbose) {
p = ncol(list_merged$G)
print("Allele effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
print("Relative posisitions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print("Relative positions of allele effects across the genome:")
tryCatch(txtplot::txtplot(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down Expand Up @@ -1182,12 +1182,12 @@ fn_gBLUP = function(list_merged, vec_idx_training, vec_idx_validation, other_par
p = length(vec_effects)
if (length(b_hat) > 1) {
print("Fixed effects distribution:")
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(b_hat[!is.na(b_hat) & !is.infinite(b_hat)]), error=function(e){print("Empty plot")})
} else {
print(paste0("Intercept = ", b_hat))
}
print("Random effects distribution, i.e. BLUPs of each sample:")
tryCatch(txtplot::txtdensity(u_hat[!is.na(u_hat) & !is.infinite(u_hat)]), error=function(e){print(e)})
tryCatch(txtplot::txtdensity(u_hat[!is.na(u_hat) & !is.infinite(u_hat)]), error=function(e){print("Empty plot")})
print(paste0("Number of non-zero effects: ", n_non_zero, " (", round(100*n_non_zero/p), "%)"))
}
### Evaluate prediction performance
Expand Down
2 changes: 1 addition & 1 deletion inst/plot_gs_gp/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ fn_across_lopo_table_metrics_server = function(input, list_list_output) {
fn_across_lopo_scatter_server = function(input, list_list_output) {
list_output = list_list_output[[input$across_lopo_scat_trait]]
# if (!is.na(list_output$YPRED_ACROSS_POP_LOPO[1])[1]) {
if (!is.null(list_output$YPRED_ACROSS_POP_LOPO)) {
if (is.null(list_output$YPRED_ACROSS_POP_LOPO) | is.na(head(list_output$YPRED_ACROSS_POP_LOPO, n=1)[1])) {
df = data.frame(ID="No across populations data available", x=0, y=0)
p = plotly::plot_ly(data=df, x=~x, y=~y, type="scatter", mode='markers', text=~ID)
return(p)
Expand Down

0 comments on commit a8d327c

Please sign in to comment.