diff --git a/DESCRIPTION b/DESCRIPTION index 88e82c2..abdfb0d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ Depends: R (>= 4.2) Imports: shiny, shinyBS, shinyjs, shinybusy, dplyr, ggplot2, plotly, data.table, Hmisc, MSstats, MSstatsTMT, MSstatsPTM, MSstatsConvert, gplots, marray, DT, readxl, ggrepel, uuid, utils, stats, htmltools, methods, tidyr, grDevices, graphics, mockery, MSstatsBioNet, - shinydashboard, arrow, tools + shinydashboard, arrow, tools, MSstatsResponse Suggests: rmarkdown, tinytest, diff --git a/NAMESPACE b/NAMESPACE index 9e72d74..f61c14a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,6 +48,7 @@ importFrom(MSstatsPTM,SkylinetoMSstatsPTMFormat) importFrom(MSstatsPTM,SpectronauttoMSstatsPTMFormat) importFrom(MSstatsPTM,dataProcessPlotsPTM) importFrom(MSstatsPTM,groupComparisonPlotsPTM) +importFrom(MSstatsResponse,convertGroupToNumericDose) importFrom(arrow,read_parquet) importFrom(data.table,copy) importFrom(dplyr,`%>%`) diff --git a/R/constants.R b/R/constants.R index cf9224f..3385c1c 100644 --- a/R/constants.R +++ b/R/constants.R @@ -15,5 +15,6 @@ CONSTANTS_STATMODEL = list( comparison_mode_all_pairwise = "comparison_mode_all_pairwise", comparison_mode_all_vs_one = "comparison_mode_all_vs_one", comparison_mode_custom_pairwise = "comparison_mode_custom_pairwise", - comparison_mode_custom_nonpairwise = "comparison_mode_custom_nonpairwise" + comparison_mode_custom_nonpairwise = "comparison_mode_custom_nonpairwise", + comparison_mode_response_curve = "comparison_mode_response_curve" ) \ No newline at end of file diff --git a/R/module-statmodel-server.R b/R/module-statmodel-server.R index a1643e2..5dd9b57 100644 --- a/R/module-statmodel-server.R +++ b/R/module-statmodel-server.R @@ -32,6 +32,8 @@ get_contrast_panel_ui <- function(mode, ns) { build_all_pairwise_panel(ns) } else if (mode == CONSTANTS_STATMODEL$comparison_mode_custom_nonpairwise) { build_custom_nonpairwise_panel(ns) + } else if (mode == CONSTANTS_STATMODEL$comparison_mode_response_curve) { + build_response_curve_panel(ns) } else { NULL } @@ -202,6 +204,13 @@ build_all_pair_contrast = function(input, condition_list, contrast, comp_list, r return(contrast$matrix) } +#' @importFrom MSstatsResponse convertGroupToNumericDose +build_response_curve_matrix = function(contrast, condition_list) { + condition_to_metadata_table = convertGroupToNumericDose(condition_list) + contrast$matrix = data.frame(GROUP = condition_list, condition_to_metadata_table) + return(contrast$matrix) +} + # Todo: Add helper function to build dose response curve mapper matrix # ============================================================================ @@ -509,6 +518,9 @@ statmodelServer = function(id, parent_session, loadpage_input, qc_input, } else if (input[[NAMESPACE_STATMODEL$comparison_mode]] == CONSTANTS_STATMODEL$comparison_mode_all_pairwise) { contrast$matrix = build_all_pair_contrast( input, condition_list(), contrast, comp_list, row(), loadpage_input()) + } else if (input[[NAMESPACE_STATMODEL$comparison_mode]] == CONSTANTS_STATMODEL$comparison_mode_response_curve) { + contrast$matrix = build_response_curve_matrix( + contrast, condition_list()) } enable("calculate") diff --git a/R/statmodel-ui-comparisons.R b/R/statmodel-ui-comparisons.R index d2278cf..9df89b7 100644 --- a/R/statmodel-ui-comparisons.R +++ b/R/statmodel-ui-comparisons.R @@ -23,13 +23,14 @@ create_contrast_radio_buttons <- function(ns) { "1. Define comparisons - contrast matrix", class = "icon-wrapper", icon("question-circle", lib = "font-awesome"), - div("Define what conditions you want to compare here.", class = "icon-tooltip") + div("Define what conditions you want to compare here", class = "icon-tooltip") ), c( "All possible pairwise comparisons" = CONSTANTS_STATMODEL$comparison_mode_all_pairwise, "Compare all against one" = CONSTANTS_STATMODEL$comparison_mode_all_vs_one, "Create custom pairwise comparisons" = CONSTANTS_STATMODEL$comparison_mode_custom_pairwise, - "Create custom non-pairwise comparisons" = CONSTANTS_STATMODEL$comparison_mode_custom_nonpairwise + "Create custom non-pairwise comparisons" = CONSTANTS_STATMODEL$comparison_mode_custom_nonpairwise, + "Create response curves" = CONSTANTS_STATMODEL$comparison_mode_response_curve ), selected = character(0) ) @@ -78,4 +79,14 @@ build_custom_nonpairwise_panel <- function(ns) { actionButton(ns(NAMESPACE_STATMODEL$comparisons_submit), "Add"), actionButton(ns(NAMESPACE_STATMODEL$comparisons_clear), "Clear matrix") ) +} + +#' Create panel for configuring response curve metadata +#' @noRd +build_response_curve_panel <- function(ns) { + tagList( + h5("Set up response curve configuration:"), + actionButton(ns(NAMESPACE_STATMODEL$comparisons_submit), "Setup Metadata"), + actionButton(ns(NAMESPACE_STATMODEL$comparisons_clear), "Reset") + ) } \ No newline at end of file diff --git a/R/statmodel-ui-headers.R b/R/statmodel-ui-headers.R index c3db71c..d948937 100644 --- a/R/statmodel-ui-headers.R +++ b/R/statmodel-ui-headers.R @@ -28,8 +28,8 @@ create_custom_styles <- function() { create_header_section <- function() { tagList( headerPanel("Statistical modeling and inference"), - p("In this tab a statistical model is built in three steps:"), - p("(i) Create a contrast matrix with the correct Group comparisons,"), + 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("(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")) diff --git a/tests/testthat/test-statmodel-ui-options-contrasts.R b/tests/testthat/test-statmodel-ui-options-contrasts.R index 08e497b..4f870fb 100644 --- a/tests/testthat/test-statmodel-ui-options-contrasts.R +++ b/tests/testthat/test-statmodel-ui-options-contrasts.R @@ -52,4 +52,15 @@ test_that("build_custom_nonpairwise_panel creates correct UI structure", { expect_true(grepl(">Clear matrix<", html, fixed = TRUE)) expect_s3_class(ui, "shiny.tag.list") expect_length(ui, 5) +}) + +test_that("build_response_curve_panel creates correct UI structure", { + ns <- function(id) paste0("statmodel-", id) + ui <- build_response_curve_panel(ns) + html <- as.character(ui) + expect_true(grepl("