Skip to content

Commit

Permalink
Assorted fixes (#149)
Browse files Browse the repository at this point in the history
* fix: strip ansi codes from error messages before displaying to user

* feat: now automatically attempts to convert time to event variable to numeric before survival analysis and warns user
  • Loading branch information
selkamand authored Dec 7, 2023
1 parent 3dcf4dc commit a75a071
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Collate:
'update_starting_maf_data_pool.R'
'utils-pipe.R'
'utils_bool_to_colour.R'
'utils_error_messages.R'
'utils_installation.R'
'utils_links.R'
'utils_spacer.R'
Expand Down
8 changes: 4 additions & 4 deletions R/mod_cnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ mod_cnv_server <- function(id, maf_data_pool){
gistic_ <- TCGAgistic::tcga_gistic_load(cohort = cohort, source = source, cnLevel = cnLevel, verbose = FALSE)
},
error = function(err){
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = tags$span(tags$code(as.character(err))))
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = err2html(err))
validate("Failed to Read Gistic")
},
warning = function(warn){
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = tags$span(tags$code(as.character(warn))))
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = err2html(warn))
validate("Failed to Read Gistic")
}

Expand All @@ -197,11 +197,11 @@ mod_cnv_server <- function(id, maf_data_pool){
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = tags$span(tags$code("RDS file does not encode a GISTIC object.")))
},
error = function(err){
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = tags$span(tags$code(as.character(err))))
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = err2html(err))
validate("Please supply a valid Gistic RDS")
},
warning = function(warn){
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = tags$span(tags$code(as.character(warn))))
shinyWidgets::sendSweetAlert(session = session, title = "Failed to Read Gistic", text = err2html(warn))
validate("Please supply a valid Gistic RDS")
}
)
Expand Down
4 changes: 3 additions & 1 deletion R/mod_data_import.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ mod_data_import_server <- function(id, maf_data_pool) {
session = session,
title = paste0("Failed to Read Mutation File"),
text = tags$div(
"Please ensure ",expected_mutation_filetype()," file/s ", message, "are formatted correctly.", tags$br(), tags$br(), tags$code(maf)
"Please ensure ",expected_mutation_filetype()," file/s ", message, "are formatted correctly.",
tags$br(), tags$br(),
err2html(maf)
),
html = TRUE,
type = "warning"
Expand Down
2 changes: 1 addition & 1 deletion R/mod_mutational_signatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod_mutational_signatures_server <- function(id, maf_data_pool){
shinyWidgets::sendSweetAlert(
session = session,
title = "Failed to Read Mutalisk Input",
type = "error", text = tags$code(as.character(e))
type = "error", text = err2html(e)
)
return(NULL)
}
Expand Down
23 changes: 17 additions & 6 deletions R/mod_survival_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,18 @@ mod_survival_analysis_server <- function(id, maf_data_pool){
message('[1] Running maftools::survGroup')
result = tryCatch(
expr = {

# In case selected 'time_to_event' column is non-numeric: convert to numeric and warn the user
mymaf = maf()
vec_time_to_event <- mymaf@clinical.data[[column_time_to_event()]]
mymaf@clinical.data[[column_time_to_event()]] <- as.numeric(vec_time_to_event)
if(!is.numeric(vec_time_to_event)){
shinyWidgets::sendSweetAlert(session = session, title = 'Incorrect type', text = 'The "Time to Event" column selected is non-numeric, please ensure you have the right column',type = 'warning')
}

# Perform Survival analysis
maftools::survGroup(
maf = maf(),
maf = mymaf,
top = input$in_num_genes_to_include,
geneSetSize = input$in_num_geneset_size,
minSamples = input$in_num_minsamples,
Expand Down Expand Up @@ -143,11 +153,12 @@ mod_survival_analysis_server <- function(id, maf_data_pool){

time_column_passes_sanitychecks <- function(column_name, clinical_dataframe){
vec <- clinical_dataframe[[column_name]]

if(!is.numeric(vec))
return(FALSE)
else
return(TRUE)

return(TRUE)
# if(!is.numeric(vec))
# return(FALSE)
# else
# return(TRUE)
}


Expand Down
10 changes: 10 additions & 0 deletions R/utils_error_messages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' Format error messages as html
#'
#' @description Format error messages as html
#'
#' @return The return value, if any, from executing the utility.
#'
#' @noRd
err2html <- function(err){
tags$code(HTML(cli::ansi_html(as.character(err))))
}

0 comments on commit a75a071

Please sign in to comment.