Browse Source

(v0.8.0.9031) as.mo() improvements

new-mo-algorithm
parent
commit
09e2730b53
  1. 4
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 37
      NEWS.md
  4. 57
      R/eucast_rules.R
  5. 74
      R/mo.R
  6. BIN
      R/sysdata.rda
  7. 12
      R/zzz.R
  8. 30
      data-raw/eucast_rules.tsv
  9. 10
      data-raw/internals.R
  10. BIN
      data/example_isolates.rda
  11. 2
      docs/404.html
  12. 2
      docs/LICENSE-text.html
  13. 486
      docs/articles/AMR.html
  14. BIN
      docs/articles/AMR_files/figure-html/plot 1-1.png
  15. BIN
      docs/articles/AMR_files/figure-html/plot 3-1.png
  16. BIN
      docs/articles/AMR_files/figure-html/plot 4-1.png
  17. BIN
      docs/articles/AMR_files/figure-html/plot 5-1.png
  18. 4
      docs/articles/SPSS.html
  19. 2
      docs/articles/index.html
  20. 2
      docs/authors.html
  21. 2
      docs/index.html
  22. 448
      docs/news/index.html
  23. 28
      docs/reference/as.mo.html
  24. 16
      docs/reference/eucast_rules.html
  25. 2
      docs/reference/index.html
  26. 2
      docs/reference/resistance_predict.html
  27. 31
      man/as.mo.Rd
  28. 17
      man/eucast_rules.Rd

4
DESCRIPTION

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
Package: AMR
Version: 0.8.0.9030
Date: 2019-11-11
Version: 0.8.0.9031
Date: 2019-11-15
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),

1
NAMESPACE

@ -323,6 +323,7 @@ importFrom(stats,pchisq) @@ -323,6 +323,7 @@ importFrom(stats,pchisq)
importFrom(stats,predict)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(utils,adist)
importFrom(utils,browseURL)
importFrom(utils,menu)
importFrom(utils,read.csv)

37
NEWS.md

@ -1,5 +1,16 @@ @@ -1,5 +1,16 @@
# AMR 0.8.0.9030
<small>Last updated: 11-Nov-2019</small>
# AMR 0.8.0.9031
<small>Last updated: 15-Nov-2019</small>
### Breaking
* Adopted Adeolu *et al.* (2016), [PMID 27620848](https://www.ncbi.nlm.nih.gov/pubmed/27620848) for the `microorganisms` data set, which means that the new order Enterobacterales now consists of a part of the existing family Enterobacteriaceae, but that this family has been split into other families as well (like *Morganellaceae* and *Yersiniaceae*). Although published in 2016, this information is not yet in the Catalogue of Life version of 2019. All MDRO determinations with `mdro()` will now use the Enterobacterales order for all guidelines before 2016 that were dependent on the Enterobacteriaceae family.
* If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:
```r
if (mo_family(somebugs) == "Enterobacteriaceae") ...
```
then please adjust this to:
```r
if (mo_order(somebugs) == "Enterobacterales") ...
```
### New
* Functions `susceptibility()` and `resistance()` as aliases of `proportion_SI()` and `proportion_R()`, respectively. These functions were added to make it more clear that "I" should be considered susceptible and not resistant.
@ -16,11 +27,29 @@ @@ -16,11 +27,29 @@
* The new Verbose mode (`mdro(...., verbose = TRUE)`) returns an informative data set where the reason for MDRO determination is given for every isolate, and an list of the resistant antimicrobial agents
### Changes
* Improvements to algorithm in `as.mo()`:
* Now allows "ou" where "au" should have been used and vice versa
* More intelligent way of coping with some consonants like "l" and "r"
* Added a score (a certainty percentage) to `mo_uncertainties()`, that is calculated using the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance):
```r
as.mo(c("Stafylococcus aureus",
"staphylokok aureuz"))
#> Warning:
#> Results of two values was guessed with uncertainty. Use mo_uncertainties() to review them.
#> Class 'mo'
#> [1] B_STPHY_AURS B_STPHY_AURS
mo_uncertainties()
#> "Stafylococcus aureus" -> Staphylococcus aureus (B_STPHY_AURS, score: 95.2%)
#> "staphylokok aureuz" -> Staphylococcus aureus (B_STPHY_AURS, score: 85.7%)
```
* Removed previously deprecated function `as.atc()` - this function was replaced by `ab_atc()`
* Renamed all `portion_*` functions to `proportion_*`. All `portion_*` functions are still available as deprecated functions, and will return a warning when used.
* When running `as.rsi()` over a data set, it will now print the guideline that will be used if it is not specified by the user
* Fix for `eucast_rules()`: *Stenotrophomonas maltophilia* not interpreted "R" to ceftazidime anymore (following EUCAST v3.1)
* Adopted Adeolu *et al.* (2016), [PMID 27620848](https://www.ncbi.nlm.nih.gov/pubmed/27620848) for the `microorganisms` data set, which means that the new order Enterobacterales now consists of a part of the existing family *Enterobacteriaceae*, but that this family has been split into other families as well (like *Morganellaceae* and *Yersiniaceae*). Although published in 2016, this information is not yet in the Catalogue of Life version of 2019. All MDRO determinations with `mdro()` will now use the Enterobacterales order for all guidelines before 2016.
* Improvements for `eucast_rules()`:
* Fix where *Stenotrophomonas maltophilia* would always become ceftazidime R (following EUCAST v3.1)
* Fix where *Leuconostoc* and *Pediococcus* would not always become glyopeptides R
* non-EUCAST rules in `eucast_rules()` are now applied first and not as last anymore. This is to improve the dependency on certain antibiotics for the official EUCAST rules. Please see `?eucast_rules`.
* Fix for interpreting MIC values with `as.rsi()` where the input is `NA`
* Added "imi" and "imp" as allowed abbreviation for Imipenem (IPM)
* Fix for automatically determining columns with antibiotic results in `mdro()` and `eucast_rules()`

57
R/eucast_rules.R

@ -24,8 +24,11 @@ EUCAST_VERSION_BREAKPOINTS <- "9.0, 2019" @@ -24,8 +24,11 @@ EUCAST_VERSION_BREAKPOINTS <- "9.0, 2019"
EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016"
#' EUCAST rules
#'
#' 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.
#'
#' @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.
#'
#' To improve the interpretation of the antibiogram before EUCAST rules are applied, some non-EUCAST rules are applied at default, see Details.
#' @param x data with antibiotic columns, like e.g. \code{AMX} and \code{AMC}
#' @param info print progress
#' @param rules a character vector that specifies which rules should be applied - one or more of \code{c("breakpoints", "expert", "other", "all")}
@ -36,6 +39,19 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016" @@ -36,6 +39,19 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016"
#' \strong{Note:} This function does not translate MIC values to RSI values. Use \code{\link{as.rsi}} for that. \cr
#' \strong{Note:} When ampicillin (AMP, J01CA01) is not available but amoxicillin (AMX, J01CA04) is, the latter will be used for all rules where there is a dependency on ampicillin. These drugs are interchangeable when it comes to expression of antimicrobial resistance.
#'
#' Before further processing, some non-EUCAST rules are applied to improve the efficacy of the EUCAST rules. These non-EUCAST rules, that are applied to all isolates, are:
#' \itemize{
#' \item{Inherit amoxicillin (AMX) from ampicillin (AMP), where amoxicillin (AMX) is unavailable;}
#' \item{Inherit ampicillin (AMP) from amoxicillin (AMX), where ampicillin (AMP) is unavailable;}
#' \item{Set amoxicillin (AMX) = R where amoxicillin/clavulanic acid (AMC) = R;}
#' \item{Set piperacillin (PIP) = R where piperacillin/tazobactam (TZP) = R;}
#' \item{Set trimethoprim (TMP) = R where trimethoprim/sulfamethoxazole (SXT) = R;}
#' \item{Set amoxicillin/clavulanic acid (AMC) = S where amoxicillin (AMX) = S;}
#' \item{Set piperacillin/tazobactam (TZP) = S where piperacillin (PIP) = S;}
#' \item{Set trimethoprim/sulfamethoxazole (SXT) = S where trimethoprim (TMP) = S.}
#' }
#' To \emph{not} use these rules, please use \code{eucast_rules(..., rules = c("breakpoints", "expert"))}.
#'
#' The file containing all EUCAST rules is located here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/eucast_rules.tsv}.
#'
#' @section Antibiotics:
@ -516,29 +532,7 @@ eucast_rules <- function(x, @@ -516,29 +532,7 @@ eucast_rules <- function(x,
as.data.frame(stringsAsFactors = FALSE)
)
if (info == TRUE) {
cat(paste0(
"\nRules by the ", bold("European Committee on Antimicrobial Susceptibility Testing (EUCAST)"),
"\n", blue("http://eucast.org/"), "\n"))
}
# since ampicillin ^= amoxicillin, get the first from the latter (not in original EUCAST table)
if (!ab_missing(AMP) & !ab_missing(AMX)) {
if (verbose == TRUE) {
cat("\n VERBOSE: transforming",
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(x[, AMX] == "I" & !x[, AMP] %in% c("S", "I", "R"))),
"empty ampicillin fields to 'I' based on amoxicillin. ")
cat("\n VERBOSE: transforming",
length(which(x[, AMX] == "R" & !x[, AMP] %in% c("S", "I", "R"))),
"empty ampicillin fields to 'R' based on amoxicillin. \n")
}
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)) {
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.")))
AMP <- AMX
@ -611,6 +605,7 @@ eucast_rules <- function(x, @@ -611,6 +605,7 @@ eucast_rules <- function(x,
}
}
eucast_notification_shown <- FALSE
eucast_rules_df <- eucast_rules_file # internal data file
no_added <- 0
no_changed <- 0
@ -648,6 +643,13 @@ eucast_rules <- function(x, @@ -648,6 +643,13 @@ eucast_rules <- function(x,
next
}
if (info == TRUE & !rule_group_current %like% "other" & eucast_notification_shown == FALSE) {
cat(paste0(
"\n----\nRules by the ", bold("European Committee on Antimicrobial Susceptibility Testing (EUCAST)"),
"\n", blue("http://eucast.org/"), "\n"))
eucast_notification_shown <- TRUE
}
if (info == TRUE) {
# Print rule (group) ------------------------------------------------------
@ -660,7 +662,7 @@ eucast_rules <- function(x, @@ -660,7 +662,7 @@ eucast_rules <- function(x,
rule_group_current %like% "expert" ~
paste0("\nEUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v", EUCAST_VERSION_EXPERT_RULES, ")\n"),
TRUE ~
"\nOther rules\n"
"\nOther rules by this AMR package\n"
)
))
}
@ -707,6 +709,7 @@ eucast_rules <- function(x, @@ -707,6 +709,7 @@ eucast_rules <- function(x,
}
if (like_is_one_of == "is") {
# so 'Enterococcus' will turn into '^Enterococcus$'
mo_value <- paste0("^", eucast_rules_df[i, 3], "$")
} else if (like_is_one_of == "one_of") {
# so 'Clostridium, Actinomyces, ...' will turn into '^(Clostridium|Actinomyces|...)$'
@ -717,7 +720,7 @@ eucast_rules <- function(x, @@ -717,7 +720,7 @@ eucast_rules <- function(x,
} else if (like_is_one_of == "like") {
mo_value <- eucast_rules_df[i, 3]
} else {
stop("invalid like_is_one_of", call. = FALSE)
stop("invalid value for column 'like.is.one_of'", call. = FALSE)
}
source_antibiotics <- eucast_rules_df[i, 4]

74
R/mo.R

@ -59,15 +59,6 @@ @@ -59,15 +59,6 @@
#'
#' The algorithm uses data from the Catalogue of Life (see below) and from one other source (see \code{\link{microorganisms}}).
#'
#' \strong{Self-learning algoritm} \cr
#' The \code{as.mo()} function gains experience from previously determined microorganism IDs and learns from it. This drastically improves both speed and reliability. Use \code{clear_mo_history()} to reset the algorithms. Only experience from your current \code{AMR} package version is used. This is done because in the future the taxonomic tree (which is included in this package) may change for any organism and it consequently has to rebuild its knowledge.
#'
#' Usually, any guess after the first try runs 80-95\% faster than the first try.
#'
# \emph{For now, learning only works per session. If R is closed or terminated, the algorithms reset. This might be resolved in a future version.}
#' This resets with every update of this \code{AMR} package since results are saved to your local package library folder.
#'
#' \strong{Intelligent rules} \cr
#' The \code{as.mo()} function uses several coercion rules for fast and logical results. It assesses the input matching criteria in the following order:
#' \itemize{
@ -76,7 +67,10 @@ @@ -76,7 +67,10 @@
#' \item{Breakdown of input values to identify possible matches.}
#' }
#'
#' This will lead to the effect that e.g. \code{"E. coli"} (a highly prevalent microorganism found in humans) will return the microbial ID of \emph{Escherichia coli} and not \emph{Entamoeba coli} (a less prevalent microorganism in humans), although the latter would alphabetically come first. In addition, the \code{as.mo()} function can differentiate four levels of uncertainty to guess valid results:
#' This will lead to the effect that e.g. \code{"E. coli"} (a highly prevalent microorganism found in humans) will return the microbial ID of \emph{Escherichia coli} and not \emph{Entamoeba coli} (a less prevalent microorganism in humans), although the latter would alphabetically come first.
#'
#' \strong{Coping with uncertain results} \cr
#' In addition, the \code{as.mo()} function can differentiate four levels of uncertainty to guess valid results:
#'
#' \itemize{
#' \item{Uncertainty level 0: no additional rules are applied;}
@ -95,9 +89,12 @@ @@ -95,9 +89,12 @@
#'
#' The level of uncertainty can be set using the argument \code{allow_uncertain}. The default is \code{allow_uncertain = TRUE}, which is equal to uncertainty level 2. Using \code{allow_uncertain = FALSE} is equal to uncertainty level 0 and will skip all rules. You can also use e.g. \code{as.mo(..., allow_uncertain = 1)} to only allow up to level 1 uncertainty.
#'
#' Use \code{mo_failures()} to get a vector with all values that could not be coerced to a valid value. \cr
#' Use \code{mo_uncertainties()} to get a \code{data.frame} with all values that were coerced to a valid value, but with uncertainty. \cr
#' Use \code{mo_renamed()} to get a \code{data.frame} with all values that could be coerced based on an old, previously accepted taxonomic name.
#' There are three helper functions that can be run after then \code{as.mo()} function:
#' \itemize{
#' \item{Use \code{mo_uncertainties()} to get a \code{data.frame} with all values that were coerced to a valid value, but with uncertainty. The output contains a score, that is calculated as \code{(n - 0.5 * L) / n}, where \emph{n} is the number of characters of the returned full name of the microorganism, and \emph{L} is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance} between that full name and the user input.}
#' \item{Use \code{mo_failures()} to get a vector with all values that could not be coerced to a valid value.}
#' \item{Use \code{mo_renamed()} to get a \code{data.frame} with all values that could be coerced based on an old, previously accepted taxonomic name.}
#' }
#'
#' \strong{Microbial prevalence of pathogens in humans} \cr
#' The intelligent rules consider the prevalence of microorganisms in humans grouped into three groups, which is available as the \code{prevalence} columns in the \code{\link{microorganisms}} and \code{\link{microorganisms.old}} data sets. The grouping into prevalence groups is based on experience from several microbiological laboratories in the Netherlands in conjunction with international reports on pathogen prevalence.
@ -107,6 +104,14 @@ @@ -107,6 +104,14 @@
#' Group 2 consists of all microorganisms where the taxonomic phylum is Proteobacteria, Firmicutes, Actinobacteria or Sarcomastigophora, or where the taxonomic genus is \emph{Aspergillus}, \emph{Bacteroides}, \emph{Candida}, \emph{Capnocytophaga}, \emph{Chryseobacterium}, \emph{Cryptococcus}, \emph{Elisabethkingia}, \emph{Flavobacterium}, \emph{Fusobacterium}, \emph{Giardia}, \emph{Leptotrichia}, \emph{Mycoplasma}, \emph{Prevotella}, \emph{Rhodotorula}, \emph{Treponema}, \emph{Trichophyton} or \emph{Ureaplasma}.
#'
#' Group 3 (least prevalent microorganisms) consists of all other microorganisms.
#'
#' \strong{Self-learning algorithm} \cr
#' The \code{as.mo()} function gains experience from previously determined microorganism IDs and learns from it. This drastically improves both speed and reliability. Use \code{clear_mo_history()} to reset the algorithms. Only experience from your current \code{AMR} package version is used. This is done because in the future the taxonomic tree (which is included in this package) may change for any organism and it consequently has to rebuild its knowledge.
#'
#' Usually, any guess after the first try runs 80-95\% faster than the first try.
#'
# \emph{For now, learning only works per session. If R is closed or terminated, the algorithms reset. This might be resolved in a future version.}
#' This resets with every update of this \code{AMR} package since results are saved to your local package library folder.
#' @inheritSection catalogue_of_life Catalogue of Life
# (source as a section here, so it can be inherited by other man pages:)
#' @section Source:
@ -134,7 +139,7 @@ @@ -134,7 +139,7 @@
#' as.mo("S aureus")
#' as.mo("Staphylococcus aureus")
#' as.mo("Staphylococcus aureus (MRSA)")
#' as.mo("Sthafilokkockus aaureuz") # handles incorrect spelling
#' as.mo("Zthafilokkoockus oureuz") # handles incorrect spelling
#' as.mo("MRSA") # Methicillin Resistant S. aureus
#' as.mo("VISA") # Vancomycin Intermediate S. aureus
#' as.mo("VRSA") # Vancomycin Resistant S. aureus
@ -287,7 +292,7 @@ exec_as.mo <- function(x, @@ -287,7 +292,7 @@ exec_as.mo <- function(x,
disable_mo_history = FALSE,
debug = FALSE,
reference_data_to_use = microorganismsDT) {
if (!"AMR" %in% base::.packages()) {
require("AMR")
# check onLoad() in R/zzz.R: data tables are created there.
@ -518,7 +523,7 @@ exec_as.mo <- function(x, @@ -518,7 +523,7 @@ exec_as.mo <- function(x,
x <- gsub("(alpha|beta|gamma).?ha?emoly", "\\1-haemoly", x)
# remove genus as first word
x <- gsub("^genus ", "", x)
# remove 'uncertain' like texts
# remove 'uncertain'-like texts
x <- trimws(gsub("(uncertain|susp[ie]c[a-z]+|verdacht)", "", x))
# allow characters that resemble others = dyslexia_mode ----
if (dyslexia_mode == TRUE) {
@ -539,13 +544,19 @@ exec_as.mo <- function(x, @@ -539,13 +544,19 @@ exec_as.mo <- function(x,
x <- gsub("e+", "e+", x)
x <- gsub("o+", "o+", x)
x <- gsub("(.)\\1+", "\\1+", x)
# allow multiplication of all other consonants
x <- gsub("([bdghjlnrw]+)", "\\1+", x)
# allow ending in -en or -us
x <- gsub("e\\+n(?![a-z[])", "(e+n|u+(c|k|q|qu|s|z|x|ks)+)", x, perl = TRUE)
# if the input is longer than 10 characters, allow any constant between all characters, as some might have forgotten a character
# if the input is longer than 10 characters, allow any forgotten consonant between all characters, as some might just have forgotten one...
# this will allow "Pasteurella damatis" to be correctly read as "Pasteurella dagmatis".
constants <- paste(letters[!letters %in% c("a", "e", "i", "o", "u")], collapse = "")
x[nchar(x_backup_without_spp) > 10] <- gsub("[+]", paste0("+[", constants, "]?"), x[nchar(x_backup_without_spp) > 10])
consonants <- paste(letters[!letters %in% c("a", "e", "i", "o", "u")], collapse = "")
x[nchar(x_backup_without_spp) > 10] <- gsub("[+]", paste0("+[", consonants, "]?"), x[nchar(x_backup_without_spp) > 10])
# allow au and ou after all these regex implementations
x <- gsub("a+[bcdfghjklmnpqrstvwxyz]?u+[bcdfghjklmnpqrstvwxyz]?", "(a+u+|o+u+)[bcdfghjklmnpqrstvwxyz]?", x, fixed = TRUE)
x <- gsub("o+[bcdfghjklmnpqrstvwxyz]?u+[bcdfghjklmnpqrstvwxyz]?", "(a+u+|o+u+)[bcdfghjklmnpqrstvwxyz]?", x, fixed = TRUE)
# make sure to remove regex overkill (will lead to errors)
x <- gsub("++", "+", x, fixed = TRUE)
}
x <- strip_whitespace(x, dyslexia_mode)
@ -578,7 +589,7 @@ exec_as.mo <- function(x, @@ -578,7 +589,7 @@ exec_as.mo <- function(x,
}
progress <- progress_estimated(n = length(x), min_time = 3)
for (i in seq_len(length(x))) {
progress$tick()$print()
@ -834,8 +845,8 @@ exec_as.mo <- function(x, @@ -834,8 +845,8 @@ exec_as.mo <- function(x,
next
}
# streptococcal groups: milleri and viridans
if (x_trimmed[i] %like_case% "strepto.* milleri"
| x_backup_without_spp[i] %like_case% "strepto.* milleri"
if (x_trimmed[i] %like_case% "strepto.* mil+er+i"
| x_backup_without_spp[i] %like_case% "strepto.* mil+er+i"
| x_backup_without_spp[i] %like_case% "mgs[^a-z]?$") {
# Milleri Group Streptococcus (MGS)
x[i] <- microorganismsDT[mo == "B_STRPT_MILL", ..property][[1]][1L]
@ -1863,6 +1874,7 @@ mo_uncertainties <- function() { @@ -1863,6 +1874,7 @@ mo_uncertainties <- function() {
#' @exportMethod print.mo_uncertainties
#' @importFrom crayon green yellow red white black bgGreen bgYellow bgRed
#' @importFrom cleaner percentage
#' @export
#' @noRd
print.mo_uncertainties <- function(x, ...) {
@ -1890,7 +1902,9 @@ print.mo_uncertainties <- function(x, ...) { @@ -1890,7 +1902,9 @@ print.mo_uncertainties <- function(x, ...) {
paste0(colour2(paste0(" [", x[i, "uncertainty"], "] ")), ' "', x[i, "input"], '" -> ',
colour1(paste0(italic(x[i, "fullname"]),
ifelse(!is.na(x[i, "renamed_to"]), paste(", renamed to", italic(x[i, "renamed_to"])), ""),
" (", x[i, "mo"], ")"))),
" (", x[i, "mo"],
", score: ", percentage(levenshtein_fraction(x[i, "input"], x[i, "fullname"]), digits = 1),
")"))),
sep = "\n")
}
cat(msg)
@ -1977,3 +1991,15 @@ load_mo_failures_uncertainties_renamed <- function(metadata) { @@ -1977,3 +1991,15 @@ load_mo_failures_uncertainties_renamed <- function(metadata) {
options("mo_uncertainties" = metadata$uncertainties)
options("mo_renamed" = metadata$renamed)
}
#' @importFrom utils adist
levenshtein_fraction <- function(input, output) {
levenshtein <- double(length = length(input))
for (i in seq_len(length(input))) {
# determine levenshtein distance, but maximise to nchar of output
levenshtein[i] <- base::min(base::as.double(adist(input[i], output[i], ignore.case = TRUE)),
base::nchar(output[i]))
}
# self-made score between 0 and 1 (for % certainty, so 0 means huge distance, 1 means no distance)
(base::nchar(output) - 0.5 * levenshtein) / nchar(output)
}

BIN
R/sysdata.rda

Binary file not shown.

12
R/zzz.R

@ -47,15 +47,21 @@ @@ -47,15 +47,21 @@
# maybe add survey later: "https://www.surveymonkey.com/r/AMR_for_R"
#' @importFrom data.table as.data.table setkey
#' @importFrom dplyr %>% mutate case_when
make_DT <- function() {
microorganismsDT <- as.data.table(AMR::microorganisms %>%
mutate(kingdom_index = case_when(kingdom == "Bacteria" ~ 1,
kingdom == "Fungi" ~ 2,
kingdom == "Protozoa" ~ 3,
kingdom == "Archaea" ~ 4,
TRUE ~ 6)))
# for fullname_lower: keep only dots, letters, numbers, slashes, spaces and dashes
microorganismsDT$fullname_lower <- gsub("[^.a-z0-9/ \\-]+", "", tolower(microorganismsDT$fullname))
TRUE ~ 99),
# for fullname_lower: keep only dots, letters,
# numbers, slashes, spaces and dashes
fullname_lower = gsub("[^.a-z0-9/ \\-]+", "",
# use this paste instead of `fullname` to
# work with Viridans Group Streptococci, etc.
tolower(trimws(paste(genus, species, subspecies))))))
# so arrange data on prevalence first, then kingdom, then full name
setkey(microorganismsDT,
prevalence,
kingdom_index,

30
data-raw/eucast_rules.tsv

@ -9,6 +9,19 @@ @@ -9,6 +9,19 @@
# >>>>> IF YOU WANT TO IMPORT THIS FILE INTO YOUR OWN SOFTWARE, HAVE THE FIRST 10 LINES SKIPPED <<<<<
# -------------------------------------------------------------------------------------------------------------------------------
if_mo_property like.is.one_of this_value and_these_antibiotics have_these_values then_change_these_antibiotics to_value reference.rule reference.rule_group
genus like .* AMP S AMX S Non-EUCAST: inherit ampicillin results for unavailable amoxicillin Other rules
genus like .* AMP I AMX I Non-EUCAST: inherit ampicillin results for unavailable amoxicillin Other rules
genus like .* AMP R AMX R Non-EUCAST: inherit ampicillin results for unavailable amoxicillin Other rules
genus like .* AMX S AMP S Non-EUCAST: inherit amoxicillin results for unavailable ampicillin Other rules
genus like .* AMX I AMP I Non-EUCAST: inherit amoxicillin results for unavailable ampicillin Other rules
genus like .* AMX R AMP R Non-EUCAST: inherit amoxicillin results for unavailable ampicillin Other rules
genus like .* AMC R AMP, AMX R Non-EUCAST: set ampicillin = R where amoxicillin/clav acid = R Other rules
genus like .* TZP R PIP R Non-EUCAST: set piperacillin = R where piperacillin/tazobactam = R Other rules
genus like .* SXT R TMP R Non-EUCAST: set trimethoprim = R where trimethoprim/sulfa = R Other rules
genus like .* AMP S AMC S Non-EUCAST: set amoxicillin/clav acid = S where ampicillin = S Other rules
genus like .* AMX S AMC S Non-EUCAST: set amoxicillin/clav acid = S where ampicillin = S Other rules
genus like .* PIP S TZP S Non-EUCAST: set piperacillin/tazobactam = S where piperacillin = S Other rules
genus like .* TMP S SXT S Non-EUCAST: set trimethoprim/sulfa = S where trimethoprim = S Other rules
order is Enterobacterales AMP S AMX S Enterobacterales (Order) Breakpoints
order is Enterobacterales AMP I AMX I Enterobacterales (Order) Breakpoints
order is Enterobacterales AMP R AMX R Enterobacterales (Order) Breakpoints
@ -53,7 +66,7 @@ genus_species like ^Streptococcus (australis|bovis|constellatus|cristatus|gallol @@ -53,7 +66,7 @@ genus_species like ^Streptococcus (australis|bovis|constellatus|cristatus|gallol
genus_species like ^Streptococcus (australis|bovis|constellatus|cristatus|gallolyticus|gordonii|infantarius|infantis|mitis|mutans|oligofermentans|oralis|peroris|pseudopneumoniae|salivarius|sinensis|sobrinus|thermophilus|vestibularis|anginosus|equinus|intermedius|parasanguinis|sanguinis)$ AMP I AMX, AMC, PIP, TZP I Viridans group streptococci Breakpoints
genus_species like ^Streptococcus (australis|bovis|constellatus|cristatus|gallolyticus|gordonii|infantarius|infantis|mitis|mutans|oligofermentans|oralis|peroris|pseudopneumoniae|salivarius|sinensis|sobrinus|thermophilus|vestibularis|anginosus|equinus|intermedius|parasanguinis|sanguinis)$ AMP R AMX, AMC, PIP, TZP R Viridans group streptococci Breakpoints
genus_species is Haemophilus influenzae AMP S AMX, PIP S Haemophilus influenzae Breakpoints
genus_species is ^Haemophilus influenzae AMP I AMX, PIP I Haemophilus influenzae Breakpoints
genus_species is Haemophilus influenzae AMP I AMX, PIP I Haemophilus influenzae Breakpoints
genus_species is Haemophilus influenzae AMP R AMX, PIP R Haemophilus influenzae Breakpoints
genus_species is Haemophilus influenzae PEN S AMP, AMX, AMC, PIP, TZP S Haemophilus influenzae Breakpoints
genus_species is Haemophilus influenzae AMC S TZP S Haemophilus influenzae Breakpoints
@ -164,7 +177,7 @@ genus_species is Enterococcus casseliflavus FUS, CAZ, cephalosporins_without_C @@ -164,7 +177,7 @@ genus_species is Enterococcus casseliflavus FUS, CAZ, cephalosporins_without_C
genus_species is Enterococcus faecium FUS, CAZ, cephalosporins_without_CAZ, aminoglycosides, macrolides, TMP, SXT R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus is Corynebacterium FOS R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus_species is Listeria monocytogenes cephalosporins R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus is Leuconostoc, Pediococcus glycopeptides R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus one_of Leuconostoc, Pediococcus glycopeptides R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus is Lactobacillus glycopeptides R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus_species is Clostridium ramosum VAN R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
genus_species is Clostridium innocuum VAN R Table 04: Intrinsic resistance in Gram-positive bacteria Expert Rules
@ -172,9 +185,9 @@ genus_species like ^Streptococcus (pyogenes|agalactiae|dysgalactiae|group A|grou @@ -172,9 +185,9 @@ genus_species like ^Streptococcus (pyogenes|agalactiae|dysgalactiae|group A|grou
genus is Enterococcus AMP R ureidopenicillins, carbapenems R Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci Expert Rules
genus is Enterococcus AMX R ureidopenicillins, carbapenems R Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci Expert Rules
family is Enterobacteriaceae TIC, PIP R, S PIP R Table 09: Interpretive rules for B-lactam agents and Gram-negative rods Expert Rules
genus is .* ERY S AZM, CLR S Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus is .* ERY I AZM, CLR I Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus is .* ERY R AZM, CLR R Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus like .* ERY S AZM, CLR S Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus like .* ERY I AZM, CLR I Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus like .* ERY R AZM, CLR R Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins Expert Rules
genus is Staphylococcus TOB R KAN, AMK R Table 12: Interpretive rules for aminoglycosides Expert Rules
genus is Staphylococcus GEN R aminoglycosides R Table 12: Interpretive rules for aminoglycosides Expert Rules
order is Enterobacterales GEN, TOB I, S GEN R Table 12: Interpretive rules for aminoglycosides Expert Rules
@ -183,10 +196,3 @@ genus is Staphylococcus MFX R fluoroquinolones R Table 13: Interpretive rules fo @@ -183,10 +196,3 @@ genus is Staphylococcus MFX R fluoroquinolones R Table 13: Interpretive rules fo
genus_species is Streptococcus pneumoniae MFX R fluoroquinolones R Table 13: Interpretive rules for quinolones Expert Rules
order is Enterobacterales CIP R fluoroquinolones R Table 13: Interpretive rules for quinolones Expert Rules
genus_species is Neisseria gonorrhoeae CIP R fluoroquinolones R Table 13: Interpretive rules for quinolones Expert Rules
genus is .* AMC R AMP, AMX R Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R Other rules
genus is .* TZP R PIP R Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R Other rules
genus is .* SXT R TMP R Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R Other rules
genus is .* AMP S AMC S Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S Other rules
genus is .* AMX S AMC S Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S Other rules
genus is .* PIP S TZP S Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S Other rules
genus is .* TMP S SXT S Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S Other rules

Can't render this file because it contains an unexpected character in line 6 and column 96.

10
data-raw/internals.R

@ -2,14 +2,18 @@ @@ -2,14 +2,18 @@
# source("data-raw/internals.R")
# See 'data-raw/eucast_rules.tsv' for the EUCAST reference file
eucast_rules_file <- dplyr::arrange(
.data = utils::read.delim(file = "data-raw/eucast_rules.tsv",
eucast_rules_file <- utils::read.delim(file = "data-raw/eucast_rules.tsv",
skip = 10,
sep = "\t",
stringsAsFactors = FALSE,
header = TRUE,
strip.white = TRUE,
na = c(NA, "", NULL)),
na = c(NA, "", NULL))
# take the order of the reference.rule_group column in the orginal data file
eucast_rules_file$reference.rule_group <- factor(eucast_rules_file$reference.rule_group,
levels = unique(eucast_rules_file$reference.rule_group),
ordered = TRUE)
eucast_rules_file <- dplyr::arrange(eucast_rules_file,
reference.rule_group,
reference.rule)

BIN
data/example_isolates.rda

Binary file not shown.

2
docs/404.html

@ -84,7 +84,7 @@ @@ -84,7 +84,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9031</span>
</span>
</div>

2
docs/LICENSE-text.html

@ -84,7 +84,7 @@ @@ -84,7 +84,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9031</span>
</span>
</div>

486
docs/articles/AMR.html

@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.8.0.9031</span>
</span>
</div>
@ -187,7 +187,7 @@ @@ -187,7 +187,7 @@
<h1>How to conduct AMR analysis</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">11 November 2019</h4>
<h4 class="date">15 November 2019</h4>
<div class="hidden name"><code>AMR.Rmd</code></div>
@ -196,7 +196,7 @@ @@ -196,7 +196,7 @@
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 11 November 2019.</p>
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 15 November 2019.</p>
<div id="introduction" class="section level1">
<h1 class="hasAnchor">
<a href="#introduction" class="anchor"></a>Introduction</h1>
@ -212,21 +212,21 @@ @@ -212,21 +212,21 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2019-11-11</td>
<td align="center">2019-11-15</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
</tr>
<tr class="even">
<td align="center">2019-11-11</td>
<td align="center">2019-11-15</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">R</td>
</tr>
<tr class="odd">
<td align="center">2019-11-11</td>
<td align="center">2019-11-15</td>
<td align="center">efgh</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
@ -321,10 +321,10 @@ @@ -321,10 +321,10 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2011-09-25</td>
<td align="center">O7</td>
<td align="center">Hospital C</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">2015-09-02</td>
<td align="center">V3</td>
<td align="center">Hospital B</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
@ -332,53 +332,53 @@ @@ -332,53 +332,53 @@
<td align="center">F</td>
</tr>
<tr class="even">
<td align="center">2012-04-04</td>
<td align="center">O9</td>
<td align="center">Hospital A</td>
<td align="center">2017-06-27</td>
<td align="center">H4</td>
<td align="center">Hospital C</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2015-03-11</td>
<td align="center">S3</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">2012-05-31</td>
<td align="center">X3</td>
<td align="center">Hospital B</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="even">
<td align="center">2014-12-11</td>
<td align="center">G1</td>
<td align="center">2013-06-08</td>
<td align="center">K2</td>
<td align="center">Hospital B</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2013-01-02</td>
<td align="center">J8</td>
<td align="center">Hospital D</td>
<td align="center">2012-02-10</td>
<td align="center">M5</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2014-08-17</td>
<td align="center">S8</td>
<td align="center">Hospital C</td>
<td align="center">2010-06-25</td>
<td align="center">N7</td>
<td align="center">Hospital D</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
@ -406,8 +406,8 @@ @@ -406,8 +406,8 @@
#
# Item Count Percent Cum. Count Cum. Percent
# --- ----- ------- -------- ----------- -------------
# 1 M 10,427 52.14% 10,427 52.14%
# 2 F 9,573 47.87% 20,000 100.00%</code></pre>
# 1 M 10,309 51.55% 10,309 51.55%
# 2 F 9,691 48.46% 20,000 100.00%</code></pre>
<p>So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values <code>M</code> and <code>F</code>. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.</p>
<p>The data is already quite clean, but we still need to transform some variables. The <code>bacteria</code> 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 <code><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate()</a></code> function of the <code>dplyr</code> package makes this really easy:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span></a>
@ -419,60 +419,62 @@ @@ -419,60 +419,62 @@
<p>Because the amoxicillin (column <code>AMX</code>) and amoxicillin/clavulanic acid (column <code>AMC</code>) in our data were generated randomly, some rows will undoubtedly contain AMX = S and AMC = R, which is technically impossible. The <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> fixes this:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" data-line-number="1">data &lt;-<span class="st"> </span><span class="kw"><a href="../reference/eucast_rules.html">eucast_rules</a></span>(data, <span class="dt">col_mo =</span> <span class="st">"bacteria"</span>)</a>
<a class="sourceLine" id="cb14-2" data-line-number="2"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-3" data-line-number="3"><span class="co"># Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)</span></a>
<a class="sourceLine" id="cb14-4" data-line-number="4"><span class="co"># http://eucast.org/</span></a>
<a class="sourceLine" id="cb14-5" data-line-number="5"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-6" data-line-number="6"><span class="co"># EUCAST Clinical Breakpoints (v9.0, 2019)</span></a>
<a class="sourceLine" id="cb14-7" data-line-number="7"><span class="co"># Aerococcus sanguinicola (no changes)</span></a>
<a class="sourceLine" id="cb14-8" data-line-number="8"><span class="co"># Aerococcus urinae (no changes)</span></a>
<a class="sourceLine" id="cb14-9" data-line-number="9"><span class="co"># Anaerobic Gram-negatives (no changes)</span></a>
<a class="sourceLine" id="cb14-10" data-line-number="10"><span class="co"># Anaerobic Gram-positives (no changes)</span></a>
<a class="sourceLine" id="cb14-11" data-line-number="11"><span class="co"># Campylobacter coli (no changes)</span></a>
<a class="sourceLine" id="cb14-12" data-line-number="12"><span class="co"># Campylobacter jejuni (no changes)</span></a>
<a class="sourceLine" id="cb14-13" data-line-number="13"><span class="co"># Enterobacterales (Order) (no changes)</span></a>
<a class="sourceLine" id="cb14-14" data-line-number="14"><span class="co"># Enterococcus (no changes)</span></a>
<a class="sourceLine" id="cb14-15" data-line-number="15"><span class="co"># Haemophilus influenzae (no changes)</span></a>
<a class="sourceLine" id="cb14-16" data-line-number="16"><span class="co"># Kingella kingae (no changes)</span></a>
<a class="sourceLine" id="cb14-17" data-line-number="17"><span class="co"># Moraxella catarrhalis (no changes)</span></a>
<a class="sourceLine" id="cb14-18" data-line-number="18"><span class="co"># Pasteurella multocida (no changes)</span></a>
<a class="sourceLine" id="cb14-19" data-line-number="19"><span class="co"># Staphylococcus (no changes)</span></a>
<a class="sourceLine" id="cb14-20" data-line-number="20"><span class="co"># Streptococcus groups A, B, C, G (no changes)</span></a>
<a class="sourceLine" id="cb14-21" data-line-number="21"><span class="co"># Streptococcus pneumoniae (1,552 values changed)</span></a>
<a class="sourceLine" id="cb14-22" data-line-number="22"><span class="co"># Viridans group streptococci (no changes)</span></a>
<a class="sourceLine" id="cb14-23" data-line-number="23"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-24" data-line-number="24"><span class="co"># EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)</span></a>
<a class="sourceLine" id="cb14-25" data-line-number="25"><span class="co"># Table 01: Intrinsic resistance in Enterobacteriaceae (1,279 values changed)</span></a>
<a class="sourceLine" id="cb14-26" data-line-number="26"><span class="co"># Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-27" data-line-number="27"><span class="co"># Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-28" data-line-number="28"><span class="co"># Table 04: Intrinsic resistance in Gram-positive bacteria (2,800 values changed)</span></a>
<a class="sourceLine" id="cb14-29" data-line-number="29"><span class="co"># Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)</span></a>
<a class="sourceLine" id="cb14-30" data-line-number="30"><span class="co"># Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)</span></a>
<a class="sourceLine" id="cb14-31" data-line-number="31"><span class="co"># Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)</span></a>
<a class="sourceLine" id="cb14-32" data-line-number="32"><span class="co"># Table 12: Interpretive rules for aminoglycosides (no changes)</span></a>
<a class="sourceLine" id="cb14-33" data-line-number="33"><span class="co"># Table 13: Interpretive rules for quinolones (no changes)</span></a>
<a class="sourceLine" id="cb14-3" data-line-number="3"><span class="co"># Other rules by this AMR package</span></a>
<a class="sourceLine" id="cb14-4" data-line-number="4"><span class="co"># Non-EUCAST: inherit amoxicillin results for unavailable ampicillin (no changes)</span></a>
<a class="sourceLine" id="cb14-5" data-line-number="5"><span class="co"># Non-EUCAST: inherit ampicillin results for unavailable amoxicillin (no changes)</span></a>
<a class="sourceLine" id="cb14-6" data-line-number="6"><span class="co"># Non-EUCAST: set amoxicillin/clav acid = S where ampicillin = S (3,022 values changed)</span></a>
<a class="sourceLine" id="cb14-7" data-line-number="7"><span class="co"># Non-EUCAST: set ampicillin = R where amoxicillin/clav acid = R (151 values changed)</span></a>
<a class="sourceLine" id="cb14-8" data-line-number="8"><span class="co"># Non-EUCAST: set piperacillin = R where piperacillin/tazobactam = R (no changes)</span></a>
<a class="sourceLine" id="cb14-9" data-line-number="9"><span class="co"># Non-EUCAST: set piperacillin/tazobactam = S where piperacillin = S (no changes)</span></a>
<a class="sourceLine" id="cb14-10" data-line-number="10"><span class="co"># Non-EUCAST: set trimethoprim = R where trimethoprim/sulfa = R (no changes)</span></a>
<a class="sourceLine" id="cb14-11" data-line-number="11"><span class="co"># Non-EUCAST: set trimethoprim/sulfa = S where trimethoprim = S (no changes)</span></a>
<a class="sourceLine" id="cb14-12" data-line-number="12"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-13" data-line-number="13"><span class="co"># ----</span></a>
<a class="sourceLine" id="cb14-14" data-line-number="14"><span class="co"># Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)</span></a>
<a class="sourceLine" id="cb14-15" data-line-number="15"><span class="co"># http://eucast.org/</span></a>
<a class="sourceLine" id="cb14-16" data-line-number="16"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-17" data-line-number="17"><span class="co"># EUCAST Clinical Breakpoints (v9.0, 2019)</span></a>
<a class="sourceLine" id="cb14-18" data-line-number="18"><span class="co"># Aerococcus sanguinicola (no changes)</span></a>
<a class="sourceLine" id="cb14-19" data-line-number="19"><span class="co"># Aerococcus urinae (no changes)</span></a>
<a class="sourceLine" id="cb14-20" data-line-number="20"><span class="co"># Anaerobic Gram-negatives (no changes)</span></a>
<a class="sourceLine" id="cb14-21" data-line-number="21"><span class="co"># Anaerobic Gram-positives (no changes)</span></a>
<a class="sourceLine" id="cb14-22" data-line-number="22"><span class="co"># Campylobacter coli (no changes)</span></a>
<a class="sourceLine" id="cb14-23" data-line-number="23"><span class="co"># Campylobacter jejuni (no changes)</span></a>
<a class="sourceLine" id="cb14-24" data-line-number="24"><span class="co"># Enterobacterales (Order) (no changes)</span></a>
<a class="sourceLine" id="cb14-25" data-line-number="25"><span class="co"># Enterococcus (no changes)</span></a>
<a class="sourceLine" id="cb14-26" data-line-number="26"><span class="co"># Haemophilus influenzae (no changes)</span></a>
<a class="sourceLine" id="cb14-27" data-line-number="27"><span class="co"># Kingella kingae (no changes)</span></a>
<a class="sourceLine" id="cb14-28" data-line-number="28"><span class="co"># Moraxella catarrhalis (no changes)</span></a>
<a class="sourceLine" id="cb14-29" data-line-number="29"><span class="co"># Pasteurella multocida (no changes)</span></a>
<a class="sourceLine" id="cb14-30" data-line-number="30"><span class="co"># Staphylococcus (no changes)</span></a>
<a class="sourceLine" id="cb14-31" data-line-number="31"><span class="co"># Streptococcus groups A, B, C, G (no changes)</span></a>
<a class="sourceLine" id="cb14-32" data-line-number="32"><span class="co"># Streptococcus pneumoniae (1,071 values changed)</span></a>
<a class="sourceLine" id="cb14-33" data-line-number="33"><span class="co"># Viridans group streptococci (no changes)</span></a>
<a class="sourceLine" id="cb14-34" data-line-number="34"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-35" data-line-number="35"><span class="co"># Other rules</span></a>
<a class="sourceLine" id="cb14-36" data-line-number="36"><span class="co"># Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,257 values changed)</span></a>
<a class="sourceLine" id="cb14-37" data-line-number="37"><span class="co"># Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (132 values changed)</span></a>
<a class="sourceLine" id="cb14-38" data-line-number="38"><span class="co"># Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)</span></a>
<a class="sourceLine" id="cb14-39" data-line-number="39"><span class="co"># Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)</span></a>
<a class="sourceLine" id="cb14-40" data-line-number="40"><span class="co"># Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)</span></a>
<a class="sourceLine" id="cb14-41" data-line-number="41"><span class="co"># Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)</span></a>
<a class="sourceLine" id="cb14-42" data-line-number="42"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-43" data-line-number="43"><span class="co"># --------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-44" data-line-number="44"><span class="co"># EUCAST rules affected 6,599 out of 20,000 rows, making a total of 8,020 edits</span></a>
<a class="sourceLine" id="cb14-45" data-line-number="45"><span class="co"># =&gt; added 0 test results</span></a>
<a class="sourceLine" id="cb14-46" data-line-number="46"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-47" data-line-number="47"><span class="co"># =&gt; changed 8,020 test results</span></a>
<a class="sourceLine" id="cb14-48" data-line-number="48"><span class="co"># - 119 test results changed from S to I</span></a>
<a class="sourceLine" id="cb14-49" data-line-number="49"><span class="co"># - 4,832 test results changed from S to R</span></a>
<a class="sourceLine" id="cb14-50" data-line-number="50"><span class="co"># - 1,096 test results changed from I to S</span></a>
<a class="sourceLine" id="cb14-51" data-line-number="51"><span class="co"># - 342 test results changed from I to R</span></a>
<a class="sourceLine" id="cb14-52" data-line-number="52"><span class="co"># - 1,607 test results changed from R to S</span></a>
<a class="sourceLine" id="cb14-53" data-line-number="53"><span class="co"># - 24 test results changed from R to I</span></a>
<a class="sourceLine" id="cb14-54" data-line-number="54"><span class="co"># --------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-55" data-line-number="55"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-56" data-line-number="56"><span class="co"># Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.</span></a></code></pre></div>
<a class="sourceLine" id="cb14-35" data-line-number="35"><span class="co"># EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)</span></a>
<a class="sourceLine" id="cb14-36" data-line-number="36"><span class="co"># Table 01: Intrinsic resistance in Enterobacteriaceae (1,282 values changed)</span></a>
<a class="sourceLine" id="cb14-37" data-line-number="37"><span class="co"># Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-38" data-line-number="38"><span class="co"># Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-39" data-line-number="39"><span class="co"># Table 04: Intrinsic resistance in Gram-positive bacteria (2,783 values changed)</span></a>
<a class="sourceLine" id="cb14-40" data-line-number="40"><span class="co"># Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)</span></a>
<a class="sourceLine" id="cb14-41" data-line-number="41"><span class="co"># Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)</span></a>
<a class="sourceLine" id="cb14-42" data-line-number="42"><span class="co"># Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)</span></a>
<a class="sourceLine" id="cb14-43" data-line-number="43"><span class="co"># Table 12: Interpretive rules for aminoglycosides (no changes)</span></a>
<a class="sourceLine" id="cb14-44" data-line-number="44"><span class="co"># Table 13: Interpretive rules for quinolones (no changes)</span></a>
<a class="sourceLine" id="cb14-45" data-line-number="45"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-46" data-line-number="46"><span class="co"># --------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-47" data-line-number="47"><span class="co"># EUCAST rules affected 6,586 out of 20,000 rows, making a total of 8,309 edits</span></a>
<a class="sourceLine" id="cb14-48" data-line-number="48"><span class="co"># =&gt; added 0 test results</span></a>
<a class="sourceLine" id="cb14-49" data-line-number="49"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-50" data-line-number="50"><span class="co"># =&gt; changed 8,309 test results</span></a>
<a class="sourceLine" id="cb14-51" data-line-number="51"><span class="co"># - 129 test results changed from S to I</span></a>
<a class="sourceLine" id="cb14-52" data-line-number="52"><span class="co"># - 4,834 test results changed from S to R</span></a>
<a class="sourceLine" id="cb14-53" data-line-number="53"><span class="co"># - 1,222 test results changed from I to S</span></a>
<a class="sourceLine" id="cb14-54" data-line-number="54"><span class="co"># - 324 test results changed from I to R</span></a>
<a class="sourceLine" id="cb14-55" data-line-number="55"><span class="co"># - 1,800 test results changed from R to S</span></a>
<a class="sourceLine" id="cb14-56" data-line-number="56"><span class="co"># --------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-57" data-line-number="57"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-58" data-line-number="58"><span class="co"># Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.</span></a></code></pre></div>
</div>
<div id="adding-new-variables" class="section level1">
<h1 class="hasAnchor">
@ -497,8 +499,8 @@ @@ -497,8 +499,8 @@
<a class="sourceLine" id="cb16-3" data-line-number="3"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb16-4" data-line-number="4"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `date` as input for `col_date`.</span></a>
<a class="sourceLine" id="cb16-5" data-line-number="5"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb16-6" data-line-number="6"><span class="co"># =&gt; Found 5,657 first isolates (28.3% of total)</span></a></code></pre></div>
<p>So only 28.3% is suitable for resistance analysis! We can now filter on it with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<a class="sourceLine" id="cb16-6" data-line-number="6"><span class="co"># =&gt; Found 5,688 first isolates (28.4% of total)</span></a></code></pre></div>
<p>So only 28.4% is suitable for resistance analysis! We can now filter on it with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" data-line-number="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb17-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(first <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>)</a></code></pre></div>
<p>For future use, the above two syntaxes can be shortened with the <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> function:</p>
@ -508,7 +510,7 @@ @@ -508,7 +510,7 @@
<div id="first-weighted-isolates" class="section level2">
<h2 class="hasAnchor">
<a href="#first-weighted-isolates" class="anchor"></a>First <em>weighted</em> isolates</h2>
<p>We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient D2, sorted on date:</p>
<p>We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient I9, sorted on date:</p>
<table class="table">
<thead><tr class="header">
<th align="center">isolate</th>
@ -524,19 +526,19 @@ @@ -524,19 +526,19 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-02-14</td>
<td align="center">D2</td>
<td align="center">2010-02-08</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-04-27</td>
<td align="center">D2</td>
<td align="center">2010-03-05</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
@ -546,30 +548,30 @@ @@ -546,30 +548,30 @@
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-05-31</td>
<td align="center">D2</td>
<td align="center">2010-05-14</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-08-21</td>
<td align="center">D2</td>
<td align="center">2010-12-10</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-09-21</td>
<td align="center">D2</td>
<td align="center">2010-12-17</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
@ -579,30 +581,30 @@ @@ -579,30 +581,30 @@
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-10-04</td>
<td align="center">D2</td>
<td align="center">2011-04-18</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2010-10-11</td>
<td align="center">D2</td>
<td align="center">2011-04-25</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2010-11-16</td>
<td align="center">D2</td>
<td align="center">2011-06-06</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
@ -612,23 +614,23 @@ @@ -612,23 +614,23 @@
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2011-03-05</td>
<td align="center">D2</td>
<td align="center">2011-07-14</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2011-04-18</td>
<td align="center">D2</td>
<td align="center">2011-07-31</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
@ -645,7 +647,7 @@ @@ -645,7 +647,7 @@
<a class="sourceLine" id="cb19-7" data-line-number="7"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb19-8" data-line-number="8"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.</span></a>
<a class="sourceLine" id="cb19-9" data-line-number="9"><span class="co"># [Criterion] Inclusion based on key antibiotics, ignoring I</span></a>
<a class="sourceLine" id="cb19-10" data-line-number="10"><span class="co"># =&gt; Found 15,009 first weighted isolates (75.0% of total)</span></a></code></pre></div>
<a class="sourceLine" id="cb19-10" data-line-number="10"><span class="co"># =&gt; Found 15,051 first weighted isolates (75.3% of total)</span></a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th align="center">isolate</th>
@ -662,20 +664,20 @@ @@ -662,20 +664,20 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-02-14</td>
<td align="center">D2</td>
<td align="center">2010-02-08</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-04-27</td>
<td align="center">D2</td>
<td align="center">2010-03-05</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
@ -686,68 +688,68 @@ @@ -686,68 +688,68 @@
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-05-31</td>
<td align="center">D2</td>
<td align="center">2010-05-14</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-08-21</td>
<td align="center">D2</td>
<td align="center">2010-12-10</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-09-21</td>
<td align="center">D2</td>
<td align="center">2010-12-17</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-10-04</td>
<td align="center">D2</td>
<td align="center">2011-04-18</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2010-10-11</td>
<td align="center">D2</td>
<td align="center">2011-04-25</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2010-11-16</td>
<td align="center">D2</td>
<td align="center">2011-06-06</td>
<td align="center">I9</td>
<td align="center">B_ESCHR_COLI</td>
<td align="center">S</td>
<td align="center">S</td>
@ -758,35 +760,35 @@ @@ -758,35 +760,35 @@