Skip to content

Commit

Permalink
[WIP] - starting ggridges implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldguyot committed Jul 18, 2024
1 parent a2fb93a commit 36414b0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ importFrom(RColorBrewer,brewer.pal)
importFrom(SummarizedExperiment,assay)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
importFrom(ggplot2,aes)
importFrom(ggplot2,ggplot)
importFrom(ggridges,geom_density_ridges)
importFrom(htmltools,HTML)
importFrom(htmltools,a)
importFrom(htmltools,br)
Expand All @@ -40,6 +43,7 @@ importFrom(plotly,add_annotations)
importFrom(plotly,add_histogram)
importFrom(plotly,add_trace)
importFrom(plotly,config)
importFrom(plotly,ggplotly)
importFrom(plotly,hide_colorbar)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
Expand Down
25 changes: 9 additions & 16 deletions R/interface_module_normalisation_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @importFrom shiny fluidRow NS actionButton icon uiOutput
#' @importFrom shinydashboardPlus box
#' @importFrom htmltools tagList
#' @importFrom htmltools tagList h2
#' @importFrom shinyBS bsTooltip
#'
interface_module_normalisation_tab <- function(id) {
Expand Down Expand Up @@ -34,32 +34,21 @@ interface_module_normalisation_tab <- function(id) {
solidHeader = TRUE,
collapsible = FALSE,
fluidRow(
box(
title = "Prior Distribution",
status = "primary",
width = 5,
solidHeader = TRUE,
collapsible = TRUE,
withSpinner(plotlyOutput(outputId = NS(id, "prior_dist")),
type = 6,
color = "#3c8dbc"
)
),
box(
title = "Post Distribution",
status = "primary",
width = 5,
width = 9,
solidHeader = TRUE,
collapsible = TRUE,
withSpinner(plotlyOutput(outputId = NS(id, "post_dist")),
withSpinner(plotlyOutput(outputId = NS(id, "density_plot")),
type = 6,
color = "#3c8dbc"
)
),
box(
title = "Normalisation Settings",
status = "primary",
width = 2,
width = 3,
solidHeader = TRUE,
collapsible = TRUE,
selectInput(inputId = NS(id, "method"),
Expand All @@ -75,7 +64,11 @@ interface_module_normalisation_tab <- function(id) {
"quantiles.robust",
"vsn"),
selected = "center.median"
)
),
h2("Plot options"),
selectInput(inputId = NS(id, "color"),
label = "Color by",
choices = NULL)
)
)
),
Expand Down
24 changes: 23 additions & 1 deletion R/server_module_normalisation_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ server_module_normalisation_tab <- function(id, step_number) {
)
})

output$density_plot <- renderPlotly({
req(processed_assays())
density_by_sample_plotly(
qfeatures = processed_assays(),
color = input$color
)
# error_handler(
# density_by_sample_plotly,
# component_name = "Density by sample plotly",
# qfeatures = processed_assays(),
# color = input$color)
})

observe({
req(processed_assays())
updateSelectInput(session,
"color",
choices = colnames(colData(processed_assays()))
)
})

observeEvent(input$export, {
req(processed_assays())
loading(paste("Be aware that this operation",
Expand All @@ -43,5 +64,6 @@ server_module_normalisation_tab <- function(id, step_number) {
)
removeModal()
})

})
}
}
37 changes: 36 additions & 1 deletion R/utils_global.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,39 @@ normalisation_qfeatures <- function(qfeatures, method) {
})
names(el) <- names(qfeatures)
QFeatures(el, colData = colData(qfeatures))
}
}


#'A function that return a plot of the densities of intensities by sample
#'
#' @param qfeatures `QFeatures` object
#' @param color `str` colname of the column of colData to use as color
#' @return a plotly object
#'
#' @rdname INTERNAL_density_by_sample_plotly
#' @keywords internal
#' @importFrom plotly ggplotly
#' @importFrom ggplot2 ggplot aes
#' @importFrom ggridges geom_density_ridges

density_by_sample_plotly <- function(qfeatures, color) {

combined_df <- data.frame(intensity = numeric(), sample = character())
for (assayName in names(qfeatures)) {
assayData <- assay(qfeatures[[assayName]])

intensities <- as.vector(assayData)
sampleNames <- rep(colnames(assayData), each = nrow(assayData))

assay_df <- data.frame(intensity = intensities, sample = sampleNames)

combined_df <- rbind(combined_df, assay_df)
}
print(colData(qfeatures)[combined_df$sample, color])
combined_df$color <- colData(qfeatures)[combined_df$sample, color]

plot <- ggplot(combined_df, aes(x = intensity, y = sample, fill = color)) +
geom_density_ridges()

ggplotly(plot)
}

0 comments on commit 36414b0

Please sign in to comment.