Skip to content

Commit

Permalink
Use z-score scaling_method and updated expected stretch and shift val…
Browse files Browse the repository at this point in the history
…ues in registration unit tests
  • Loading branch information
ruthkr committed Aug 30, 2023
1 parent f4cf99d commit efc11aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-dynamics.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ query <- "Col0"
gene_data <- brapa_sample_data[gene_id == "BRAA03G051930.3C"]

test_that("calc_loglik_H1 and calc_loglik_H2 work", {
all_data <- preprocess_data(gene_data, reference, query)
all_data <- preprocess_data(gene_data, reference, query, scaling_method = "z-score")

# Expected outputs
expect_no_error(calc_loglik_H2(all_data))
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-optimisation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ brapa_sample_data <- data.table::fread(system.file("extdata/brapa_arabidopsis_al
reference <- "Ro18"
query <- "Col0"
gene_data <- brapa_sample_data[gene_id == "BRAA03G051930.3C"]
all_data <- preprocess_data(gene_data, reference, query)
all_data <- preprocess_data(gene_data, reference, query, scaling_method = "z-score")

test_that("get_search_space_limits works", {
space_lims <- get_search_space_limits(all_data)
Expand Down Expand Up @@ -35,7 +35,7 @@ test_that("get_search_space_limits_from_params works", {
})

test_that("calc_overlapping_percent works", {
all_data_reg <- apply_registration(all_data, 2.75, 3.6)
all_data_reg <- apply_registration(all_data, 3.10, 2.13)
overlapping_raw <- calc_overlapping_percent(all_data)
overlapping_reg <- calc_overlapping_percent(all_data_reg)

Expand All @@ -46,7 +46,7 @@ test_that("calc_overlapping_percent works", {

test_that("objective_fun works", {
# Expected outputs
expect_equal(objective_fun(all_data, 2.75, 3.6, 0.5), -11.19, tolerance = 1e-2)
expect_equal(objective_fun(all_data, 3.10, 2.13, 0.5), -11.19, tolerance = 1e-2)
expect_equal(objective_fun(all_data), -999)
})

Expand Down
22 changes: 13 additions & 9 deletions tests/testthat/test-registration.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ gene_data <- brapa_sample_data[gene_id == "BRAA03G051930.3C"]
test_that("preprocess_data works", {
all_data <- preprocess_data(brapa_sample_data, reference, query)
all_data_norm <- preprocess_data(brapa_sample_data, reference, query, scaling_method = "z-score")
all_data_minmax <- preprocess_data(brapa_sample_data, reference, query, scaling_method = "min-max")

# Expected outputs
expect_equal(class(all_data)[1], "data.table")
expect_equal(class(all_data_norm)[1], "data.table")
expect_equal(class(all_data_minmax)[1], "data.table")
expect_gte(mean(all_data$expression_value), mean(all_data_norm$expression_value))
expect_equal(colnames(all_data), c(colnames(brapa_sample_data), "time_delta", "var"))
expect_equal(levels(unique(all_data$accession)), c("ref", "query"))
expect_equal(nrow(all_data), nrow(brapa_sample_data))
})

test_that("register_manually works", {
gene_data <- preprocess_data(gene_data, reference, query)
stretch <- 2.75
shift <- 3.6
gene_data <- preprocess_data(gene_data, reference, query, scaling_method = "z-score")
stretch <- 3.10
shift <- 2.13
loglik_separate <- -10.404
results <- register_manually(gene_data, stretch, shift, loglik_separate)
results_simple <- register_manually(gene_data, stretch, shift, loglik_separate, return_data_reg = FALSE)
Expand All @@ -40,15 +42,16 @@ test_that("register_manually works", {
# Full pipeline ----

test_that("register (with no optimisation) works", {
stretch <- 2.75
shift <- 3.6
stretch <- 3.10
shift <- 2.13
registration_results <- register(
gene_data,
reference = "Ro18",
query = "Col0",
stretches = stretch,
shifts = shift,
optimise_registration_parameters = FALSE
optimise_registration_parameters = FALSE,
scaling_method = "z-score"
) |>
suppressMessages()

Expand All @@ -68,7 +71,8 @@ test_that("register (with optimisation) works", {
gene_data,
reference = "Ro18",
query = "Col0",
optimisation_method = "nm",
optimisation_method = "lbfgsb",
scaling_method = "z-score",
optimisation_config = list(num_iterations = 10, num_fun_evals = 10)
) |>
suppressMessages()
Expand All @@ -81,7 +85,7 @@ test_that("register (with optimisation) works", {
expect_equal(colnames(data_reg), c("gene_id", "accession", "expression_value", "replicate", "timepoint", "timepoint_reg"))
expect_equal(colnames(model_comparison), c("gene_id", "stretch", "shift", "BIC_diff", "registered"))
expect_equal(model_comparison$registered, TRUE)
expect_equal(model_comparison$stretch, 2.809, tolerance = 1e-2)
expect_equal(model_comparison$shift, 0.143, tolerance = 1e-2)
expect_equal(model_comparison$stretch, 3.10, tolerance = 1e-2)
expect_equal(model_comparison$shift, 2.13, tolerance = 1e-2)
expect_error(register(gene_data, reference = "Ro19", query = "Col0"))
})

0 comments on commit efc11aa

Please sign in to comment.