1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 08:06:12 +01:00

(v1.5.0.9037) quick test

This commit is contained in:
dr. M.S. (Matthijs) Berends 2021-03-08 00:13:13 +01:00
parent 68163e3089
commit a12975bc6e
3 changed files with 33 additions and 18 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 1.5.0.9036 Version: 1.5.0.9037
Date: 2021-03-07 Date: 2021-03-07
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Authors@R: c( Authors@R: c(

41
R/rsi.R
View File

@ -721,10 +721,10 @@ exec_as.rsi <- function(method,
warned <- FALSE warned <- FALSE
method_param <- toupper(method) method_param <- toupper(method)
genera <- mo_genus(mo) genera <- mo_genus(mo, language = NULL)
mo_genus <- as.mo(genera) mo_genus <- as.mo(genera, language = NULL)
mo_family <- as.mo(mo_family(mo)) mo_family <- as.mo(mo_family(mo, language = NULL))
mo_order <- as.mo(mo_order(mo)) mo_order <- as.mo(mo_order(mo, language = NULL))
if (any(genera == "Staphylococcus", na.rm = TRUE)) { if (any(genera == "Staphylococcus", na.rm = TRUE)) {
mo_becker <- as.mo(mo, Becker = TRUE) mo_becker <- as.mo(mo, Becker = TRUE)
} else { } else {
@ -809,25 +809,40 @@ exec_as.rsi <- function(method,
pm_arrange(pm_desc(nchar(mo))) pm_arrange(pm_desc(nchar(mo)))
} }
if (NROW(get_record) > 0) {
get_record <- get_record[1L, , drop = FALSE] get_record <- get_record[1L, , drop = FALSE]
if (is.na(x[i])) {
if (NROW(get_record) > 0) {
pkg_env$strange <- list(x_dbl = as.double(x[i]),
x_chr = as.character(x[i]),
get_record = get_record,
guideline_coerced = guideline_coerced,
lookup = c(lookup_mo[i],
lookup_genus[i],
lookup_family[i],
lookup_order[i],
lookup_becker[i],
lookup_lancefield[i],
lookup_other[i]),
is_intrinsic_r = is_intrinsic_r,
c1 = x[i] <= get_record$breakpoint_S,
c2 = guideline_coerced %like% "EUCAST" & x[i] > get_record$breakpoint_R,
c2 = guideline_coerced %like% "CLSI" & x[i] >= get_record$breakpoint_R)
if (is.na(x[i]) | (is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R))) {
new_rsi[i] <- NA_character_ new_rsi[i] <- NA_character_
} else if (method == "mic") { } else if (method == "mic") {
new_rsi[i] <- quick_case_when(is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R) ~ NA_character_, new_rsi[i] <- quick_case_when(isTRUE(conserve_capped_values) & x[i] %like% "^<[0-9]" ~ "S",
isTRUE(conserve_capped_values) & x[i] %like% "^<[0-9]" ~ "S",
isTRUE(conserve_capped_values) & x[i] %like% "^>[0-9]" ~ "R", isTRUE(conserve_capped_values) & x[i] %like% "^>[0-9]" ~ "R",
# start interpreting: EUCAST uses <= S and > R, CLSI uses <=S and >= R # start interpreting: EUCAST uses <= S and > R, CLSI uses <=S and >= R
as.double(x[i]) <= get_record$breakpoint_S ~ "S", x[i] <= get_record$breakpoint_S ~ "S",
guideline_coerced %like% "EUCAST" & as.double(x[i]) > get_record$breakpoint_R ~ "R", guideline_coerced %like% "EUCAST" & x[i] > get_record$breakpoint_R ~ "R",
guideline_coerced %like% "CLSI" & as.double(x[i]) >= get_record$breakpoint_R ~ "R", guideline_coerced %like% "CLSI" & x[i] >= get_record$breakpoint_R ~ "R",
# return "I" when not match the bottom or top # return "I" when not match the bottom or top
!is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I", !is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I",
# and NA otherwise # and NA otherwise
TRUE ~ NA_character_) TRUE ~ NA_character_)
} else if (method == "disk") { } else if (method == "disk") {
new_rsi[i] <- quick_case_when(is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R) ~ NA_character_, new_rsi[i] <- quick_case_when(isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S",
isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S",
# start interpreting: EUCAST uses >= S and < R, CLSI uses >=S and <= R # start interpreting: EUCAST uses >= S and < R, CLSI uses >=S and <= R
guideline_coerced %like% "EUCAST" & guideline_coerced %like% "EUCAST" &
isTRUE(as.double(x[i]) < as.double(get_record$breakpoint_R)) ~ "R", isTRUE(as.double(x[i]) < as.double(get_record$breakpoint_R)) ~ "R",

View File

@ -95,20 +95,20 @@ test_that("mic2rsi works", {
mo = "B_STRPT_PNMN", mo = "B_STRPT_PNMN",
ab = "AMP", ab = "AMP",
guideline = "EUCAST 2020")), guideline = "EUCAST 2020")),
c("S", "S", "I", "I", "R")) c("S", "S", "I", "I", "R"), info = pkg_env$strange)
# S. pneumoniae/amoxicillin in CLSI 2019: 2-8 ug/ml (R is 8 and > 8) # S. pneumoniae/amoxicillin in CLSI 2019: 2-8 ug/ml (R is 8 and > 8)
expect_equal(as.character( expect_equal(as.character(
as.rsi(x = as.mic(c(1, 2, 4, 8, 16)), as.rsi(x = as.mic(c(1, 2, 4, 8, 16)),
mo = "B_STRPT_PNMN", mo = "B_STRPT_PNMN",
ab = "AMX", ab = "AMX",
guideline = "CLSI 2019")), guideline = "CLSI 2019")),
c("S", "S", "I", "R", "R")) c("S", "S", "I", "R", "R"), info = pkg_env$strange)
# cutoffs at MIC = 8 # cutoffs at MIC = 8
expect_equal(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020"), expect_equal(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020"),
as.rsi("S"), info = paste0(as.mo("E. coli"), as.ab("ampicillin"))) as.rsi("S"), info = pkg_env$strange)
expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"), expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"),
as.rsi("R")) as.rsi("R"), info = pkg_env$strange)
expect_true(suppressWarnings(example_isolates %>% expect_true(suppressWarnings(example_isolates %>%
mutate(amox_mic = as.mic(2)) %>% mutate(amox_mic = as.mic(2)) %>%