Skip to content

Commit

Permalink
adjustments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed Jan 7, 2024
1 parent c828e06 commit c7861fa
Show file tree
Hide file tree
Showing 6 changed files with 2,301 additions and 7 deletions.
6 changes: 4 additions & 2 deletions R/APOTCPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ APOTCPlot <- function(
legend_text_size = 5,
add_legend_background = TRUE
) {

varargs_list <- list(...)
args <- hash::hash(as.list(environment()))
args$run_id <- infer_object_id_if_needed(args, varargs_list = list(...))
args$run_id <- infer_object_id_if_needed(args, varargs_list = varargs_list)
APOTCPlot_error_handler(args)

apotc_obj <- getApotcData(seurat_obj, args$run_id)
Expand Down Expand Up @@ -224,4 +224,6 @@ APOTCPlot_error_handler <- function(args) {
}

# TODO: Add more specific checks for other parameters

check_filtering_conditions(args)
}
7 changes: 4 additions & 3 deletions R/AdjustAPOTC.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ AdjustAPOTC <- function(
#interactive = FALSE,
verbose = TRUE
) {
varargs_list <- list(...)
args <- hash::hash(as.list(environment()))
AdjustAPOTC_error_handler(args = args, varargs_list = list(...))
AdjustAPOTC_error_handler(args)

object_id <- infer_object_id_if_needed(args, varargs_list = list(...))
object_id <- infer_object_id_if_needed(args, varargs_list = varargs_list)
apotc_obj <- getApotcData(seurat_obj, object_id)
args <- hash::hash(as.list(environment()))

Expand Down Expand Up @@ -119,7 +120,7 @@ AdjustAPOTC <- function(
seurat_obj
}

AdjustAPOTC_error_handler <- function(args, varargs_list) {
AdjustAPOTC_error_handler <- function(args) {
# TODO - type check
# TODO rest of errors

Expand Down
1 change: 1 addition & 0 deletions R/RunAPOTC.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ RunAPOTC_parameter_checker <- function(args) {
check_filtering_conditions(args)
}

# assumes varargs_list is present
check_filtering_conditions <- function(args) {
if (is_empty(args$varargs_list)) return()
metadata_cols <- names(args$seurat_obj@meta.data)
Expand Down
1,135 changes: 1,135 additions & 0 deletions tests/testthat/_snaps/AdjustAPOTC/adjustapotc-plot-repulsed-with-label.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,119 changes: 1,119 additions & 0 deletions tests/testthat/_snaps/AdjustAPOTC/adjustapotc-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 38 additions & 2 deletions tests/testthat/test-AdjustAPOTC.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,47 @@ test_that("AdjustAPOTC works", {
)

# sanity check - Adjust nothing

expect_doppelganger(
.defaultApotcPlot,
suppressMessages(APOTCPlot(AdjustAPOTC(combined_pbmc, verbose = FALSE)))
)

# change clone and rad scale, nudge first clusters 1 & 2,
# move clusters 3 & 4, recolor 5th and 6th clusters
combined_pbmc <- AdjustAPOTC(combined_pbmc, run_id = "r2", verbose = FALSE,
new_rad_scale_factor = 0.9,
new_clone_scale_factor = 0.35,
nudge_cluster = c(1, 2),
nudge_vector = c(1, 1),
relocate_cluster = c(3, 4),
relocation_coord = list(c(-0.5, -2.5), c(3, -4.5)),
recolor_cluster = c(5, 6),
new_color = c("green", "cyan")
)

expect_doppelganger(
"AdjustAPOTC_plot",
suppressMessages(APOTCPlot(combined_pbmc, run_id = "r2"))
)

# sanity check - r1 isnt modified
expect_doppelganger(
.defaultApotcPlot,
APOTCPlot(AdjustAPOTC(combined_pbmc, verbose = FALSE))
APOTCPlot(
AdjustAPOTC(combined_pbmc, run_id = "r1", verbose = FALSE),
run_id = "r1"
)
)

# TODO adjust
# repulse and add labels
combined_pbmc <- AdjustAPOTC(combined_pbmc, run_id = "r2", verbose = FALSE,
repulse = TRUE
)

expect_doppelganger(
"AdjustAPOTC_plot_repulsed_with_label",
APOTCPlot(combined_pbmc, run_id = "r2", show_labels = TRUE, label_size = 7)
)

})

0 comments on commit c7861fa

Please sign in to comment.