diff --git a/.Rprofile b/.Rprofile index 427e285..557ddf4 100644 --- a/.Rprofile +++ b/.Rprofile @@ -1,3 +1,15 @@ +# For Ubuntu 18.04 (also known as Bionic) +options(repos = c( + REPO_NAME = "https://packagemanager.rstudio.com/all/__linux__/bionic/latest", + getOption("repos") +)) + +# For Ubuntu 20.04 (also known as Focal) +options(repos = c( + REPO_NAME = "https://packagemanager.rstudio.com/all/__linux__/focal/latest", + getOption("repos") + )) + if (interactive()) { source("renv/activate.R") suppressMessages(require(devtools)) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index a4a0680..ecab34a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,12 +1,10 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - main - - master + branches: [main, master, staging, develop] pull_request: - branches: - - main - - master + branches: [main, master, staging, develop] name: R-CMD-check @@ -20,8 +18,9 @@ jobs: fail-fast: false matrix: config: - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", http-user-agent: "R/4.1.0 (ubuntu-20.04) R (4.1.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } + - {os: macOS-latest, r: '4.1.0'} + - {os: windows-latest, r: '4.1.0'} + - {os: ubuntu-20.04, r: '4.1.0', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true @@ -31,47 +30,24 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-r@v1 with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes', repos = "http://cran.us.r-project.org") - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Restore R package cache - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r-dependencies@v1 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + extra-packages: rcmdcheck - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} + - uses: r-lib/actions/check-r-package@v1 - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + - name: Show testthat output + if: always() + run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash - name: Upload check results if: failure() diff --git a/DESCRIPTION b/DESCRIPTION index fc4d4a2..0092629 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: iatlas.modules Title: iAatlas Modules Type: Package -Version: 0.5.7 +Version: 0.6.0 Date: 2021-1-30 Author: Andrew Lamb Maintainer: Andrew Lamb diff --git a/R/barplot_server.R b/R/barplot_server.R index d3461e8..a557050 100644 --- a/R/barplot_server.R +++ b/R/barplot_server.R @@ -4,8 +4,8 @@ #' @param id Module ID #' @param plot_data_function A shiny::reactive that returns a function #' The function must take an argument called ".feature_class" and return a -#' dataframe with columns "sample", "feature", "feature_value", "group", -#' and optionally "group_description" +#' dataframe with columns "sample_name", "feature_name", "feature_value", +#' "group_name", and optionally "group_description" #' @param feature_classes A shiny::reactive that returns a vector of strings. #' One of these strings are passed to plot_data_function #' @param barplot_xlab A shiny::reactive that returns a string @@ -75,9 +75,9 @@ barplot_server <- function( plotly_bar( summarized_barplot_data(), source_name = barplot_source_name(), - x_col = "group", + x_col = "group_name", y_col = "MEAN", - color_col = "feature", + color_col = "feature_name", error_col = "SE", text_col = "text", xlab = barplot_xlab(), @@ -101,8 +101,8 @@ barplot_server <- function( barplot_eventdata <- shiny::reactive({ shiny::req(barplot_source_name(), summarized_barplot_data()) eventdata <- plotly::event_data("plotly_click", barplot_source_name()) - if(is.null(eventdata) & !is.null(input$test_event_data)){ - eventdata <- input$test_event_data + if(is.null(eventdata) & !is.null(input$mock_event_data)){ + eventdata <- input$mock_event_data } shiny::validate(shiny::need(eventdata, "Click on above barplot.")) return(eventdata) @@ -116,10 +116,10 @@ barplot_server <- function( scatterplot_data <- shiny::reactive({ shiny::req(barplot_data(), selected_group()) barplot_data() %>% - dplyr::filter(.data$group == selected_group()) %>% - dplyr::select("sample", "group", "feature", "feature_value") %>% + dplyr::filter(.data$group_name == selected_group()) %>% + dplyr::select("sample_name", "group_name", "feature_name", "feature_value") %>% tidyr::pivot_wider( - ., values_from = "feature_value", names_from = "feature" + ., values_from = "feature_value", names_from = "feature_name" ) }) diff --git a/R/barplot_server_functions.R b/R/barplot_server_functions.R index aad6442..ad3b8f4 100644 --- a/R/barplot_server_functions.R +++ b/R/barplot_server_functions.R @@ -2,25 +2,36 @@ build_barplot_data <- function(plot_data_function, feature_class_choice){ data <- plot_data_function(.feature_class = feature_class_choice) %>% dplyr::select(dplyr::any_of( - c("sample", "feature", "feature_value", "group", "group_description") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description" + ) )) } summarise_barplot_se <- function(data, title){ data %>% - dplyr::select("group", "feature", "feature_value") %>% + dplyr::select("group_name", "feature_name", "feature_value") %>% tidyr::drop_na() %>% - dplyr::group_by_at(dplyr::vars("group", "feature")) %>% + dplyr::group_by_at(dplyr::vars("group_name", "feature_name")) %>% dplyr::summarise( "MEAN" = mean(.data$feature_value), "SE" = .data$MEAN / sqrt(dplyr::n()), .groups = "drop" ) %>% - create_plotly_text(.data$feature, .data$group, c("MEAN", "SE"), title) + create_plotly_text( + .data$feature_name, + .data$group_name, + c("MEAN", "SE"), + title + ) } get_barplot_group_data <- function(barplot_data){ barplot_data %>% - dplyr::select("group", "description" = "group_description") %>% + dplyr::select("group_name", "group_description") %>% dplyr::distinct() } diff --git a/R/distributions_plot_server.R b/R/distributions_plot_server.R index 7819be8..bb0a432 100644 --- a/R/distributions_plot_server.R +++ b/R/distributions_plot_server.R @@ -1,12 +1,13 @@ -#' Barplot Server +#' Distributions Plot Server #' #' @param id Module ID #' @param plot_data_function A shiny::reactive that returns a function. #' The function must take an argument called ".feature" and return a -#' dataframe with columns "sample", "feature", "feature_value", "group", -#' and optionally "group_description", "color" -#' @param features A shiny::reactive that returns a dataframe with "feature", +#' dataframe with columns "sample_name", "feature_name", "feature_value", +#' "group_name", +#' and optionally "group_description", "group_color" +#' @param features A shiny::reactive that returns a dataframe with "feature_name", #' "feature_display", and any other additional optional columns to group the #' features by. If not given, the argument to plot_data_function will be Null. #' @param distplot_xlab A shiny::reactive that returns a string @@ -143,9 +144,9 @@ distributions_plot_server <- function( plot_fill_colors <- shiny::reactive({ shiny::req(distplot_data()) - if("color" %in% colnames(distplot_data())){ + if("group_color" %in% colnames(distplot_data())){ fill_colors <- distplot_data() %>% - dplyr::select("group", "color") %>% + dplyr::select("group_name", "group_color") %>% dplyr::distinct() %>% tibble::deframe(.) } else { @@ -176,7 +177,7 @@ distributions_plot_server <- function( plotly_function()( plot_data = distplot_data(), source_name = distplot_source_name(), - x_col = "group", + x_col = "group_name", y_col = "feature_value", fill_colors = plot_fill_colors(), title = plot_title(), @@ -188,6 +189,9 @@ distributions_plot_server <- function( distplot_eventdata <- shiny::reactive({ shiny::req(distplot_source_name(), distplot_data(), plotly_function()) eventdata <- plotly::event_data("plotly_click", distplot_source_name()) + if(is.null(eventdata) & !is.null(input$mock_event_data)){ + eventdata <- input$mock_event_data + } shiny::validate(shiny::need(eventdata, "Click on above barplot.")) return(eventdata) }) @@ -195,7 +199,7 @@ distributions_plot_server <- function( group_data <- shiny::reactive({ shiny::req("group_description" %in% colnames(distplot_data())) distplot_data() %>% - dplyr::select("group", "description" = "group_description") %>% + dplyr::select("group_name", "group_description") %>% dplyr::distinct() }) diff --git a/R/distributions_plot_server_functions.R b/R/distributions_plot_server_functions.R index 4265d1c..601e142 100644 --- a/R/distributions_plot_server_functions.R +++ b/R/distributions_plot_server_functions.R @@ -47,8 +47,8 @@ create_distplot_data <- function( reafctor_by_tbl_value_column(reorder_method_choice) %>% dplyr::select(dplyr::any_of( c( - "sample", "feature", "feature_value", "group", "group_description", - "color" + "sample_name", "feature_name", "feature_value", "group_name", "group_description", + "group_color" ) )) } diff --git a/R/drilldown_histogram_server.R b/R/drilldown_histogram_server.R index 54a346a..f6ea5ae 100644 --- a/R/drilldown_histogram_server.R +++ b/R/drilldown_histogram_server.R @@ -3,7 +3,7 @@ #' #' @param id Module ID #' @param plot_data A shiny::reactive that returns a dataframe with columns -#' "group", "feature_value" +#' "group_name", "feature_value" #' @param eventdata A shiny::reactive that returns a dataframe with column #' "key" #' @param ... arguments sents to plotly_histogram @@ -30,10 +30,10 @@ drilldown_histogram_server <- function( shiny::req( plot_data(), selected_group(), - selected_group() %in% plot_data()$group + selected_group() %in% plot_data()$group_name ) plot_data() %>% - dplyr::filter(.data$group == selected_group()) %>% + dplyr::filter(.data$group_name == selected_group()) %>% dplyr::select("feature_value") }) diff --git a/R/drilldown_scatterplot_server.R b/R/drilldown_scatterplot_server.R index 1212351..d3b308d 100644 --- a/R/drilldown_scatterplot_server.R +++ b/R/drilldown_scatterplot_server.R @@ -3,7 +3,7 @@ #' #' @param id Module ID #' @param scatterplot_data A shiny::reactive that returns a dataframe with columns -#' "sample", "group", "feature", "feature_value" +#' "sample_name", "group_name", and two value columns #' @param x_feature_input A shiny::reactive that returns a string #' @param y_feature_input A shiny::reactive that returns a string #' @param selected_group A string, this gets added to the sample label @@ -25,7 +25,7 @@ drilldown_scatterplot_server <- function( scatterplot_feature_columns <- shiny::reactive({ scatterplot_data() %>% colnames() %>% - setdiff(c("sample", "group")) + setdiff(c("sample_name", "group_name")) }) display_feature_selection_ui <- shiny::reactive({ diff --git a/R/drilldown_scatterplot_server_functions.R b/R/drilldown_scatterplot_server_functions.R index 32cf131..521a677 100644 --- a/R/drilldown_scatterplot_server_functions.R +++ b/R/drilldown_scatterplot_server_functions.R @@ -16,11 +16,11 @@ format_scatterplot_data <- function( ){ plot_data %>% dplyr::select(dplyr::all_of(c( - "sample", "group", "x" = x_feature, "y" = y_feature + "sample_name", "group_name", "x" = x_feature, "y" = y_feature ))) %>% tidyr::drop_na() %>% create_plotly_text( - .data$sample, .data$group, c("x", "y"), "Sample" + .data$sample_name, .data$group_name, c("x", "y"), "Sample" ) %>% dplyr::select("x", "y", "text") } diff --git a/R/example_data.R b/R/example_data.R index d69a16e..3646c62 100644 --- a/R/example_data.R +++ b/R/example_data.R @@ -4,13 +4,13 @@ utils::globalVariables("iris") example_starwars_data <- function(){ dplyr::starwars %>% dplyr::select( - "sample" = "name", - "group" = "species", + "sample_name" = "name", + "group_name" = "species", "height", "mass" ) %>% tidyr::pivot_longer( - -c("sample", "group"), names_to = "feature", values_to = "feature_value" + -c("sample_name", "group_name"), names_to = "feature_name", values_to = "feature_value" ) } @@ -23,34 +23,31 @@ example_starwars_data_func <- function(.feature_class){ example_iris_data <- function(){ iris %>% dplyr::as_tibble() %>% - dplyr::mutate("sample" = as.character(1:dplyr::n())) %>% + dplyr::mutate("sample_name" = as.character(1:dplyr::n())) %>% + dplyr::rename("group_name" = "Species") %>% tidyr::pivot_longer( - !c("Species", "sample"), - names_to = "feature", + !c("group_name", "sample_name"), + names_to = "feature_name", values_to = "feature_value" ) %>% - dplyr::rename("group" = "Species") %>% dplyr::inner_join( dplyr::tribble( - ~group, ~color, - "setosa", "#FF0000", - "versicolor", "#0000FF", - "virginica", "#FFFF00" + ~group_name, ~group_color, ~group_description, + "setosa", "#FF0000", "Iris Species: Setosa", + "versicolor", "#0000FF", "Iris Species: Versicolor", + "virginica", "#FFFF00", "Iris Species: Virginica", ), - by = "group" - ) %>% - dplyr::mutate( - "group_description" = stringr::str_c("Iris Species: ", .data$group), + by = "group_name" ) %>% dplyr::inner_join( dplyr::tribble( - ~feature_class, ~feature, ~feature_class2, ~feature_display, + ~feature_class, ~feature_name, ~feature_class2, ~feature_display, "Length", "Sepal.Length", "Sepal", "Sepal Length", "Width", "Sepal.Width", "Sepal", "Sepal Width", "Length", "Petal.Length", "Petal", "Petal Length", "Width", "Petal.Width", "Petal", "Petal Width" ), - by = "feature" + by = "feature_name" ) } @@ -60,7 +57,7 @@ example_iris_data_func <- function(.feature_class = NULL, .feature = NULL){ iris_data <- dplyr::filter(iris_data, .data$feature_class == .feature_class) } if (!is.null(.feature)){ - iris_data <- dplyr::filter(iris_data, .data$feature == .feature) + iris_data <- dplyr::filter(iris_data, .data$feature_name == .feature) } dplyr::select(iris_data, -"feature_class") } @@ -92,11 +89,13 @@ get_pcawg_heatmap_example <- function(){ iatlas.api.client::query_feature_values( cohorts = "PCAWG", feature_classes = "Adaptive Receptor - T cell" ) %>% + print() dplyr::select( - "sample", - "feature" = "feature_display", + "sample_name" = "sample", + "feature_name", + "feature_display", "feature_value", - "order" = "feature_order" + "feature_order" ) response_data <- @@ -104,8 +103,9 @@ get_pcawg_heatmap_example <- function(){ cohorts = "PCAWG", features = "age_at_diagnosis" ) %>% dplyr::select( - "sample", - "response" = "feature_display", + "sample_name" = "sample", + "response_name" = "feature_name", + "response_display" = "feature_display", "response_value" = "feature_value" ) @@ -114,8 +114,8 @@ get_pcawg_heatmap_example <- function(){ cohorts = "PCAWG", parent_tags = "Immune_Subtype" ) %>% dplyr::select( - "sample" = "sample_name", - "group" = "tag_short_display", + "sample_name" = "sample_name", + "group_name" = "tag_short_display", "group_description" = "tag_characteristics" ) @@ -123,11 +123,11 @@ get_pcawg_heatmap_example <- function(){ dplyr::inner_join( feature_data, response_data, - by = "sample" + by = "sample_name" ) %>% dplyr::inner_join( group_data, - by = "sample" + by = "sample_name" ) } @@ -138,7 +138,7 @@ get_pcawg_scatterplot_example <- function(){ iatlas.api.client::query_feature_values( cohorts = "PCAWG", feature_classes = "Adaptive Receptor - T cell" ) %>% - dplyr::select("sample","feature_display", "feature_value") %>% + dplyr::select("sample_name" = "sample", "feature_display", "feature_value") %>% tidyr::pivot_wider( names_from = "feature_display", values_from = "feature_value" ) %>% @@ -148,13 +148,13 @@ get_pcawg_scatterplot_example <- function(){ iatlas.api.client::query_tag_samples( cohorts = "PCAWG", parent_tags = "Immune_Subtype" ) %>% - dplyr::select("sample" = "sample_name", "group" = "tag_short_display") + dplyr::select("sample_name", "group_name" = "tag_short_display") plot_data <- dplyr::inner_join( feature_data, group_data, - by = "sample" + by = "sample_name" ) } @@ -165,33 +165,42 @@ get_pcawg_feature_values_by_feature <- function(.feature){ iatlas.api.client::query_feature_values( cohorts = "PCAWG", features = .feature ) %>% - dplyr::select("sample", "feature" = "feature_display", "feature_value") + dplyr::select( + "sample_name" = "sample", + "feature_name", + "feature_display", + "feature_value" + ) group_data <- iatlas.api.client::query_tag_samples( cohorts = "PCAWG", parent_tags = "Immune_Subtype" ) %>% dplyr::select( - "sample" = "sample_name", - "group" = "tag_short_display", + "sample_name", + "group_name" = "tag_short_display", "group_description" = "tag_characteristics", - "color" = "tag_color" + "group_color" = "tag_color" ) dplyr::inner_join( feature_data, group_data, - by = "sample" + by = "sample_name" ) } -get_pcawg_feature_values_by_class <- function(.class){ +get_pcawg_feature_values_by_class <- function(.feature_class){ feature_data <- iatlas.api.client::query_feature_values( - cohorts = "PCAWG", feature_classes = .class + cohorts = "PCAWG", feature_classes = .feature_class ) %>% dplyr::select( - "sample", "feature" = "feature_display", "feature_value", "feature_order" + "sample_name" = "sample", + "feature_name", + "feature_display", + "feature_value", + "feature_order" ) group_data <- @@ -199,39 +208,41 @@ get_pcawg_feature_values_by_class <- function(.class){ cohorts = "PCAWG", parent_tags = "Immune_Subtype" ) %>% dplyr::select( - "sample" = "sample_name", - "group" = "tag_short_display", + "sample_name", + "group_name" = "tag_short_display", "group_description" = "tag_characteristics", - "color" = "tag_color" + "group_color" = "tag_color" ) dplyr::inner_join( feature_data, group_data, - by = "sample" + by = "sample_name" ) } -get_feature_values_by_class_no_data <- function(.class){ +get_feature_values_by_class_no_data <- function(.feature_class){ dplyr::tibble( - "sample" = character(), - "group" = character(), - "feature" = character(), + "sample_name" = character(), + "group_name" = character(), + "feature_name" = character(), + "feature_display" = character(), "feature_value" = character(), "feature_order" = character(), "group_description" = character(), - "color" = character() + "group_color" = character() ) } get_feature_values_by_feature_no_data <- function(.feature){ dplyr::tibble( - "sample" = character(), - "group" = character(), - "feature" = character(), + "sample_name" = character(), + "group_name" = character(), + "feature_name" = character(), + "feature_display" = character(), "feature_value" = character(), "feature_order" = character(), "group_description" = character(), - "color" = character() + "group_color" = character() ) } diff --git a/R/heatmap_functions.R b/R/heatmap_functions.R index f1c63b4..81c4833 100644 --- a/R/heatmap_functions.R +++ b/R/heatmap_functions.R @@ -1,9 +1,9 @@ build_heatmap_tbl <- function(tbl, func){ tbl %>% dplyr::select( - "feature", "feature_order", "group", "feature_value", "response_value" + "feature" = "feature_display", "feature_order", "group_name", "feature_value", "response_value" ) %>% - dplyr::group_by(.data$group, .data$feature, .data$feature_order) %>% + dplyr::group_by(.data$group_name, .data$feature, .data$feature_order) %>% dplyr::summarise("value" = func( .data$feature_value, .data$response_value @@ -13,7 +13,7 @@ build_heatmap_tbl <- function(tbl, func){ tidyr::drop_na() %>% tidyr::pivot_wider( ., - names_from = "group", + names_from = "group_name", values_from = "value" ) } diff --git a/R/heatmap_server.R b/R/heatmap_server.R index 98fd1b3..684c6a3 100644 --- a/R/heatmap_server.R +++ b/R/heatmap_server.R @@ -10,11 +10,12 @@ #' The selected feature will be passed to the repsonse_data_function as .feature. #' @param feature_data_function A shiny::reactive that returns a function #' The function must take an argument called ".feature_class" and return a -#' dataframe with columns "sample", "group", "feature", "feature_value", -#' "feature_order", "group_description", "color" +#' dataframe with columns "sample_name", "group_name", "feature_name", +#' "feature_display", "feature_value", "feature_order", "group_description", +#' "group_color" #' @param response_data_function A shiny::reactive that returns a function #' The function must take an argument called ".feature" and return a -#' dataframe with columns "sample", "feature_value" +#' dataframe with columns "sample_name", "feature_name", "feature_value" #' @param summarise_function_list A shiny::reactive that returns a either a function #' or a named list of functions. If a list is passed, it will be passed to #' shiny::selectInput. Each function must take vectors. The first one will be @@ -112,15 +113,16 @@ heatmap_server <- function( feature_values_tbl <- shiny::reactive({ shiny::req(input$feature_class_choice, feature_data_function()) - tbl <- feature_data_function()(.class = input$feature_class_choice) %>% + tbl <- feature_data_function()(.feature_class = input$feature_class_choice) %>% dplyr::select( - "sample", - "feature", + "sample_name", + "feature_name", + "feature_display", "feature_value", "feature_order", - "group", + "group_name", "group_description", - "color" + "group_color" ) shiny::validate(shiny::need( nrow(tbl) > 0, @@ -131,18 +133,31 @@ heatmap_server <- function( response_values_tbl <- shiny::reactive({ shiny::req(input$response_feature_choice, response_data_function()) - tbl <- response_data_function()(.feature = input$response_feature_choice) %>% - dplyr::select("sample", "response" = "feature", "response_value" = "feature_value") + + tbl <- + response_data_function()(.feature = input$response_feature_choice) %>% + dplyr::select( + "sample_name", + "response_name" = "feature_name", + "response_display" = "feature_display", + "response_value" = "feature_value" + ) + shiny::validate(shiny::need( nrow(tbl) > 0, "Response feature choice did not produce any data, please select a different one." )) + return(tbl) }) joined_tibble <- shiny::reactive({ shiny::req(feature_values_tbl(), response_values_tbl()) - dplyr::inner_join(feature_values_tbl(), response_values_tbl(), by = "sample") + dplyr::inner_join( + feature_values_tbl(), + response_values_tbl(), + by = "sample_name" + ) }) summarise_function <- shiny::reactive({ @@ -190,8 +205,8 @@ heatmap_server <- function( heatmap_eventdata <- shiny::reactive({ shiny::req(heatmap_source_name(), heatmap()) eventdata <- plotly::event_data("plotly_click", heatmap_source_name()) - if(is.null(eventdata) & !is.null(input$test_event_data)){ - eventdata <- input$test_event_data + if(is.null(eventdata) & !is.null(input$mock_event_data)){ + eventdata <- input$mock_event_data } shiny::validate(shiny::need(eventdata, "Click on above heatmap.")) return(eventdata) @@ -200,7 +215,7 @@ heatmap_server <- function( group_data <- shiny::reactive({ shiny::req("group_description" %in% colnames(feature_values_tbl())) feature_values_tbl() %>% - dplyr::select("group", "description" = "group_description") %>% + dplyr::select("group_name", "group_description") %>% dplyr::distinct() }) @@ -223,7 +238,7 @@ heatmap_server <- function( response_feature <- shiny::reactive({ shiny::req(response_values_tbl()) - response_values_tbl()$response[[1]] + response_values_tbl()$response_display[[1]] }) scatterplot_data <- shiny::reactive({ @@ -233,8 +248,8 @@ heatmap_server <- function( shiny::validate(shiny::need( all( - selected_group() %in% joined_tibble()$group, - selected_feature() %in% joined_tibble()$feature + selected_group() %in% joined_tibble()$group_name, + selected_feature() %in% joined_tibble()$feature_display ), "Plot has been updated, please click on plot." )) @@ -246,10 +261,10 @@ heatmap_server <- function( joined_tibble() %>% dplyr::filter( - .data$feature == selected_feature(), - .data$group == selected_group() + .data$feature_display == selected_feature(), + .data$group_name == selected_group() ) %>% - dplyr::select("sample", "group", "feature_value", "response_value") %>% + dplyr::select("sample_name", "group_name", "feature_value", "response_value") %>% dplyr::rename( !!selected_feature() := .data$feature_value, !!response_feature() := .data$response_value diff --git a/R/utils.R b/R/utils.R index 0504b14..f42c625 100644 --- a/R/utils.R +++ b/R/utils.R @@ -81,7 +81,7 @@ scale_tbl_value_column <- function(tbl, scale_method = "None"){ #' Refactor By Tibble Value Column #' #' @param reorder_method One of "None", "Median", "Mean", "Max", "Min -#' @param tbl A Tibble with columns "feature_value", "group" +#' @param tbl A Tibble with columns "feature_value", "group_name" #' #' @importFrom magrittr %>% #' @importFrom rlang .data @@ -92,7 +92,7 @@ reafctor_by_tbl_value_column <- function(tbl, reorder_method = "None"){ if(reorder_method == "None") { tbl <- tbl %>% dplyr::mutate( - "group" = factor(.data$group) + "group_name" = factor(.data$group_name) ) } else { reorder_method <- switch( @@ -108,10 +108,10 @@ reafctor_by_tbl_value_column <- function(tbl, reorder_method = "None"){ "feature_value" = reorder_method(.data$feature_value), .groups = "drop" ) %>% dplyr::arrange(.data$feature_value) %>% - dplyr::pull("group") + dplyr::pull("group_name") tbl <- tbl %>% dplyr::mutate( - "group" = factor(.data$group, levels = new_levels) + "group_name" = factor(.data$group, levels = new_levels) ) } } @@ -269,8 +269,8 @@ get_values_from_eventdata <- function(eventdata, col = "x"){ create_group_text_from_eventdata <- function(eventdata, group_tbl){ selected_group <- get_values_from_eventdata(eventdata) group_tbl %>% - dplyr::filter(.data$group == selected_group) %>% - dplyr::pull("description") + dplyr::filter(.data$group_name == selected_group) %>% + dplyr::pull("group_description") } # misc ------------------------------------------------------------------------ diff --git a/app/server.R b/app/server.R index 5595760..7c73f0e 100644 --- a/app/server.R +++ b/app/server.R @@ -46,7 +46,7 @@ server <- function(input, output, session) { example_iris_data() %>% dplyr::select( "feature_class", - "feature_name" = "feature", + "feature_name", "feature_display" ) %>% dplyr::distinct() @@ -63,7 +63,7 @@ server <- function(input, output, session) { dplyr::select( "Class1" = "feature_class", "Class2" = "feature_class2", - "feature_name" = "feature", + "feature_name", "feature_display" ) %>% dplyr::distinct() @@ -80,12 +80,13 @@ server <- function(input, output, session) { function(.feature){ iatlas.modules2::pcawg_immune_subtype_cohort_obj$get_gene_values(entrez = as.integer(.feature)) %>% dplyr::select( - "sample" = "sample_name", - "group" = "group_short_name", - "feature" = "hgnc", + "sample_name", + "group_name" = "group_short_name", + "feature_name" = "entrez", + "feature_display" = "hgnc", "feature_value" = "rna_seq_expr", "group_description" = "group_characteristics", - "color" = "group_color" + "group_color" = "group_color" ) } }), diff --git a/man/barplot_server.Rd b/man/barplot_server.Rd index 4588c84..f4cdb77 100644 --- a/man/barplot_server.Rd +++ b/man/barplot_server.Rd @@ -21,8 +21,8 @@ barplot_server( \item{plot_data_function}{A shiny::reactive that returns a function The function must take an argument called ".feature_class" and return a -dataframe with columns "sample", "feature", "feature_value", "group", -and optionally "group_description"} +dataframe with columns "sample_name", "feature_name", "feature_value", +"group_name", and optionally "group_description"} \item{feature_classes}{A shiny::reactive that returns a vector of strings. One of these strings are passed to plot_data_function} diff --git a/man/distributions_plot_server.Rd b/man/distributions_plot_server.Rd index fa80b6b..d610b8e 100644 --- a/man/distributions_plot_server.Rd +++ b/man/distributions_plot_server.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/distributions_plot_server.R \name{distributions_plot_server} \alias{distributions_plot_server} -\title{Barplot Server} +\title{Distributions Plot Server} \usage{ distributions_plot_server( id, @@ -20,10 +20,11 @@ distributions_plot_server( \item{plot_data_function}{A shiny::reactive that returns a function. The function must take an argument called ".feature" and return a -dataframe with columns "sample", "feature", "feature_value", "group", -and optionally "group_description", "color"} +dataframe with columns "sample_name", "feature_name", "feature_value", +"group_name", +and optionally "group_description", "group_color"} -\item{features}{A shiny::reactive that returns a dataframe with "feature", +\item{features}{A shiny::reactive that returns a dataframe with "feature_name", "feature_display", and any other additional optional columns to group the features by. If not given, the argument to plot_data_function will be Null.} @@ -38,5 +39,5 @@ features by. If not given, the argument to plot_data_function will be Null.} \item{...}{shiny::reactives passed to drilldown_histogram_server} } \description{ -Barplot Server +Distributions Plot Server } diff --git a/man/drilldown_histogram_server.Rd b/man/drilldown_histogram_server.Rd index c2f85cb..1ee5ea8 100644 --- a/man/drilldown_histogram_server.Rd +++ b/man/drilldown_histogram_server.Rd @@ -10,7 +10,7 @@ drilldown_histogram_server(id, plot_data, eventdata, ...) \item{id}{Module ID} \item{plot_data}{A shiny::reactive that returns a dataframe with columns -"group", "feature_value"} +"group_name", "feature_value"} \item{eventdata}{A shiny::reactive that returns a dataframe with column "key"} diff --git a/man/drilldown_scatterplot_server.Rd b/man/drilldown_scatterplot_server.Rd index 145b4f6..76d6cc4 100644 --- a/man/drilldown_scatterplot_server.Rd +++ b/man/drilldown_scatterplot_server.Rd @@ -16,7 +16,7 @@ drilldown_scatterplot_server( \item{id}{Module ID} \item{scatterplot_data}{A shiny::reactive that returns a dataframe with columns -"sample", "group", "feature", "feature_value"} +"sample_name", "group_name", and two value columns} \item{x_feature_input}{A shiny::reactive that returns a string} diff --git a/man/heatmap_server.Rd b/man/heatmap_server.Rd index cc6f41d..c976b89 100644 --- a/man/heatmap_server.Rd +++ b/man/heatmap_server.Rd @@ -30,12 +30,13 @@ The selected feature will be passed to the repsonse_data_function as .feature.} \item{feature_data_function}{A shiny::reactive that returns a function The function must take an argument called ".feature_class" and return a -dataframe with columns "sample", "group", "feature", "feature_value", -"feature_order", "group_description", "color"} +dataframe with columns "sample_name", "group_name", "feature_name", +"feature_display", "feature_value", "feature_order", "group_description", +"group_color"} \item{response_data_function}{A shiny::reactive that returns a function The function must take an argument called ".feature" and return a -dataframe with columns "sample", "feature_value"} +dataframe with columns "sample_name", "feature_name", "feature_value"} \item{summarise_function_list}{A shiny::reactive that returns a either a function or a named list of functions. If a list is passed, it will be passed to diff --git a/man/reafctor_by_tbl_value_column.Rd b/man/reafctor_by_tbl_value_column.Rd index 1ef375b..e39cf8b 100644 --- a/man/reafctor_by_tbl_value_column.Rd +++ b/man/reafctor_by_tbl_value_column.Rd @@ -7,7 +7,7 @@ reafctor_by_tbl_value_column(tbl, reorder_method = "None") } \arguments{ -\item{tbl}{A Tibble with columns "feature_value", "group"} +\item{tbl}{A Tibble with columns "feature_value", "group_name"} \item{reorder_method}{One of "None", "Median", "Mean", "Max", "Min} } diff --git a/tests/testthat/test-barplot_server.R b/tests/testthat/test-barplot_server.R index dff4416..c1d1545 100644 --- a/tests/testthat/test-barplot_server.R +++ b/tests/testthat/test-barplot_server.R @@ -9,37 +9,57 @@ test_that("barplot_server_iris", { "drilldown" = shiny::reactive(T) ), { + session$setInputs("feature_class_choice" = "Length") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = 1, + "pointNumber" = 2, + "x" = "virginica", + "y" = 6.588, + "key" = "virginica" + )) + expect_true(display_feature_class_selection_ui()) expect_type(output$feature_class_selection_ui, "list") - session$setInputs("feature_class_choice" = "Length") + expect_type(barplot_data(), "list") expect_named( barplot_data(), - c("sample", "feature", "feature_value", "group", "group_description") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description" + ) ) expect_type(summarized_barplot_data(), "list") expect_named( summarized_barplot_data(), - c("group", "feature", "text", "MEAN", "SE") + c("group_name", "feature_name", "text", "MEAN", "SE") ) expect_equal(barplot_source_name(), "proxy1-barplot") expect_type(output$barplot, "character") expect_type(group_data(), "list") - expect_named(group_data(), c("group", "description")) + expect_named(group_data(), c("group_name", "group_description")) - expect_error( - barplot_eventdata(), - regexp = "Click on above barplot.", - class = c("shiny.silent.error") - ) - session$setInputs("test_event_data" = data.frame("key" = "setosa")) expect_type(barplot_eventdata(), "list") - expect_named(barplot_eventdata(), "key") - expect_equal(selected_group(), "setosa") + expect_named(barplot_eventdata(), c("curveNumber", "pointNumber", "x", "y", "key")) + expect_equal(selected_group(), "virginica") expect_type(scatterplot_data(), "list") expect_named( scatterplot_data(), - c("sample", "group", "Sepal.Length", "Petal.Length") + c("sample_name", "group_name", "Sepal.Length", "Petal.Length") + ) + + res <- session$getReturned() + scatterplot_data <- res$scatterplot_data() + expect_type(scatterplot_data, "list") + expect_named(scatterplot_data, c("x", "y", "text")) + barplot_data <- res$barplot_data() + expect_type(barplot_data, "list") + expect_named( + barplot_data, + c('group_name', 'feature_name', 'text', 'MEAN', 'SE') ) } ) @@ -58,12 +78,18 @@ test_that("barplot_server_iris2", { expect_type(barplot_data(), "list") expect_named( barplot_data(), - c("sample", "feature", "feature_value", "group", "group_description") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description" + ) ) expect_type(summarized_barplot_data(), "list") expect_named( summarized_barplot_data(), - c("group", "feature", "text", "MEAN", "SE") + c("group_name", "feature_name", "text", "MEAN", "SE") ) expect_equal(barplot_source_name(), "proxy1-barplot") expect_type(output$barplot, "character") @@ -73,7 +99,7 @@ test_that("barplot_server_iris2", { class = c("shiny.silent.error") ) expect_type(group_data(), "list") - expect_named(group_data(), c("group", "description")) + expect_named(group_data(), c("group_name", "group_description")) } ) }) @@ -90,12 +116,17 @@ test_that("barplot_server_starwars", { expect_type(barplot_data(), "list") expect_named( barplot_data(), - c("sample", "feature", "feature_value", "group") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name" + ) ) expect_type(summarized_barplot_data(), "list") expect_named( summarized_barplot_data(), - c("group", "feature", "text", "MEAN", "SE") + c("group_name", "feature_name", "text", "MEAN", "SE") ) expect_equal(barplot_source_name(), "proxy1-barplot") expect_type(output$barplot, "character") diff --git a/tests/testthat/test-distributions_plot_server.R b/tests/testthat/test-distributions_plot_server.R index 44c1d07..bb74833 100644 --- a/tests/testthat/test-distributions_plot_server.R +++ b/tests/testthat/test-distributions_plot_server.R @@ -10,16 +10,56 @@ test_that("distributions_plot_server_no_classes", { { session$setInputs("scale_method_choice" = "None") session$setInputs("reorder_method_choice" = "None") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = c(0,0), + "pointNumber" = c(0,0), + "x" = "setosa", + "y" = c(5.1, 2.1), + "key" = "setosa" + )) expect_equal(feature_classes(), character(0)) expect_false(display_feature_class_selection_ui()) expect_false(display_feature_selection_ui()) expect_named( distplot_data(), - c("sample", "feature", "feature_value", "group", "group_description", "color") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description", + "group_color" + ) ) session$setInputs("plot_type_choice" = "Violin") expect_type(output$distplot, "character") + expect_type(distplot_eventdata(), "list") + expect_named( + distplot_eventdata(), + c("curveNumber", "pointNumber", "x", "y", "key") + ) + expect_type(group_data(), "list") + expect_named(group_data(), c("group_name", "group_description")) + + res <- session$getReturned() + histogram_data <- res$histogram_data() + expect_type(histogram_data, "list") + expect_named(histogram_data, "feature_value") + distplot_data <- res$distplot_data() + expect_type(distplot_data, "list") + expect_named( + distplot_data, + c( + 'sample_name', + 'feature_name', + 'feature_value', + 'group_name', + 'group_description', + 'group_color' + ) + ) + } ) }) @@ -34,7 +74,7 @@ test_that("distributions_plot_server_1_class", { example_iris_data() %>% dplyr::select( "feature_class", - "feature_name" = "feature", + "feature_name", "feature_display", ) %>% dplyr::distinct() @@ -54,7 +94,14 @@ test_that("distributions_plot_server_1_class", { expect_named( distplot_data(), - c("sample", "feature", "feature_value", "group", "group_description", "color") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description", + "group_color" + ) ) expect_equal(distplot_source_name(), "proxy1-distplot") session$setInputs("plot_type_choice" = "Violin") @@ -76,7 +123,7 @@ test_that("distributions_plot_server_with_2_classes", { example_iris_data() %>% dplyr::select( "feature_class", - "feature_name" = "feature", + "feature_name", "feature_display", "feature_class2", ) %>% @@ -101,7 +148,14 @@ test_that("distributions_plot_server_with_2_classes", { expect_named( distplot_data(), - c("sample", "feature", "feature_value", "group", "group_description", "color") + c( + "sample_name", + "feature_name", + "feature_value", + "group_name", + "group_description", + "group_color" + ) ) session$setInputs("plot_type_choice" = "Violin") expect_type(output$distplot, "character") diff --git a/tests/testthat/test-drilldown_histogram_server.R b/tests/testthat/test-drilldown_histogram_server.R index 5431bf2..c1bae23 100644 --- a/tests/testthat/test-drilldown_histogram_server.R +++ b/tests/testthat/test-drilldown_histogram_server.R @@ -6,7 +6,7 @@ test_that("drilldown_histogram_server", { "plot_data" = shiny::reactive( dplyr::select( example_iris_data(), - "group", + "group_name", "feature_value" ) ), diff --git a/tests/testthat/test-drilldown_scatterplot_server.R b/tests/testthat/test-drilldown_scatterplot_server.R index 8877a1e..d8c19e6 100644 --- a/tests/testthat/test-drilldown_scatterplot_server.R +++ b/tests/testthat/test-drilldown_scatterplot_server.R @@ -6,7 +6,7 @@ test_that("drilldown_scatterplot_server_wide_data_2_features", { args = list( "scatterplot_data" = shiny::reactive( get_pcawg_scatterplot_example() %>% - dplyr::select("sample", "group", "TCR Evenness", "TCR Richness"), + dplyr::select("sample_name", "group_name", "TCR Evenness", "TCR Richness"), ), "selected_group" = shiny::reactive("C1") ), diff --git a/tests/testthat/test-example_data.R b/tests/testthat/test-example_data.R deleted file mode 100644 index 8849056..0000000 --- a/tests/testthat/test-example_data.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -}) diff --git a/tests/testthat/test-heatmap_server.R b/tests/testthat/test-heatmap_server.R index f6fc1e2..3b311dc 100644 --- a/tests/testthat/test-heatmap_server.R +++ b/tests/testthat/test-heatmap_server.R @@ -1,105 +1,231 @@ -test_that("heatmap_server_error_default_class_and_feature", { +test_that("heatmap_server", { shiny::testServer( heatmap_server, args = list( "feature_classes" = shiny::reactive(get_pcawg_feature_class_list()), "response_features" = shiny::reactive(get_pcawg_feature_list()), - "feature_data_function" = shiny::reactive(get_feature_values_by_class_no_data), + "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), "summarise_function_list" = shiny::reactive( purrr::partial(stats::cor, method = "pearson") ), - "default_feature" = shiny::reactive("T_cells_gamma_delta"), - "default_class" = shiny::reactive("MCPcounter") + "drilldown" = shiny::reactive(T) ), { - expect_equal(default_class(), "MCPcounter") - expect_equal(default_class2(), "MCPcounter") + session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") + session$setInputs("response_feature_choice" = "age_at_diagnosis") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = 0, + "pointNumber" = 1, + "x" = "C4", + "y" = "TCR Richness", + "z" = "0.1805093" + )) - expect_equal(default_feature(), "T_cells_gamma_delta") - expect_equal(default_feature2(), "T_cells_gamma_delta") + expect_type(output$class_selection_ui, "list") + expect_type(output$response_selection_ui, "list") + expect_false(display_summarise_function_ui()) + expect_type(feature_values_tbl(), "list") + expect_named( + feature_values_tbl(), + c( + "sample_name", + "feature_name", + "feature_display", + "feature_value", + "feature_order", + "group_name", + "group_description", + "group_color" + ) + ) + expect_type(response_values_tbl(), "list") + expect_named( + response_values_tbl(), + c("sample_name", "response_name", "response_display", "response_value") + ) + expect_type(summarise_function, "closure") + expect_type(heatmap_tibble(), "list") + expect_named(heatmap_tibble(), c('feature', 'C1', 'C2', 'C3', 'C4', 'C6')) + expect_type(heatmap_matrix(), "double") + expect_type(summarise_function(), "closure") + expect_equal(heatmap_source_name(), "proxy1-heatmap") + expect_type(output$heatmap, "character") + + expect_type(heatmap_eventdata(), "list") + expect_named( + heatmap_eventdata(), + c("curveNumber", "pointNumber", "x", "y", "z") + ) + expect_named(group_data(), c("group_name", "group_description")) + expect_equal(selected_feature(), "TCR Richness") + expect_equal(selected_group(), "C4") + expect_equal(response_feature(), "Age At Diagnosis") + expect_type(scatterplot_data(), "list") + expect_named( + scatterplot_data(), + c("sample_name", "group_name", "TCR Richness", "Age At Diagnosis") + ) + expect_true(nrow(scatterplot_data()) > 0) + + res <- session$getReturned() + scatterplot_data <- res$scatterplot_data() + expect_type(scatterplot_data, "list") + expect_named(scatterplot_data, c("x", "y", "text")) + heatmap_data <- res$heatmap_data() + expect_type(heatmap_data, "list") + expect_named( + heatmap_data, + c('feature', 'C1', 'C2', 'C3', 'C4', 'C6') + ) } ) }) - - -test_that("heatmap_server_error_no_feature_data", { +test_that("heatmap_server_multiple_summarise_functions", { shiny::testServer( heatmap_server, args = list( "feature_classes" = shiny::reactive(get_pcawg_feature_class_list()), "response_features" = shiny::reactive(get_pcawg_feature_list()), - "feature_data_function" = shiny::reactive(get_feature_values_by_class_no_data), + "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), "summarise_function_list" = shiny::reactive( - purrr::partial(stats::cor, method = "pearson") - ) + list( + "Pearson" = purrr::partial(stats::cor, method = "pearson"), + "Spearman" = purrr::partial(stats::cor, method = "spearman") + ) + ), + "drilldown" = shiny::reactive(T) ), { session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") - expect_error( + session$setInputs("response_feature_choice" = "age_at_diagnosis") + session$setInputs("summarise_function_choice" = "Spearman") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = 0, + "pointNumber" = 1, + "x" = "C4", + "y" = "TCR Richness", + "z" = "0.1805093" + )) + + expect_null(default_class()) + expect_equal(default_class2(), "Adaptive Receptor - T cell") + + expect_null(default_feature()) + expect_equal(default_feature2(), "TCR_Evenness") + + expect_type(output$class_selection_ui, "list") + expect_type(output$response_selection_ui, "list") + expect_true(display_summarise_function_ui()) + expect_type(output$summarise_function_ui, "list") + + expect_type(feature_values_tbl(), "list") + expect_named( feature_values_tbl(), - regexp = "Feature class choice did not produce any data, please select a different one." + c( + "sample_name", + "feature_name", + "feature_display", + "feature_value", + "feature_order", + "group_name", + "group_description", + "group_color" + ) ) + expect_type(response_values_tbl(), "list") + expect_named( + response_values_tbl(), + c("sample_name", "response_name", "response_display", "response_value") + ) + expect_type(summarise_function, "closure") + expect_type(heatmap_matrix(), "double") + expect_type(summarise_function(), "closure") + expect_equal(heatmap_source_name(), "proxy1-heatmap") + expect_type(output$heatmap, "character") + + expect_type(heatmap_eventdata(), "list") + expect_named( + heatmap_eventdata(), + c("curveNumber", "pointNumber", "x", "y", "z") + ) + expect_named(group_data(), c("group_name", "group_description")) + expect_equal(selected_feature(), "TCR Richness") + expect_equal(selected_group(), "C4") + expect_equal(response_feature(), "Age At Diagnosis") + expect_type(scatterplot_data(), "list") + expect_named( + scatterplot_data(), + c("sample_name", "group_name", "TCR Richness", "Age At Diagnosis") + ) + + res <- session$getReturned() + scatterplot_data <- res$scatterplot_data() + expect_type(scatterplot_data, "list") + expect_named(scatterplot_data, c("x", "y", "text")) + heatmap_data <- res$heatmap_data() + expect_type(heatmap_data, "list") + expect_named(heatmap_data, c('feature', 'C1', 'C2', 'C3', 'C4', 'C6')) } ) }) -test_that("heatmap_server_error_no_response_data", { + +test_that("heatmap_server_error_default_class_and_feature", { shiny::testServer( heatmap_server, args = list( "feature_classes" = shiny::reactive(get_pcawg_feature_class_list()), "response_features" = shiny::reactive(get_pcawg_feature_list()), - "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), - "response_data_function" = shiny::reactive(get_feature_values_by_feature_no_data), + "feature_data_function" = shiny::reactive(get_feature_values_by_class_no_data), + "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), "summarise_function_list" = shiny::reactive( purrr::partial(stats::cor, method = "pearson") - ) + ), + "default_feature" = shiny::reactive("T_cells_gamma_delta"), + "default_class" = shiny::reactive("MCPcounter") ), { - session$setInputs("response_feature_choice" = "age_at_diagnosis") - expect_error( - response_values_tbl(), - regexp = "Response feature choice did not produce any data, please select a different one." - ) + expect_equal(default_class(), "MCPcounter") + expect_equal(default_class2(), "MCPcounter") + + expect_equal(default_feature(), "T_cells_gamma_delta") + expect_equal(default_feature2(), "T_cells_gamma_delta") } ) }) -test_that("heatmap_server_chosen_features_are_equal", { + +test_that("heatmap_server_error_no_feature_data", { shiny::testServer( heatmap_server, args = list( "feature_classes" = shiny::reactive(get_pcawg_feature_class_list()), "response_features" = shiny::reactive(get_pcawg_feature_list()), - "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), + "feature_data_function" = shiny::reactive(get_feature_values_by_class_no_data), "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), "summarise_function_list" = shiny::reactive( purrr::partial(stats::cor, method = "pearson") - ), - "drilldown" = shiny::reactive(T) + ) ), { session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") - session$setInputs("response_feature_choice" = "TCR_Richness") - session$setInputs("test_event_data" = data.frame( - "x" = "C1", "y" = "TCR Richness" - )) expect_error( - scatterplot_data(), - regexp = "Selected features to compare are the same, please select new features." + feature_values_tbl(), + regexp = "Feature class choice did not produce any data, please select a different one." ) } ) }) -test_that("heatmap_server_plot_updated", { + +test_that("heatmap_server_error_no_response_data", { shiny::testServer( heatmap_server, @@ -107,29 +233,23 @@ test_that("heatmap_server_plot_updated", { "feature_classes" = shiny::reactive(get_pcawg_feature_class_list()), "response_features" = shiny::reactive(get_pcawg_feature_list()), "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), - "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), + "response_data_function" = shiny::reactive(get_feature_values_by_feature_no_data), "summarise_function_list" = shiny::reactive( purrr::partial(stats::cor, method = "pearson") - ), - "drilldown" = shiny::reactive(T) + ) ), { - session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") session$setInputs("response_feature_choice" = "age_at_diagnosis") - session$setInputs("test_event_data" = data.frame( - "x" = "C1", "y" = "Eosinophils" - )) - expect_error( - scatterplot_data(), - regexp = "Plot has been updated, please click on plot." + response_values_tbl(), + regexp = "Response feature choice did not produce any data, please select a different one." ) } ) }) -test_that("heatmap_server", { +test_that("heatmap_server_chosen_features_are_equal", { shiny::testServer( heatmap_server, @@ -145,66 +265,23 @@ test_that("heatmap_server", { ), { session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") - session$setInputs("response_feature_choice" = "age_at_diagnosis") - - expect_type(output$class_selection_ui, "list") - expect_type(output$response_selection_ui, "list") - expect_false(display_summarise_function_ui()) - expect_type(feature_values_tbl(), "list") - expect_named( - feature_values_tbl(), - c( - "sample", - "feature", - "feature_value", - "feature_order", - "group", - "group_description", - "color" - ) - ) - expect_type(response_values_tbl(), "list") - expect_named( - response_values_tbl(), c("sample", "response", "response_value") - ) - expect_type(summarise_function, "closure") - expect_type(heatmap_matrix(), "double") - expect_type(summarise_function(), "closure") - expect_equal(heatmap_source_name(), "proxy1-heatmap") - expect_type(output$heatmap, "character") - expect_error( - heatmap_eventdata(), - regexp = "Click on above heatmap.", - class = c("shiny.silent.error") - ) - session$setInputs("test_event_data" = data.frame( - "x" = "C1", "y" = "TCR Richness" + session$setInputs("response_feature_choice" = "TCR_Richness") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = 0, + "pointNumber" = 1, + "x" = "C4", + "y" = "TCR Richness", + "z" = "0.1805093" )) - expect_type(heatmap_eventdata(), "list") - expect_named(heatmap_eventdata(), c("x", "y")) - expect_named(group_data(), c("group", "description")) - expect_equal(selected_feature(), "TCR Richness") - expect_equal(selected_group(), "C1") - expect_equal(response_feature(), "Age At Diagnosis") - expect_type(scatterplot_data(), "list") - expect_named( + expect_error( scatterplot_data(), - c("sample", "group", "TCR Richness", "Age At Diagnosis") + regexp = "Selected features to compare are the same, please select new features." ) - expect_true(nrow(scatterplot_data()) > 0) - - res <- session$getReturned() - scatterplot_data <- res$scatterplot_data() - expect_type(scatterplot_data, "list") - expect_named(scatterplot_data, c("x", "y", "text")) - heatmap_data <- res$heatmap_data() - expect_type(heatmap_data, "list") - expect_named(heatmap_data, c('feature', 'C1', 'C2', 'C3', 'C4', 'C6')) } ) }) -test_that("heatmap_server_multiple_summarise_functions", { +test_that("heatmap_server_plot_updated", { shiny::testServer( heatmap_server, @@ -214,78 +291,25 @@ test_that("heatmap_server_multiple_summarise_functions", { "feature_data_function" = shiny::reactive(get_pcawg_feature_values_by_class), "response_data_function" = shiny::reactive(get_pcawg_feature_values_by_feature), "summarise_function_list" = shiny::reactive( - list( - "Pearson" = purrr::partial(stats::cor, method = "pearson"), - "Spearman" = purrr::partial(stats::cor, method = "spearman") - ) + purrr::partial(stats::cor, method = "pearson") ), "drilldown" = shiny::reactive(T) ), { session$setInputs("feature_class_choice" = "Adaptive Receptor - T cell") session$setInputs("response_feature_choice" = "age_at_diagnosis") - session$setInputs("summarise_function_choice" = "Spearman") - - expect_null(default_class()) - expect_equal(default_class2(), "Adaptive Receptor - T cell") - - expect_null(default_feature()) - expect_equal(default_feature2(), "TCR_Evenness") - - expect_type(output$class_selection_ui, "list") - expect_type(output$response_selection_ui, "list") - expect_true(display_summarise_function_ui()) - expect_type(output$summarise_function_ui, "list") + session$setInputs("mock_event_data" = data.frame( + "curveNumber" = 0, + "pointNumber" = 1, + "x" = "C4", + "y" = "Eosinophils", + "z" = "0.1805093" + )) - expect_type(feature_values_tbl(), "list") - expect_named( - feature_values_tbl(), - c( - "sample", - "feature", - "feature_value", - "feature_order", - "group", - "group_description", - "color" - ) - ) - expect_type(response_values_tbl(), "list") - expect_named( - response_values_tbl(), c("sample", "response", "response_value") - ) - expect_type(summarise_function, "closure") - expect_type(heatmap_matrix(), "double") - expect_type(summarise_function(), "closure") - expect_equal(heatmap_source_name(), "proxy1-heatmap") - expect_type(output$heatmap, "character") expect_error( - heatmap_eventdata(), - regexp = "Click on above heatmap.", - class = c("shiny.silent.error") - ) - session$setInputs("test_event_data" = data.frame( - "x" = "C1", "y" = "TCR Richness" - )) - expect_type(heatmap_eventdata(), "list") - expect_named(heatmap_eventdata(), c("x", "y")) - expect_named(group_data(), c("group", "description")) - expect_equal(selected_feature(), "TCR Richness") - expect_equal(selected_group(), "C1") - expect_equal(response_feature(), "Age At Diagnosis") - expect_type(scatterplot_data(), "list") - expect_named( scatterplot_data(), - c("sample", "group", "TCR Richness", "Age At Diagnosis") + regexp = "Plot has been updated, please click on plot." ) - - res <- session$getReturned() - scatterplot_data <- res$scatterplot_data() - expect_type(scatterplot_data, "list") - expect_named(scatterplot_data, c("x", "y", "text")) - heatmap_data <- res$heatmap_data() - expect_type(heatmap_data, "list") - expect_named(heatmap_data, c('feature', 'C1', 'C2', 'C3', 'C4', 'C6')) } ) }) diff --git a/tests/testthat/test-plotly_bar.R b/tests/testthat/test-plotly_bar.R index 0d595fb..5e3893d 100644 --- a/tests/testthat/test-plotly_bar.R +++ b/tests/testthat/test-plotly_bar.R @@ -3,9 +3,9 @@ test_that("plotly_bar_one_group", { summarise_barplot_se(title = "Sample") %>% plotly_bar( source_name = "test", - x_col = "group", + x_col = "group_name", y_col = "MEAN", - color_col = "feature", + color_col = "feature_name", error_col = "SE", text_col = "text" ) @@ -18,9 +18,9 @@ test_that("plotly_bar_two_groups", { summarise_barplot_se(title = "Sample") %>% plotly_bar( source_name = "test", - x_col = "group", + x_col = "group_name", y_col = "MEAN", - color_col = "feature", + color_col = "feature_name", text_col = "text" ) expect_type(p, "list") diff --git a/tests/testthat/test-plotly_server.R b/tests/testthat/test-plotly_server.R index 6e0cfce..a483901 100644 --- a/tests/testthat/test-plotly_server.R +++ b/tests/testthat/test-plotly_server.R @@ -14,12 +14,12 @@ test_that("plotly_server", { ) %>% dplyr::mutate("error" = .data$y / sqrt(.data$count)) - eventdata <-dplyr::filter(plot_data, x == "Aleena") + eventdata <- dplyr::filter(plot_data, x == "Aleena") group_data <- plot_data %>% - dplyr::select("group" = "x") %>% + dplyr::select("group_name" = "x") %>% dplyr::distinct() %>% - dplyr::mutate("description" = stringr::str_c("Race: ", .data$group)) + dplyr::mutate("group_description" = stringr::str_c("Race: ", .data$group_name)) shiny::testServer( diff --git a/tests/testthat/test-plotly_violin.R b/tests/testthat/test-plotly_violin.R index a7636d6..84f88c0 100644 --- a/tests/testthat/test-plotly_violin.R +++ b/tests/testthat/test-plotly_violin.R @@ -1,9 +1,9 @@ test_that("violin_plot", { p <- example_starwars_data() %>% - dplyr::filter(.data$group %in% c("Human", "Droid", "Wookiee")) %>% + dplyr::filter(.data$group_name %in% c("Human", "Droid", "Wookiee")) %>% tidyr::drop_na() %>% plotly_violin( - x_col = "group", + x_col = "group_name", y_col = "feature_value" ) expect_type(p, "list")