-
Notifications
You must be signed in to change notification settings - Fork 10
fix(plots): Fix plotting bugs in statistical analysis page #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4d2e55
b5f13e3
cdde69f
0e12d23
f547738
7a20fb7
b46e6cd
3ccf5e8
1cc7eac
b023986
d28c6b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,36 @@ render_group_comparison_plot_inputs = function(output, session, rownames, get_da | |
| ns = session$ns | ||
|
|
||
| output[[NAMESPACE_STATMODEL$visualization_which_comparison]] = renderUI({ | ||
| comparison_names <- rownames() | ||
| req(length(comparison_names) > 0) | ||
| selectInput(ns(NAMESPACE_STATMODEL$visualization_which_comparison), | ||
| label = h5("Select comparison to plot"), | ||
| c("all", rownames()), selected = "all") | ||
| comparison_names, selected = comparison_names[1]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with Heatmap plots here? I think Heatmap plots benefit from being able to select "all" (does a single comparison selected for a Heatmap work?).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tonywu1999 You're right, it doesn't work. for a single comparison |
||
| }) | ||
|
|
||
| # Dynamically filter plot type choices based on number of comparisons. | ||
| # Skips response curve mode (handled separately in module-statmodel-server.R). | ||
| observe({ | ||
| req(input[[NAMESPACE_STATMODEL$comparison_mode]]) | ||
| mode <- input[[NAMESPACE_STATMODEL$comparison_mode]] | ||
| if (mode == CONSTANTS_STATMODEL$comparison_mode_response_curve) return() | ||
|
|
||
| comparison_names <- rownames() | ||
| n_comparisons <- length(comparison_names) | ||
|
|
||
| choices <- c( | ||
| "Volcano Plot" = CONSTANTS_STATMODEL$plot_type_volcano_plot, | ||
| "Comparison Plot" = CONSTANTS_STATMODEL$plot_type_comparison_plot | ||
| ) | ||
| if (n_comparisons >= 2) { | ||
| choices <- c( | ||
| "Volcano Plot" = CONSTANTS_STATMODEL$plot_type_volcano_plot, | ||
| "Heatmap" = CONSTANTS_STATMODEL$plot_type_heatmap, | ||
| "Comparison Plot" = CONSTANTS_STATMODEL$plot_type_comparison_plot | ||
| ) | ||
| } | ||
| updateSelectInput(session, NAMESPACE_STATMODEL$visualization_plot_type, | ||
| choices = choices) | ||
| }) | ||
|
|
||
| output[[NAMESPACE_STATMODEL$visualization_which_protein]] = renderUI({ | ||
|
|
@@ -21,9 +48,7 @@ render_group_comparison_plot_inputs = function(output, session, rownames, get_da | |
| plot_type = input[[NAMESPACE_STATMODEL$visualization_plot_type]] | ||
|
|
||
| if (plot_type == CONSTANTS_STATMODEL$plot_type_volcano_plot) { | ||
| show_protein_name = !is.null(loadpage_input()$DDA_DIA) && | ||
| loadpage_input()$DDA_DIA != "TMT" | ||
| create_volcano_plot_options(ns, show_protein_name) | ||
| create_volcano_plot_options(ns) | ||
| } else if (plot_type == CONSTANTS_STATMODEL$plot_type_comparison_plot) { | ||
| create_comparison_plot_options(ns) | ||
| } else if (plot_type == CONSTANTS_STATMODEL$plot_type_heatmap) { | ||
|
|
@@ -78,10 +103,6 @@ create_group_comparison_plot = function(input, loadpage_input, data_comparison) | |
| fold_change_cutoff = ifelse(!is.null(input[[NAMESPACE_STATMODEL$visualization_fold_change_input]]), input[[NAMESPACE_STATMODEL$visualization_fold_change_input]], FALSE) | ||
|
|
||
| tryCatch({ | ||
| if (input[[NAMESPACE_STATMODEL$visualization_plot_type]] == CONSTANTS_STATMODEL$plot_type_volcano_plot && input[[NAMESPACE_STATMODEL$visualization_which_comparison]] == "all") { | ||
| remove_modal_spinner() | ||
| stop('** Cannot generate multiple plots in a screen. Please refine selection or save to a pdf. **') | ||
| } | ||
| if (loadpage_input$BIO == "PTM") { | ||
| result = groupComparisonPlotsPTM( | ||
| data_comparison, | ||
|
|
@@ -90,7 +111,9 @@ create_group_comparison_plot = function(input, loadpage_input, data_comparison) | |
| FCcutoff = fold_change_cutoff, | ||
| logBase.pvalue = as.integer(input[[NAMESPACE_STATMODEL$visualization_logp_base]]), | ||
| ProteinName = TRUE, | ||
| which.Comparison = input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Comparison = if (input[[NAMESPACE_STATMODEL$visualization_plot_type]] == | ||
| CONSTANTS_STATMODEL$plot_type_heatmap) "all" | ||
| else input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| address = FALSE, | ||
| isPlotly = TRUE | ||
| ) | ||
|
|
@@ -108,7 +131,9 @@ create_group_comparison_plot = function(input, loadpage_input, data_comparison) | |
| ProteinName = TRUE, | ||
| numProtein = input[[NAMESPACE_STATMODEL$visualization_heatmap_number_proteins]], | ||
| clustering = input[[NAMESPACE_STATMODEL$visualization_heatmap_cluster_option]], | ||
| which.Comparison = input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Comparison = if (input[[NAMESPACE_STATMODEL$visualization_plot_type]] == | ||
| CONSTANTS_STATMODEL$plot_type_heatmap) "all" | ||
| else input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Protein = input[[NAMESPACE_STATMODEL$visualization_which_protein]], | ||
| height = input[[NAMESPACE_STATMODEL$visualization_plot_height_slider]], | ||
| address = "Ex_", | ||
|
|
@@ -121,10 +146,12 @@ create_group_comparison_plot = function(input, loadpage_input, data_comparison) | |
| sig = input[[NAMESPACE_STATMODEL$visualization_volcano_significance_cutoff]], | ||
| FCcutoff = fold_change_cutoff, | ||
| logBase.pvalue = as.numeric(input[[NAMESPACE_STATMODEL$visualization_logp_base]]), | ||
| ProteinName = input[[NAMESPACE_STATMODEL$visualization_volcano_display_protein_name]], | ||
| ProteinName = TRUE, | ||
| numProtein = input[[NAMESPACE_STATMODEL$visualization_heatmap_number_proteins]], | ||
| clustering = input[[NAMESPACE_STATMODEL$visualization_heatmap_cluster_option]], | ||
| which.Comparison = input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Comparison = if (input[[NAMESPACE_STATMODEL$visualization_plot_type]] == | ||
| CONSTANTS_STATMODEL$plot_type_heatmap) "all" | ||
| else input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Protein = input[[NAMESPACE_STATMODEL$visualization_which_protein]], | ||
| height = input[[NAMESPACE_STATMODEL$visualization_plot_height_slider]], | ||
| address = "Ex_", | ||
|
|
@@ -272,8 +299,10 @@ create_download_plot_handler <- function(output, input, contrast, preprocess_dat | |
| sig = input[[NAMESPACE_STATMODEL$visualization_volcano_significance_cutoff]], | ||
| FCcutoff = fold_change_cutoff, | ||
| logBase.pvalue = as.integer(input[[NAMESPACE_STATMODEL$visualization_logp_base]]), | ||
| ProteinName = input[[NAMESPACE_STATMODEL$visualization_volcano_display_protein_name]], | ||
| which.Comparison = input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| ProteinName = TRUE, | ||
| which.Comparison = if (plot_type == | ||
| CONSTANTS_STATMODEL$plot_type_heatmap) "all" | ||
| else input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| address = address_prefix | ||
| ) | ||
| } else { | ||
|
|
@@ -283,10 +312,12 @@ create_download_plot_handler <- function(output, input, contrast, preprocess_dat | |
| sig = input[[NAMESPACE_STATMODEL$visualization_volcano_significance_cutoff]], | ||
| FCcutoff = fold_change_cutoff, | ||
| logBase.pvalue = as.numeric(input[[NAMESPACE_STATMODEL$visualization_logp_base]]), | ||
| ProteinName = input[[NAMESPACE_STATMODEL$visualization_volcano_display_protein_name]], | ||
| ProteinName = TRUE, | ||
| numProtein = input[[NAMESPACE_STATMODEL$visualization_heatmap_number_proteins]], | ||
| clustering = input[[NAMESPACE_STATMODEL$visualization_heatmap_cluster_option]], | ||
| which.Comparison = input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Comparison = if (plot_type == | ||
| CONSTANTS_STATMODEL$plot_type_heatmap) "all" | ||
| else input[[NAMESPACE_STATMODEL$visualization_which_comparison]], | ||
| which.Protein = input[[NAMESPACE_STATMODEL$visualization_which_protein]], | ||
| height = input[[NAMESPACE_STATMODEL$visualization_plot_height_slider]], | ||
| address = address_prefix, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,13 +39,10 @@ test_that("Correct elements are present in create_volcano_plot_options", { | |
| ui_html <- htmltools::renderTags(result)$html | ||
| expect_true(grepl(NAMESPACE_STATMODEL$visualization_which_comparison, ui_html), | ||
| info = "Which comparison namespace should be present") | ||
| expect_true(grepl(NAMESPACE_STATMODEL$visualization_volcano_display_protein_name, ui_html), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just get rid of this unit test. Also, can the constant be deleted too? |
||
| info = "Display protein name checkbox namespace should be present") | ||
| expect_true(grepl(NAMESPACE_STATMODEL$visualization_logp_base, ui_html), | ||
| info = "Log p-value base namespace should be present") | ||
| expect_true(grepl(NAMESPACE_STATMODEL$visualization_volcano_significance_cutoff, ui_html), | ||
| info = "Significance cutoff namespace should be present") | ||
|
|
||
| }) | ||
|
|
||
| test_that("All possible options in create_plot_type_selector", { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-default observer can clobber user-typed comparison names.
This
observere-fires not only wheninput[[comparison_mode]]switches tocustom_nonpairwise, but also any timecontrast$matrixchanges (e.g., theinput$table_cell_editobserver at lines 396–400, or aftermatrix_buildmutates the matrix). Each time it fires it unconditionally callsupdateTextInput(...), which will overwrite any name the user has typed into the comparison name field (for example, while they are editing a cell in the existing matrix or right after submitting a row).Consider gating the update so it only runs on mode entry or when a new row was actually appended (e.g., scope the dependency with
observeEvent(input[[comparison_mode]], ...)and readcontrast$matrixinsideisolate(), or only update when the current text input value already matches a previously-generated"custom comparison N").🛠️ Suggested fix sketch
🤖 Prompt for AI Agents