From afc40adaae635f11d0063534ab357ab549661b3e Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Sun, 11 Feb 2024 16:30:20 -0500 Subject: [PATCH 1/8] Add panel tab for Marker Genes --- inst/shiny/server.R | 24 +++++++++++++++++++++- inst/shiny/ui_09_2_seuratWorkflow.R | 32 +++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index b75e4f951..3ef1f178d 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8554,6 +8554,26 @@ shinyServer(function(input, output, session) { defaultFilterValues = c("0.05"), topText = "You can view the marker genes in the table below and apply custom filters to filter the table accordingly. A joint heatmap for all the marker genes available in the table is plotted underneath the table. Additional visualizations are plotted for select genes which can be selected by clicking on the rows of the table." ) + + shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") + + shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") + + orderByLFCMarkers_reactive <- reactive({ + orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers + orderByLFCMarkers <- orderByLFCMarkers[order(-orderByLFCMarkers$avg_log2FC), ] + return(orderByLFCMarkers) + }) + + observe({ + gene_choices <- orderByLFCMarkers$gene.id + + updateSelectInput(session, "selectGenesFindMarker", + choices = gene_choices, + selected = gene_choices[1]) # Optionally, pre-select the first gene + }) + + # vals$fts <- callModule( # module = filterTableServer, # id = "filterSeuratFindMarker", @@ -8723,7 +8743,6 @@ shinyServer(function(input, output, session) { }) }) updateCollapse(session = session, "SeuratUI", style = list("2D-Embedding" = "success")) - shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") S4Vectors::metadata(vals$counts)$seuratMarkers <- NULL shinyjs::hide( selector = "div[value='Downstream Analysis']") @@ -9013,6 +9032,9 @@ shinyServer(function(input, output, session) { shinyjs::disable( selector = "#ScanpyUI > div[value='Clustering']") + shinyjs::disable( + selector = "#SeuratUI > div[value='Marker Gene Plots']") + shinyjs::disable( selector = "#SeuratUI > div[value='Scale Data']") shinyjs::disable( diff --git a/inst/shiny/ui_09_2_seuratWorkflow.R b/inst/shiny/ui_09_2_seuratWorkflow.R index c4de910f5..3f4c8da1d 100644 --- a/inst/shiny/ui_09_2_seuratWorkflow.R +++ b/inst/shiny/ui_09_2_seuratWorkflow.R @@ -378,20 +378,34 @@ shinyPanelSeurat <- fluidPage( ) ) ), - br(), - hidden( - tags$div(class = "seurat_findmarker_plots", - panel(heading = "Marker Gene Plots", - HTML("
Click on the rows of the table above to plot the selected marker genes below!

"), - tabsetPanel(id = "seuratFindMarkerPlotTabset", type = "tabs")) - ) - ) ) ) ) ), - style = "primary") + style = "primary"), + + bsCollapsePanel("Marker Gene Plots", + fluidRow( + column(4, + fluidRow( + column(12, + panel(heading = "Options", + selectInput("selectGenesFindMarker", "Select a gene:", choices = NULL, multiple = TRUE), + ) + ) + ) + ), + column(8, + tags$div(class = "seurat_findmarker_plots", + panel(heading = "", + HTML("
Click on the rows of the table above to plot the selected marker genes below!

"), + tabsetPanel(id = "seuratFindMarkerPlotTabset", type = "tabs")) + ) + ) + ), + style = "primary" + ) ), nonLinearWorkflowUI(id = "nlw-seurat") ) From 7920cae7b5b9fd22bca3602a980155c6db936631 Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Sun, 11 Feb 2024 17:26:33 -0500 Subject: [PATCH 2/8] Saving work --- inst/shiny/server.R | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 3ef1f178d..e792ccd6b 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8559,12 +8559,6 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") - orderByLFCMarkers_reactive <- reactive({ - orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers - orderByLFCMarkers <- orderByLFCMarkers[order(-orderByLFCMarkers$avg_log2FC), ] - return(orderByLFCMarkers) - }) - observe({ gene_choices <- orderByLFCMarkers$gene.id @@ -8581,6 +8575,20 @@ shinyServer(function(input, output, session) { # ) })) + observeEvent(input$selectGenesFindMarker, { + orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers + orderByLFCMarkers <- orderByLFCMarkers[order(-orderByLFCMarkers$avg_log2FC), ] + # Filter orderByLFCMarkers to find the row with the selected gene.id + selected_gene_info <- orderByLFCMarkers[orderByLFCMarkers$gene.id == input$selectGenesFindMarker, ] + + # Store the filtered dataframe in vals$selectedGenes + vals$selectedGenes <- selected_gene_info + + # Optionally, print the selected gene row to verify + print(selected_gene_info) + + }) + observeEvent(input$findMarkerHeatmapPlotFullNumericRun, withConsoleMsgRedirect( msg = "Please wait while heatmap is being plotted. See console log for progress.", { @@ -8629,9 +8637,7 @@ shinyServer(function(input, output, session) { })) observe({ - req(vals$fts$data) - req(vals$fts$selectedRows) - df <- vals$fts$data[vals$fts$selectedRows, ] + df <- vals$selectedGenes output$findMarkerRidgePlot <- renderPlot({ plotSeuratGenes( inSCE = vals$counts, From a83dbfb979d5bbb4f2fc1daeb57906b986bdd458 Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Mon, 12 Feb 2024 12:22:14 -0500 Subject: [PATCH 3/8] Select marker genes now working --- inst/shiny/server.R | 26 ++++++++++---------------- inst/shiny/ui_09_2_seuratWorkflow.R | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index e792ccd6b..02518a368 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8560,11 +8560,11 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") observe({ - gene_choices <- orderByLFCMarkers$gene.id + gene_choices <- setNames(nm = orderByLFCMarkers$gene.id, order(1:nrow(orderByLFCMarkers))) updateSelectInput(session, "selectGenesFindMarker", choices = gene_choices, - selected = gene_choices[1]) # Optionally, pre-select the first gene + ) }) @@ -8578,15 +8578,9 @@ shinyServer(function(input, output, session) { observeEvent(input$selectGenesFindMarker, { orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers orderByLFCMarkers <- orderByLFCMarkers[order(-orderByLFCMarkers$avg_log2FC), ] - # Filter orderByLFCMarkers to find the row with the selected gene.id - selected_gene_info <- orderByLFCMarkers[orderByLFCMarkers$gene.id == input$selectGenesFindMarker, ] - - # Store the filtered dataframe in vals$selectedGenes - vals$selectedGenes <- selected_gene_info - - # Optionally, print the selected gene row to verify - print(selected_gene_info) - + selected_row_number <- as.numeric(input$selectGenesFindMarker) + # Retrieve the selected gene's information using the row number + vals$selectedGenes <- orderByLFCMarkers[selected_row_number, ] }) observeEvent(input$findMarkerHeatmapPlotFullNumericRun, withConsoleMsgRedirect( @@ -8642,7 +8636,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "ridge", - features = df$gene_id, + features = df$gene.id, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE @@ -8652,7 +8646,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "violin", - features = df$gene_id, + features = df$gene.id, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE @@ -8662,7 +8656,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "feature", - features = df$gene_id, + features = df$gene.id, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE, @@ -8673,7 +8667,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "dot", - features = df$gene_id, + features = df$gene.id, groupVariable = input$seuratFindMarkerSelectPhenotype ) }) @@ -8681,7 +8675,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "heatmap", - features = df$gene_id, + features = df$gene.id, groupVariable = input$seuratFindMarkerSelectPhenotype ) }) diff --git a/inst/shiny/ui_09_2_seuratWorkflow.R b/inst/shiny/ui_09_2_seuratWorkflow.R index 3f4c8da1d..a99bc93d5 100644 --- a/inst/shiny/ui_09_2_seuratWorkflow.R +++ b/inst/shiny/ui_09_2_seuratWorkflow.R @@ -387,7 +387,7 @@ shinyPanelSeurat <- fluidPage( bsCollapsePanel("Marker Gene Plots", fluidRow( - column(4, + column(12, fluidRow( column(12, panel(heading = "Options", @@ -396,7 +396,7 @@ shinyPanelSeurat <- fluidPage( ) ) ), - column(8, + column(12, tags$div(class = "seurat_findmarker_plots", panel(heading = "", HTML("
Click on the rows of the table above to plot the selected marker genes below!

"), From a0ea35e09e93b15ae64d86f616bbe9f42781939e Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Mon, 12 Feb 2024 12:22:44 -0500 Subject: [PATCH 4/8] Change default plot message --- inst/shiny/ui_09_2_seuratWorkflow.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/shiny/ui_09_2_seuratWorkflow.R b/inst/shiny/ui_09_2_seuratWorkflow.R index a99bc93d5..3abde6ef2 100644 --- a/inst/shiny/ui_09_2_seuratWorkflow.R +++ b/inst/shiny/ui_09_2_seuratWorkflow.R @@ -399,7 +399,7 @@ shinyPanelSeurat <- fluidPage( column(12, tags$div(class = "seurat_findmarker_plots", panel(heading = "", - HTML("
Click on the rows of the table above to plot the selected marker genes below!

"), + HTML("
Select marker genes above to plot them below!

"), tabsetPanel(id = "seuratFindMarkerPlotTabset", type = "tabs")) ) ) From 58c7449bd6da6d93582df49d7ec04c705b7ba63e Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Mon, 12 Feb 2024 12:28:39 -0500 Subject: [PATCH 5/8] Add req to beginning of plotting --- inst/shiny/server.R | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 02518a368..43b4c0a01 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8631,6 +8631,7 @@ shinyServer(function(input, output, session) { })) observe({ + req(vals$selectedGenes) df <- vals$selectedGenes output$findMarkerRidgePlot <- renderPlot({ plotSeuratGenes( From bd7f6f2b386da1c0263677f5f7eca55d8af2cfc1 Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Sun, 25 Feb 2024 13:21:19 -0500 Subject: [PATCH 6/8] Change names for marker plot and make tab available after clustering --- inst/shiny/server.R | 70 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 43b4c0a01..49b15101b 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -1649,34 +1649,34 @@ shinyServer(function(input, output, session) { removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Dot Plot") removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") - appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Ridge Plot", - panel(heading = "Ridge Plot", + appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "2D Embedding (Feature Plot)", + panel(heading = "Feature Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerRidgePlot") + plotOutput(outputId = "findMarkerFeaturePlot") ) ) ) ) - appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Violin Plot", - panel(heading = "Violin Plot", + appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Dot Plot", + panel(heading = "Dot Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerViolinPlot") + plotOutput(outputId = "findMarkerDotPlot") ) ) ) ) - appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Feature Plot", - panel(heading = "Feature Plot", + appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Ridge Plot", + panel(heading = "Ridge Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerFeaturePlot") + plotOutput(outputId = "findMarkerRidgePlot") ) ) ) ) - appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Dot Plot", - panel(heading = "Dot Plot", + appendTab(inputId = "seuratFindMarkerPlotTabset", tabPanel(title = "Violin Plot", + panel(heading = "Violin Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerDotPlot") + plotOutput(outputId = "findMarkerViolinPlot") ) ) ) @@ -8252,6 +8252,8 @@ shinyServer(function(input, output, session) { shinyjs::enable( selector = "#SeuratUI > div[value='Find Markers']") + shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") + #update colData names updateColDataNames() @@ -8357,8 +8359,8 @@ shinyServer(function(input, output, session) { removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Ridge Plot", - panel(heading = "Ridge Plot", + tabPanel(title = "Feature Plot", + panel(heading = "2D Embedding (Feature Plot)", fluidRow( column(12, align = "center", panel( @@ -8370,8 +8372,8 @@ shinyServer(function(input, output, session) { ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Violin Plot", - panel(heading = "Violin Plot", + tabPanel(title = "Dot Plot", + panel(heading = "Dot Plot", fluidRow( column(12, align = "center", panel( @@ -8383,8 +8385,8 @@ shinyServer(function(input, output, session) { ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Feature Plot", - panel(heading = "Feature Plot", + tabPanel(title = "Ridge Plot", + panel(heading = "Ridge Plot", fluidRow( column(12, align = "center", panel( @@ -8396,8 +8398,8 @@ shinyServer(function(input, output, session) { ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Dot Plot", - panel(heading = "Dot Plot", + tabPanel(title = "Violin Plot", + panel(heading = "Violin Plot", fluidRow( column(12, align = "center", panel( @@ -8450,7 +8452,7 @@ shinyServer(function(input, output, session) { } showTab(inputId = "seuratFindMarkerPlotTabset", target = "Joint Heatmap Plot") - updateTabsetPanel(session = session, inputId = "seuratFindMarkerPlotTabset", selected = "Ridge Plot") + updateTabsetPanel(session = session, inputId = "seuratFindMarkerPlotTabset", selected = "2D Embedding (Feature Plot)") shinyjs::show(selector = ".seurat_findmarker_plots") # Output the heatmap @@ -8492,37 +8494,37 @@ shinyServer(function(input, output, session) { removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Ridge Plot", - panel(heading = "Ridge Plot", + tabPanel(title = "2D Embedding (Feature Plot)", + panel(heading = "Feature Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerRidgePlot") + plotOutput(outputId = "findMarkerFeaturePlot") ) ) ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Violin Plot", - panel(heading = "Violin Plot", + tabPanel(title = "Dot Plot", + panel(heading = "Dot Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerViolinPlot") + plotOutput(outputId = "findMarkerDotPlot") ) ) ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Feature Plot", - panel(heading = "Feature Plot", + tabPanel(title = "Ridge Plot", + panel(heading = "Ridge Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerFeaturePlot") + plotOutput(outputId = "findMarkerRidgePlot") ) ) ) ) appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Dot Plot", - panel(heading = "Dot Plot", + tabPanel(title = "Violin Plot", + panel(heading = "Violin Plot", shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerDotPlot") + plotOutput(outputId = "findMarkerViolinPlot") ) ) ) @@ -8557,8 +8559,6 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") - shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") - observe({ gene_choices <- setNames(nm = orderByLFCMarkers$gene.id, order(1:nrow(orderByLFCMarkers))) From 953b85d286e9ead0394a065965cde6aa3ed9e78c Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Sun, 25 Feb 2024 14:51:40 -0500 Subject: [PATCH 7/8] Saving changes --- inst/shiny/server.R | 46 ++++++++++++++++++----------- inst/shiny/ui_09_2_seuratWorkflow.R | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 49b15101b..c75f0a940 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8254,6 +8254,13 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") + #MARKER SETTINGS + geneChoices <- ifelse(is.na(rowData(vals$counts)$Symbol), rowData(vals$counts)$Symbol_TENx, rowData(vals$counts)$Symbol) + updateSelectInput(session, "selectGenesMarkerPlots", + choices = geneChoices) + + shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") + #update colData names updateColDataNames() @@ -8559,14 +8566,6 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") - observe({ - gene_choices <- setNames(nm = orderByLFCMarkers$gene.id, order(1:nrow(orderByLFCMarkers))) - - updateSelectInput(session, "selectGenesFindMarker", - choices = gene_choices, - ) - }) - # vals$fts <- callModule( # module = filterTableServer, @@ -8575,12 +8574,24 @@ shinyServer(function(input, output, session) { # ) })) - observeEvent(input$selectGenesFindMarker, { - orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers - orderByLFCMarkers <- orderByLFCMarkers[order(-orderByLFCMarkers$avg_log2FC), ] - selected_row_number <- as.numeric(input$selectGenesFindMarker) - # Retrieve the selected gene's information using the row number - vals$selectedGenes <- orderByLFCMarkers[selected_row_number, ] + observeEvent(input$selectGenesMarkerPlots, { + # Assuming rowData is stored in a variable for easier access + gene_info <- rowData(vals$counts) + + # Initialize an empty data frame to store selected genes information + selected_genes_info <- data.frame() + + # Check if any genes were selected + if (length(input$selectGenesMarkerPlots) > 0) { + # Find the rows where the Symbol or Symbol_TENx matches any of the selected gene symbols + selected_rows_indices <- which(gene_info$Symbol %in% input$selectGenesMarkerPlots | gene_info$Symbol_TENx %in% input$selectGenesMarkerPlots) + + # Subset the gene_info data frame to get only the selected rows + selected_genes_info <- gene_info[selected_rows_indices, ] + } + + # Store the selected genes information in vals$selectedGenes + vals$selectedGenesMarkerPlot <- selected_genes_info }) observeEvent(input$findMarkerHeatmapPlotFullNumericRun, withConsoleMsgRedirect( @@ -8631,13 +8642,14 @@ shinyServer(function(input, output, session) { })) observe({ - req(vals$selectedGenes) - df <- vals$selectedGenes + req(vals$selectedGenesMarkerPlot) + df <- vals$selectedGenesMarkerPlot + print(df) output$findMarkerRidgePlot <- renderPlot({ plotSeuratGenes( inSCE = vals$counts, plotType = "ridge", - features = df$gene.id, + features = df, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE diff --git a/inst/shiny/ui_09_2_seuratWorkflow.R b/inst/shiny/ui_09_2_seuratWorkflow.R index 3abde6ef2..790edb180 100644 --- a/inst/shiny/ui_09_2_seuratWorkflow.R +++ b/inst/shiny/ui_09_2_seuratWorkflow.R @@ -391,7 +391,7 @@ shinyPanelSeurat <- fluidPage( fluidRow( column(12, panel(heading = "Options", - selectInput("selectGenesFindMarker", "Select a gene:", choices = NULL, multiple = TRUE), + selectInput("selectGenesMarkerPlots", "Select a gene:", choices = NULL, multiple = TRUE), ) ) ) From 620934efb01045a6c3c7568ac973591b68db2bdb Mon Sep 17 00:00:00 2001 From: Akshay Aravind Date: Sun, 25 Feb 2024 15:24:04 -0500 Subject: [PATCH 8/8] Select genes now working after cluster --- inst/shiny/server.R | 224 ++++++++-------------------- inst/shiny/ui_09_2_seuratWorkflow.R | 45 +++--- 2 files changed, 87 insertions(+), 182 deletions(-) diff --git a/inst/shiny/server.R b/inst/shiny/server.R index c75f0a940..6ebb6a6b4 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -8255,12 +8255,69 @@ shinyServer(function(input, output, session) { shinyjs::enable(selector = "#SeuratUI > div[value='Marker Gene Plots']") #MARKER SETTINGS - geneChoices <- ifelse(is.na(rowData(vals$counts)$Symbol), rowData(vals$counts)$Symbol_TENx, rowData(vals$counts)$Symbol) - updateSelectInput(session, "selectGenesMarkerPlots", + geneChoices <- rowData(vals$counts)$Symbol_TENx + updateSelectizeInput(session, "selectGenesMarkerPlots", choices = geneChoices) shinyjs::enable(selector = "#SeuratUI > div[value='Clustering']") + removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Ridge Plot") + removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Violin Plot") + removeTab(inputId = "seuratFindMarkerPlotTabset", target = "2D Embedding (Feature Plot)") + removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Dot Plot") + removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") + + + appendTab(inputId = "seuratFindMarkerPlotTabset", + tabPanel(title = "2D Embedding (Feature Plot)", + panel(heading = "Feature Plot", + shinyjqui::jqui_resizable( + plotOutput(outputId = "findMarkerFeaturePlot") + ) + ) + ) + ) + appendTab(inputId = "seuratFindMarkerPlotTabset", + tabPanel(title = "Dot Plot", + panel(heading = "Dot Plot", + shinyjqui::jqui_resizable( + plotOutput(outputId = "findMarkerDotPlot") + ) + ) + ) + ) + appendTab(inputId = "seuratFindMarkerPlotTabset", + tabPanel(title = "Ridge Plot", + panel(heading = "Ridge Plot", + shinyjqui::jqui_resizable( + plotOutput(outputId = "findMarkerRidgePlot") + ) + ) + ) + ) + appendTab(inputId = "seuratFindMarkerPlotTabset", + tabPanel(title = "Violin Plot", + panel(heading = "Violin Plot", + shinyjqui::jqui_resizable( + plotOutput(outputId = "findMarkerViolinPlot") + ) + ) + ) + ) + appendTab(inputId = "seuratFindMarkerPlotTabset", + tabPanel(title = "Heatmap Plot", + panel(heading = "Heatmap Plot", + fluidRow( + column(12, align = "center", + panel( + plotOutput(outputId = "findMarkerHeatmapPlot") + ) + ) + ) + ) + ) + ) + updateTabsetPanel(session = session, inputId = "seuratFindMarkerPlotTabset", selected = "2D Embedding (Feature Plot)") #update colData names updateColDataNames() @@ -8359,78 +8416,6 @@ shinyServer(function(input, output, session) { shinyjs::show(selector = ".seurat_findmarker_jointHeatmap") shinyjs::show(selector = ".seurat_findmarker_plots") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Ridge Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Violin Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Feature Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Dot Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") - - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Feature Plot", - panel(heading = "2D Embedding (Feature Plot)", - fluidRow( - column(12, align = "center", - panel( - HTML(paste("Select genes from the above table to plot!")) - ) - ) - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Dot Plot", - panel(heading = "Dot Plot", - fluidRow( - column(12, align = "center", - panel( - HTML(paste("Select genes from the above table to plot!")) - ) - ) - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Ridge Plot", - panel(heading = "Ridge Plot", - fluidRow( - column(12, align = "center", - panel( - HTML(paste("Select genes from the above table to plot!")) - ) - ) - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Violin Plot", - panel(heading = "Violin Plot", - fluidRow( - column(12, align = "center", - panel( - HTML(paste("Select genes from the above table to plot!")) - ) - ) - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Heatmap Plot", - panel(heading = "Heatmap Plot", - fluidRow( - column(12, align = "center", - panel( - HTML(paste("Select genes from the above table to plot!")) - ) - ) - ) - ) - ) - ) - #df <- metadata(vals$counts)$seuratMarkers[which(metadata(vals$counts)$seuratMarkers$p_val_adj < 0.05, arr.ind = TRUE),] df <- metadata(vals$counts)$seuratMarkers seuratObject <- convertSCEToSeurat(vals$counts, normAssay = "seuratNormData") @@ -8459,7 +8444,6 @@ shinyServer(function(input, output, session) { } showTab(inputId = "seuratFindMarkerPlotTabset", target = "Joint Heatmap Plot") - updateTabsetPanel(session = session, inputId = "seuratFindMarkerPlotTabset", selected = "2D Embedding (Feature Plot)") shinyjs::show(selector = ".seurat_findmarker_plots") # Output the heatmap @@ -8494,62 +8478,6 @@ shinyServer(function(input, output, session) { updateCollapse(session = session, "SeuratUI", style = list("Downstream Analysis" = "info")) - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Ridge Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Violin Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Feature Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Dot Plot") - removeTab(inputId = "seuratFindMarkerPlotTabset", target = "Heatmap Plot") - - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "2D Embedding (Feature Plot)", - panel(heading = "Feature Plot", - shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerFeaturePlot") - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Dot Plot", - panel(heading = "Dot Plot", - shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerDotPlot") - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Ridge Plot", - panel(heading = "Ridge Plot", - shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerRidgePlot") - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Violin Plot", - panel(heading = "Violin Plot", - shinyjqui::jqui_resizable( - plotOutput(outputId = "findMarkerViolinPlot") - ) - ) - ) - ) - appendTab(inputId = "seuratFindMarkerPlotTabset", - tabPanel(title = "Heatmap Plot", - panel(heading = "Heatmap Plot", - fluidRow( - column(12, align = "center", - panel( - plotOutput(outputId = "findMarkerHeatmapPlot") - ) - ) - ) - ) - ) - ) - #singleCellTK:::.exportMetaSlot(vals$counts, "seuratMarkers") orderByLFCMarkers <- metadata(vals$counts)$seuratMarkers @@ -8574,26 +8502,6 @@ shinyServer(function(input, output, session) { # ) })) - observeEvent(input$selectGenesMarkerPlots, { - # Assuming rowData is stored in a variable for easier access - gene_info <- rowData(vals$counts) - - # Initialize an empty data frame to store selected genes information - selected_genes_info <- data.frame() - - # Check if any genes were selected - if (length(input$selectGenesMarkerPlots) > 0) { - # Find the rows where the Symbol or Symbol_TENx matches any of the selected gene symbols - selected_rows_indices <- which(gene_info$Symbol %in% input$selectGenesMarkerPlots | gene_info$Symbol_TENx %in% input$selectGenesMarkerPlots) - - # Subset the gene_info data frame to get only the selected rows - selected_genes_info <- gene_info[selected_rows_indices, ] - } - - # Store the selected genes information in vals$selectedGenes - vals$selectedGenesMarkerPlot <- selected_genes_info - }) - observeEvent(input$findMarkerHeatmapPlotFullNumericRun, withConsoleMsgRedirect( msg = "Please wait while heatmap is being plotted. See console log for progress.", { @@ -8642,14 +8550,12 @@ shinyServer(function(input, output, session) { })) observe({ - req(vals$selectedGenesMarkerPlot) - df <- vals$selectedGenesMarkerPlot - print(df) + req(input$selectGenesMarkerPlots) output$findMarkerRidgePlot <- renderPlot({ plotSeuratGenes( inSCE = vals$counts, plotType = "ridge", - features = df, + features = input$selectGenesMarkerPlots, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE @@ -8659,7 +8565,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "violin", - features = df$gene.id, + features = input$selectGenesMarkerPlots, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE @@ -8669,7 +8575,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "feature", - features = df$gene.id, + features = input$selectGenesMarkerPlots, groupVariable = input$seuratFindMarkerSelectPhenotype, ncol = 2, combine = TRUE, @@ -8680,7 +8586,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "dot", - features = df$gene.id, + features = input$selectGenesMarkerPlots, groupVariable = input$seuratFindMarkerSelectPhenotype ) }) @@ -8688,7 +8594,7 @@ shinyServer(function(input, output, session) { plotSeuratGenes( inSCE = vals$counts, plotType = "heatmap", - features = df$gene.id, + features = input$selectGenesMarkerPlots, groupVariable = input$seuratFindMarkerSelectPhenotype ) }) diff --git a/inst/shiny/ui_09_2_seuratWorkflow.R b/inst/shiny/ui_09_2_seuratWorkflow.R index 790edb180..9694f15c0 100644 --- a/inst/shiny/ui_09_2_seuratWorkflow.R +++ b/inst/shiny/ui_09_2_seuratWorkflow.R @@ -287,6 +287,27 @@ shinyPanelSeurat <- fluidPage( ) ), style = "primary"), + bsCollapsePanel("Marker Gene Plots", + fluidRow( + column(12, + fluidRow( + column(12, + panel(heading = "Options", + selectizeInput("selectGenesMarkerPlots", "Select a gene:", choices = NULL, multiple = TRUE, options = list('plugins' = list('remove_button'), server = TRUE)), + ) + ) + ) + ), + column(12, + tags$div(class = "seurat_findmarker_plots", + panel(heading = "", + HTML("
Select marker genes above to plot them below!

"), + tabsetPanel(id = "seuratFindMarkerPlotTabset", type = "tabs")) + ) + ) + ), + style = "primary" + ), bsCollapsePanel("Find Markers", fluidRow( column(4, @@ -383,29 +404,7 @@ shinyPanelSeurat <- fluidPage( ) ) ), - style = "primary"), - - bsCollapsePanel("Marker Gene Plots", - fluidRow( - column(12, - fluidRow( - column(12, - panel(heading = "Options", - selectInput("selectGenesMarkerPlots", "Select a gene:", choices = NULL, multiple = TRUE), - ) - ) - ) - ), - column(12, - tags$div(class = "seurat_findmarker_plots", - panel(heading = "", - HTML("
Select marker genes above to plot them below!

"), - tabsetPanel(id = "seuratFindMarkerPlotTabset", type = "tabs")) - ) - ) - ), - style = "primary" - ) + style = "primary") ), nonLinearWorkflowUI(id = "nlw-seurat") )