-
Notifications
You must be signed in to change notification settings - Fork 2
Sample pca filtering #60
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
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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ server_module_qc_metrics <- function(id, assays_to_process) { | |
| choices = names(choices) | ||
| ) | ||
| }) | ||
|
|
||
| single_assay <- reactive({ | ||
| req(input$selected_assay) | ||
| req(assays_to_process()) | ||
|
|
@@ -37,18 +38,36 @@ server_module_qc_metrics <- function(id, assays_to_process) { | |
| assays_choices_vector()[input$selected_assay] | ||
| )) | ||
| }) | ||
| annotation_names <- reactive({ | ||
| req(single_assay()) | ||
| if (input$assay_type == "features") { | ||
| c("NULL", colnames(rowData(single_assay()))) | ||
| } else { | ||
| c("NULL", colnames(colData(single_assay()))) | ||
| } | ||
| }) | ||
|
|
||
| observe({ | ||
| req(single_assay()) | ||
| req(annotation_names()) | ||
| stopifnot(is(single_assay(), "SummarizedExperiment")) | ||
| updateSelectInput(session, | ||
| "pca_color", | ||
| choices = annotation_names(), | ||
| selected = "NULL" | ||
| ) | ||
| }) | ||
|
|
||
| server_module_pca_box( | ||
| id = "features", | ||
| single_assay = single_assay, | ||
| method = input$selected_method, | ||
| transpose = FALSE | ||
| ) | ||
| server_module_pca_box( | ||
| id = "samples", | ||
| single_assay = single_assay, | ||
| method = input$selected_method, | ||
| transpose = TRUE | ||
| id = "features", | ||
| single_assay = single_assay, | ||
| method = reactive(input$selected_method), | ||
| pca_type = reactive(input$assay_type), | ||
| scale = reactive(input$scale), | ||
| center = reactive(input$center), | ||
| color = reactive(input$pca_color), | ||
| show_legend = reactive(input$show_legend), | ||
| color_width = reactive(input$color_width) | ||
| ) | ||
|
|
||
| server_module_viz_box("viz_box", assays_to_process) | ||
|
|
@@ -60,9 +79,14 @@ server_module_qc_metrics <- function(id, assays_to_process) { | |
| #' @param id module id | ||
| #' @param single_assay a reactiveVal that contains the selected assay | ||
| #' @param method a character string specifying the PCA method to use | ||
| #' valid values are c("nipals") | ||
| #' @param transpose a boolean that specifies if the PCA should be transposed | ||
| #' TRUE for samples and FALSE for features | ||
| #' valid values are c("nipals", "ppca", "svdImpute") | ||
| #' @param pca_type sample or features | ||
| #' @param scale a boolean that specifies if the data should be scaled | ||
| #' @param center a boolen that specifies if the data should be centered | ||
| #' @param show_legend a boolean that specifies if the legend should be shown | ||
| #' @param color which metadata use for color | ||
| #' @param color_width how many letter display in the legend | ||
| #' | ||
| #' @return A shiny module server function that contains the PCA logic | ||
| #' @rdname INTERNAL_server_module_pca_box | ||
| #' @keywords internal | ||
|
|
@@ -73,46 +97,35 @@ server_module_qc_metrics <- function(id, assays_to_process) { | |
| #' @importFrom pcaMethods pca scores | ||
| #' @importFrom methods is | ||
| #' | ||
| server_module_pca_box <- function(id, single_assay, method, transpose) { | ||
| server_module_pca_box <- function(id, single_assay, method, pca_type, scale, center, show_legend, color, color_width) { | ||
|
||
| moduleServer(id, function(input, output, session) { | ||
| annotation_names <- reactive({ | ||
| req(single_assay()) | ||
| if (id == "features") { | ||
| c("NULL", colnames(rowData(single_assay()))) | ||
| } else { | ||
| c("NULL", colnames(colData(single_assay()))) | ||
| } | ||
| }) | ||
|
|
||
| observe({ | ||
| req(single_assay()) | ||
| req(annotation_names()) | ||
| stopifnot(is(single_assay(), "SummarizedExperiment")) | ||
| updateSelectInput(session, | ||
| "pca_color", | ||
| choices = annotation_names(), | ||
| selected = "NULL" | ||
| ) | ||
| }) | ||
| stopifnot(is.reactive(method)) | ||
| stopifnot(is.reactive(pca_type)) | ||
| stopifnot(is.reactive(scale)) | ||
| stopifnot(is.reactive(center)) | ||
| stopifnot(is.reactive(show_legend)) | ||
| stopifnot(is.reactive(color)) | ||
| stopifnot(is.reactive(color_width)) | ||
|
|
||
|
|
||
| color_data <- reactive({ | ||
| req(single_assay()) | ||
| req(input$pca_color) | ||
| if (input$pca_color != "NULL") { | ||
| if (id == "features") { | ||
| df <- rowData(single_assay())[, input$pca_color, drop = FALSE] | ||
| req(color()) | ||
| if (color() != "NULL") { | ||
| if (pca_type() == "features") { | ||
| df <- rowData(single_assay())[, color(), drop = FALSE] | ||
| } else { | ||
| df <- colData(single_assay())[, input$pca_color, drop = FALSE] | ||
| df <- colData(single_assay())[, color(), drop = FALSE] | ||
| } | ||
| if (is.character(df[, 1])) { | ||
| df[, 1] <- ifelse(nchar(df[, 1]) > input$color_width, | ||
| paste0(substr(df[, 1], 1, input$color_width), "..."), df[, 1] | ||
| df[, 1] <- ifelse(nchar(df[, 1]) > color_width(), | ||
| paste0(substr(df[, 1], 1, color_width()), "..."), df[, 1] | ||
| ) | ||
| } | ||
| if (all(is.na(df))) { | ||
| df[, 1] <- "NA" | ||
| } | ||
| colnames(df) <- input$pca_color | ||
| colnames(df) <- color() | ||
| return(df) | ||
| } | ||
| }) | ||
|
|
@@ -124,18 +137,18 @@ server_module_pca_box <- function(id, single_assay, method, transpose) { | |
| req(ncol(single_assay()) > 0L) | ||
| pcaMethods_wrapper( | ||
| single_assay(), | ||
| method = method, | ||
| transpose = transpose, | ||
| scale = input$scale, | ||
| center = input$center | ||
| method = method(), | ||
| transpose = pca_type() == "samples", | ||
| scale = scale(), | ||
| center = center() | ||
| ) | ||
| }) | ||
| dataframe <- reactive({ | ||
| req(single_assay()) | ||
| req(!is_empty_set(single_assay())) | ||
| req(ncol(single_assay()) > 0L) | ||
| req(pca_result()) | ||
| if (input$pca_color == "NULL") { | ||
| if (color() == "NULL") { | ||
| as.data.frame( | ||
| data.frame(scores(pca_result())) | ||
| ) | ||
|
|
@@ -195,8 +208,8 @@ server_module_pca_box <- function(id, single_assay, method, transpose) { | |
| component_name = "PCA quality control plot", | ||
| df = dataframe(), | ||
| pca_result = pca_result(), | ||
| color_name = input$pca_color, | ||
| show_legend = input$show_legend | ||
| color_name = color(), | ||
| show_legend = show_legend() | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
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.
interface_module_qc_metrics()receives atypeargument (passed byinterface_module_filtering_tab()as either "samples" or "features"), but the newassay_typeselector is hard-coded toselected = "samples"and thetypeargument is otherwise unused. This makes the default PCA orientation inconsistent with the filtering tab type. Consider validatingtypeviamatch.arg()and using it as the defaultselectedvalue (or remove thetypeparameter entirely if it’s no longer intended to control the UI).