Skip to content

Commit

Permalink
update PCA module
Browse files Browse the repository at this point in the history
  • Loading branch information
BFalquet committed Oct 17, 2024
1 parent 0e67ed5 commit ccd3d9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/boxplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
$ fill : chr "#F8766D" "#F8766D" "#F8766D" "#F8766D" ...
$ x : 'mapped_discrete' num 1 1 1 1 1 1 1 1 1 1 ...
$ density : num 0.000161 0.000161 0.000161 0.00016 0.00016 ...
$ scaled : num 0.492 0.492 0.492 0.492 0.492 ...
$ ndensity : num 0.492 0.492 0.492 0.492 0.492 ...
$ scaled : num 0.493 0.492 0.492 0.492 0.492 ...
$ ndensity : num 0.493 0.492 0.492 0.492 0.492 ...
$ count : num 0.000642 0.000642 0.000642 0.000642 0.000641 ...
$ n : int 4 4 4 4 4 4 4 4 4 4 ...
$ y : num 650 659 667 676 684 ...
$ PANEL : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
$ group : int 1 1 1 1 1 1 1 1 1 1 ...
$ violinwidth: num 0.492 0.492 0.492 0.492 0.492 ...
$ violinwidth: num 0.493 0.492 0.492 0.492 0.492 ...
$ flipped_aes: logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ width : num 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 ...
$ xmin : 'mapped_discrete' num 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 ...
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/_snaps/pca.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@
8 -0.30521740 -0.58893592 1 -1 19 black 1.5 NA NA 0.5
9 -0.44180789 0.50479025 1 -1 19 black 1.5 NA NA 0.5

---

Code
cat(res)
Output
colour x y PANEL group shape size fill alpha stroke
1 #F8766D -0.08263642 0.6615253 1 1 19 1.5 NA NA 0.5
2 #F8766D -0.53157947 -0.4023279 1 1 19 1.5 NA NA 0.5
3 #F8766D 0.61421589 -0.2591974 1 1 19 1.5 NA NA 0.5

---

Code
Expand Down
36 changes: 13 additions & 23 deletions tests/testthat/test-pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ test_that("pca module works as expected in the test app", {
)

# Add a gene filter and deselect everything and check that it does not crash.
app$set_inputs(!!ns2("add-MAE-hd1-row_to_add") := "chromosome_name")
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-MAE-hd1-row_to_add` = "chromosome", allow_no_input_binding_ = TRUE)
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-hd1-MAE_chromosome_hd1_subset-inputs-selection` = character())
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-hd1-MAE_chromosome_hd1_subset-inputs-selection_open` = FALSE, allow_no_input_binding_ = TRUE)
app$wait_for_idle()
app$set_inputs(!!ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-inputs-selection_open") := TRUE, allow_no_input_binding_ = TRUE)
app$set_inputs(!!ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-inputs-keep_na-value") := FALSE)
app$set_inputs(!!ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-inputs-selection") := character())
app$set_inputs(!!ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-inputs-selection_open") := FALSE, allow_no_input_binding_ = TRUE)

app$wait_for_idle()
res <- app$get_value(output = ns("test_pca"))
expect_match(res$message, "No genes or samples included in this experiment, please adjust filters")

# Remove filters
app$click(ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-remove"))
# app$click(ns2("active-MAE-hd1-MAE_chromosome_name_hd1_subset-remove"))
app$click("teal-teal_modules-pca-filter_panel-filters-MAE-hd1-MAE_chromosome_hd1_subset-remove")
app$wait_for_idle()

# Update the tab selection.
app$set_inputs(!!ns("tab_selected") := "PC and Sample Correlation")
Expand Down Expand Up @@ -171,33 +170,24 @@ test_that("pca module works as expected in the test app", {
app$set_inputs(!!ns("label") := TRUE)
app$set_inputs(!!ns("show_matrix") := TRUE)

app$set_inputs(!!ns2("add-MAE-subjects-var_to_add") := "SEX")
app$wait_for_idle(timeout = 40000)
app$set_inputs(!!ns2("active-MAE-subjects-MAE_SEX-inputs-selection") := "M")
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-MAE-subjects-var_to_add` = "SEX", allow_no_input_binding_ = TRUE)
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-subjects-MAE_SEX-inputs-selection` = "F")
app$set_inputs(`teal-teal_modules-pca-filter_panel-filters-MAE-subjects-MAE_SEX-inputs-selection_open` = FALSE, allow_no_input_binding_ = TRUE)

# Ensure xvar and yvar get resetted to pc1 and pc2.
# Ensure xvar and yvar DONT get reset.
app$wait_for_idle(timeout = 20000)
res <- app$get_value(input = ns("x_var"))
expect_identical(res, "1")
expect_identical(res, "3")
res <- app$get_value(input = ns("y_var"))
expect_identical(res, "2")

res <- app$get_value(output = ns("test_pca"))
expect_snapshot(
cat(res)
)

# Update to cor tab.
app$set_inputs(!!ns2("active-MAE-subjects-MAE_SEX-inputs-selection_open") := TRUE, allow_no_input_binding_ = TRUE)
app$set_inputs(!!ns2("active-MAE-subjects-MAE_SEX-inputs-selection") := "F")
app$set_inputs(!!ns2("active-MAE-subjects-MAE_SEX-inputs-selection_open") := FALSE, allow_no_input_binding_ = TRUE)
expect_identical(res, "4")

app$wait_for_idle()
res <- app$get_value(output = ns("test_pca"))
expect_identical(res$message, "Sample size is too small. PCA needs more than 2 samples.")

# Remove filter.
app$click(ns2("active-MAE-subjects-MAE_SEX-remove"))
app$click("teal-teal_modules-pca-filter_panel-filters-MAE-subjects-MAE_SEX-remove")

# Initiate the use of Top Variance Genes filtering functionality.
app$set_inputs(!!ns("filter_top") := TRUE)
Expand Down

0 comments on commit ccd3d9f

Please sign in to comment.