mirror of
https://github.com/msberends/AMR.git
synced 2026-05-31 20:21:47 +02:00
Generalise interpretive rules for multi-guideline support (#268)
- Rename data-raw/eucast_rules.tsv → interpretive_rules.tsv; add rule.provider column (value: "EUCAST") to distinguish future CLSI rows - Rename EUCAST_RULES_DF → INTERPRETIVE_RULES_DF in _pre_commit_checks.R; filter by rule.provider == guideline when applying rules in interpretive_rules() - Rename custom_eucast_rules() → custom_interpretive_rules() with new S3 class "custom_interpretive_rules"; old function becomes a deprecated wrapper in zz_deprecated.R; backward-compat S3 dispatch shims added for old class - Remove stop_if(guideline == "CLSI", ...) so clsi_rules() no longer errors - Add .onLoad shim in zzz.R to create INTERPRETIVE_RULES_DF from EUCAST_RULES_DF for transitional compatibility until sysdata.rda is regenerated https://claude.ai/code/session_01D46BTsfJSPo3HnLWp3PRkP
This commit is contained in:
@@ -32,8 +32,9 @@ test_that("test-eucast_rules.R", {
|
||||
|
||||
# thoroughly check input table
|
||||
expect_equal(
|
||||
sort(colnames(AMR:::EUCAST_RULES_DF)),
|
||||
sort(colnames(AMR:::INTERPRETIVE_RULES_DF)),
|
||||
sort(c(
|
||||
"rule.provider",
|
||||
"if_mo_property", "like.is.one_of", "this_value",
|
||||
"and_these_antibiotics", "have_these_values",
|
||||
"then_change_these_antibiotics", "to_value",
|
||||
@@ -42,7 +43,7 @@ test_that("test-eucast_rules.R", {
|
||||
"note"
|
||||
))
|
||||
)
|
||||
MOs_mentioned <- unique(AMR:::EUCAST_RULES_DF$this_value)
|
||||
MOs_mentioned <- unique(AMR:::INTERPRETIVE_RULES_DF$this_value)
|
||||
MOs_mentioned <- sort(trimws(unlist(strsplit(MOs_mentioned[!AMR:::is_valid_regex(MOs_mentioned)], ",", fixed = TRUE))))
|
||||
MOs_test <- suppressWarnings(
|
||||
trimws(paste(
|
||||
@@ -219,7 +220,7 @@ test_that("test-eucast_rules.R", {
|
||||
expect_inherits(eucast_dosage(c("tobra", "genta", "cipro")), "data.frame")
|
||||
|
||||
|
||||
x <- custom_eucast_rules(
|
||||
x <- custom_interpretive_rules(
|
||||
AMC == "R" & genus == "Klebsiella" ~ aminopenicillins == "R",
|
||||
AMC == "I" & genus == "Klebsiella" ~ aminopenicillins == "I",
|
||||
AMX == "S" ~ AMC == "S"
|
||||
@@ -240,4 +241,17 @@ test_that("test-eucast_rules.R", {
|
||||
8,
|
||||
tolerance = 0.5
|
||||
)
|
||||
|
||||
# deprecated custom_eucast_rules() still works and emits a warning
|
||||
expect_warning(
|
||||
x_old <- custom_eucast_rules(AMC == "R" ~ aminopenicillins == "R"),
|
||||
regexp = "custom_interpretive_rules"
|
||||
)
|
||||
expect_inherits(x_old, "custom_interpretive_rules")
|
||||
|
||||
# clsi_rules() no longer errors (returns data unchanged until CLSI rows are added)
|
||||
expect_identical(
|
||||
suppressWarnings(clsi_rules(example_isolates, info = FALSE)),
|
||||
example_isolates
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user