Skip to content

Commit

Permalink
Error Handling enrichment Analysis (#164)
Browse files Browse the repository at this point in the history
* Correct tryCatch placement, shiny does not fail anymore when supplying wrong organism or type of annotation.

* Switching between Modals now, no double appearance.

* Small adjustment to modal.

* Added Contactmail
  • Loading branch information
PaulJonasJost authored Jan 29, 2024
1 parent ff79bc1 commit 72ea5bd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 37 deletions.
69 changes: 53 additions & 16 deletions program/shinyApp/R/enrichment_analysis/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,16 @@ enrichment_analysis_Server <- function(id, data, params, updates){
anno_results <- check_annotation_enrichment_analysis(ea_reactives$data)
ea_reactives$data <- anno_results$new_data
ea_reactives$can_start <- anno_results$can_start
if(anno_results$no_ann){
translation_modal <- function(){
showModal(modalDialog(
title = "No annotation type detected",
footer = NULL,
p("No valid annotation type was detected in your row annotation. Please indicate the type of annotation with which you uploaded your genes."),
p(paste0(
"No valid annotation type was detected in your row annotation. ",
"Please indicate the type of annotation with which you uploaded your genes.\n",
"Here are the first 5 rownames of your row annotation: \n",
toString(rownames(ea_reactives$data)[1:5])
)),
selectInput(
inputId = ns("AnnotationSelection"),
label = "Which annotation are you using?",
Expand All @@ -739,6 +744,9 @@ enrichment_analysis_Server <- function(id, data, params, updates){
),
actionButton(inputId = ns("AMC"), label = "Proceed"),
))
}
if(anno_results$no_ann){
translation_modal()
}else if(anno_results$can_start == FALSE){
if(input$ORA_or_GSE == "GeneSetEnrichment"){
ea_reactives$data <- translate_genes_ea(
Expand All @@ -757,25 +765,54 @@ enrichment_analysis_Server <- function(id, data, params, updates){
}
ea_reactives$can_start <- TRUE
}
# Modal in case translation fails
observeEvent(input$translation_again, {
# close modal
removeModal()
# call translation again
translation_modal()
})
# close modal on button click
observeEvent(input$AMC, {
anno_results$base_annotation <- input$AnnotationSelection
removeModal()
if(input$ORA_or_GSE == "GeneSetEnrichment"){
ea_reactives$data <- translate_genes_ea(
data = ea_reactives$data,
annotation_results = anno_results,
input = input
)
}else{
ea_reactives$tmp_genes <<- translate_genes_oa(
annotation_results = anno_results,
input = input,
geneSetChoice = ea_reactives$tmp_genes,
geneSet2Enrich = input$GeneSet2Enrich
tryCatch(
{
if(input$ORA_or_GSE == "GeneSetEnrichment"){
ea_reactives$data <- translate_genes_ea(
data = ea_reactives$data,
annotation_results = anno_results,
input = input
)
}else{
ea_reactives$tmp_genes <- translate_genes_oa(
annotation_results = anno_results,
input = input,
geneSetChoice = ea_reactives$tmp_genes,
geneSet2Enrich = input$GeneSet2Enrich
)
}
ea_reactives$can_start <- TRUE
},
error=function(e){
showModal(modalDialog(
title = HTML("<font color='red'>An Error occured</font>"),
footer = actionButton(
inputId = ns("translation_again"),
label = "Choose another annotation type"
),
HTML(paste0(
"<font color='red'>Error: ",e$message,"</font><br><br>",
"It is highly likely that the error is caused by the fact that the ",
"gene names in your data set do not match the gene names in the ",
"annotation you selected. Please check your data set and annotation ",
"and try again.<br><br>",
"Otherwise, please contact the cOmicsArtist Lea and Paul ",
"(<a href = 'mailto: [email protected]'>[email protected]</a>)."
))
))
}
)
}
ea_reactives$can_start <- TRUE
})
# start the analysis if ea_reactives$can_start == TRUE
observeEvent(ea_reactives$can_start, {
Expand Down
27 changes: 6 additions & 21 deletions program/shinyApp/R/enrichment_analysis/translation.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,13 @@ translate_genes_ea <- function(data, annotation_results, input){
}else{
orgDb <- org.Mm.eg.db::org.Mm.eg.db
}
tryCatch(
{
rowData(data)[["ENTREZID"]] <- AnnotationDbi::mapIds(
orgDb,
keys = rowData(data)[[annotation_results$base_annotation]],
column = "ENTREZID",
keytype = annotation_results$base_annotation
)
return(data)
},
error = function(e) {
show_toast(
title = "You chose the wrong Organism. Please restart the app.",
type = "info",
position = "top",
timerProgressBar = TRUE,
width = "30%"
)
# let the program wait for 5 seconds
Sys.sleep(3)
}
rowData(data)[["ENTREZID"]] <- AnnotationDbi::mapIds(
orgDb,
keys = rowData(data)[[annotation_results$base_annotation]],
column = "ENTREZID",
keytype = annotation_results$base_annotation
)
return(data)
}

# input$GeneSet2Enrich
Expand Down

0 comments on commit 72ea5bd

Please sign in to comment.