Store EUCAST MIC breakpoints exactly as published, and compare dilutions in as.sir() (#331)

The reproduction script no longer maps MIC breakpoints to AMR:::COMMON_MIC_VALUES, and also keeps the off-scale S breakpoint of 0.001 mg/L. as.sir() compares through the new internal mic_dilution_level(), so that e.g. an MIC of 0.032 and a breakpoint of 0.03 are the same dilution, and shows the published breakpoints in sir_interpretation_history().

Every parsed breakpoint now holds the address of its workbook cell in breakpoints_eucast_raw, and the script stops if a second reading of the workbooks with readxl does not find the value in that cell.

The data sets are rebuilt once, at the end of this PR.
This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2026-11-02 16:56:51 +01:00
1 parent 844e2581ee
commit 5eed396dce
5 files changed
+119 -19

No files matched your search

+14
View File
@@ -56,6 +56,20 @@ COMMON_MIC_VALUES <- c(
1024, 2048, 4096
)
# Guidelines publish the twofold dilutions below 0.125 mg/L in rounded notations, e.g., EUCAST prints 0.03 for the dilution that this package holds as 0.032, while laboratories may report 0.03, 0.031, 0.03125 or 0.032. These all denote one dilution. This returns the value of that dilution in COMMON_MIC_VALUES, and leaves all other values as they are.
mic_dilution_level <- function(x) {
notation <- c(
0.0039, 0.0078, 0.015, 0.0156, 0.03, 0.031, 0.0313, 0.03125, 0.06, 0.063, 0.0625, 0.12
)
level <- c(
0.004, 0.008, 0.016, 0.016, 0.032, 0.032, 0.032, 0.032, 0.064, 0.064, 0.064, 0.125
)
x <- as.double(x)
hit <- match(x, notation)
x[!is.na(hit)] <- level[hit[!is.na(hit)]]
x
}
#' Transform Input to Minimum Inhibitory Concentrations (MIC)
#'
#' This transforms vectors to a new class [`mic`], which treats the input as decimal numbers, while maintaining operators (such as ">=") and only allowing valid MIC values known to the field of (medical) microbiology.
Executable → Regular
+12 -3
View File
@@ -1906,9 +1906,18 @@ as_sir_method <- function(method_short,
)
}
# EUCAST indicates that there is no S category with an off-scale S breakpoint of 0.001 mg/L (stored as 0.0001 in
# clinical_breakpoints), so that wild-type isolates are I; capped MICs such as "<=0.5" must then not be S or NI (#295)
# clinical_breakpoints holds breakpoints as published, so keep these for sir_interpretation_history() (#331)
breakpoint_S_R_published <- paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE])
# EUCAST indicates that there is no S category with an off-scale S breakpoint of 0.001 mg/L, so that wild-type isolates are I, also below that value; capped MICs such as "<=0.5" must then not be S or NI (#295)
no_S_category <- method == "mic" & isTRUE(breakpoints_current$breakpoint_S <= 0.001)
if (method == "mic") {
# compare dilutions, not their notation, e.g. an MIC of 0.032 and a breakpoint of 0.03 are the same dilution (#331)
breakpoints_current$breakpoint_S <- mic_dilution_level(breakpoints_current$breakpoint_S)
breakpoints_current$breakpoint_R <- mic_dilution_level(breakpoints_current$breakpoint_R)
if (guideline_current %like% "EUCAST" && !custom_breakpoints_set && isTRUE(breakpoints_current$breakpoint_S == 0.001)) {
breakpoints_current$breakpoint_S <- 0.0001
}
}
middle_sir <- if (isTRUE(breakpoints_current$is_SDD)) as.sir("SDD") else as.sir("I")
clsi_closed_R <- !custom_breakpoints_set & guideline_current %like% "CLSI"
capped_low_not_R <- (as.character(input_original) %like% "^<[0-9]" & as.double(input_clean) <= breakpoints_current$breakpoint_R) |
@@ -2097,7 +2106,7 @@ as_sir_method <- function(method_short,
guideline = vectorise_log_entry(guideline_current, length(rows)),
ref_table = vectorise_log_entry(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)),
uti = vectorise_log_entry(breakpoints_current[, "uti", drop = TRUE], length(rows)),
breakpoint_S_R = vectorise_log_entry(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)),
breakpoint_S_R = vectorise_log_entry(breakpoint_S_R_published, length(rows)),
stringsAsFactors = FALSE
)
out <- subset(out, !is.na(input_given))