Skip to content

Commit

Permalink
Make seed optional argument, random if NULL resolves #8
Browse files Browse the repository at this point in the history
  • Loading branch information
zenalapp committed Nov 20, 2023
1 parent c6ed007 commit 319a4a8
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 28 deletions.
4 changes: 2 additions & 2 deletions R/bistro.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#' @param threads Number of threads to use when calculating log10_lrs.
#' [euroformix::contLikSearch()] argument. Default: 4
#' @param seed Seed when calculating log10_lrs. [euroformix::contLikSearch()]
#' argument. Default: 1
#' argument. Default: NULL (no seed)
#' @param time_limit Time limit in minutes to run the
#' [euroformix::contLikSearch()] function on 1 bloodmeal-human pair. Default:
#' 3
Expand Down Expand Up @@ -102,7 +102,7 @@ bistro <-
model_fw_stutt = FALSE,
difftol = 1,
threads = 4,
seed = 1,
seed = NULL,
time_limit = 3,
return_lrs = FALSE) {
check_pkg_version("tidyr", utils::packageVersion("tidyr"), "1.3.0")
Expand Down
8 changes: 5 additions & 3 deletions R/calc_log10_lrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ calc_one_log10_lr <-
model_fw_stutt = FALSE,
difftol = 1,
threads = 4,
seed = 1,
seed = NULL,
time_limit = 3) {
bloodmeal_profile <- bloodmeal_profiles |>
dplyr::filter(SampleName == bloodmeal_id)
Expand Down Expand Up @@ -154,7 +154,7 @@ calc_log10_lrs <-
model_fw_stutt = FALSE,
difftol = 1,
threads = 4,
seed = 1,
seed = NULL,
time_limit = 3,
check_inputs = TRUE) {
if (check_inputs) {
Expand Down Expand Up @@ -197,7 +197,9 @@ calc_log10_lrs <-
check_is_bool(model_fw_stutt, "model_fw_stutt")
check_is_numeric(difftol, "difftol", pos = TRUE)
check_is_numeric(threads, "threads", pos = TRUE)
check_is_numeric(seed, "seed")
if(!is.null(seed)){
check_is_numeric(seed, "seed")
}
check_is_numeric(time_limit, "time_limit", pos = TRUE)
}

Expand Down
4 changes: 3 additions & 1 deletion R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ check_bistro_inputs <-
check_is_bool(return_lrs, "return_lrs")
check_is_numeric(difftol, "difftol", pos = TRUE)
check_is_numeric(threads, "threads", pos = TRUE)
check_is_numeric(seed, "seed")
if(!is.null(seed)){
check_is_numeric(seed, "seed")
}
check_is_numeric(time_limit, "time_limit", pos = TRUE)
}

Expand Down
4 changes: 2 additions & 2 deletions man/bistro.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/calc_log10_lrs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/calc_one_log10_lr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_bistro_inputs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tests/testthat/_snaps/bistro.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Code
bistro(data.frame(bm_evid1), data.frame(hu_p1), pop_allele_freqs = pop_allele_freqs,
kit = "ESX17", peak_thresh = 200)
kit = "ESX17", peak_thresh = 200, seed = 1)
Message
1/17 markers in kit but not in pop_allele_freqs: AMEL
Formatting bloodmeal profiles
Expand All @@ -24,7 +24,8 @@
---

Code
bistro(bm_evid1, hu_p1, calc_allele_freqs = TRUE, kit = "ESX17", peak_thresh = 200)
bistro(bm_evid1, hu_p1, calc_allele_freqs = TRUE, kit = "ESX17", peak_thresh = 200,
seed = 1)
Message
Formatting bloodmeal profiles
Removing 4 peaks under the threshold of 200 RFU.
Expand All @@ -46,7 +47,7 @@

Code
bistro(bm_evid1, human_profiles, pop_allele_freqs = pop_allele_freqs, kit = "ESX17",
peak_thresh = 200, return_lrs = TRUE)
peak_thresh = 200, seed = 1, return_lrs = TRUE)
Message
1/17 markers in kit but not in pop_allele_freqs: AMEL
Formatting bloodmeal profiles
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/calc_log10_lrs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
calc_one_log10_lr(bloodmeal_profiles_sub, "evid1", human_profiles,
"00-JP0001-14_20142342311_NO-3241", pop_allele_freqs = pop_allele_freqs, kit = "ESX17",
peak_thresh = 200)
peak_thresh = 200, seed = 1)
Output
# A tibble: 1 x 7
bloodmeal_id human_id locus_count est_noc efm_noc log10_lr notes
Expand All @@ -15,7 +15,7 @@
Code
calc_one_log10_lr(bloodmeal_profiles_sub, "evid2", human_profiles,
"00-JP0001-14_20142342311_NO-3241", pop_allele_freqs = pop_allele_freqs, kit = "ESX17",
peak_thresh = 200)
peak_thresh = 200, seed = 1)
Output
# A tibble: 1 x 7
bloodmeal_id human_id locus_count est_noc efm_noc log10_lr notes
Expand All @@ -27,7 +27,7 @@
Code
calc_one_log10_lr(bloodmeal_profiles_sub, "evid4", human_profiles,
"00-JP0001-14_20142342311_NO-3241", pop_allele_freqs = pop_allele_freqs, kit = "ESX17",
peak_thresh = 200)
peak_thresh = 200, seed = 1)
Output
# A tibble: 1 x 7
bloodmeal_id human_id locus_count est_noc efm_noc log10_lr notes
Expand All @@ -38,7 +38,7 @@

Code
calc_one_log10_lr(bloodmeal_profiles_sub, "evid2", human_profiles, "P1",
pop_allele_freqs = pop_allele_freqs, kit = "ESX17", peak_thresh = 200)
pop_allele_freqs = pop_allele_freqs, kit = "ESX17", peak_thresh = 200, seed = 1)
Output
# A tibble: 1 x 7
bloodmeal_id human_id locus_count est_noc efm_noc log10_lr notes
Expand All @@ -61,7 +61,7 @@

Code
calc_log10_lrs(bm_profs, hu_profs, pop_allele_freqs = pop_allele_freqs, kit = "ESX17",
peak_thresh = 200, check_inputs = FALSE)
peak_thresh = 200, seed = 1, check_inputs = FALSE)
Message
# bloodmeal ids: 2
# human ids: 1
Expand Down
15 changes: 13 additions & 2 deletions tests/testthat/test-bistro.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ test_that("bistro works", {
data.frame(hu_p1),
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

suppressMessages(expect_no_error(bistro(
data.frame(bm_evid1),
data.frame(hu_p1),
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
)))

expect_snapshot(bistro(
bm_evid1,
hu_p1,
calc_allele_freqs = TRUE,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
))

expect_error(
Expand All @@ -38,6 +48,7 @@ test_that("bistro works", {
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200,
seed = 1,
return_lrs = TRUE
))
})
25 changes: 21 additions & 4 deletions tests/testthat/test-calc_log10_lrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ test_that("calc_log10_lrs works", {
"00-JP0001-14_20142342311_NO-3241",
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

Expand All @@ -29,7 +30,8 @@ test_that("calc_log10_lrs works", {
"00-JP0001-14_20142342311_NO-3241",
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

Expand All @@ -41,7 +43,8 @@ test_that("calc_log10_lrs works", {
"00-JP0001-14_20142342311_NO-3241",
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

Expand All @@ -53,7 +56,8 @@ test_that("calc_log10_lrs works", {
"P1",
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

Expand All @@ -77,7 +81,20 @@ test_that("calc_log10_lrs works", {
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200,
seed = 1,
check_inputs = FALSE
)
)

suppressMessages(expect_no_error(calc_log10_lrs(
bm_profs,
hu_profs,
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200,
# seed = 1,
check_inputs = TRUE
)))


})
3 changes: 2 additions & 1 deletion tests/testthat/test-identify_matches.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ test_that("identify_matches works", {
human_profiles,
pop_allele_freqs = pop_allele_freqs,
kit = "ESX17",
peak_thresh = 200
peak_thresh = 200,
seed = 1
)
)

Expand Down

0 comments on commit 319a4a8

Please sign in to comment.