Define custom EUCAST rules for your organisation or specific analysis and use the output of this function in eucast_rules()
.
Arguments
- ...
rules in formula notation, see Examples
Value
A list containing the custom rules
Details
Some organisations have their own adoption of EUCAST rules. This function can be used to define custom EUCAST rules to be used in the eucast_rules()
function.
How it works
Basics
If you are familiar with the case_when()
function of the dplyr
package, you will recognise the input method to set your own rules. Rules must be set using what R considers to be the 'formula notation'. The rule itself is written before the tilde (~
) and the consequence of the rule is written after the tilde:
These are two custom EUCAST rules: if TZP (piperacillin/tazobactam) is "S", all aminopenicillins (ampicillin and amoxicillin) must be made "S", and if TZP is "R", aminopenicillins must be made "R". These rules can also be printed to the console, so it is immediately clear how they work:
The rules (the part before the tilde, in above example TZP == "S"
and TZP == "R"
) must be evaluable in your data set: it should be able to run as a filter in your data set without errors. This means for the above example that the column TZP
must exist. We will create a sample data set and test the rules set:
Using taxonomic properties in rules
There is one exception in variables used for the rules: all column names of the microorganisms data set can also be used, but do not have to exist in the data set. These column names are: r vector_and(colnames(microorganisms), sort = FALSE)
. Thus, this next example will work as well, despite the fact that the df
data set does not contain a column genus
:
Usage of antibiotic group names
It is possible to define antibiotic groups instead of single antibiotics for the rule consequence, the part after the tilde. In above examples, the antibiotic group aminopenicillins
is used to include ampicillin and amoxicillin. The following groups are allowed (case-insensitive). Within parentheses are the agents that will be matched when running the rule.
r paste0(" * ", sapply(DEFINED_AB_GROUPS, function(x) paste0("\"", tolower(gsub("^AB_", "", x)), "\"\\cr(", vector_and(ab_name(eval(parse(text = x), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), quotes = FALSE), ")"), USE.NAMES = FALSE), "\n", collapse = "")
Examples
x <- custom_eucast_rules(
AMC == "R" & genus == "Klebsiella" ~ aminopenicillins == "R",
AMC == "I" & genus == "Klebsiella" ~ aminopenicillins == "I"
)
x
#> A set of custom EUCAST rules:
#>
#> 1. If AMC is "R" and genus is "Klebsiella" then set to R :
#> amoxicillin (AMX), ampicillin (AMP)
#>
#> 2. If AMC is "I" and genus is "Klebsiella" then set to I :
#> amoxicillin (AMX), ampicillin (AMP)
# run the custom rule set (verbose = TRUE will return a logbook instead of the data set):
eucast_rules(example_isolates,
rules = "custom",
custom_rules = x,
info = FALSE,
verbose = TRUE
)
#> # A tibble: 8 × 9
#> row col mo_fullname old new rule rule_…¹ rule_…² rule_…³
#> <int> <chr> <chr> <ord> <chr> <chr> <chr> <chr> <chr>
#> 1 33 AMP Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 2 33 AMX Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 3 34 AMP Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 4 34 AMX Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 5 531 AMP Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 6 531 AMX Klebsiella pneumoniae R I "report… Custom… Custom… Object…
#> 7 1485 AMP Klebsiella oxytoca R I "report… Custom… Custom… Object…
#> 8 1485 AMX Klebsiella oxytoca R I "report… Custom… Custom… Object…
#> # … with abbreviated variable names ¹rule_group, ²rule_name, ³rule_source
# combine rule sets
x2 <- c(
x,
custom_eucast_rules(TZP == "R" ~ carbapenems == "R")
)
x2
#> A set of custom EUCAST rules:
#>
#> 1. If AMC is "R" and genus is "Klebsiella" then set to R :
#> amoxicillin (AMX), ampicillin (AMP)
#>
#> 2. If AMC is "I" and genus is "Klebsiella" then set to I :
#> amoxicillin (AMX), ampicillin (AMP)
#>
#> 3. If TZP is "R" then set to R :
#> biapenem (BIA), doripenem (DOR), ertapenem (ETP), imipenem (IPM),
#> imipenem/EDTA (IPE), imipenem/relebactam (IMR), meropenem (MEM),
#> meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), panipenem (PAN),
#> razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), tebipenem (TBP)