diff --git a/R/module-help-ui.R b/R/module-help-ui.R index f3b697b..fea37d1 100644 --- a/R/module-help-ui.R +++ b/R/module-help-ui.R @@ -80,7 +80,12 @@ helpUI <- function(id) { experiments should likely use a subset of features due to the very \ large number of available features."), tags$li("Missing value imputation (can be MAR/MNAR depending on \ - spectral processing tool used.):"), + spectral processing tool used). Imputation runs only when \ + (a) the protein has at least one observed feature in the \ + current run, AND (b) the missing feature is observed in at \ + least one other run. Proteins entirely missing from a run \ + and features never observed in the dataset are not \ + imputed. Censoring assumptions:"), tags$ul( tags$li("Assume all NAs as censored (ie missing not at random)"), tags$li("Assume all intensities between 0 and 1 as censored and NAs as \ diff --git a/R/module-loadpage-server.R b/R/module-loadpage-server.R index 68aabc9..4c00602 100644 --- a/R/module-loadpage-server.R +++ b/R/module-loadpage-server.R @@ -563,6 +563,53 @@ loadpageServer <- function(id, parent_session, is_web_server = FALSE, app_templa ) }) + observeEvent(input$proceed1, { + shinyjs::disable("download_msstats_format") + }) + + observeEvent(get_data(), { + req(get_data()) + shinyjs::enable("download_msstats_format") + }) + + output$download_msstats_format = downloadHandler( + filename = function() { + data <- get_data() + if (inherits(data, "data.frame")) { + paste0("MSstats_format-", Sys.Date(), ".csv") + } else { + paste0("MSstats_format-", Sys.Date(), ".zip") + } + }, + content = function(file) { + tryCatch({ + data <- get_data() + if (inherits(data, "data.frame")) { + data.table::fwrite(data, file) + } else { + tmp_dir <- tempfile("msstats_format_") + dir.create(tmp_dir) + on.exit(unlink(tmp_dir, recursive = TRUE), add = TRUE) + tmp_files <- character() + for (nm in names(data)) { + tbl <- data[[nm]] + if (is.null(tbl)) next + if (NROW(tbl) == 0L) next + tmp_path <- file.path(tmp_dir, paste0(nm, ".csv")) + data.table::fwrite(tbl, tmp_path) + tmp_files <- c(tmp_files, tmp_path) + } + if (length(tmp_files) == 0L) { + stop("No non-empty tables available to export.") + } + utils::zip(zipfile = file, files = tmp_files, flags = "-j") + } + }, error = function(e) { + writeLines(paste("Failed to export MSstats format:", conditionMessage(e)), file) + }) + } + ) + get_data_code = eventReactive(input$calculate, { getDataCode(input) diff --git a/R/module-loadpage-ui.R b/R/module-loadpage-ui.R index 4d00a9c..e9f9292 100644 --- a/R/module-loadpage-ui.R +++ b/R/module-loadpage-ui.R @@ -49,8 +49,15 @@ loadpageUI <- function(id) { # Processing options create_processing_options(ns), - # Action button - disabled(actionButton(inputId = ns("proceed1"), label = "Upload Data")) + # Action buttons + tags$div( + style = "display:flex; gap:8px; align-items:center;", + disabled(actionButton(inputId = ns("proceed1"), label = "Upload Data")), + shinyjs::disabled(downloadButton( + ns("download_msstats_format"), + "Download MSstats-format CSV" + )) + ) ), column(width = 8, diff --git a/R/module-qc-ui.R b/R/module-qc-ui.R index 39994b7..f729573 100644 --- a/R/module-qc-ui.R +++ b/R/module-qc-ui.R @@ -22,7 +22,7 @@ qcUI <- function(id) { tags$link(rel = "stylesheet", type = "text/css", href = "assets/style.css"), ), headerPanel("Process and quantify data"), - p("Feature summarization and missing value imputation. Includes options for vizualizing summarization through data tables and multiple plots. All outputs are available to download in 'csv' format."), + p("Feature summarization and missing value imputation. Includes options for visualizing summarization through data tables and multiple plots. Summarized tables and processed datasets are available to download in CSV format. Imputation runs only when a feature is observed in some other run AND the protein has at least one observed feature in the current run."), tags$br(), sidebarPanel( # transformation @@ -141,7 +141,7 @@ qcUI <- function(id) { h4("Imputation"), conditionalPanel(condition = "input['qc-censInt'] == 'NA' || input['qc-censInt'] == '0'", checkboxInput(ns("MBi"), label=tags$div("Model based imputation",class = "icon-wrapper",icon("question-circle", lib = "font-awesome"), - div("If unchecked the values set as cutoff for censored will be used", class = "icon-tooltip")),value = TRUE + div("Fills in missing intensities only when (a) the protein has at least one observed feature in that run, AND (b) the missing feature is observed in at least one other run. Proteins entirely missing from a run, and features never observed in the dataset, are not imputed. If unchecked, the cutoff for censored values is used instead.", class = "icon-tooltip")),value = TRUE )), # # cutoff for censored # conditionalPanel(condition = "input.censInt == 'NA' || input.censInt == '0'", diff --git a/R/module-statmodel-server.R b/R/module-statmodel-server.R index 7efa844..0337d5d 100644 --- a/R/module-statmodel-server.R +++ b/R/module-statmodel-server.R @@ -53,6 +53,9 @@ statmodelServer = function(id, parent_session, loadpage_input, qc_input, choices = c("Turnover Curve" = CONSTANTS_STATMODEL$plot_type_response_curve), selected = CONSTANTS_STATMODEL$plot_type_response_curve) updateCheckboxInput(session, NAMESPACE_STATMODEL$modeling_response_curve_increasing_trend, value = TRUE) + shinyjs::hide("statmodel_contrast_header", asis = TRUE) + shinyjs::hide("statmodel_workflow_bullet_default", asis = TRUE) + shinyjs::show("statmodel_workflow_bullet_response_curve", asis = TRUE) } else if (template == TEMPLATES$chemoproteomics) { updateRadioButtons(session, NAMESPACE_STATMODEL$comparison_mode, choices = c("Create dose-response curves" = CONSTANTS_STATMODEL$comparison_mode_response_curve), @@ -61,6 +64,9 @@ statmodelServer = function(id, parent_session, loadpage_input, qc_input, choices = c("Dose-Response Curve" = CONSTANTS_STATMODEL$plot_type_response_curve), selected = CONSTANTS_STATMODEL$plot_type_response_curve) updateCheckboxInput(session, NAMESPACE_STATMODEL$modeling_response_curve_increasing_trend, value = FALSE) + shinyjs::hide("statmodel_contrast_header", asis = TRUE) + shinyjs::hide("statmodel_workflow_bullet_default", asis = TRUE) + shinyjs::show("statmodel_workflow_bullet_response_curve", asis = TRUE) } else { updateRadioButtons(session, NAMESPACE_STATMODEL$comparison_mode, choices = c( @@ -77,6 +83,9 @@ statmodelServer = function(id, parent_session, loadpage_input, qc_input, "Comparison Plot" = CONSTANTS_STATMODEL$plot_type_comparison_plot )) updateCheckboxInput(session, NAMESPACE_STATMODEL$modeling_response_curve_increasing_trend, value = FALSE) + shinyjs::show("statmodel_contrast_header", asis = TRUE) + shinyjs::show("statmodel_workflow_bullet_default", asis = TRUE) + shinyjs::hide("statmodel_workflow_bullet_response_curve", asis = TRUE) } }, ignoreInit = FALSE) diff --git a/R/statmodel-ui-comparisons.R b/R/statmodel-ui-comparisons.R index f89807a..c47167d 100644 --- a/R/statmodel-ui-comparisons.R +++ b/R/statmodel-ui-comparisons.R @@ -21,6 +21,7 @@ create_contrast_radio_buttons <- function(ns) { ns(NAMESPACE_STATMODEL$comparison_mode), label = h4( "1. Define comparisons - contrast matrix", + id = "statmodel_contrast_header", class = "icon-wrapper", icon("question-circle", lib = "font-awesome"), div("Define what conditions you want to compare here", class = "icon-tooltip") diff --git a/R/statmodel-ui-headers.R b/R/statmodel-ui-headers.R index a07d29d..8e866c1 100644 --- a/R/statmodel-ui-headers.R +++ b/R/statmodel-ui-headers.R @@ -41,7 +41,12 @@ create_header_section <- function() { tagList( headerPanel("Statistical modeling and inference"), p("In this tab, build your statistical model in three steps:"), - p("(i) Create a contrast matrix for a group comparison or set up a configuration for a response curve analysis,"), + p(id = "statmodel_workflow_bullet_default", + "(i) Create a contrast matrix for a group comparison,"), + shinyjs::hidden( + p(id = "statmodel_workflow_bullet_response_curve", + "(i) Configure the response curve analysis,") + ), p("(ii) generate the model and "), p("(iii) view result plots."), p("More info ", a("here", href="https://www.rdocumentation.org/packages/MSstats/versions/3.4.0/topics/groupComparisonPlots"))