diff --git a/DESCRIPTION b/DESCRIPTION index 4c7042a5..d456ba3e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.5.0.9003 -Date: 2021-01-15 +Version: 1.5.0.9004 +Date: 2021-01-17 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index 370d824e..b5b96919 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,6 +52,7 @@ S3method(plot,rsi) S3method(print,ab) S3method(print,bug_drug_combinations) S3method(print,catalogue_of_life_version) +S3method(print,custom_mdro_guideline) S3method(print,disk) S3method(print,isolate_identifier) S3method(print,mic) @@ -120,6 +121,7 @@ export(count_all) export(count_df) export(count_resistant) export(count_susceptible) +export(custom_mdro_guideline) export(eucast_dosage) export(eucast_exceptional_phenotypes) export(eucast_rules) diff --git a/NEWS.md b/NEWS.md index 20ca2958..5425bf8e 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,11 @@ -# AMR 1.5.0.9003 -## Last updated: 15 January 2021 +# AMR 1.5.0.9004 +## Last updated: 17 January 2021 ### New * Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package. * Data set `dosage` to fuel the new `eucast_dosage()` function and to make this data available in a structured way * Function `eucast_dosage()` to get a `data.frame` with advised dosages of a certain bug-drug combination, which is based on the new `dosage` data set +* Support for custom MDRO guidelines, using the new `custom_mdro_guideline()` function, please see `mdro()` for additional info * Function `isolate_identifier()`, which will paste a microorganism code with all antimicrobial results of a data set into one string for each row. This is useful to compare isolates, e.g. between institutions or regions, when there is no genotyping available. * Function `mo_is_yeast()`, which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales: ```r diff --git a/R/mdro.R b/R/mdro.R index 9387c887..dfca9d93 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -25,10 +25,10 @@ #' Determine multidrug-resistant organisms (MDRO) #' -#' Determine which isolates are multidrug-resistant organisms (MDRO) according to international and national guidelines. +#' Determine which isolates are multidrug-resistant organisms (MDRO) according to international, national and custom guidelines. #' @inheritSection lifecycle Stable lifecycle #' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank for automatic determination. -#' @param guideline a specific guideline to follow. When left empty, the publication by Magiorakos *et al.* (2012, Clinical Microbiology and Infection) will be followed, please see *Details*. +#' @param guideline a specific guideline to follow. Can also have [custom_mdro_guideline()] as input. When left empty, the publication by Magiorakos *et al.* (2012, Clinical Microbiology and Infection) will be followed, please see *Details*. #' @inheritParams eucast_rules #' @param pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for *S. aureus*. Setting this `pct_required_classes` argument to `0.5` (default) means that for every *S. aureus* isolate at least 8 different classes must be available. Any lower number of available classes will return `NA` for that isolate. #' @param combine_SI a [logical] to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the [mdro()] function, it follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using `combine_SI = FALSE`, resistance is considered when isolates are R or I. @@ -39,6 +39,10 @@ #' #' For the `pct_required_classes` argument, values above 1 will be divided by 100. This is to support both fractions (`0.75` or `3/4`) and percentages (`75`). #' +#' **Note:** Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named *order* Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu *et al.* in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this [mdro()] function makes sure that results from before 2016 and after 2016 are identical. +#' +#' ### International / National guidelines +#' #' Currently supported guidelines are (case-insensitive): #' #' * `guideline = "CMI2012"` (default) @@ -67,7 +71,40 @@ #' #' Please suggest your own (country-specific) guidelines by letting us know: . #' -#' **Note:** Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named *order* Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu *et al.* in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this [mdro()] function makes sure that results from before 2016 and after 2016 are identical. +#' +#' ### Custom guidelines +#' +#' Custom guidelines can be set with the [custom_mdro_guideline()] function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data. +#' +#' If you are familiar with `case_when()` 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': +#' +#' ``` +#' custom <- custom_mdro_guideline("CIP == 'R' & age > 60" ~ "Elderly Type A", +#' "ERY == 'R' & age > 60" ~ "Elderly Type B") +#' ``` +#' +#' If a row/an isolate matches the first rule, the value after the first `~` (in this case *'Elderly Type A'*) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited. +#' +#' You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours. +#' +#' ``` +#' custom +#' #> A set of custom MDRO rules: +#' #> 1. CIP == "R" & age > 60 -> "Elderly Type A" +#' #> 2. ERY == "R" & age > 60 -> "Elderly Type B" +#' #> 3. Otherwise -> "Negative" +#' #> +#' #> Unmatched rows will return NA. +#' ``` +#' +#' The outcome of the function can be used for the `guideline` argument in the [mdro()] function: +#' +#' ``` +#' x <- mdro(example_isolates, guideline = custom) +#' table(x) +#' ``` +#' +#' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()], #' @inheritSection as.rsi Interpretation of R and S/I #' @return #' - CMI 2012 paper - function [mdr_cmi2012()] or [mdro()]:\cr @@ -76,7 +113,7 @@ #' Ordered [factor] with levels `Negative` < `Mono-resistant` < `Poly-resistant` < `Multi-drug-resistant` < `Extensively drug-resistant` #' - German guideline - function [mrgn()] or [`mdro(..., guideline = "MRGN")`][mdro()]:\cr #' Ordered [factor] with levels `Negative` < `3MRGN` < `4MRGN` -#' - Everything else:\cr +#' - Everything else, except for custom guidelines:\cr #' Ordered [factor] with levels `Negative` < `Positive, unconfirmed` < `Positive`. The value `"Positive, unconfirmed"` means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests #' @rdname mdro #' @aliases MDR XDR PDR BRMO 3MRGN 4MRGN @@ -87,6 +124,10 @@ #' @examples #' mdro(example_isolates, guideline = "EUCAST") #' +#' mdro(example_isolates, +#' guideline = custom_mdro_guideline("AMX == 'R'" ~ "Custom MDRO 1", +#' "VAN == 'R'" ~ "Custom MDRO 2")) +#' #' \donttest{ #' if (require("dplyr")) { #' example_isolates %>% @@ -113,7 +154,7 @@ mdro <- function(x, x <- get_current_data(arg_name = "x", call = -2) } meet_criteria(x, allow_class = "data.frame") - meet_criteria(guideline, allow_class = "character", has_length = 1, allow_NULL = TRUE) + meet_criteria(guideline, allow_class = c("list", "character"), allow_NULL = TRUE) meet_criteria(col_mo, allow_class = "character", has_length = 1, is_in = colnames(x), allow_NULL = TRUE) meet_criteria(info, allow_class = "logical", has_length = 1) meet_criteria(pct_required_classes, allow_class = "numeric", has_length = 1) @@ -153,6 +194,30 @@ mdro <- function(x, } guideline.bak <- guideline + if (is.list(guideline)) { + # Custom MDRO guideline --------------------------------------------------- + stop_ifnot(inherits(guideline, "custom_mdro_guideline"), "use `custom_mdro_guideline()` to create custom guidelines") + if (info == TRUE) { + cat("Determining MDROs based on custom rules.\n") + } + x <- run_custom_mdro_guideline(x, guideline) + if (info == TRUE) { + if (sum(!is.na(x$MDRO)) == 0) { + cat(font_bold(paste0("=> Found 0 MDROs since no isolates are covered by the custom guideline"))) + } else { + cat(font_bold(paste0("=> Found ", sum(x$MDRO != "Negative", na.rm = TRUE), " custom defined MDROs out of ", sum(!is.na(x$MDRO)), + " isolates (", trimws(percentage(sum(x$MDRO != "Negative", na.rm = TRUE) / sum(!is.na(x$MDRO)))), ")\n"))) + } + } + if (verbose == TRUE) { + return(x[, c("row_number", + "MDRO", + "reason", + "columns_nonsusceptible")]) + } else { + return(x$MDRO) + } + } guideline <- tolower(gsub("[^a-zA-Z0-9.]+", "", guideline)) if (is.null(guideline)) { # default to the paper by Magiorakos et al. (2012) @@ -583,6 +648,11 @@ mdro <- function(x, ab_NA <- function(x) { x[!is.na(x)] } + try_ab <- function(expr) { + out <- tryCatch(expr, error = function(e) FALSE) + out[is.na(out)] <- FALSE + out + } # antibiotic classes # nolint start @@ -1041,52 +1111,52 @@ mdro <- function(x, if (guideline$code == "mrgn") { # Germany ----------------------------------------------------------------- - CTX_or_CAZ <- CTX %or% CAZ - IPM_or_MEM <- IPM %or% MEM # Table 1 trans_tbl(2, # 3MRGN which((x$order == "Enterobacterales" | # following in fact the old Enterobacteriaceae classification (x$genus == "Acinetobacter" & x$species == "baumannii")) & - x[, PIP, drop = TRUE] == "R" & - x[, CTX_or_CAZ, drop = TRUE] == "R" & - x[, IPM_or_MEM, drop = TRUE] == "S" & - x[, CIP, drop = TRUE] == "R"), + try_ab(x[, PIP, drop = TRUE] == "R") & + (try_ab(x[, CTX, drop = TRUE] == "R") | try_ab(x[, CAZ, drop = TRUE] == "R")) & + (try_ab(x[, IPM, drop = TRUE] != "R") | try_ab(x[, MEM, drop = TRUE] != "R")) & + try_ab(x[, CIP, drop = TRUE] == "R")), c(PIP, CTX, CAZ, IPM, MEM, CIP), "any") trans_tbl(3, # 4MRGN, overwrites 3MRGN if applicable which((x$order == "Enterobacterales" | # following in fact the old Enterobacteriaceae classification (x$genus == "Acinetobacter" & x$species == "baumannii")) & - x[, PIP, drop = TRUE] == "R" & - x[, CTX_or_CAZ, drop = TRUE] == "R" & - x[, IPM_or_MEM, drop = TRUE] == "R" & - x[, CIP, drop = TRUE] == "R"), + try_ab(x[, PIP, drop = TRUE] == "R") & + (try_ab(x[, CTX, drop = TRUE] == "R") | try_ab(x[, CAZ, drop = TRUE] == "R")) & + (try_ab(x[, IPM, drop = TRUE] == "R") | try_ab(x[, MEM, drop = TRUE] == "R")) & + try_ab(x[, CIP, drop = TRUE] == "R")), c(PIP, CTX, CAZ, IPM, MEM, CIP), "any") trans_tbl(3, # 4MRGN, overwrites 3MRGN if applicable which((x$order == "Enterobacterales" | # following in fact the old Enterobacteriaceae classification (x$genus == "Acinetobacter" & x$species == "baumannii")) & - (x[, IPM, drop = TRUE] == "R" | x[, MEM, drop = TRUE] == "R")), + (try_ab(x[, IPM, drop = TRUE] == "R") | try_ab(x[, MEM, drop = TRUE] == "R"))), c(IPM, MEM), "any") trans_tbl(2, # 3MRGN, if only 1 group is S which(x$genus == "Pseudomonas" & x$species == "aeruginosa" & - (x[, PIP, drop = TRUE] == "S") + - (x[, CTX_or_CAZ, drop = TRUE] == "S") + - (x[, IPM_or_MEM, drop = TRUE] == "S") + - (x[, CIP, drop = TRUE] == "S") == 1), + try_ab(x[, PIP, drop = TRUE] == "S") + + try_ab(x[, CTX, drop = TRUE] == "S") + + try_ab(x[, CAZ, drop = TRUE] == "S") + + try_ab(x[, IPM, drop = TRUE] == "S") + + try_ab(x[, MEM, drop = TRUE] == "S") + + try_ab(x[, CIP, drop = TRUE] == "S") == 1), c(PIP, CTX, CAZ, IPM, MEM, CIP), "any") trans_tbl(3, # 4MRGN otherwise which((x$genus == "Pseudomonas" & x$species == "aeruginosa") & - (x[, PIP, drop = TRUE] == "R" | x[, TZP, drop = TRUE] == "R") & - x[, CTX_or_CAZ, drop = TRUE] == "R" & - x[, IPM_or_MEM, drop = TRUE] == "R" & - x[, CIP, drop = TRUE] == "R"), + try_ab(x[, PIP, drop = TRUE] == "R") & + (try_ab(x[, CTX, drop = TRUE] == "R") | try_ab(x[, CAZ, drop = TRUE] == "R")) & + (try_ab(x[, IPM, drop = TRUE] == "R") | try_ab(x[, MEM, drop = TRUE] == "R")) & + try_ab(x[, CIP, drop = TRUE] == "R")), c(PIP, CTX, CAZ, IPM, MEM, CIP), "any") @@ -1237,7 +1307,7 @@ mdro <- function(x, } if (info == TRUE) { - if (sum(!is.na(x$MDRO) == 0)) { + if (sum(!is.na(x$MDRO)) == 0) { cat(font_bold(paste0("=> Found 0 MDROs since no isolates are covered by the guideline"))) } else { cat(font_bold(paste0("=> Found ", sum(x$MDRO %in% c(2:5), na.rm = TRUE), " ", guideline$type, " out of ", sum(!is.na(x$MDRO)), @@ -1298,6 +1368,71 @@ mdro <- function(x, } +#' @rdname mdro +#' @export +custom_mdro_guideline <- function(...) { + dots <- list(...) + n_dots <- length(dots) + stop_if(n_dots == 0, "no custom rules were set. Please read the documentation using `?mdro`.") + out <- vector("list", n_dots) + for (i in seq_len(n_dots)) { + stop_ifnot(inherits(dots[[i]], "formula"), + "element ", i, " must be a valid formula input (e.g., using '~'), please see `?mdro`") + qry <- as.character(dots[[i]][[2]]) + val <- tryCatch(eval(dots[[i]][[3]]), error = function(e) NULL) + stop_if(is.null(val), "element ", i, " must return a valid value, it now returns an error: ", tryCatch(eval(dots[[i]][[3]]), error = function(e) e$message)) + stop_if(length(val) > 1, "element ", i, " must return a value of length 1, not ", length(val)) + stop_if(qry %like% "(&&|\\|\\|)", + "element ", i, " contains `&&` or `||` which will return `TRUE`/`FALSE` with length 1 (i.e., unvectorised)") + out[[i]]$query <- parse(text = qry) + out[[i]]$value <- as.character(val) + } + names(out) <- paste0("rule", seq_len(n_dots)) + set_clean_class(out, new_class = c("custom_mdro_guideline", "list")) +} + +#' @method print custom_mdro_guideline +#' @export +#' @noRd +print.custom_mdro_guideline <- function(x, ...) { + cat("A set of custom MDRO rules:\n") + for (i in seq_len(length(x))) { + rule <- x[[i]] + cat(" ", i, ". ", font_blue(as.character(rule$query)), " -> ", font_red(paste0('"', rule$value, '"')), "\n", sep = "") + } + cat(" ", i + 1, ". Otherwise -> ", font_red(paste0('"Negative"')), "\n", sep = "") + cat("\nUnmatched rows will return ", font_red("NA"), ".\n", sep = "") +} + +run_custom_mdro_guideline <- function(df, guideline) { + n_dots <- length(guideline) + stop_if(n_dots == 0, "no custom guidelines set", call = -2) + out <- character(length = NROW(df)) + reasons <- character(length = NROW(df)) + for (i in seq_len(n_dots)) { + qry <- eval(guideline[[i]]$query, envir = df, enclos = parent.frame()) + stop_ifnot(is.logical(qry), "`", guideline[[i]]$query, "` must return `TRUE` or `FALSE`", call = -2) + val <- guideline[[i]]$value + out[which(qry)] <- val + reasons[which(qry)] <- paste0("matched ", names(guideline)[i], ": ", as.character(guideline[[i]]$query)) + } + out[out == ""] <- "Negative" + reasons[out == "Negative"] <- "no rules matched" + + rsi_cols <- vapply(FUN.VALUE = logical(1), df, function(x) is.rsi(x)) + columns_nonsusceptible <- as.data.frame(t(df[, rsi_cols] == "R")) + columns_nonsusceptible <- vapply(FUN.VALUE = character(1), + columns_nonsusceptible, + function(x) paste0(rownames(columns_nonsusceptible)[which(x)], collapse = " ")) + columns_nonsusceptible[is.na(out)] <- NA_character_ + + data.frame(row_number = seq_len(NROW(df)), + MDRO = out, + reason = reasons, + columns_nonsusceptible = columns_nonsusceptible, + stringsAsFactors = FALSE) +} + #' @rdname mdro #' @export brmo <- function(x, guideline = "BRMO", ...) { diff --git a/data-raw/AMR_1.5.0.9003.tar.gz b/data-raw/AMR_1.5.0.9004.tar.gz similarity index 76% rename from data-raw/AMR_1.5.0.9003.tar.gz rename to data-raw/AMR_1.5.0.9004.tar.gz index fc61f440..51183693 100644 Binary files a/data-raw/AMR_1.5.0.9003.tar.gz and b/data-raw/AMR_1.5.0.9004.tar.gz differ diff --git a/docs/404.html b/docs/404.html index 797effbb..c5deb831 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index efa0c3e7..66b90fd9 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 diff --git a/docs/articles/index.html b/docs/articles/index.html index ea874fc0..113becb2 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 diff --git a/docs/authors.html b/docs/authors.html index 406c0264..29f2c543 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 diff --git a/docs/index.html b/docs/index.html index bd854553..1498990d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 diff --git a/docs/news/index.html b/docs/news/index.html index 6f930006..5065a3bb 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004 @@ -236,13 +236,13 @@ Source: NEWS.md -
-

-AMR 1.5.0.9003 Unreleased +
+

+AMR 1.5.0.9004 Unreleased

-
+

-Last updated: 15 January 2021 +Last updated: 17 January 2021

@@ -251,6 +251,7 @@
  • Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the eucast_rules() function and in as.rsi() to interpret MIC and disk diffusion values. This is now the default guideline in this package.

  • Data set dosage to fuel the new eucast_dosage() function and to make this data available in a structured way

  • Function eucast_dosage() to get a data.frame with advised dosages of a certain bug-drug combination, which is based on the new dosage data set

  • +
  • Support for custom MDRO guidelines, using the new custom_mdro_guideline() function, please see mdro() for additional info

  • Function isolate_identifier(), which will paste a microorganism code with all antimicrobial results of a data set into one string for each row. This is useful to compare isolates, e.g. between institutions or regions, when there is no genotyping available.

  • Function mo_is_yeast(), which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales:

    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3fb7b69f..cd1bae0f 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: datasets: datasets.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2021-01-15T21:44Z +last_built: 2021-01-16T23:26Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/index.html b/docs/reference/index.html index 8d540810..94f13e17 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004
  • @@ -508,7 +508,7 @@ -

    mdro() brmo() mrgn() mdr_tb() mdr_cmi2012() eucast_exceptional_phenotypes()

    +

    mdro() custom_mdro_guideline() brmo() mrgn() mdr_tb() mdr_cmi2012() eucast_exceptional_phenotypes()

    Determine multidrug-resistant organisms (MDRO)

    diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index f895e783..5dc5fd35 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9003 + 1.5.0.9004
    @@ -239,7 +239,7 @@
    -

    Determine which isolates are multidrug-resistant organisms (MDRO) according to international and national guidelines.

    +

    Determine which isolates are multidrug-resistant organisms (MDRO) according to international, national and custom guidelines.

    mdro(
    @@ -253,6 +253,8 @@
       ...
     )
     
    +custom_mdro_guideline(...)
    +
     brmo(x, guideline = "BRMO", ...)
     
     mrgn(x, guideline = "MRGN", ...)
    @@ -272,7 +274,7 @@
         
         
           guideline
    -      

    a specific guideline to follow. When left empty, the publication by Magiorakos et al. (2012, Clinical Microbiology and Infection) will be followed, please see Details.

    +

    a specific guideline to follow. Can also have custom_mdro_guideline() as input. When left empty, the publication by Magiorakos et al. (2012, Clinical Microbiology and Infection) will be followed, please see Details.

    col_mo @@ -313,7 +315,7 @@ Ordered factor with levels factor with levels Negative < Mono-resistant < Poly-resistant < Multi-drug-resistant < Extensively drug-resistant

  • German guideline - function mrgn() or mdro(..., guideline = "MRGN"):
    Ordered factor with levels Negative < 3MRGN < 4MRGN

  • -
  • Everything else:
    +

  • Everything else, except for custom guidelines:
    Ordered factor with levels Negative < Positive, unconfirmed < Positive. The value "Positive, unconfirmed" means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests

  • @@ -321,6 +323,9 @@ Ordered factor with levels These functions are context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, please see Examples.

    For the pct_required_classes argument, values above 1 will be divided by 100. This is to support both fractions (0.75 or 3/4) and percentages (75).

    +

    Note: Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named order Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu et al. in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this mdro() function makes sure that results from before 2016 and after 2016 are identical.

    International / National guidelines

    + +

    Currently supported guidelines are (case-insensitive):

    • guideline = "CMI2012" (default)

      Magiorakos AP, Srinivasan A et al. "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance." Clinical Microbiology and Infection (2012) (link)

    • @@ -337,7 +342,31 @@ Ordered factor with levels

      Please suggest your own (country-specific) guidelines by letting us know: https://github.com/msberends/AMR/issues/new.

      -

      Note: Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named order Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu et al. in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this mdro() function makes sure that results from before 2016 and after 2016 are identical.

      + +

      Custom guidelines

      + + +

      Custom guidelines can be set with the custom_mdro_guideline() function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.

      +

      If you are familiar with case_when() 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':

      custom <- custom_mdro_guideline("CIP == 'R' & age > 60" ~ "Elderly Type A",
      +                                "ERY == 'R' & age > 60" ~ "Elderly Type B")
      +
      + +

      If a row/an isolate matches the first rule, the value after the first ~ (in this case 'Elderly Type A') will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited.

      +

      You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.

      custom
      +#> A set of custom MDRO rules:
      +#>   1. CIP == "R" & age > 60 -> "Elderly Type A"
      +#>   2. ERY == "R" & age > 60 -> "Elderly Type B"
      +#>   3. Otherwise -> "Negative"
      +#> 
      +#> Unmatched rows will return NA.
      +
      + +

      The outcome of the function can be used for the guideline argument in the mdro() function:

      x <- mdro(example_isolates, guideline = custom)
      +table(x)
      +
      + +

      The rules set (the custom object in this case) could be exported to a shared file location using saveRDS() if you collaborate with multiple users. The custom rules set could then be imported using readRDS(),

      +

      Stable lifecycle

      @@ -375,6 +404,10 @@ A microorganism is categorised as Susceptible, Increased exposure when

      Examples

      mdro(example_isolates, guideline = "EUCAST")
       
      +mdro(example_isolates,
      +     guideline = custom_mdro_guideline("AMX == 'R'" ~ "Custom MDRO 1",
      +                                       "VAN == 'R'" ~ "Custom MDRO 2"))
      +
       # \donttest{
       if (require("dplyr")) {
         example_isolates %>%
      diff --git a/docs/survey.html b/docs/survey.html
      index f73840db..1c39a2ac 100644
      --- a/docs/survey.html
      +++ b/docs/survey.html
      @@ -81,7 +81,7 @@
             
             
               AMR (for R)
      -        1.5.0.9003
      +        1.5.0.9004
             
           
    diff --git a/man/mdro.Rd b/man/mdro.Rd index a1c16b5f..096759aa 100644 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -8,6 +8,7 @@ \alias{BRMO} \alias{3MRGN} \alias{4MRGN} +\alias{custom_mdro_guideline} \alias{brmo} \alias{mrgn} \alias{mdr_tb} @@ -29,6 +30,8 @@ mdro( ... ) +custom_mdro_guideline(...) + brmo(x, guideline = "BRMO", ...) mrgn(x, guideline = "MRGN", ...) @@ -42,7 +45,7 @@ eucast_exceptional_phenotypes(x, guideline = "EUCAST", ...) \arguments{ \item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank for automatic determination.} -\item{guideline}{a specific guideline to follow. When left empty, the publication by Magiorakos \emph{et al.} (2012, Clinical Microbiology and Infection) will be followed, please see \emph{Details}.} +\item{guideline}{a specific guideline to follow. Can also have \code{\link[=custom_mdro_guideline]{custom_mdro_guideline()}} as input. When left empty, the publication by Magiorakos \emph{et al.} (2012, Clinical Microbiology and Infection) will be followed, please see \emph{Details}.} \item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} @@ -64,18 +67,21 @@ Ordered \link{factor} with levels \code{Negative} < \code{Multi-drug-resistant ( Ordered \link{factor} with levels \code{Negative} < \code{Mono-resistant} < \code{Poly-resistant} < \code{Multi-drug-resistant} < \verb{Extensively drug-resistant} \item German guideline - function \code{\link[=mrgn]{mrgn()}} or \code{\link[=mdro]{mdro(..., guideline = "MRGN")}}:\cr Ordered \link{factor} with levels \code{Negative} < \verb{3MRGN} < \verb{4MRGN} -\item Everything else:\cr +\item Everything else, except for custom guidelines:\cr Ordered \link{factor} with levels \code{Negative} < \verb{Positive, unconfirmed} < \code{Positive}. The value \code{"Positive, unconfirmed"} means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests } } \description{ -Determine which isolates are multidrug-resistant organisms (MDRO) according to international and national guidelines. +Determine which isolates are multidrug-resistant organisms (MDRO) according to international, national and custom guidelines. } \details{ These functions are context-aware when used inside \code{dplyr} verbs, such as \code{filter()}, \code{mutate()} and \code{summarise()}. This means that then the \code{x} argument can be left blank, please see \emph{Examples}. For the \code{pct_required_classes} argument, values above 1 will be divided by 100. This is to support both fractions (\code{0.75} or \code{3/4}) and percentages (\code{75}). +\strong{Note:} Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named \emph{order} Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu \emph{et al.} in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this \code{\link[=mdro]{mdro()}} function makes sure that results from before 2016 and after 2016 are identical. +\subsection{International / National guidelines}{ + Currently supported guidelines are (case-insensitive): \itemize{ \item \code{guideline = "CMI2012"} (default) @@ -99,8 +105,33 @@ The Dutch national guideline - Rijksinstituut voor Volksgezondheid en Milieu "WI } Please suggest your own (country-specific) guidelines by letting us know: \url{https://github.com/msberends/AMR/issues/new}. +} -\strong{Note:} Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named \emph{order} Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu \emph{et al.} in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this \code{\link[=mdro]{mdro()}} function makes sure that results from before 2016 and after 2016 are identical. +\subsection{Custom guidelines}{ + +Custom guidelines can be set with the \code{\link[=custom_mdro_guideline]{custom_mdro_guideline()}} function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data. + +If you are familiar with \code{case_when()} of the \code{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':\preformatted{custom <- custom_mdro_guideline("CIP == 'R' & age > 60" ~ "Elderly Type A", + "ERY == 'R' & age > 60" ~ "Elderly Type B") +} + +If a row/an isolate matches the first rule, the value after the first \code{~} (in this case \emph{'Elderly Type A'}) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited. + +You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.\preformatted{custom +#> A set of custom MDRO rules: +#> 1. CIP == "R" & age > 60 -> "Elderly Type A" +#> 2. ERY == "R" & age > 60 -> "Elderly Type B" +#> 3. Otherwise -> "Negative" +#> +#> Unmatched rows will return NA. +} + +The outcome of the function can be used for the \code{guideline} argument in the \code{\link[=mdro]{mdro()}} function:\preformatted{x <- mdro(example_isolates, guideline = custom) +table(x) +} + +The rules set (the \code{custom} object in this case) could be exported to a shared file location using \code{\link[=saveRDS]{saveRDS()}} if you collaborate with multiple users. The custom rules set could then be imported using \code{\link[=readRDS]{readRDS()}}, +} } \section{Stable lifecycle}{ @@ -142,6 +173,10 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/ \examples{ mdro(example_isolates, guideline = "EUCAST") +mdro(example_isolates, + guideline = custom_mdro_guideline("AMX == 'R'" ~ "Custom MDRO 1", + "VAN == 'R'" ~ "Custom MDRO 2")) + \donttest{ if (require("dplyr")) { example_isolates \%>\% diff --git a/tests/testthat/test-mdro.R b/tests/testthat/test-mdro.R index e66c07d4..9ca66ce1 100755 --- a/tests/testthat/test-mdro.R +++ b/tests/testthat/test-mdro.R @@ -223,4 +223,15 @@ test_that("mdro works", { expect_equal(as.integer(mdro(acin)), c(1:4)) expect_s3_class(mdro(acin, verbose = TRUE), "data.frame") + # custom rules + custom <- custom_mdro_guideline("CIP == 'R' & age > 60" ~ "Elderly Type A", + "ERY == 'R' & age > 60" ~ "Elderly Type B") + expect_output(print(custom)) + x <- mdro(example_isolates, guideline = custom, info = TRUE) + expect_equal(as.double(table(x)), c(43, 891, 1066)) + expect_error(custom_mdro_guideline()) + expect_error(custom_mdro_guideline("test")) + expect_error(custom_mdro_guideline("test" ~ c(1:3))) + expect_error(custom_mdro_guideline("test" ~ A)) + })