diff --git a/DESCRIPTION b/DESCRIPTION index 331974c1..2b574620 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.6.1.9034 -Date: 2019-05-20 +Version: 0.6.1.9035 +Date: 2019-05-23 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NAMESPACE b/NAMESPACE index 7c5b7957..a84b5929 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -132,6 +132,7 @@ export(kurtosis) export(labels_rsi_count) export(left_join_microorganisms) export(like) +export(mdr_tb) export(mdro) export(mo_authors) export(mo_class) diff --git a/NEWS.md b/NEWS.md index ec01cb5a..588f0965 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,10 @@ -# AMR 0.6.1.9001 +# AMR 0.6.1.90xx **Note: latest development version** #### New * Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use `as.rsi()` on an MIC value (created with `as.mic()`), a disk diffusion value (created with the new `as.disk()`) or on a complete date set containing columns with MIC or disk diffusion values. * Function `mo_name()` as alias of `mo_fullname()` +* Added guidelines of the WHO to determine mutli-drug resistance (MDR) for TB (`mdr_tb()`) and added a new vignette about MDR #### Changed * Completely reworked the `antibiotics` data set: @@ -11,7 +12,7 @@ * Column `ab` contains a human readable EARS-Net code, used by ECDC and WHO/WHONET - this is the primary identifier used in this package * Column `atc` contains the ATC code, used by WHO/WHOCC * Column `cid` contains the CID code (Compound ID), used by PubChem - * Based on the Compound ID, more than a thousand official brand names have been added from many different countries + * Based on the Compound ID, almost 5,000 official brand names have been added from many different countries * All references to antibiotics in our package now use EARS-Net codes, like `AMX` for amoxicillin * Functions `atc_certe`, `ab_umcg` and `atc_trivial_nl` have been removed * All `atc_*` functions are superceded by `ab_*` functions @@ -24,7 +25,10 @@ * Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function * This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as 'increased exposure' and not 'intermediate' anymore. For functions like `portion_df()` and `count_df()` this means that their new parameter `combine_SI` is TRUE at default. * Removed deprecated functions `guess_mo()`, `guess_atc()`, `EUCAST_rules()`, `interpretive_reading()`, `rsi()` -* Frequency tables of microbial IDs speed improvement +* Frequency tables (`freq()`): + * speed improvement for microbial IDs + * fixed level names in markdown + * * Removed all hardcoded EUCAST rules and replaced them with a new reference file: `./inst/eucast/eucast.tsv` * Added ceftazidim intrinsic resistance to *Streptococci* * Changed default settings for `age_groups()`, to let groups of fives and tens end with 100+ instead of 120+ diff --git a/R/data.R b/R/data.R index 0aec1b15..2264ad45 100755 --- a/R/data.R +++ b/R/data.R @@ -22,7 +22,7 @@ #' Data set with ~450 antibiotics #' #' A data set containing all antibiotics. Use \code{\link{as.ab}} or one of the \code{\link{ab_property}} functions to retrieve values from this data set. Three identifiers are included in this data set: an antibiotic ID (\code{ab}, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (\code{atc}) as defined by the WHO, and a Compound ID (\code{cid}) as found in PubChem. Other properties in this data set are derived from one or more of these codes. -#' @format A \code{\link{data.frame}} with 455 observations and 13 variables: +#' @format A \code{\link{data.frame}} with 454 observations and 13 variables: #' \describe{ #' \item{\code{ab}}{Antibiotic ID as used in this package (like \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available} #' \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}} diff --git a/R/eucast_rules.R b/R/eucast_rules.R index b92fae3a..64ac2ebf 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -116,7 +116,7 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016" #' @export #' @importFrom dplyr %>% select pull mutate_at vars group_by summarise n #' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic strip_style white -#' @return The input of \code{tbl_}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations. +#' @return The input of \code{x}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations. #' @source #' \itemize{ #' \item{ @@ -184,16 +184,16 @@ eucast_rules <- function(x, verbose = FALSE, ...) { - tbl_ <- x + x <- x - if (!is.data.frame(tbl_)) { + if (!is.data.frame(x)) { stop("`x` must be a data frame.", call. = FALSE) } # try to find columns based on type # -- mo if (is.null(col_mo)) { - col_mo <- search_type_in_df(tbl = tbl_, type = "mo") + col_mo <- search_type_in_df(x = x, type = "mo") } if (is.null(col_mo)) { stop("`col_mo` must be set.", call. = FALSE) @@ -376,12 +376,12 @@ eucast_rules <- function(x, edit_rsi <- function(to, rule, rows, cols) { cols <- unique(cols[!is.na(cols) & !is.null(cols)]) if (length(rows) > 0 & length(cols) > 0) { - before_df <- tbl_original - before <- as.character(unlist(as.list(tbl_original[rows, cols]))) + before_df <- x_original + before <- as.character(unlist(as.list(x_original[rows, cols]))) tryCatch( # insert into original table - tbl_original[rows, cols] <<- to, + x_original[rows, cols] <<- to, warning = function(w) { if (w$message %like% 'invalid factor level') { warning('Value "', to, '" could not be applied to column(s) `', paste(cols, collapse = '`, `'), '` because this value is not an existing factor level.', call. = FALSE) @@ -396,9 +396,9 @@ eucast_rules <- function(x, } ) - tbl_[rows, cols] <<- tbl_original[rows, cols] + x[rows, cols] <<- x_original[rows, cols] - after <- as.character(unlist(as.list(tbl_original[rows, cols]))) + after <- as.character(unlist(as.list(x_original[rows, cols]))) # before_df might not be a data.frame, but a tibble of data.table instead old <- as.data.frame(before_df, stringsAsFactors = FALSE)[rows,] @@ -406,9 +406,9 @@ eucast_rules <- function(x, for (i in 1:length(cols)) { verbose_new <- data.frame(row = rows, col = cols[i], - mo_fullname = tbl_[rows, "fullname"], + mo_fullname = x[rows, "fullname"], old = as.character(old[, cols[i]]), - new = as.character(tbl_[rows, cols[i]]), + new = as.character(x[rows, cols[i]]), rule = strip_style(rule[1]), rule_group = strip_style(rule[2]), rule_name = strip_style(rule[3]), @@ -426,11 +426,11 @@ eucast_rules <- function(x, } # save original table - tbl_original <- tbl_ + x_original <- x # join to microorganisms data set suppressWarnings( - tbl_ <- tbl_ %>% + x <- x %>% mutate_at(vars(col_mo), as.mo) %>% left_join_microorganisms(by = col_mo, suffix = c("_oldcols", "")) %>% mutate(gramstain = mo_gramstain(pull(., col_mo), language = "en"), @@ -448,18 +448,18 @@ eucast_rules <- function(x, if (!ab_missing(AMP) & !ab_missing(AMX)) { if (verbose == TRUE) { cat("\n VERBOSE: transforming", - length(which(tbl_[, AMX] == "S" & !tbl_[, AMP] %in% c("S", "I", "R"))), + length(which(x[, AMX] == "S" & !x[, AMP] %in% c("S", "I", "R"))), "empty ampicillin fields to 'S' based on amoxicillin. ") cat("\n VERBOSE: transforming", - length(which(tbl_[, AMX] == "I" & !tbl_[, AMP] %in% c("S", "I", "R"))), + length(which(x[, AMX] == "I" & !x[, AMP] %in% c("S", "I", "R"))), "empty ampicillin fields to 'I' based on amoxicillin. ") cat("\n VERBOSE: transforming", - length(which(tbl_[, AMX] == "R" & !tbl_[, AMP] %in% c("S", "I", "R"))), + length(which(x[, AMX] == "R" & !x[, AMP] %in% c("S", "I", "R"))), "empty ampicillin fields to 'R' based on amoxicillin. \n") } - tbl_[which(tbl_[, AMX] == "S" & !tbl_[, AMP] %in% c("S", "I", "R")), AMP] <- "S" - tbl_[which(tbl_[, AMX] == "I" & !tbl_[, AMP] %in% c("S", "I", "R")), AMP] <- "I" - tbl_[which(tbl_[, AMX] == "R" & !tbl_[, AMP] %in% c("S", "I", "R")), AMP] <- "R" + x[which(x[, AMX] == "S" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "S" + x[which(x[, AMX] == "I" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "I" + x[which(x[, AMX] == "R" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "R" } else if (ab_missing(AMP) & !ab_missing(AMX)) { # ampicillin column is missing, but amoxicillin is available message(blue(paste0("NOTE: Using column `", bold(AMX), "` as input for ampicillin (J01CA01) since many EUCAST rules depend on it."))) @@ -605,36 +605,36 @@ eucast_rules <- function(x, target_value <- eucast_rules_df[i, 7] if (is.na(source_antibiotics)) { - rows <- tryCatch(which(tbl_[, col_mo_property] %like% mo_value), + rows <- tryCatch(which(x[, col_mo_property] %like% mo_value), error = function(e) integer(0)) } else { - source_antibiotics <- get_antibiotic_columns(source_antibiotics, tbl_) + source_antibiotics <- get_antibiotic_columns(source_antibiotics, x) if (length(source_value) == 1 & length(source_antibiotics) > 1) { source_value <- rep(source_value, length(source_antibiotics)) } if (length(source_antibiotics) == 0) { rows <- integer(0) } else if (length(source_antibiotics) == 1) { - rows <- tryCatch(which(tbl_[, col_mo_property] %like% mo_value - & tbl_[, source_antibiotics[1L]] == source_value[1L]), + rows <- tryCatch(which(x[, col_mo_property] %like% mo_value + & x[, source_antibiotics[1L]] == source_value[1L]), error = function(e) integer(0)) } else if (length(source_antibiotics) == 2) { - rows <- tryCatch(which(tbl_[, col_mo_property] %like% mo_value - & tbl_[, source_antibiotics[1L]] == source_value[1L] - & tbl_[, source_antibiotics[2L]] == source_value[2L]), + rows <- tryCatch(which(x[, col_mo_property] %like% mo_value + & x[, source_antibiotics[1L]] == source_value[1L] + & x[, source_antibiotics[2L]] == source_value[2L]), error = function(e) integer(0)) } else if (length(source_antibiotics) == 3) { - rows <- tryCatch(which(tbl_[, col_mo_property] %like% mo_value - & tbl_[, source_antibiotics[1L]] == source_value[1L] - & tbl_[, source_antibiotics[2L]] == source_value[2L] - & tbl_[, source_antibiotics[3L]] == source_value[3L]), + rows <- tryCatch(which(x[, col_mo_property] %like% mo_value + & x[, source_antibiotics[1L]] == source_value[1L] + & x[, source_antibiotics[2L]] == source_value[2L] + & x[, source_antibiotics[3L]] == source_value[3L]), error = function(e) integer(0)) } else { stop("only 3 antibiotics supported for source_antibiotics ", call. = FALSE) } } - cols <- get_antibiotic_columns(target_antibiotics, tbl_) + cols <- get_antibiotic_columns(target_antibiotics, x) # Apply rule on data ------------------------------------------------------ # this will return the unique number of changes @@ -671,7 +671,7 @@ eucast_rules <- function(x, cat(paste0("\n", silver(strrep("-", options()$width - 1)), "\n")) cat(bold(paste('EUCAST rules', paste0(wouldve, 'affected'), formatnr(n_distinct(verbose_info$row)), - 'out of', formatnr(nrow(tbl_original)), + 'out of', formatnr(nrow(x_original)), 'rows, making a total of', formatnr(nrow(verbose_info)), 'edits\n'))) n_added <- verbose_info %>% filter(is.na(old)) %>% nrow() @@ -742,7 +742,7 @@ eucast_rules <- function(x, if (verbose == TRUE) { verbose_info } else { - tbl_original + x_original } } diff --git a/R/first_isolate.R b/R/first_isolate.R index c315b660..8c6637c2 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -191,7 +191,7 @@ first_isolate <- function(x, # try to find columns based on type # -- mo if (is.null(col_mo)) { - col_mo <- search_type_in_df(tbl = x, type = "mo") + col_mo <- search_type_in_df(x = x, type = "mo") } if (is.null(col_mo)) { stop("`col_mo` must be set.", call. = FALSE) @@ -199,7 +199,7 @@ first_isolate <- function(x, # -- date if (is.null(col_date)) { - col_date <- search_type_in_df(tbl = x, type = "date") + col_date <- search_type_in_df(x = x, type = "date") } if (is.null(col_date)) { stop("`col_date` must be set.", call. = FALSE) @@ -217,7 +217,7 @@ first_isolate <- function(x, col_patient_id <- "patient_id" message(blue(paste0("NOTE: Using combined columns ", bold("`First name`, `Last name` and `Sex`"), " as input for `col_patient_id`."))) } else { - col_patient_id <- search_type_in_df(tbl = x, type = "patient_id") + col_patient_id <- search_type_in_df(x = x, type = "patient_id") } } if (is.null(col_patient_id)) { @@ -226,7 +226,7 @@ first_isolate <- function(x, # -- key antibiotics if (is.null(col_keyantibiotics)) { - col_keyantibiotics <- search_type_in_df(tbl = x, type = "keyantibiotics") + col_keyantibiotics <- search_type_in_df(x = x, type = "keyantibiotics") } if (isFALSE(col_keyantibiotics)) { col_keyantibiotics <- NULL @@ -234,7 +234,7 @@ first_isolate <- function(x, # -- specimen if (is.null(col_specimen)) { - col_specimen <- search_type_in_df(tbl = x, type = "specimen") + col_specimen <- search_type_in_df(x = x, type = "specimen") } if (isFALSE(col_specimen)) { col_specimen <- NULL @@ -547,10 +547,10 @@ filter_first_isolate <- function(x, col_mo = NULL, ...) { filter(x, first_isolate(x = x, - col_date = col_date, - col_patient_id = col_patient_id, - col_mo = col_mo, - ...)) + col_date = col_date, + col_patient_id = col_patient_id, + col_mo = col_mo, + ...)) } #' @rdname first_isolate diff --git a/R/freq.R b/R/freq.R index ad9b68a6..776fe011 100755 --- a/R/freq.R +++ b/R/freq.R @@ -336,9 +336,10 @@ frequency_tbl <- function(x, cols <- unlist(strsplit(x.name, "$", fixed = TRUE))[2] x.name <- unlist(strsplit(x.name, "$", fixed = TRUE))[1] # try to find the object to determine dimensions + x.obj <- tryCatch(get(x.name), error = function(e) NULL) x.name <- paste0("`", x.name , "`") - if (!is.null(x.obj)) { + if (!is.null(dim(x.obj))) { x.name <- paste0(x.name, " (", x.obj %>% @@ -664,6 +665,10 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ", if (nchar(levels_text) > 70) { # levels text wider than half the console levels_text <- paste0(substr(levels_text, 1, 70 - 3), "...") + if (nchar(gsub("[^`]", "", levels_text)) %% 2 == 1) { + # odd number of backticks, should be even + levels_text <- paste0(levels_text, "`") + } } header$levels <- paste0(length(header$levels), ": ", levels_text) header <- header[names(header) != "ordered"] diff --git a/R/key_antibiotics.R b/R/key_antibiotics.R index 6ffd9804..d6dd5b6a 100755 --- a/R/key_antibiotics.R +++ b/R/key_antibiotics.R @@ -22,7 +22,7 @@ #' Key antibiotics for first \emph{weighted} isolates #' #' These function can be used to determine first isolates (see \code{\link{first_isolate}}). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates will then be called first \emph{weighted} isolates. -#' @param tbl table with antibiotics coloms, like \code{amox} and \code{amcl}. +#' @param x table with antibiotics coloms, like \code{AMX} or \code{amox} #' @param x,y characters to compare #' @inheritParams first_isolate #' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of \strong{broad-spectrum} antibiotics, case-insensitive. At default, the columns containing these antibiotics will be guessed with \code{\link{guess_ab_col}}. @@ -76,33 +76,33 @@ #' #' key_antibiotics_equal(strainA, strainB, ignore_I = FALSE) #' # FALSE, because I is not ignored and so the 4th value differs -key_antibiotics <- function(tbl, +key_antibiotics <- function(x, col_mo = NULL, - universal_1 = guess_ab_col(tbl, "AMX"), - universal_2 = guess_ab_col(tbl, "AMC"), - universal_3 = guess_ab_col(tbl, "CXM"), - universal_4 = guess_ab_col(tbl, "TZP"), - universal_5 = guess_ab_col(tbl, "CIP"), - universal_6 = guess_ab_col(tbl, "SXT"), - GramPos_1 = guess_ab_col(tbl, "VAN"), - GramPos_2 = guess_ab_col(tbl, "TEC"), - GramPos_3 = guess_ab_col(tbl, "TCY"), - GramPos_4 = guess_ab_col(tbl, "ERY"), - GramPos_5 = guess_ab_col(tbl, "OXA"), - GramPos_6 = guess_ab_col(tbl, "RIF"), - GramNeg_1 = guess_ab_col(tbl, "GEN"), - GramNeg_2 = guess_ab_col(tbl, "TOB"), - GramNeg_3 = guess_ab_col(tbl, "COL"), - GramNeg_4 = guess_ab_col(tbl, "CTX"), - GramNeg_5 = guess_ab_col(tbl, "CAZ"), - GramNeg_6 = guess_ab_col(tbl, "MEM"), + universal_1 = guess_ab_col(x, "AMX"), + universal_2 = guess_ab_col(x, "AMC"), + universal_3 = guess_ab_col(x, "CXM"), + universal_4 = guess_ab_col(x, "TZP"), + universal_5 = guess_ab_col(x, "CIP"), + universal_6 = guess_ab_col(x, "SXT"), + GramPos_1 = guess_ab_col(x, "VAN"), + GramPos_2 = guess_ab_col(x, "TEC"), + GramPos_3 = guess_ab_col(x, "TCY"), + GramPos_4 = guess_ab_col(x, "ERY"), + GramPos_5 = guess_ab_col(x, "OXA"), + GramPos_6 = guess_ab_col(x, "RIF"), + GramNeg_1 = guess_ab_col(x, "GEN"), + GramNeg_2 = guess_ab_col(x, "TOB"), + GramNeg_3 = guess_ab_col(x, "COL"), + GramNeg_4 = guess_ab_col(x, "CTX"), + GramNeg_5 = guess_ab_col(x, "CAZ"), + GramNeg_6 = guess_ab_col(x, "MEM"), warnings = TRUE, ...) { # try to find columns based on type # -- mo if (is.null(col_mo)) { - col_mo <- search_type_in_df(tbl = tbl, type = "mo") + col_mo <- search_type_in_df(x = x, type = "mo") } if (is.null(col_mo)) { stop("`col_mo` must be set.", call. = FALSE) @@ -112,7 +112,7 @@ key_antibiotics <- function(tbl, col.list <- c(universal_1, universal_2, universal_3, universal_4, universal_5, universal_6, GramPos_1, GramPos_2, GramPos_3, GramPos_4, GramPos_5, GramPos_6, GramNeg_1, GramNeg_2, GramNeg_3, GramNeg_4, GramNeg_5, GramNeg_6) - check_available_columns <- function(tbl, col.list, info = TRUE) { + check_available_columns <- function(x, col.list, info = TRUE) { # check columns col.list <- col.list[!is.na(col.list) & !is.null(col.list)] names(col.list) <- col.list @@ -121,18 +121,18 @@ key_antibiotics <- function(tbl, for (i in 1:length(col.list)) { if (is.null(col.list[i]) | isTRUE(is.na(col.list[i]))) { col.list[i] <- NA - } else if (toupper(col.list[i]) %in% colnames(tbl)) { + } else if (toupper(col.list[i]) %in% colnames(x)) { col.list[i] <- toupper(col.list[i]) - } else if (tolower(col.list[i]) %in% colnames(tbl)) { + } else if (tolower(col.list[i]) %in% colnames(x)) { col.list[i] <- tolower(col.list[i]) - } else if (!col.list[i] %in% colnames(tbl)) { + } else if (!col.list[i] %in% colnames(x)) { col.list[i] <- NA } } - if (!all(col.list %in% colnames(tbl))) { + if (!all(col.list %in% colnames(x))) { if (info == TRUE) { warning('Some columns do not exist and will be ignored: ', - col.list.bak[!(col.list %in% colnames(tbl))] %>% toString(), + col.list.bak[!(col.list %in% colnames(x))] %>% toString(), '.\nTHIS MAY STRONGLY INFLUENCE THE OUTCOME.', immediate. = TRUE, call. = FALSE) @@ -141,7 +141,7 @@ key_antibiotics <- function(tbl, col.list } - col.list <- check_available_columns(tbl = tbl, col.list = col.list, info = warnings) + col.list <- check_available_columns(x = x, col.list = col.list, info = warnings) universal_1 <- col.list[universal_1] universal_2 <- col.list[universal_2] universal_3 <- col.list[universal_3] @@ -183,30 +183,30 @@ key_antibiotics <- function(tbl, } # join to microorganisms data set - tbl <- tbl %>% + x <- x %>% mutate_at(vars(col_mo), as.mo) %>% left_join_microorganisms(by = col_mo) %>% mutate(key_ab = NA_character_, gramstain = mo_gramstain(pull(., col_mo))) # Gram + - tbl <- tbl %>% mutate(key_ab = - if_else(gramstain == "Gram positive", - apply(X = tbl[, gram_positive], - MARGIN = 1, - FUN = function(x) paste(x, collapse = "")), - key_ab)) + x <- x %>% mutate(key_ab = + if_else(gramstain == "Gram positive", + apply(X = x[, gram_positive], + MARGIN = 1, + FUN = function(x) paste(x, collapse = "")), + key_ab)) # Gram - - tbl <- tbl %>% mutate(key_ab = - if_else(gramstain == "Gram negative", - apply(X = tbl[, gram_negative], - MARGIN = 1, - FUN = function(x) paste(x, collapse = "")), - key_ab)) + x <- x %>% mutate(key_ab = + if_else(gramstain == "Gram negative", + apply(X = x[, gram_negative], + MARGIN = 1, + FUN = function(x) paste(x, collapse = "")), + key_ab)) # format - key_abs <- tbl %>% + key_abs <- x %>% pull(key_ab) %>% gsub('(NA|NULL)', '.', .) %>% gsub('[^SIR]', '.', ., ignore.case = TRUE) diff --git a/R/mdro.R b/R/mdro.R index 175bf947..6cd37db3 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -23,12 +23,25 @@ #' #' Determine which isolates are multidrug-resistant organisms (MDRO) according to country-specific guidelines. #' @param x table with antibiotic columns, like e.g. \code{AMX} and \code{AMC} -#' @param country country code to determine guidelines. EUCAST rules will be used when left empty, see Details. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive. Currently supported are \code{de} (Germany) and \code{nl} (the Netherlands). +#' @param country country code to determine guidelines. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive. +#' @param guideline a specific guideline to mention. For some countries this will be determined automatically, see Details. EUCAST guidelines will be used when left empty, see Details. #' @param info print progress #' @inheritParams eucast_rules #' @param verbose print additional info: missing antibiotic columns per parameter #' @inheritSection eucast_rules Antibiotics -#' @details When \code{country} will be left blank, guidelines will be taken from EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link}). +#' @details When \code{country} is set, the parameter guideline will be ignored as these guidelines will be used: +#' +#' \itemize{ +#' \item{\code{country = "nl"}: Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link})} +#' } +#' +#' Please suggest your own country's specific guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}. +#' +#' Other currently supported guidelines are: +#' \itemize{ +#' \item{\code{guideline = "eucast"}: EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link})} +#' \item{\code{guideline = "tb"}: World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link})} +#' } #' @return Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}. #' @rdname mdro #' @importFrom dplyr %>% @@ -43,21 +56,41 @@ #' BRMO = brmo(.)) mdro <- function(x, country = NULL, + guideline = NULL, col_mo = NULL, info = TRUE, verbose = FALSE, ...) { - tbl_ <- x - - if (!is.data.frame(tbl_)) { + if (!is.data.frame(x)) { stop("`x` must be a data frame.", call. = FALSE) } + if (length(guideline) > 1) { + stop("`guideline` must be a length one character string.", call. = FALSE) + } + if (!is.null(country)) { + guideline <- country + } + if (is.null(guideline)) { + guideline <- "eucast" + } + if (!tolower(guideline) %in% c("nl", "de", "eucast", "tb")) { + stop("invalid guideline: ", guideline, call. = FALSE) + } + guideline <- list(code = tolower(guideline)) + # try to find columns based on type # -- mo if (is.null(col_mo)) { - col_mo <- search_type_in_df(tbl = tbl_, type = "mo") + col_mo <- search_type_in_df(x = x, type = "mo") + } + if (is.null(col_mo) & guideline$code == "tb") { + message(blue("NOTE: No column found as input for `col_mo`,", + bold("assuming all records contain", + italic("Mycobacterium tuberculosis.")))) + x$mo <- AMR::as.mo("Mycobacterium tuberculosis") + col_mo <- "mo" } if (is.null(col_mo)) { stop("`col_mo` must be set.", call. = FALSE) @@ -67,50 +100,59 @@ mdro <- function(x, stop("`country` must be a length one character string.", call. = FALSE) } - if (is.null(country)) { - country <- "EUCAST" - } - country <- trimws(country) - if (tolower(country) != "eucast" & !country %like% "^[a-z]{2}$") { - stop("This is not a valid ISO 3166-1 alpha-2 country code: '", country, "'. Please see ?mdro.", call. = FALSE) - } - - # create list and make country code case-independent - guideline <- list(country = list(code = tolower(country))) - - if (guideline$country$code == "eucast") { - guideline$country$name <- "(European guidelines)" + if (guideline$code == "eucast") { guideline$name <- "EUCAST Expert Rules, \"Intrinsic Resistance and Exceptional Phenotypes Tables\"" - guideline$version <- "Version 3.1" + guideline$author <- "EUCAST (European Committee on Antimicrobial Susceptibility Testing)" + guideline$version <- "3.1" guideline$source <- "http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf" + + } else if (guideline$code == "tb") { + guideline$name <- "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" + guideline$author <- "WHO (World Health Organization)" + guideline$version <- "WHO/HTM/TB/2014.11" + guideline$source <- "https://www.who.int/tb/publications/pmdt_companionhandbook/en/" + # support per country: - } else if (guideline$country$code == "de") { - guideline$country$name <- "Germany" + } else if (guideline$code == "de") { + guideline$name <- "Germany" guideline$name <- "" guideline$version <- "" guideline$source <- "" - } else if (guideline$country$code == "nl") { - guideline$country$name <- "The Netherlands" - guideline$name <- "WIP-Richtlijn BRMO" + } else if (guideline$code == "nl") { + guideline$name <- "WIP-Richtlijn Bijzonder Resistente Micro-organismen (BRMO)" + guideline$author <- "RIVM (Rijksinstituut voor de Volksgezondheid)" guideline$version <- "Revision as of December 2017" guideline$source <- "https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH" # add here more countries like this: # } else if (country$code == "xx") { # country$name <- "country name" } else { - stop("This country code is currently unsupported: ", guideline$country$code, call. = FALSE) + stop("This guideline is currently unsupported: ", guideline$code, call. = FALSE) } if (info == TRUE) { cat("Determining multidrug-resistant organisms (MDRO), according to:\n", - "Guideline: ", red(paste0(guideline$name, ", ", guideline$version, "\n")), - "Country : ", red(paste0(guideline$country$name, "\n")), - "Source : ", blue(paste0(guideline$source, "\n")), + "Guideline: ", red(guideline$name), "\n", + "Version: ", red(guideline$version), "\n", + "Author: ", red(guideline$author), "\n", + "Source: ", blue(guideline$source), "\n", "\n", sep = "") } - - cols_ab <- get_column_abx(x = x, verbose = verbose, ...) + if (guideline$code == "tb") { + cols_ab <- get_column_abx(x = x, + soft_dependencies = c("CAP", + "ETH", + "GAT", + "INH", + "PZA", + "RIF", + "RIB", + "RFP"), + verbose = verbose, ...) + } else { + cols_ab <- get_column_abx(x = x, verbose = verbose, ...) + } AMC <- cols_ab["AMC"] AMK <- cols_ab["AMK"] @@ -175,7 +217,20 @@ mdro <- function(x, TOB <- cols_ab["TOB"] TZP <- cols_ab["TZP"] VAN <- cols_ab["VAN"] - + # additional for TB + CAP <- cols_ab["CAP"] + ETH <- cols_ab["ETH"] + GAT <- cols_ab["GAT"] + INH <- cols_ab["INH"] + PZA <- cols_ab["PZA"] + RIF <- cols_ab["RIF"] + RIB <- cols_ab["RIB"] + RFP <- cols_ab["RFP"] + abx_tb <- c(CAP, ETH, GAT, INH, PZA, RIF, RIB, RFP) + abx_tb <- abx_tb[!is.na(abx_tb)] + if (guideline$code == "tb" & length(abx_tb) == 0) { + stop("No antimycobacterials found in data set.", call. = FALSE) + } ab_missing <- function(ab) { isTRUE(ab %in% c(NULL, NA)) | length(ab) == 0 @@ -194,96 +249,96 @@ mdro <- function(x, cols <- cols[!is.na(cols)] if (length(rows) > 0 & length(cols) > 0) { if (any_all == "any") { - row_filter <- which(tbl_[, cols] == "R") + row_filter <- which(x[, cols] == "R") } else if (any_all == "all") { - row_filter <- tbl_ %>% + row_filter <- x %>% mutate(index = 1:nrow(.)) %>% filter_at(vars(cols), all_vars(. == "R")) %>% pull((index)) } rows <- rows[rows %in% row_filter] - tbl_[rows, "MDRO"] <<- to + x[rows, "MDRO"] <<- to } } - tbl_ <- tbl_ %>% + x <- x %>% mutate_at(vars(col_mo), as.mo) %>% # join to microorganisms data set left_join_microorganisms(by = col_mo) %>% # add unconfirmed to where genus is available mutate(MDRO = ifelse(!is.na(genus), 1, NA_integer_)) - if (guideline$country$code == "eucast") { + if (guideline$code == "eucast") { # EUCAST ------------------------------------------------------------------ # Table 5 trans_tbl(3, - which(tbl_$family == "Enterobacteriaceae" - | tbl_$fullname %like% "^Pseudomonas aeruginosa" - | tbl_$genus == "Acinetobacter"), + which(x$family == "Enterobacteriaceae" + | x$fullname %like% "^Pseudomonas aeruginosa" + | x$genus == "Acinetobacter"), COL, "all") trans_tbl(3, - which(tbl_$fullname %like% "^Salmonella Typhi"), + which(x$fullname %like% "^Salmonella Typhi"), c(carbapenems, fluoroquinolones), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Haemophilus influenzae"), + which(x$fullname %like% "^Haemophilus influenzae"), c(cephalosporins_3rd, carbapenems, fluoroquinolones), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Moraxella catarrhalis"), + which(x$fullname %like% "^Moraxella catarrhalis"), c(cephalosporins_3rd, fluoroquinolones), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Neisseria meningitidis"), + which(x$fullname %like% "^Neisseria meningitidis"), c(cephalosporins_3rd, fluoroquinolones), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Neisseria gonorrhoeae"), + which(x$fullname %like% "^Neisseria gonorrhoeae"), AZM, "any") # Table 6 trans_tbl(3, - which(tbl_$fullname %like% "^Staphylococcus (aureus|epidermidis|coagulase negatief|hominis|haemolyticus|intermedius|pseudointermedius)"), + which(x$fullname %like% "^Staphylococcus (aureus|epidermidis|coagulase negatief|hominis|haemolyticus|intermedius|pseudointermedius)"), c(VAN, TEC, DAP, LNZ, QDA, TGC), "any") trans_tbl(3, - which(tbl_$genus == "Corynebacterium"), + which(x$genus == "Corynebacterium"), c(VAN, TEC, DAP, LNZ, QDA, TGC), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Streptococcus pneumoniae"), + which(x$fullname %like% "^Streptococcus pneumoniae"), c(carbapenems, VAN, TEC, DAP, LNZ, QDA, TGC, RIF), "any") trans_tbl(3, # Sr. groups A/B/C/G - which(tbl_$fullname %like% "^Streptococcus (pyogenes|agalactiae|equisimilis|equi|zooepidemicus|dysgalactiae|anginosus)"), + which(x$fullname %like% "^Streptococcus (pyogenes|agalactiae|equisimilis|equi|zooepidemicus|dysgalactiae|anginosus)"), c(PEN, cephalosporins, VAN, TEC, DAP, LNZ, QDA, TGC), "any") trans_tbl(3, - which(tbl_$genus == "Enterococcus"), + which(x$genus == "Enterococcus"), c(DAP, LNZ, TGC, TEC), "any") trans_tbl(3, - which(tbl_$fullname %like% "^Enterococcus faecalis"), + which(x$fullname %like% "^Enterococcus faecalis"), c(AMP, AMX), "any") # Table 7 trans_tbl(3, - which(tbl_$genus == "Bacteroides"), + which(x$genus == "Bacteroides"), MTR, "any") trans_tbl(3, - which(tbl_$fullname %like% "^Clostridium difficile"), + which(x$fullname %like% "^Clostridium difficile"), c(MTR, VAN), "any") } - if (guideline$country$code == "de") { + if (guideline$code == "de") { # Germany ----------------------------------------------------------------- stop("We are still working on German guidelines in this beta version.", call. = FALSE) } - if (guideline$country$code == "nl") { + if (guideline$code == "nl") { # Netherlands ------------------------------------------------------------- aminoglycosides <- aminoglycosides[!is.na(aminoglycosides)] fluoroquinolones <- fluoroquinolones[!is.na(fluoroquinolones)] @@ -298,32 +353,32 @@ mdro <- function(x, # Table 1 trans_tbl(3, - which(tbl_$family == "Enterobacteriaceae"), + which(x$family == "Enterobacteriaceae"), c(aminoglycosides, fluoroquinolones), "all") trans_tbl(2, - which(tbl_$family == "Enterobacteriaceae"), + which(x$family == "Enterobacteriaceae"), carbapenems, "any") trans_tbl(2, - which(tbl_$family == "Enterobacteriaceae"), + which(x$family == "Enterobacteriaceae"), ESBLs, "all") # Table 2 trans_tbl(2, - which(tbl_$genus == "Acinetobacter"), + which(x$genus == "Acinetobacter"), c(carbapenems), "any") trans_tbl(3, - which(tbl_$genus == "Acinetobacter"), + which(x$genus == "Acinetobacter"), c(aminoglycosides, fluoroquinolones), "all") trans_tbl(3, - which(tbl_$fullname %like% "^Stenotrophomonas maltophilia"), + which(x$fullname %like% "^Stenotrophomonas maltophilia"), SXT, "all") @@ -332,39 +387,108 @@ mdro <- function(x, & !ab_missing(CIP) & !ab_missing(CAZ) & !ab_missing(TZP) ) { - tbl_$psae <- 0 - tbl_[which(tbl_[, MEM] == "R" | tbl_[, IPM] == "R"), "psae"] <- 1 + tbl_[which(tbl_[, MEM] == "R" | tbl_[, IPM] == "R"), "psae"] - tbl_[which(tbl_[, GEN] == "R" & tbl_[, TOB] == "R"), "psae"] <- 1 + tbl_[which(tbl_[, GEN] == "R" & tbl_[, TOB] == "R"), "psae"] - tbl_[which(tbl_[, CIP] == "R"), "psae"] <- 1 + tbl_[which(tbl_[, CIP] == "R"), "psae"] - tbl_[which(tbl_[, CAZ] == "R"), "psae"] <- 1 + tbl_[which(tbl_[, CAZ] == "R"), "psae"] - tbl_[which(tbl_[, TZP] == "R"), "psae"] <- 1 + tbl_[which(tbl_[, TZP] == "R"), "psae"] + x$psae <- 0 + x[which(x[, MEM] == "R" | x[, IPM] == "R"), "psae"] <- 1 + x[which(x[, MEM] == "R" | x[, IPM] == "R"), "psae"] + x[which(x[, GEN] == "R" & x[, TOB] == "R"), "psae"] <- 1 + x[which(x[, GEN] == "R" & x[, TOB] == "R"), "psae"] + x[which(x[, CIP] == "R"), "psae"] <- 1 + x[which(x[, CIP] == "R"), "psae"] + x[which(x[, CAZ] == "R"), "psae"] <- 1 + x[which(x[, CAZ] == "R"), "psae"] + x[which(x[, TZP] == "R"), "psae"] <- 1 + x[which(x[, TZP] == "R"), "psae"] } else { - tbl_$psae <- 0 + x$psae <- 0 } - tbl_[which( - tbl_$fullname %like% "Pseudomonas aeruginosa" - & tbl_$psae >= 3 + x[which( + x$fullname %like% "Pseudomonas aeruginosa" + & x$psae >= 3 ), "MDRO"] <- 3 # Table 3 trans_tbl(3, - which(tbl_$fullname %like% "Streptococcus pneumoniae"), + which(x$fullname %like% "Streptococcus pneumoniae"), PEN, "all") trans_tbl(3, - which(tbl_$fullname %like% "Streptococcus pneumoniae"), + which(x$fullname %like% "Streptococcus pneumoniae"), VAN, "all") trans_tbl(3, - which(tbl_$fullname %like% "Enterococcus faecium"), + which(x$fullname %like% "Enterococcus faecium"), c(PEN, VAN), "all") } - factor(x = tbl_$MDRO, - levels = 1:3, - labels = c("Negative", "Positive, unconfirmed", "Positive"), - ordered = TRUE) + prepare_drug <- function(ab) { + # returns vector values of drug + # if `ab` is a column name, looks up the values in `x` + if (length(ab) == 1 & is.character(ab)) { + if (ab %in% colnames(x)) { + ab <- as.data.frame(x)[, ab] + } + } + ab <- as.character(as.rsi(ab)) + ab[is.na(ab)] <- "" + ab + } + drug_is_R <- function(ab) { + # returns logical vector + ab <- prepare_drug(ab) + if (length(ab) == 1) { + rep(ab, NROW(x)) == "R" + } else { + ab == "R" + } + } + drug_is_not_R <- function(ab) { + # returns logical vector + ab <- prepare_drug(ab) + if (length(ab) == 1) { + rep(ab, NROW(x)) != "R" + } else { + ab != "R" + } + } + + if (guideline$code == "tb") { + # Tuberculosis ------------------------------------------------------------ + x <- x %>% + mutate(mono_count = 0, + mono_count = ifelse(drug_is_R(INH), mono_count + 1, mono_count), + mono_count = ifelse(drug_is_R(RIF), mono_count + 1, mono_count), + mono_count = ifelse(drug_is_R(ETH), mono_count + 1, mono_count), + mono_count = ifelse(drug_is_R(PZA), mono_count + 1, mono_count), + mono_count = ifelse(drug_is_R(RIB), mono_count + 1, mono_count), + mono_count = ifelse(drug_is_R(RFP), mono_count + 1, mono_count), + # from here on logicals + mono = mono_count > 0, + poly = ifelse(mono_count > 1 & drug_is_not_R(RIF) & drug_is_not_R(INH), + TRUE, FALSE), + mdr = ifelse(drug_is_R(RIF) & drug_is_R(INH), + TRUE, FALSE), + xdr = ifelse(drug_is_R(LVX) | drug_is_R(MFX) | drug_is_R(GAT), + TRUE, FALSE), + second = ifelse(drug_is_R(CAP) | drug_is_R(KAN) | drug_is_R(AMK), + TRUE, FALSE), + xdr = ifelse(mdr & xdr & second, TRUE, FALSE)) %>% + mutate(mdr_tb = case_when(xdr ~ 5, + mdr ~ 4, + poly ~ 3, + mono ~ 2, + TRUE ~ 1), + # keep all real TB, make other species NA + mdr_tb = ifelse(x$fullname == "Mycobacterium tuberculosis", mdr_tb, NA_real_)) + } + + # return results + if (guideline$code == "tb") { + factor(x = x$mdr_tb, + levels = 1:5, + labels = c("Negative", "Mono-resistance", "Poly-resistance", "Multidrug resistance", "Extensive drug resistance"), + ordered = TRUE) + } else { + factor(x = x$MDRO, + levels = 1:3, + labels = c("Negative", "Positive, unconfirmed", "Positive"), + ordered = TRUE) + } } #' @rdname mdro @@ -381,6 +505,12 @@ mrgn <- function(x, country = "de", ...) { #' @rdname mdro #' @export -eucast_exceptional_phenotypes <- function(x, country = "EUCAST", ...) { - mdro(x = x, country = "EUCAST", ...) +mdr_tb <- function(x, guideline = "TB", ...) { + mdro(x = x, guideline = "TB", ...) +} + +#' @rdname mdro +#' @export +eucast_exceptional_phenotypes <- function(x, guideline = "EUCAST", ...) { + mdro(x = x, guideline = "EUCAST", ...) } diff --git a/R/misc.R b/R/misc.R index 8c4eb0f8..0dab33fb 100755 --- a/R/misc.R +++ b/R/misc.R @@ -87,43 +87,43 @@ percent <- function(x, round = 1, force_zero = FALSE, decimal.mark = getOption(" #' @importFrom crayon blue bold red #' @importFrom dplyr %>% pull -search_type_in_df <- function(tbl, type) { +search_type_in_df <- function(x, type) { # try to find columns based on type found <- NULL - colnames(tbl) <- trimws(colnames(tbl)) + colnames(x) <- trimws(colnames(x)) # -- mo if (type == "mo") { - if ("mo" %in% lapply(tbl, class)) { - found <- colnames(tbl)[lapply(tbl, class) == "mo"][1] - } else if (any(colnames(tbl) %like% "^(mo|microorganism|organism|bacteria)")) { - found <- colnames(tbl)[colnames(tbl) %like% "^(mo|microorganism|organism|bacteria)"][1] - } else if (any(colnames(tbl) %like% "species")) { - found <- colnames(tbl)[colnames(tbl) %like% "species"][1] + if ("mo" %in% lapply(x, class)) { + found <- colnames(x)[lapply(x, class) == "mo"][1] + } else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria)s?$")) { + found <- colnames(x)[colnames(x) %like% "^(mo|microorganism|organism|bacteria)s?$"][1] + } else if (any(colnames(x) %like% "species")) { + found <- colnames(x)[colnames(x) %like% "species"][1] } } # -- key antibiotics if (type == "keyantibiotics") { - if (any(colnames(tbl) %like% "^key.*(ab|antibiotics)")) { - found <- colnames(tbl)[colnames(tbl) %like% "^key.*(ab|antibiotics)"][1] + if (any(colnames(x) %like% "^key.*(ab|antibiotics)")) { + found <- colnames(x)[colnames(x) %like% "^key.*(ab|antibiotics)"][1] } } # -- date if (type == "date") { - if (any(colnames(tbl) %like% "^(specimen date|specimen_date|spec_date)")) { + if (any(colnames(x) %like% "^(specimen date|specimen_date|spec_date)")) { # WHONET support - found <- colnames(tbl)[colnames(tbl) %like% "^(specimen date|specimen_date|spec_date)"][1] - if (!any(class(tbl %>% pull(found)) %in% c("Date", "POSIXct"))) { + found <- colnames(x)[colnames(x) %like% "^(specimen date|specimen_date|spec_date)"][1] + if (!any(class(x %>% pull(found)) %in% c("Date", "POSIXct"))) { stop(red(paste0("ERROR: Found column `", bold(found), "` to be used as input for `col_", type, "`, but this column contains no valid dates. Transform its values to valid dates first.")), call. = FALSE) } } else { - for (i in 1:ncol(tbl)) { - if (any(class(tbl %>% pull(i)) %in% c("Date", "POSIXct"))) { - found <- colnames(tbl)[i] + for (i in 1:ncol(x)) { + if (any(class(x %>% pull(i)) %in% c("Date", "POSIXct"))) { + found <- colnames(x)[i] break } } @@ -131,16 +131,16 @@ search_type_in_df <- function(tbl, type) { } # -- patient id if (type == "patient_id") { - if (any(colnames(tbl) %like% "^(identification |patient|patid)")) { - found <- colnames(tbl)[colnames(tbl) %like% "^(identification |patient|patid)"][1] + if (any(colnames(x) %like% "^(identification |patient|patid)")) { + found <- colnames(x)[colnames(x) %like% "^(identification |patient|patid)"][1] } } # -- specimen if (type == "specimen") { - if (any(colnames(tbl) %like% "(specimen type|spec_type)")) { - found <- colnames(tbl)[colnames(tbl) %like% "(specimen type|spec_type)"][1] - } else if (any(colnames(tbl) %like% "^(specimen)")) { - found <- colnames(tbl)[colnames(tbl) %like% "^(specimen)"][1] + if (any(colnames(x) %like% "(specimen type|spec_type)")) { + found <- colnames(x)[colnames(x) %like% "(specimen type|spec_type)"][1] + } else if (any(colnames(x) %like% "^(specimen)")) { + found <- colnames(x)[colnames(x) %like% "^(specimen)"][1] } } diff --git a/R/portion.R b/R/portion.R index 9d94f80f..a11d3990 100755 --- a/R/portion.R +++ b/R/portion.R @@ -31,7 +31,7 @@ #' @param data a \code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}}) #' @param translate_ab a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations to, using \code{\link{ab_property}} #' @inheritParams ab_property -#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}. +#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}. #' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}. #' @inheritSection as.rsi Interpretation of S, I and R #' @details \strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set. diff --git a/R/resistance_predict.R b/R/resistance_predict.R index 00b42277..7b344346 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -140,7 +140,7 @@ resistance_predict <- function(x, # -- date if (is.null(col_date)) { - col_date <- search_type_in_df(tbl = x, type = "date") + col_date <- search_type_in_df(x = x, type = "date") } if (is.null(col_date)) { stop("`col_date` must be set.", call. = FALSE) diff --git a/R/rsi.R b/R/rsi.R index d62f21cf..c0f83de4 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -39,9 +39,9 @@ #' In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". #' #' \itemize{ -#' \item{\strong{S}}{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} -#' \item{\strong{I}}{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} -#' \item{\strong{R}}{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} +#' \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} +#' \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} +#' \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} #' } #' #' Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. @@ -259,9 +259,9 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) { #' @importFrom crayon red blue #' @export as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) { - tbl_ <- x + x <- x - ab_cols <- colnames(tbl_)[sapply(tbl_, function(x) is.mic(x) | is.disk(x))] + ab_cols <- colnames(x)[sapply(x, function(y) is.mic(y) | is.disk(y))] if (length(ab_cols) == 0) { stop("No columns with MIC values or disk zones found in this data set. Use as.mic or as.disk to transform antibiotic columns.", call. = FALSE) } @@ -269,14 +269,14 @@ as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) { # try to find columns based on type # -- mo if (is.null(col_mo)) { - col_mo <- search_type_in_df(tbl = tbl_, type = "mo") + col_mo <- search_type_in_df(x = x, type = "mo") } if (is.null(col_mo)) { stop("`col_mo` must be set.", call. = FALSE) } # transform all MICs - ab_cols <- colnames(tbl_)[sapply(tbl_, is.mic)] + ab_cols <- colnames(x)[sapply(x, is.mic)] if (length(ab_cols) > 0) { for (i in 1:length(ab_cols)) { if (is.na(suppressWarnings(as.ab(ab_cols[i])))) { @@ -284,16 +284,16 @@ as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) { next } message(blue(paste0("Interpreting column `", bold(ab_cols[i]), "` (", ab_name(ab_cols[i], tolower = TRUE), ")...")), appendLF = FALSE) - tbl_[, ab_cols[i]] <- exec_as.rsi(method = "mic", - x = tbl_ %>% pull(ab_cols[i]), - mo = tbl_ %>% pull(col_mo), + x[, ab_cols[i]] <- exec_as.rsi(method = "mic", + x = x %>% pull(ab_cols[i]), + mo = x %>% pull(col_mo), ab = as.ab(ab_cols[i]), guideline = guideline) message(blue(" OK.")) } } # transform all disks - ab_cols <- colnames(tbl_)[sapply(tbl_, is.disk)] + ab_cols <- colnames(x)[sapply(x, is.disk)] if (length(ab_cols) > 0) { for (i in 1:length(ab_cols)) { if (is.na(suppressWarnings(as.ab(ab_cols[i])))) { @@ -301,16 +301,16 @@ as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) { next } message(blue(paste0("Interpreting column `", bold(ab_cols[i]), "` (", ab_name(ab_cols[i], tolower = TRUE), ")...")), appendLF = FALSE) - tbl_[, ab_cols[i]] <- exec_as.rsi(method = "disk", - x = tbl_ %>% pull(ab_cols[i]), - mo = tbl_ %>% pull(col_mo), + x[, ab_cols[i]] <- exec_as.rsi(method = "disk", + x = x %>% pull(ab_cols[i]), + mo = x %>% pull(col_mo), ab = as.ab(ab_cols[i]), guideline = guideline) message(blue(" OK.")) } } - tbl_ + x } #' @rdname as.rsi diff --git a/_pkgdown.yml b/_pkgdown.yml index ebe89a1b..cf1f13f6 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -38,6 +38,9 @@ navbar: - text: 'Predict antimicrobial resistance' icon: 'fa-dice' href: 'articles/resistance_predict.html' + - text: 'Determine multi-drug resistance (MDR)' + icon: 'fa-skull-crossbones' + href: 'articles/MDR.html' - text: 'Work with WHONET data' icon: 'fa-globe-americas' href: 'articles/WHONET.html' diff --git a/data/antibiotics.rda b/data/antibiotics.rda index 14248d0e..4b6213b4 100755 Binary files a/data/antibiotics.rda and b/data/antibiotics.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index f314972c..fe103ca0 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -114,6 +114,13 @@ Predict antimicrobial resistance +
  • + + + + Determine multi-drug resistance (MDR) + +
  • diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 43dbe901..125f9a2e 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to conduct AMR analysis

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    @@ -201,7 +208,7 @@ -

    Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 20 May 2019.

    +

    Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 23 May 2019.

    Introduction

    @@ -217,21 +224,21 @@ -2019-05-20 +2019-05-23 abcd Escherichia coli S S -2019-05-20 +2019-05-23 abcd Escherichia coli S R -2019-05-20 +2019-05-23 efgh Escherichia coli R @@ -327,66 +334,66 @@ -2013-08-26 -Q7 -Hospital A +2012-10-26 +T6 +Hospital D Staphylococcus aureus -S -S +R +R S S F -2012-10-04 +2011-10-13 +Y4 +Hospital B +Streptococcus pneumoniae +R +S +S +S +F + + +2010-02-09 O2 -Hospital A -Escherichia coli +Hospital B +Streptococcus pneumoniae R S S S F - -2012-10-23 -C4 -Hospital C -Escherichia coli -S -I -S -S -M - -2011-08-17 -R4 +2010-09-18 +T5 Hospital B Escherichia coli -R S -R +S +S S F -2016-01-18 -L2 -Hospital B -Escherichia coli -S +2017-07-26 +J10 +Hospital D +Staphylococcus aureus +R S S S M -2011-09-06 -O1 -Hospital A -Escherichia coli -R +2015-09-19 +P5 +Hospital D +Streptococcus pneumoniae +S S S S @@ -411,8 +418,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,378 51.9% 10,378 51.9% -# 2 F 9,622 48.1% 20,000 100.0% +# 1 M 10,310 51.6% 10,310 51.6% +# 2 F 9,690 48.4% 20,000 100.0%

    So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M and F. From a researcher perspective: there are slightly more men. Nothing we didn’t already know.

    The data is already quite clean, but we still need to transform some variables. The bacteria column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate() function of the dplyr package makes this really easy:

    data <- data %>%
    @@ -442,14 +449,14 @@
     # Pasteurella multocida (no new changes)
     # Staphylococcus (no new changes)
     # Streptococcus groups A, B, C, G (no new changes)
    -# Streptococcus pneumoniae (1443 new changes)
    +# Streptococcus pneumoniae (1542 new changes)
     # Viridans group streptococci (no new changes)
     # 
     # EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
    -# Table 01: Intrinsic resistance in Enterobacteriaceae (1303 new changes)
    +# Table 01: Intrinsic resistance in Enterobacteriaceae (1286 new changes)
     # Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no new changes)
     # Table 03: Intrinsic resistance in other Gram-negative bacteria (no new changes)
    -# Table 04: Intrinsic resistance in Gram-positive bacteria (2746 new changes)
    +# Table 04: Intrinsic resistance in Gram-positive bacteria (2788 new changes)
     # Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no new changes)
     # Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no new changes)
     # Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no new changes)
    @@ -457,24 +464,24 @@
     # Table 13: Interpretive rules for quinolones (no new changes)
     # 
     # Other rules
    -# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2313 new changes)
    -# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (115 new changes)
    +# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2231 new changes)
    +# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (126 new changes)
     # Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no new changes)
     # Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no new changes)
     # Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no new changes)
     # Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no new changes)
     # 
     # --------------------------------------------------------------------------
    -# EUCAST rules affected 6,579 out of 20,000 rows, making a total of 7,920 edits
    +# EUCAST rules affected 6,562 out of 20,000 rows, making a total of 7,973 edits
     # => added 0 test results
     # 
    -# => changed 7,920 test results
    -#    - 123 test results changed from S to I
    -#    - 4,680 test results changed from S to R
    -#    - 1,131 test results changed from I to S
    -#    - 306 test results changed from I to R
    -#    - 1,657 test results changed from R to S
    -#    - 23 test results changed from R to I
    +# => changed 7,973 test results
    +#    - 114 test results changed from S to I
    +#    - 4,779 test results changed from S to R
    +#    - 1,118 test results changed from I to S
    +#    - 330 test results changed from I to R
    +#    - 1,606 test results changed from R to S
    +#    - 26 test results changed from R to I
     # --------------------------------------------------------------------------
     # 
     # Use verbose = TRUE to get a data.frame with all specified edits instead.
    @@ -502,8 +509,8 @@ # NOTE: Using column `bacteria` as input for `col_mo`. # NOTE: Using column `date` as input for `col_date`. # NOTE: Using column `patient_id` as input for `col_patient_id`. -# => Found 5,674 first isolates (28.4% of total)
    -

    So only 28.4% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

    +# => Found 5,699 first isolates (28.5% of total) +

    So only 28.5% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

    data_1st <- data %>% 
       filter(first == TRUE)

    For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

    @@ -529,8 +536,8 @@ 1 -2010-03-19 -N8 +2010-04-13 +S1 B_ESCHR_COL S S @@ -540,10 +547,10 @@ 2 -2010-05-06 -N8 +2010-06-02 +S1 B_ESCHR_COL -R +S S S S @@ -551,43 +558,43 @@ 3 -2010-05-20 -N8 +2010-07-21 +S1 B_ESCHR_COL +I +S R S -S -S FALSE 4 -2010-07-20 -N8 +2010-09-19 +S1 B_ESCHR_COL +R S -S -S +R S FALSE 5 -2010-09-04 -N8 +2010-09-19 +S1 B_ESCHR_COL S S S -S +R FALSE 6 -2010-09-13 -N8 +2010-10-14 +S1 B_ESCHR_COL -R +S S S S @@ -595,19 +602,19 @@ 7 -2011-04-01 -N8 +2010-10-28 +S1 B_ESCHR_COL S S S S -TRUE +FALSE 8 -2011-10-15 -N8 +2010-12-09 +S1 B_ESCHR_COL R S @@ -617,8 +624,8 @@ 9 -2011-11-14 -N8 +2010-12-15 +S1 B_ESCHR_COL S S @@ -628,18 +635,18 @@ 10 -2012-02-11 -N8 +2011-01-07 +S1 B_ESCHR_COL -S -S +R +I S S FALSE -

    Only 2 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

    +

    Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

    If a column exists with a name like ‘key(…)ab’ the first_isolate() function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:

    data <- data %>% 
       mutate(keyab = key_antibiotics(.)) %>% 
    @@ -650,7 +657,7 @@
     # NOTE: Using column `patient_id` as input for `col_patient_id`.
     # NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
     # [Criterion] Inclusion based on key antibiotics, ignoring I.
    -# => Found 14,968 first weighted isolates (74.8% of total)
    +# => Found 15,125 first weighted isolates (75.6% of total) @@ -667,8 +674,8 @@ - - + + @@ -679,58 +686,58 @@ - - + + - + - + - - + + + + - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + + + + + + + + + - - + + - + @@ -739,20 +746,20 @@ - - + + - - + + - - + + @@ -763,8 +770,8 @@ - - + + @@ -775,23 +782,23 @@ - - + + - - + + - +
    isolate
    12010-03-19N82010-04-13S1 B_ESCHR_COL S S
    22010-05-06N82010-06-02S1 B_ESCHR_COLRS S S S FALSETRUEFALSE
    32010-05-20N82010-07-21S1 B_ESCHR_COLIS R SSSFALSEFALSE
    42010-07-20N8B_ESCHR_COLSSSS FALSE TRUE
    52010-09-04N8
    42010-09-19S1 B_ESCHR_COLR SSSR S FALSE FALSE
    52010-09-19S1B_ESCHR_COLSSSRFALSETRUE
    62010-09-13N82010-10-14S1 B_ESCHR_COLRS S S S
    72011-04-01N82010-10-28S1 B_ESCHR_COL S S S STRUETRUEFALSEFALSE
    82011-10-15N82010-12-09S1 B_ESCHR_COL R S
    92011-11-14N82010-12-15S1 B_ESCHR_COL S S
    102012-02-11N82011-01-07S1 B_ESCHR_COLSSRI S S FALSEFALSETRUE
    -

    Instead of 2, now 7 isolates are flagged. In total, 74.8% of all isolates are marked ‘first weighted’ - 46.5% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

    +

    Instead of 1, now 7 isolates are flagged. In total, 75.6% of all isolates are marked ‘first weighted’ - 47.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

    As with filter_first_isolate(), there’s a shortcut for this new algorithm too:

    data_1st <- data %>% 
       filter_first_weighted_isolate()
    -

    So we end up with 14,968 isolates for analysis.

    +

    So we end up with 15,125 isolates for analysis.

    We can remove unneeded columns:

    data_1st <- data_1st %>% 
       select(-c(first, keyab))
    @@ -799,6 +806,7 @@
    head(data_1st)
    + @@ -815,12 +823,13 @@ - - - + + + + - - + + @@ -830,9 +839,58 @@ - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -844,60 +902,16 @@ - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -921,9 +935,9 @@
    freq(paste(data_1st$genus, data_1st$species))

    Or can be used like the dplyr way, which is easier readable:

    data_1st %>% freq(genus, species)
    -

    Frequency table of genus and species from a data.frame (14,968 x 13)

    +

    Frequency table of genus and species from a data.frame (15,125 x 13)

    Columns: 2
    -Length: 14,968 (of which NA: 0 = 0.00%)
    +Length: 15,125 (of which NA: 0 = 0.00%)
    Unique: 4

    Shortest: 16
    Longest: 24

    @@ -940,33 +954,33 @@ Longest: 24

    - - - - + + + + - - - + + + - - - - + + + + - - - + + + @@ -977,7 +991,7 @@ Longest: 24

    Resistance percentages

    The functions portion_S(), portion_SI(), portion_I(), portion_IR() and portion_R() can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()) and susceptibility as the portion of S and I (portion_SI()). These functions can be used on their own:

    data_1st %>% portion_R(AMX)
    -# [1] 0.4659941
    +# [1] 0.4628099

    Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

    data_1st %>% 
       group_by(hospital) %>% 
    @@ -990,19 +1004,19 @@ Longest: 24

    - + - + - + - +
    date patient_id hospital
    2013-08-26Q7Hospital A12012-10-26T6Hospital D B_STPHY_AURSSRR S S FTRUE
    2012-10-0422011-10-13Y4Hospital BB_STRPT_PNERRSRFGram positiveStreptococcuspneumoniaeTRUE
    32010-02-09 O2Hospital AHospital BB_STRPT_PNERRSRFGram positiveStreptococcuspneumoniaeTRUE
    62015-09-19P5Hospital DB_STRPT_PNESSSRFGram positiveStreptococcuspneumoniaeTRUE
    72011-05-13X5Hospital B B_ESCHR_COL R Scoli TRUE
    2012-10-23C4
    82015-03-07Z7 Hospital C B_ESCHR_COL S SSSMGram negativeEscherichiacoliTRUE
    2011-08-17R4Hospital BB_ESCHR_COL R SRSFGram negativeEscherichiacoliTRUE
    2016-01-18L2Hospital BB_ESCHR_COLSSSSMGram negativeEscherichiacoliTRUE
    2011-09-06O1Hospital AB_ESCHR_COLRSSS F Gram negative Escherichia
    1 Escherichia coli7,39449.4%7,39449.4%7,48649.5%7,48649.5%
    2 Staphylococcus aureus3,71624.8%11,1103,73124.7%11,217 74.2%
    3 Streptococcus pneumoniae2,29115.3%13,40189.5%2,36015.6%13,57789.8%
    4 Klebsiella pneumoniae1,56710.5%14,9681,54810.2%15,125 100.0%
    Hospital A0.47085400.4556355
    Hospital B0.46175850.4661553
    Hospital C0.46220300.4759657
    Hospital D0.46916890.4577347
    @@ -1020,23 +1034,23 @@ Longest: 24

    Hospital A -0.4708540 -4426 +0.4556355 +4587 Hospital B -0.4617585 -5243 +0.4661553 +5215 Hospital C -0.4622030 -2315 +0.4759657 +2330 Hospital D -0.4691689 -2984 +0.4577347 +2993 @@ -1056,27 +1070,27 @@ Longest: 24

    Escherichia -0.9249391 -0.8991074 -0.9935082 +0.9226556 +0.8966070 +0.9941224 Klebsiella -0.8162093 -0.9119336 -0.9910657 +0.8113695 +0.9102067 +0.9909561 Staphylococcus -0.9179225 -0.9198062 -0.9916577 +0.9187885 +0.9193246 +0.9949075 Streptococcus -0.6294195 +0.6152542 0.0000000 -0.6294195 +0.6152542 diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index dcc9a169..9a180f49 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 21f93a78..90452215 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 0003b4a2..49e0a370 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 8eb926cf..046f85ef 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/EUCAST.html b/docs/articles/EUCAST.html index d99e246f..dbf906e3 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to apply EUCAST rules

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index 929930c9..f4f51f2e 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -40,7 +40,7 @@
    AMR (for R) - 0.6.1.9003 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to use the G-test

    Matthijs S. Berends

    -

    17 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/MDR.html b/docs/articles/MDR.html new file mode 100644 index 00000000..a9bbdf47 --- /dev/null +++ b/docs/articles/MDR.html @@ -0,0 +1,323 @@ + + + + + + + +How to determine multi-drug resistance (MDR) • AMR (for R) + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    With the function mdro(), you can determine multi-drug resistant organisms (MDRO). It currently support these guidelines:

    +
      +
    • “Intrinsic Resistance and Exceptional Phenotypes Tables”, by EUCAST (European Committee on Antimicrobial Susceptibility Testing)
    • +
    • “Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis”, by WHO (World Health Organization)
    • +
    • “WIP-Richtlijn Bijzonder Resistente Micro-organismen (BRMO)”, by RIVM (Rijksinstituut voor de Volksgezondheid, the Netherlands National Institute for Public Health and the Environment)
    • +
    +

    As an example, I will make a data set to determine multi-drug resistant TB:

    + +

    Because all column names are automatically verified for valid drug names or codes, this would have worked exactly the same:

    + +

    The data set looks like this now:

    + +

    We can now add the interpretation of MDR-TB to our data set:

    + +

    And review the result with a frequency table:

    + +
    + + + +
    + + + +
    + + + + + diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html index 9f4476b1..f6e40a30 100644 --- a/docs/articles/SPSS.html +++ b/docs/articles/SPSS.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to import data from SPSS / SAS / Stata

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index 21f15619..8a94dba1 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -40,7 +40,7 @@
    AMR (for R) - 0.6.1.9003 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to work with WHONET data

    Matthijs S. Berends

    -

    17 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/ab_property.html b/docs/articles/ab_property.html index 531f999c..37f82f35 100644 --- a/docs/articles/ab_property.html +++ b/docs/articles/ab_property.html @@ -40,7 +40,7 @@
    AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to get properties of an antibiotic

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index fcd9387c..4e1f3989 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@
    AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    Benchmarks

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    @@ -217,14 +224,14 @@
    times = 10) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq max neval -# as.mo("sau") 18 18 22.0 18 18.0 62.0 10 -# as.mo("stau") 47 47 57.0 48 50.0 92.0 10 -# as.mo("staaur") 17 18 23.0 18 19.0 62.0 10 -# as.mo("STAAUR") 17 17 18.0 17 18.0 23.0 10 -# as.mo("S. aureus") 28 28 38.0 29 29.0 78.0 10 -# as.mo("S. aureus") 28 28 48.0 29 73.0 130.0 10 -# as.mo("Staphylococcus aureus") 8 8 8.1 8 8.1 8.2 10
    +# expr min lq mean median uq max neval +# as.mo("sau") 17.0 18 32.0 18 62.0 68.0 10 +# as.mo("stau") 48.0 48 64.0 53 92.0 96.0 10 +# as.mo("staaur") 17.0 18 18.0 18 18.0 19.0 10 +# as.mo("STAAUR") 17.0 17 18.0 18 18.0 20.0 10 +# as.mo("S. aureus") 28.0 28 33.0 29 29.0 73.0 10 +# as.mo("S. aureus") 28.0 28 44.0 28 29.0 140.0 10 +# as.mo("Staphylococcus aureus") 7.9 8 8.1 8 8.2 8.2 10

    In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.

    To achieve this speed, the as.mo function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISL), a bug probably never found before in humans:

    T.islandicus <- microbenchmark(as.mo("theisl"),
    @@ -236,12 +243,12 @@
     print(T.islandicus, unit = "ms", signif = 2)
     # Unit: milliseconds
     #                         expr min  lq mean median  uq max neval
    -#              as.mo("theisl") 470 480  510    520 530 530    10
    -#              as.mo("THEISL") 470 470  500    490 520 530    10
    -#       as.mo("T. islandicus")  74  75   85     76  81 120    10
    -#      as.mo("T.  islandicus")  74  75   92     76 120 140    10
    -#  as.mo("Thermus islandicus")  73  73   74     74  74  75    10
    -

    That takes 8.2 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.

    +# as.mo("theisl") 470 470 500 500 520 520 10 +# as.mo("THEISL") 470 470 510 520 520 530 10 +# as.mo("T. islandicus") 73 74 79 74 74 120 10 +# as.mo("T. islandicus") 73 74 84 74 75 130 10 +# as.mo("Thermus islandicus") 74 74 94 75 120 140 10 +

    That takes 8.1 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.

    In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is very uncommon):

    par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
     
    @@ -287,8 +294,8 @@
     print(run_it, unit = "ms", signif = 3)
     # Unit: milliseconds
     #            expr min  lq mean median  uq max neval
    -#  mo_fullname(x) 677 770  812    790 884 988    10
    -

    So transforming 500,000 values (!!) of 50 unique values only takes 0.79 seconds (789 ms). You only lose time on your unique input values.

    +# mo_fullname(x) 633 675 747 722 763 933 10 +

    So transforming 500,000 values (!!) of 50 unique values only takes 0.72 seconds (721 ms). You only lose time on your unique input values.

    @@ -300,10 +307,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) # Unit: milliseconds -# expr min lq mean median uq max neval -# A 12.9 13.20 13.30 13.40 13.50 13.50 10 -# B 25.3 25.80 30.40 25.80 26.20 71.60 10 -# C 1.3 1.37 1.56 1.67 1.73 1.74 10

    +# expr min lq mean median uq max neval +# A 12.90 13.1 18.0 13.20 14.10 59.1 10 +# B 25.20 25.3 26.2 26.10 27.00 27.4 10 +# C 1.25 1.4 1.6 1.68 1.69 1.9 10

    So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0017 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:

    run_it <- microbenchmark(A = mo_species("aureus"),
                              B = mo_genus("Staphylococcus"),
    @@ -317,14 +324,14 @@
     print(run_it, unit = "ms", signif = 3)
     # Unit: milliseconds
     #  expr   min    lq  mean median    uq   max neval
    -#     A 0.442 0.477 0.583  0.572 0.673 0.806    10
    -#     B 0.442 0.502 0.626  0.611 0.761 0.826    10
    -#     C 1.360 1.620 1.820  1.810 2.060 2.150    10
    -#     D 0.449 0.514 0.622  0.639 0.725 0.798    10
    -#     E 0.401 0.440 0.530  0.508 0.568 0.799    10
    -#     F 0.353 0.391 0.502  0.494 0.635 0.695    10
    -#     G 0.451 0.559 0.595  0.609 0.646 0.747    10
    -#     H 0.191 0.278 0.395  0.376 0.528 0.653    10
    +# A 0.357 0.374 0.447 0.435 0.514 0.567 10 +# B 0.404 0.507 0.541 0.533 0.575 0.755 10 +# C 1.350 1.400 1.700 1.720 1.890 2.150 10 +# D 0.416 0.550 0.589 0.603 0.632 0.750 10 +# E 0.400 0.480 0.559 0.541 0.667 0.737 10 +# F 0.346 0.384 0.493 0.498 0.628 0.643 10 +# G 0.393 0.421 0.486 0.430 0.570 0.620 10 +# H 0.258 0.280 0.332 0.290 0.377 0.508 10

    Of course, when running mo_phylum("Firmicutes") the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes" too, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.

    @@ -351,13 +358,13 @@ print(run_it, unit = "ms", signif = 4) # Unit: milliseconds # expr min lq mean median uq max neval -# en 18.16 18.23 22.82 18.29 18.57 63.28 10 -# de 23.00 23.09 23.35 23.21 23.59 23.96 10 -# nl 36.60 36.74 37.00 36.97 37.32 37.41 10 -# es 23.10 23.15 23.40 23.29 23.63 23.97 10 -# it 23.04 23.14 23.28 23.27 23.43 23.58 10 -# fr 23.13 23.21 33.12 23.90 28.96 68.96 10 -# pt 22.98 23.16 23.37 23.44 23.51 23.65 10
    +# en 18.10 18.20 18.30 18.25 18.38 18.57 10 +# de 23.06 23.14 32.22 23.21 23.48 68.37 10 +# nl 36.30 36.40 41.09 36.59 36.85 81.13 10 +# es 22.85 23.07 23.24 23.20 23.46 23.72 10 +# it 22.92 22.99 27.72 23.17 23.61 68.07 10 +# fr 23.02 23.14 27.79 23.23 23.58 68.27 10 +# pt 23.00 23.09 23.24 23.19 23.45 23.52 10

    Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.

    diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index f1fd99d1..924101ae 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/freq.html b/docs/articles/freq.html index 5694c455..6fc26e20 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9003 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to create frequency tables

    Matthijs S. Berends

    -

    17 May 2019

    +

    23 May 2019

    @@ -714,7 +721,7 @@ Median: 31 July 2009 (47.39%)

    Assigning a frequency table to an object

    -

    A frequency table is actaually a regular data.frame, with the exception that it contains an additional class.

    +

    A frequency table is actually a regular data.frame, with the exception that it contains an additional class.

    [1] “frequency_tbl” “data.frame”

    @@ -729,7 +736,7 @@ Median: 31 July 2009 (47.39%)

    Parameter na.rm

    -

    With the na.rm parameter (defaults to TRUE, but they will always be shown into the header), you can include NA values in the frequency table:

    +

    With the na.rm parameter you can remove NA values from the frequency table (defaults to TRUE, but the number of NA values will always be shown into the header):

    septic_patients %>%
       freq(AMX, na.rm = FALSE)

    Frequency table of AMX from a data.frame (2,000 x 49)

    @@ -784,14 +791,68 @@ Group: Beta-lactams/penicillins
    +
    septic_patients %>%
    +  freq(AMX, na.rm = FALSE)
    +

    Frequency table of AMX from a data.frame (2,000 x 49)

    +

    Class: factor > ordered > rsi (numeric)
    +Length: 2,000 (of which NA: 771 = 38.55%)
    +Levels: 3: S < I < R
    +Unique: 4

    +

    Drug: Amoxicillin (AMX, J01CA04)
    +Group: Beta-lactams/penicillins
    +%SI: 44.43%

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ItemCountPercentCum. CountCum. Percent
    1(NA)77138.6%77138.6%
    2R68334.2%1,45472.7%
    3S54327.2%1,99799.8%
    4I30.2%2,000100.0%

    Parameter row.names

    -

    The default frequency tables shows row indices. To remove them, use row.names = FALSE:

    -
    septic_patients %>%
    -  freq(hospital_id, row.names = FALSE)
    +

    A frequency table shows row indices. To remove them, use row.names = FALSE:

    +
    septic_patients %>%
    +  freq(hospital_id, row.names = FALSE)

    Frequency table of hospital_id from a data.frame (2,000 x 49)

    Class: factor (numeric)
    Length: 2,000 (of which NA: 0 = 0.00%)
    @@ -842,8 +903,8 @@ Unique: 4

    Parameter markdown

    The markdown parameter is TRUE at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless nmax is set.

    -
    septic_patients %>%
    -  freq(hospital_id, markdown = TRUE)
    +
    septic_patients %>%
    +  freq(hospital_id, markdown = TRUE)

    Frequency table of hospital_id from a data.frame (2,000 x 49)

    Class: factor (numeric)
    Length: 2,000 (of which NA: 0 = 0.00%)
    diff --git a/docs/articles/index.html b/docs/articles/index.html index 1ce938da..d552f329 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035

    @@ -114,6 +114,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -239,6 +246,7 @@
  • How to conduct AMR analysis
  • How to apply EUCAST rules
  • How to use the *G*-test
  • +
  • How to determine multi-drug resistance (MDR)
  • How to import data from SPSS / SAS / Stata
  • How to work with WHONET data
  • How to get properties of an antibiotic
  • diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index bc2daca7..03c689bc 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to get properties of a microorganism

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index 224ba3ba..da34c4a8 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -40,7 +40,7 @@
    AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -76,6 +76,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -192,7 +199,7 @@

    How to predict antimicrobial resistance

    Matthijs S. Berends

    -

    20 May 2019

    +

    23 May 2019

    diff --git a/docs/authors.html b/docs/authors.html index e1b4b482..76a5d06d 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@
    AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -114,6 +114,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • diff --git a/docs/index.html b/docs/index.html index e7b5bbda..912a3c59 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -78,6 +78,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -202,19 +209,19 @@

    We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and is free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. Read the full license here.

    This package can be used for:

    This package is ready-to-use for a professional environment by specialists in the following fields:

    Medical Microbiology

    diff --git a/docs/news/index.html b/docs/news/index.html index ca6d8444..744bdd2d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -114,6 +114,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -232,9 +239,9 @@ -
    +

    -AMR 0.6.1.9001 Unreleased +AMR 0.6.1.90xx Unreleased

    Note: latest development version

    @@ -244,6 +251,7 @@
  • Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use as.rsi() on an MIC value (created with as.mic()), a disk diffusion value (created with the new as.disk()) or on a complete date set containing columns with MIC or disk diffusion values.
  • Function mo_name() as alias of mo_fullname()
  • +
  • Added guidelines of the WHO to determine mutli-drug resistance (MDR) for TB (mdr_tb()) and added a new vignette about MDR
  • @@ -259,7 +267,7 @@
  • Column cid contains the CID code (Compound ID), used by PubChem
  • -
  • Based on the Compound ID, more than a thousand official brand names have been added from many different countries
  • +
  • Based on the Compound ID, almost 5,000 official brand names have been added from many different countries
  • All references to antibiotics in our package now use EARS-Net codes, like AMX for amoxicillin
  • Functions atc_certe, ab_umcg and atc_trivial_nl have been removed
  • All atc_* functions are superceded by ab_* functions
  • @@ -275,7 +283,14 @@ Please create an issue in one of our repositories if you want additions in this
  • This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as ‘increased exposure’ and not ‘intermediate’ anymore. For functions like portion_df() and count_df() this means that their new parameter combine_SI is TRUE at default.
  • Removed deprecated functions guess_mo(), guess_atc(), EUCAST_rules(), interpretive_reading(), rsi()
  • -
  • Frequency tables of microbial IDs speed improvement
  • +
  • Frequency tables (freq()): + +
  • Removed all hardcoded EUCAST rules and replaced them with a new reference file: ./inst/eucast/eucast.tsv
  • Added ceftazidim intrinsic resistance to Streptococci @@ -1028,7 +1043,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

  • @@ -116,6 +116,13 @@ Predict antimicrobial resistance +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -245,7 +252,7 @@

    Format

    -

    A data.frame with 455 observations and 13 variables:

    +

    A data.frame with 454 observations and 13 variables:

    ab

    Antibiotic ID as used in this package (like AMC), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available

    atc

    ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like J01CR02

    cid

    Compound ID as found in PubChem

    diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html index d1046957..c3a6641a 100644 --- a/docs/reference/as.rsi.html +++ b/docs/reference/as.rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -116,6 +116,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -305,9 +312,9 @@

    In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".

      -
    • SSusceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • -
    • ISusceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • -
    • RResistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    • +
    • S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • +
    • I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • +
    • R - Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    Source: http://www.eucast.org/newsiandr/.

    diff --git a/docs/reference/count.html b/docs/reference/count.html index 343beaed..37d638bc 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -81,7 +81,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -117,6 +117,13 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -285,7 +292,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ combine_SI -

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now TRUE.

    +

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is TRUE.

    combine_IR @@ -312,9 +319,9 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_

    In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".

      -
    • SSusceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • -
    • ISusceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • -
    • RResistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    • +
    • S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • +
    • I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • +
    • R - Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    Source: http://www.eucast.org/newsiandr/.

    diff --git a/docs/reference/eucast_rules.html b/docs/reference/eucast_rules.html index 71aeb914..b516af56 100644 --- a/docs/reference/eucast_rules.html +++ b/docs/reference/eucast_rules.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -116,6 +116,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -290,7 +297,7 @@

    Value

    -

    The input of tbl_, possibly with edited values of antibiotics. Or, if verbose = TRUE, a data.frame with all original and new values of the affected bug-drug combinations.

    +

    The input of x, possibly with edited values of antibiotics. Or, if verbose = TRUE, a data.frame with all original and new values of the affected bug-drug combinations.

    Details

    diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index bb1d6dc5..e98045ed 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -116,6 +116,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -301,7 +308,7 @@ combine_SI -

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now TRUE.

    +

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is TRUE.

    combine_IR diff --git a/docs/reference/index.html b/docs/reference/index.html index a2b74a4d..da61e4ea 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@
    AMR (for R) - 0.6.1.9034 + 0.6.1.9035 @@ -114,6 +114,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -361,7 +368,7 @@ -

    mdro() brmo() mrgn() eucast_exceptional_phenotypes()

    +

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

    Determine multidrug-resistant organisms (MDRO)

    diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html index f0aa8d07..9414cb98 100644 --- a/docs/reference/key_antibiotics.html +++ b/docs/reference/key_antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -116,6 +116,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -241,20 +248,19 @@ -
    key_antibiotics(tbl, col_mo = NULL, universal_1 = guess_ab_col(tbl,
    -  "AMX"), universal_2 = guess_ab_col(tbl, "AMC"),
    -  universal_3 = guess_ab_col(tbl, "CXM"),
    -  universal_4 = guess_ab_col(tbl, "TZP"),
    -  universal_5 = guess_ab_col(tbl, "CIP"),
    -  universal_6 = guess_ab_col(tbl, "SXT"), GramPos_1 = guess_ab_col(tbl,
    -  "VAN"), GramPos_2 = guess_ab_col(tbl, "TEC"),
    -  GramPos_3 = guess_ab_col(tbl, "TCY"), GramPos_4 = guess_ab_col(tbl,
    -  "ERY"), GramPos_5 = guess_ab_col(tbl, "OXA"),
    -  GramPos_6 = guess_ab_col(tbl, "RIF"), GramNeg_1 = guess_ab_col(tbl,
    -  "GEN"), GramNeg_2 = guess_ab_col(tbl, "TOB"),
    -  GramNeg_3 = guess_ab_col(tbl, "COL"), GramNeg_4 = guess_ab_col(tbl,
    -  "CTX"), GramNeg_5 = guess_ab_col(tbl, "CAZ"),
    -  GramNeg_6 = guess_ab_col(tbl, "MEM"), warnings = TRUE, ...)
    +    
    key_antibiotics(x, col_mo = NULL, universal_1 = guess_ab_col(x, "AMX"),
    +  universal_2 = guess_ab_col(x, "AMC"), universal_3 = guess_ab_col(x,
    +  "CXM"), universal_4 = guess_ab_col(x, "TZP"),
    +  universal_5 = guess_ab_col(x, "CIP"), universal_6 = guess_ab_col(x,
    +  "SXT"), GramPos_1 = guess_ab_col(x, "VAN"),
    +  GramPos_2 = guess_ab_col(x, "TEC"), GramPos_3 = guess_ab_col(x,
    +  "TCY"), GramPos_4 = guess_ab_col(x, "ERY"),
    +  GramPos_5 = guess_ab_col(x, "OXA"), GramPos_6 = guess_ab_col(x,
    +  "RIF"), GramNeg_1 = guess_ab_col(x, "GEN"),
    +  GramNeg_2 = guess_ab_col(x, "TOB"), GramNeg_3 = guess_ab_col(x,
    +  "COL"), GramNeg_4 = guess_ab_col(x, "CTX"),
    +  GramNeg_5 = guess_ab_col(x, "CAZ"), GramNeg_6 = guess_ab_col(x,
    +  "MEM"), warnings = TRUE, ...)
     
     key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"),
       ignore_I = TRUE, points_threshold = 2, info = FALSE)
    @@ -263,8 +269,8 @@ - - + + @@ -290,10 +296,6 @@ - - - - @@ -310,6 +312,10 @@ + + + +
    tbl

    table with antibiotics coloms, like amox and amcl.

    x

    table with antibiotics coloms, like AMX or amox

    col_mo...

    other parameters passed on to function

    x, y

    characters to compare

    type

    type to determine weighed isolates; can be "keyantibiotics" or "points", see Details

    info

    print progress

    x, y

    characters to compare

    Details

    diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index 0bfea458..d0dabbe0 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -116,6 +116,13 @@ Predict antimicrobial resistance
  • +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -241,14 +248,16 @@ -
    mdro(x, country = NULL, col_mo = NULL, info = TRUE,
    -  verbose = FALSE, ...)
    +    
    mdro(x, country = NULL, guideline = NULL, col_mo = NULL,
    +  info = TRUE, verbose = FALSE, ...)
     
     brmo(..., country = "nl")
     
     mrgn(x, country = "de", ...)
     
    -eucast_exceptional_phenotypes(x, country = "EUCAST", ...)
    +mdr_tb(x, guideline = "TB", ...) + +eucast_exceptional_phenotypes(x, guideline = "EUCAST", ...)

    Arguments

    @@ -259,7 +268,11 @@ - + + + + + @@ -285,7 +298,15 @@

    Details

    -

    When country will be left blank, guidelines will be taken from EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (link).

    +

    When country is set, the parameter guideline will be ignored as these guidelines will be used:

    + +

    Please suggest your own country's specific guidelines by letting us know: https://gitlab.com/msberends/AMR/issues/new.

    +

    Other currently supported guidelines are:

    Antibiotics

    diff --git a/docs/reference/portion.html b/docs/reference/portion.html index 10e24002..093900bd 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -81,7 +81,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port AMR (for R) - 0.6.1.9033 + 0.6.1.9035 @@ -117,6 +117,13 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port Predict antimicrobial resistance +
  • + + + + Determine multi-drug resistance (MDR) + +
  • @@ -295,7 +302,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port
  • - + @@ -335,9 +342,9 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port

    In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".

      -
    • SSusceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • -
    • ISusceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • -
    • RResistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    • +
    • S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • +
    • I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • +
    • R - Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    Source: http://www.eucast.org/newsiandr/.

    diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 45016876..a683963e 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -144,6 +144,9 @@ https://msberends.gitlab.io/AMR/articles/G_test.html + + https://msberends.gitlab.io/AMR/articles/MDR.html + https://msberends.gitlab.io/AMR/articles/SPSS.html diff --git a/index.md b/index.md index f6dd6d71..8a31f550 100644 --- a/index.md +++ b/index.md @@ -15,18 +15,18 @@ This R package is actively maintained and is free software; you can freely use a This package can be used for: - * Reference for microorganisms, since it contains all microbial (sub)species from the [Catalogue of Life](http://www.catalogueoflife.org) - * Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines - * Calculating antimicrobial resistance - * Calculating empirical susceptibility of both mono therapy and combination therapy - * Predicting future antimicrobial resistance using regression models - * Getting properties for any microorganism (like Gram stain, species, genus or family) - * Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name) - * Plotting antimicrobial resistance - * Determining first isolates to be used for AMR analysis - * Applying EUCAST expert rules - * Determining multi-drug resistant organisms (MDRO) - * Descriptive statistics: frequency tables, kurtosis and skewness + * Reference for microorganisms, since it contains all microbial (sub)species from the [Catalogue of Life](http://www.catalogueoflife.org) ([manual](./reference/mo_property.html)) + * Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines ([manual](./reference/as.rsi.html)) + * Calculating antimicrobial resistance ([tutorial](./articles/AMR.html)) + * Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO) ([tutorial](./articles/MDR.html)) + * Calculating empirical susceptibility of both mono therapy and combination therapy ([tutorial](./articles/AMR.html)) + * Predicting future antimicrobial resistance using regression models ([tutorial](./articles/resistance_predict.html)) + * Getting properties for any microorganism (like Gram stain, species, genus or family) ([manual](./reference/mo_property.html)) + * Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name) ([manual](./reference/ab_property.html)) + * Plotting antimicrobial resistance ([tutorial](./articles/AMR.html)) + * Determining first isolates to be used for AMR analysis ([manual](./reference/first_isolate.html)) + * Applying EUCAST expert rules ([manual](./reference/eucast_rules.html) + * Descriptive statistics: frequency tables, kurtosis and skewness ([tutorial](./articles/freq.html)) This package is ready-to-use for a professional environment by specialists in the following fields: diff --git a/man/antibiotics.Rd b/man/antibiotics.Rd index 93776f10..9da32248 100644 --- a/man/antibiotics.Rd +++ b/man/antibiotics.Rd @@ -4,7 +4,7 @@ \name{antibiotics} \alias{antibiotics} \title{Data set with ~450 antibiotics} -\format{A \code{\link{data.frame}} with 455 observations and 13 variables: +\format{A \code{\link{data.frame}} with 454 observations and 13 variables: \describe{ \item{\code{ab}}{Antibiotic ID as used in this package (like \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available} \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}} diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd index d931ee75..b5bbdd7a 100755 --- a/man/as.rsi.Rd +++ b/man/as.rsi.Rd @@ -55,9 +55,9 @@ The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ - \item{\strong{S}}{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} - \item{\strong{I}}{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} - \item{\strong{R}}{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} + \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} + \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} + \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} } Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. diff --git a/man/count.Rd b/man/count.Rd index 9c9c4737..522efba9 100644 --- a/man/count.Rd +++ b/man/count.Rd @@ -43,7 +43,7 @@ count_df(data, translate_ab = "name", language = get_locale(), \item{language}{language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.} -\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}.} +\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.} \item{combine_IR}{a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}.} } @@ -67,9 +67,9 @@ These functions are meant to count isolates. Use the \code{\link{portion}_*} fun In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ - \item{\strong{S}}{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} - \item{\strong{I}}{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} - \item{\strong{R}}{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} + \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} + \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} + \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} } Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd index b22a637b..d24c37a5 100644 --- a/man/eucast_rules.Rd +++ b/man/eucast_rules.Rd @@ -43,7 +43,7 @@ eucast_rules_file() \item{...}{column name of an antibiotic, see section Antibiotics} } \value{ -The input of \code{tbl_}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations. +The input of \code{x}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations. } \description{ Apply susceptibility rules as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}. This includes (1) expert rules, (2) intrinsic resistance and (3) inferred resistance as defined in their breakpoint tables. diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index a49484e3..a3f8549a 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -50,7 +50,7 @@ labels_rsi_count(position = NULL, x = "Antibiotic", \item{translate_ab}{a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations to, using \code{\link{ab_property}}} -\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}.} +\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.} \item{combine_IR}{a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}.} diff --git a/man/key_antibiotics.Rd b/man/key_antibiotics.Rd index e6f71f21..85173932 100755 --- a/man/key_antibiotics.Rd +++ b/man/key_antibiotics.Rd @@ -5,26 +5,25 @@ \alias{key_antibiotics_equal} \title{Key antibiotics for first \emph{weighted} isolates} \usage{ -key_antibiotics(tbl, col_mo = NULL, universal_1 = guess_ab_col(tbl, - "AMX"), universal_2 = guess_ab_col(tbl, "AMC"), - universal_3 = guess_ab_col(tbl, "CXM"), - universal_4 = guess_ab_col(tbl, "TZP"), - universal_5 = guess_ab_col(tbl, "CIP"), - universal_6 = guess_ab_col(tbl, "SXT"), GramPos_1 = guess_ab_col(tbl, - "VAN"), GramPos_2 = guess_ab_col(tbl, "TEC"), - GramPos_3 = guess_ab_col(tbl, "TCY"), GramPos_4 = guess_ab_col(tbl, - "ERY"), GramPos_5 = guess_ab_col(tbl, "OXA"), - GramPos_6 = guess_ab_col(tbl, "RIF"), GramNeg_1 = guess_ab_col(tbl, - "GEN"), GramNeg_2 = guess_ab_col(tbl, "TOB"), - GramNeg_3 = guess_ab_col(tbl, "COL"), GramNeg_4 = guess_ab_col(tbl, - "CTX"), GramNeg_5 = guess_ab_col(tbl, "CAZ"), - GramNeg_6 = guess_ab_col(tbl, "MEM"), warnings = TRUE, ...) +key_antibiotics(x, col_mo = NULL, universal_1 = guess_ab_col(x, "AMX"), + universal_2 = guess_ab_col(x, "AMC"), universal_3 = guess_ab_col(x, + "CXM"), universal_4 = guess_ab_col(x, "TZP"), + universal_5 = guess_ab_col(x, "CIP"), universal_6 = guess_ab_col(x, + "SXT"), GramPos_1 = guess_ab_col(x, "VAN"), + GramPos_2 = guess_ab_col(x, "TEC"), GramPos_3 = guess_ab_col(x, + "TCY"), GramPos_4 = guess_ab_col(x, "ERY"), + GramPos_5 = guess_ab_col(x, "OXA"), GramPos_6 = guess_ab_col(x, + "RIF"), GramNeg_1 = guess_ab_col(x, "GEN"), + GramNeg_2 = guess_ab_col(x, "TOB"), GramNeg_3 = guess_ab_col(x, + "COL"), GramNeg_4 = guess_ab_col(x, "CTX"), + GramNeg_5 = guess_ab_col(x, "CAZ"), GramNeg_6 = guess_ab_col(x, + "MEM"), warnings = TRUE, ...) key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"), ignore_I = TRUE, points_threshold = 2, info = FALSE) } \arguments{ -\item{tbl}{table with antibiotics coloms, like \code{amox} and \code{amcl}.} +\item{x}{table with antibiotics coloms, like \code{AMX} or \code{amox}} \item{col_mo}{column name of the unique IDs of the microorganisms (see \code{\link{mo}}), defaults to the first column of class \code{mo}. Values will be coerced using \code{\link{as.mo}}.} @@ -38,8 +37,6 @@ key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"), \item{...}{other parameters passed on to function} -\item{x, y}{characters to compare} - \item{type}{type to determine weighed isolates; can be \code{"keyantibiotics"} or \code{"points"}, see Details} \item{ignore_I}{logical to determine whether antibiotic interpretations with \code{"I"} will be ignored when \code{type = "keyantibiotics"}, see Details} @@ -47,6 +44,8 @@ key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"), \item{points_threshold}{points until the comparison of key antibiotics will lead to inclusion of an isolate when \code{type = "points"}, see Details} \item{info}{print progress} + +\item{x, y}{characters to compare} } \description{ These function can be used to determine first isolates (see \code{\link{first_isolate}}). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates will then be called first \emph{weighted} isolates. diff --git a/man/mdro.Rd b/man/mdro.Rd index b5028ad8..4bc09b9d 100644 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -4,22 +4,27 @@ \alias{mdro} \alias{brmo} \alias{mrgn} +\alias{mdr_tb} \alias{eucast_exceptional_phenotypes} \title{Determine multidrug-resistant organisms (MDRO)} \usage{ -mdro(x, country = NULL, col_mo = NULL, info = TRUE, - verbose = FALSE, ...) +mdro(x, country = NULL, guideline = NULL, col_mo = NULL, + info = TRUE, verbose = FALSE, ...) brmo(..., country = "nl") mrgn(x, country = "de", ...) -eucast_exceptional_phenotypes(x, country = "EUCAST", ...) +mdr_tb(x, guideline = "TB", ...) + +eucast_exceptional_phenotypes(x, guideline = "EUCAST", ...) } \arguments{ \item{x}{table with antibiotic columns, like e.g. \code{AMX} and \code{AMC}} -\item{country}{country code to determine guidelines. EUCAST rules will be used when left empty, see Details. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive. Currently supported are \code{de} (Germany) and \code{nl} (the Netherlands).} +\item{country}{country code to determine guidelines. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive.} + +\item{guideline}{a specific guideline to mention. For some countries this will be determined automatically, see Details. EUCAST guidelines will be used when left empty, see Details.} \item{col_mo}{column name of the unique IDs of the microorganisms (see \code{\link{mo}}), defaults to the first column of class \code{mo}. Values will be coerced using \code{\link{as.mo}}.} @@ -36,7 +41,19 @@ Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}. Determine which isolates are multidrug-resistant organisms (MDRO) according to country-specific guidelines. } \details{ -When \code{country} will be left blank, guidelines will be taken from EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link}). +When \code{country} is set, the parameter guideline will be ignored as these guidelines will be used: + +\itemize{ + \item{\code{country = "nl"}: Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link})} +} + +Please suggest your own country's specific guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}. + +Other currently supported guidelines are: +\itemize{ + \item{\code{guideline = "eucast"}: EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link})} + \item{\code{guideline = "tb"}: World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link})} +} } \section{Antibiotics}{ diff --git a/man/portion.Rd b/man/portion.Rd index befc3bf3..8044a574 100644 --- a/man/portion.Rd +++ b/man/portion.Rd @@ -49,7 +49,7 @@ portion_df(data, translate_ab = "name", language = get_locale(), \item{language}{language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.} -\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}.} +\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.} \item{combine_IR}{a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}.} } @@ -87,9 +87,9 @@ These functions are not meant to count isolates, but to calculate the portion of In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ - \item{\strong{S}}{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} - \item{\strong{I}}{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} - \item{\strong{R}}{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} + \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} + \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} + \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} } Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. diff --git a/reproduction_of_antibiotics.R b/reproduction_of_antibiotics.R index 7eeb20c2..c03bb065 100644 --- a/reproduction_of_antibiotics.R +++ b/reproduction_of_antibiotics.R @@ -225,7 +225,7 @@ get_synonyms <- function(CID, clean = TRUE) { synonyms } -# get brand names (2-3 min) +# get brand names from PubChem (2-3 min) synonyms <- get_synonyms(CIDs) synonyms <- lapply(synonyms, function(x) { @@ -244,7 +244,9 @@ antibiotics <- abx2 %>% atc, cid = CIDs, # no capital after a slash: Ampicillin/Sulbactam -> Ampicillin/sulbactam - name = gsub("edta", "EDTA", gsub("/([A-Z])", "/\\L\\1", name, perl = TRUE), ignore.case = TRUE), + name = name %>% + gsub("([/-])([A-Z])", "\\1\\L\\2", ., perl = TRUE) %>% + gsub("edta", "EDTA", ., ignore.case = TRUE), group = case_when( paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "am(ph|f)enicol" ~ "Amphenicols", paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "aminoglycoside" ~ "Aminoglycosides", @@ -283,6 +285,10 @@ antibiotics <- filter(antibiotics, ab != "POL") # 'Latamoxef' (LTM) and 'Moxalactam (Latamoxef)' (MOX) both exist, so: antibiotics[which(antibiotics$ab == "LTM"), "abbreviations"][[1]] <- list(c("MOX", "moxa")) antibiotics <- filter(antibiotics, ab != "MOX") +# RFP and RFP1 (the J0 one) both mean 'rifapentine', although 'rifp' is not recognised, so: +antibiotics <- filter(antibiotics, ab != "RFP") +antibiotics[which(antibiotics$ab == "RFP1"), "ab"] <- "RFP" +antibiotics[which(antibiotics$ab == "RFP"), "abbreviations"][[1]] <- list(c("rifp")) # ESBL E-test codes: antibiotics[which(antibiotics$ab == "CCV"), "abbreviations"][[1]] <- list(c("xtzl")) antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]], "xtz", "cefta")) @@ -294,5 +300,6 @@ antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]] <- list(c(anti class(antibiotics$ab) <- "ab" class(antibiotics$atc) <- "atc" +dim(antibiotics) # for R/data.R usethis::use_data(antibiotics, overwrite = TRUE) rm(antibiotics) diff --git a/tests/testthat/test-mdro.R b/tests/testthat/test-mdro.R index 831a758e..55c2e885 100755 --- a/tests/testthat/test-mdro.R +++ b/tests/testthat/test-mdro.R @@ -24,8 +24,8 @@ context("mdro.R") test_that("mdro works", { library(dplyr) - expect_error(suppressWarnings(mdro(septic_patients, "invalid", col_mo = "mo", info = TRUE))) - expect_error(suppressWarnings(mdro(septic_patients, "fr", info = TRUE))) + expect_error(suppressWarnings(mdro(septic_patients, country = "invalid", col_mo = "mo", info = TRUE))) + expect_error(suppressWarnings(mdro(septic_patients, country = "fr", info = TRUE))) expect_error(suppressWarnings(mdro(septic_patients, country = c("de", "nl"), info = TRUE))) expect_error(suppressWarnings(mdro(septic_patients, col_mo = "invalid", info = TRUE))) @@ -46,7 +46,7 @@ test_that("mdro works", { suppressWarnings( brmo(septic_patients, info = FALSE)), suppressWarnings( - mdro(septic_patients, "nl", info = FALSE) + mdro(septic_patients, country = "nl", info = FALSE) ) ) @@ -81,4 +81,32 @@ test_that("mdro works", { info = FALSE)) ), "Positive") + # MDR TB + expect_equal( + suppressWarnings( + # select only rifampicine, mo will be determined automatically (as M. tuberculosis), + # number of mono-resistant strains should be equal to number of rifampicine-resistant strains + septic_patients %>% select(RIF) %>% mdr_tb() %>% freq() %>% pull(count) %>% .[2] + ), + count_R(septic_patients$RIF)) + + sample_rsi <- function() { + sample(c("S", "I", "R"), + size = 5000, + prob = c(0.5, 0.1, 0.4), + replace = TRUE) + } + expect_gt( + suppressWarnings( + data.frame(rifampicin = sample_rsi(), + inh = sample_rsi(), + gatifloxacin = sample_rsi(), + eth = sample_rsi(), + pza = sample_rsi(), + MFX = sample_rsi(), + KAN = sample_rsi()) %>% + mdr_tb() %>% + n_distinct()), + 2) + }) diff --git a/vignettes/MDR.Rmd b/vignettes/MDR.Rmd new file mode 100644 index 00000000..c7d9781a --- /dev/null +++ b/vignettes/MDR.Rmd @@ -0,0 +1,79 @@ +--- +title: "How to determine multi-drug resistance (MDR)" +author: "Matthijs S. Berends" +date: '`r format(Sys.Date(), "%d %B %Y")`' +output: + rmarkdown::html_vignette: + toc: true +vignette: > + %\VignetteIndexEntry{How to determine multi-drug resistance (MDR)} + %\VignetteEncoding{UTF-8} + %\VignetteEngine{knitr::rmarkdown} +editor_options: + chunk_output_type: console +--- + +```{r setup, include = FALSE, results = 'markup'} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#" +) +library(AMR) +``` + +With the function `mdro()`, you can determine multi-drug resistant organisms (MDRO). It currently support these guidelines: + +* "Intrinsic Resistance and Exceptional Phenotypes Tables", by EUCAST (European Committee on Antimicrobial Susceptibility Testing) +* "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis", by WHO (World Health Organization) +* "WIP-Richtlijn Bijzonder Resistente Micro-organismen (BRMO)", by RIVM (Rijksinstituut voor de Volksgezondheid, the Netherlands National Institute for Public Health and the Environment) + +As an example, I will make a data set to determine multi-drug resistant TB: + +```{r} +# a helper function to get a random vector with values S, I and R +# with the probabilities 50%-10%-40% +sample_rsi <- function() { + sample(c("S", "I", "R"), + size = 5000, + prob = c(0.5, 0.1, 0.4), + replace = TRUE) +} + +my_TB_data <- data.frame(rifampicin = sample_rsi(), + isoniazid = sample_rsi(), + gatifloxacin = sample_rsi(), + ethambutol = sample_rsi(), + pyrazinamide = sample_rsi(), + moxifloxacin = sample_rsi(), + kanamycin = sample_rsi()) +``` + +Because all column names are automatically verified for valid drug names or codes, this would have worked exactly the same: + +```{r, eval = FALSE} +my_TB_data <- data.frame(RIF = sample_rsi(), + INH = sample_rsi(), + GAT = sample_rsi(), + ETH = sample_rsi(), + PZA = sample_rsi(), + MFX = sample_rsi(), + KAN = sample_rsi()) +``` + +The data set looks like this now: + +```{r} +head(my_TB_data) +``` + +We can now add the interpretation of MDR-TB to our data set: + +```{r} +my_TB_data$mdr <- mdr_tb(my_TB_data) +``` + +And review the result with a frequency table: + +```{r} +freq(my_TB_data$mdr) +``` diff --git a/vignettes/freq.Rmd b/vignettes/freq.Rmd index 9f9c64de..81028383 100644 --- a/vignettes/freq.Rmd +++ b/vignettes/freq.Rmd @@ -128,7 +128,7 @@ septic_patients %>% ## Assigning a frequency table to an object -A frequency table is actaually a regular `data.frame`, with the exception that it contains an additional class. +A frequency table is actually a regular `data.frame`, with the exception that it contains an additional class. ```{r, echo = TRUE} my_df <- septic_patients %>% freq(age) @@ -144,15 +144,17 @@ dim(my_df) ## Additional parameters ### Parameter `na.rm` -With the `na.rm` parameter (defaults to `TRUE`, but they will always be shown into the header), you can include `NA` values in the frequency table: +With the `na.rm` parameter you can remove `NA` values from the frequency table (defaults to `TRUE`, but the number of `NA` values will always be shown into the header): ```{r, echo = TRUE} +septic_patients %>% + freq(AMX, na.rm = FALSE) septic_patients %>% freq(AMX, na.rm = FALSE) ``` ### Parameter `row.names` -The default frequency tables shows row indices. To remove them, use `row.names = FALSE`: +A frequency table shows row indices. To remove them, use `row.names = FALSE`: ```{r, echo = TRUE} septic_patients %>%
    country

    country code to determine guidelines. EUCAST rules will be used when left empty, see Details. Should be or a code from the list of ISO 3166-1 alpha-2 country codes. Case-insensitive. Currently supported are de (Germany) and nl (the Netherlands).

    country code to determine guidelines. Should be or a code from the list of ISO 3166-1 alpha-2 country codes. Case-insensitive.

    guideline

    a specific guideline to mention. For some countries this will be determined automatically, see Details. EUCAST guidelines will be used when left empty, see Details.

    col_mo
    combine_SI

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now TRUE.

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is TRUE.

    combine_IR