From 319a4a82aa54c7103f2e62ce9757aa46b7bd931a Mon Sep 17 00:00:00 2001 From: Zena Lapp Date: Mon, 20 Nov 2023 11:38:51 -0500 Subject: [PATCH] Make seed optional argument, random if NULL resolves #8 --- R/bistro.R | 4 ++-- R/calc_log10_lrs.R | 8 +++++--- R/checks.R | 4 +++- man/bistro.Rd | 4 ++-- man/calc_log10_lrs.Rd | 4 ++-- man/calc_one_log10_lr.Rd | 4 ++-- man/check_bistro_inputs.Rd | 2 +- tests/testthat/_snaps/bistro.md | 7 ++++--- tests/testthat/_snaps/calc_log10_lrs.md | 10 +++++----- tests/testthat/test-bistro.R | 15 +++++++++++++-- tests/testthat/test-calc_log10_lrs.R | 25 +++++++++++++++++++++---- tests/testthat/test-identify_matches.R | 3 ++- 12 files changed, 62 insertions(+), 28 deletions(-) diff --git a/R/bistro.R b/R/bistro.R index 5a3c9d4..740e15d 100644 --- a/R/bistro.R +++ b/R/bistro.R @@ -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 @@ -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") diff --git a/R/calc_log10_lrs.R b/R/calc_log10_lrs.R index 41721bb..67e3919 100644 --- a/R/calc_log10_lrs.R +++ b/R/calc_log10_lrs.R @@ -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) @@ -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) { @@ -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) } diff --git a/R/checks.R b/R/checks.R index 4e69a6f..d726597 100644 --- a/R/checks.R +++ b/R/checks.R @@ -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) } diff --git a/man/bistro.Rd b/man/bistro.Rd index 795ce8b..70da390 100644 --- a/man/bistro.Rd +++ b/man/bistro.Rd @@ -20,7 +20,7 @@ bistro( model_fw_stutt = FALSE, difftol = 1, threads = 4, - seed = 1, + seed = NULL, time_limit = 3, return_lrs = FALSE ) @@ -88,7 +88,7 @@ iterations. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} argument. Default: 4} \item{seed}{Seed when calculating log10_lrs. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} -argument. Default: 1} +argument. Default: NULL (no seed)} \item{time_limit}{Time limit in minutes to run the \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} function on 1 bloodmeal-human pair. Default: diff --git a/man/calc_log10_lrs.Rd b/man/calc_log10_lrs.Rd index c165bca..f44d258 100644 --- a/man/calc_log10_lrs.Rd +++ b/man/calc_log10_lrs.Rd @@ -17,7 +17,7 @@ calc_log10_lrs( model_fw_stutt = FALSE, difftol = 1, threads = 4, - seed = 1, + seed = NULL, time_limit = 3, check_inputs = TRUE ) @@ -72,7 +72,7 @@ iterations. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} argument. Default: 4} \item{seed}{Seed when calculating log10_lrs. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} -argument. Default: 1} +argument. Default: NULL (no seed)} \item{time_limit}{Time limit in minutes to run the \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} function on 1 bloodmeal-human pair. Default: diff --git a/man/calc_one_log10_lr.Rd b/man/calc_one_log10_lr.Rd index 4bcdd83..93e0e2b 100644 --- a/man/calc_one_log10_lr.Rd +++ b/man/calc_one_log10_lr.Rd @@ -17,7 +17,7 @@ calc_one_log10_lr( model_fw_stutt = FALSE, difftol = 1, threads = 4, - seed = 1, + seed = NULL, time_limit = 3 ) } @@ -69,7 +69,7 @@ iterations. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} argument. Default: 4} \item{seed}{Seed when calculating log10_lrs. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} -argument. Default: 1} +argument. Default: NULL (no seed)} \item{time_limit}{Time limit in minutes to run the \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} function on 1 bloodmeal-human pair. Default: diff --git a/man/check_bistro_inputs.Rd b/man/check_bistro_inputs.Rd index 9741e5d..916a8df 100644 --- a/man/check_bistro_inputs.Rd +++ b/man/check_bistro_inputs.Rd @@ -88,7 +88,7 @@ iterations. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} argument. Default: 4} \item{seed}{Seed when calculating log10_lrs. \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} -argument. Default: 1} +argument. Default: NULL (no seed)} \item{time_limit}{Time limit in minutes to run the \code{\link[euroformix:contLikSearch]{euroformix::contLikSearch()}} function on 1 bloodmeal-human pair. Default: diff --git a/tests/testthat/_snaps/bistro.md b/tests/testthat/_snaps/bistro.md index 68190e1..7c461b0 100644 --- a/tests/testthat/_snaps/bistro.md +++ b/tests/testthat/_snaps/bistro.md @@ -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 @@ -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. @@ -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 diff --git a/tests/testthat/_snaps/calc_log10_lrs.md b/tests/testthat/_snaps/calc_log10_lrs.md index f2fba57..0abd1de 100644 --- a/tests/testthat/_snaps/calc_log10_lrs.md +++ b/tests/testthat/_snaps/calc_log10_lrs.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/testthat/test-bistro.R b/tests/testthat/test-bistro.R index fea0240..9d1d701 100644 --- a/tests/testthat/test-bistro.R +++ b/tests/testthat/test-bistro.R @@ -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( @@ -38,6 +48,7 @@ test_that("bistro works", { pop_allele_freqs = pop_allele_freqs, kit = "ESX17", peak_thresh = 200, + seed = 1, return_lrs = TRUE )) }) diff --git a/tests/testthat/test-calc_log10_lrs.R b/tests/testthat/test-calc_log10_lrs.R index 5803db6..af64ba2 100644 --- a/tests/testthat/test-calc_log10_lrs.R +++ b/tests/testthat/test-calc_log10_lrs.R @@ -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 ) ) @@ -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 ) ) @@ -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 ) ) @@ -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 ) ) @@ -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 + ))) + + }) diff --git a/tests/testthat/test-identify_matches.R b/tests/testthat/test-identify_matches.R index 6d0d19a..bb8151e 100644 --- a/tests/testthat/test-identify_matches.R +++ b/tests/testthat/test-identify_matches.R @@ -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 ) )