1
0
mirror of https://github.com/msberends/AMR.git synced 2026-04-28 10:23:53 +02:00

Add add_if_missing parameter to control NA handling in interpretive rules (#264)

This commit is contained in:
Matthijs Berends
2026-04-21 21:53:43 +02:00
committed by GitHub
parent fb8758f36b
commit 8ff5d4472a
46 changed files with 1232 additions and 1016 deletions

View File

@@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 3.0.1.9044 Version: 3.0.1.9045
Date: 2026-04-04 Date: 2026-04-21
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@@ -1,4 +1,4 @@
# AMR 3.0.1.9044 # AMR 3.0.1.9045
### New ### New
* Support for clinical breakpoints of 2026 of both CLSI and EUCAST, by adding all of their over 5,700 new clinical breakpoints to the `clinical_breakpoints` data set for usage in `as.sir()`. EUCAST 2026 is now the new default guideline for all MIC and disk diffusion interpretations. * Support for clinical breakpoints of 2026 of both CLSI and EUCAST, by adding all of their over 5,700 new clinical breakpoints to the `clinical_breakpoints` data set for usage in `as.sir()`. EUCAST 2026 is now the new default guideline for all MIC and disk diffusion interpretations.
@@ -16,7 +16,9 @@
- Functions such as `susceptibility()` count WT as S and NWT as R - Functions such as `susceptibility()` count WT as S and NWT as R
* Function `interpretive_rules()`, which allows future implementation of CLSI interpretive rules (#235) * Function `interpretive_rules()`, which allows future implementation of CLSI interpretive rules (#235)
- `eucast_rules()` has become a wrapper around that function - `eucast_rules()` has become a wrapper around that function
- Gained argument `add_if_missing` (default: `TRUE`). When set to `FALSE`, rules are only applied to cells that already contain an SIR value; `NA` cells are left untouched. This is useful with `overwrite = TRUE` to update reported results without imputing values for drugs that were not tested (#259)
* Function `amr_course()`, which allows for automated download and unpacking of a GitHub repository for e.g. webinar use * Function `amr_course()`, which allows for automated download and unpacking of a GitHub repository for e.g. webinar use
* Two new `NA` objects, `NA_ab_` and `NA_mo_`, analogous to base R's `NA_character_` and `NA_integer_`, for use in pipelines that require typed missing values
### Fixes ### Fixes
* Fixed a bug in `as.sir()` where values that were purely numeric (e.g., `"1"`) and matched the broad SIR-matching regex would be incorrectly stripped of all content by the Unicode letter filter * Fixed a bug in `as.sir()` where values that were purely numeric (e.g., `"1"`) and matched the broad SIR-matching regex would be incorrectly stripped of all content by the Unicode letter filter

View File

@@ -766,7 +766,7 @@ vector_or <- function(v, quotes = TRUE, reverse = FALSE, sort = TRUE, initial_ca
} }
if (isTRUE(quotes)) { if (isTRUE(quotes)) {
if (isTRUE(documentation)) { if (isTRUE(documentation)) {
quotes <- '"' quotes <- c("`\"", "\"`")
} else { } else {
# use cli to format as values # use cli to format as values
quotes <- c("{.val ", "}") quotes <- c("{.val ", "}")

View File

@@ -35,7 +35,7 @@
#' `options(AMR_guideline = "CLSI")` #' `options(AMR_guideline = "CLSI")`
#' @section Options (alphabetical order): #' @section Options (alphabetical order):
#' * `AMR_antibiogram_formatting_type` \cr A [numeric] (1-22) to use in [antibiogram()], to indicate which formatting type to use. #' * `AMR_antibiogram_formatting_type` \cr A [numeric] (1-22) to use in [antibiogram()], to indicate which formatting type to use.
#' * `AMR_breakpoint_type` \cr A [character] to use in [as.sir()], to indicate which breakpoint type to use. This must be either `r vector_or(clinical_breakpoints$type)`. #' * `AMR_breakpoint_type` \cr A [character] to use in [as.sir()], to indicate which breakpoint type to use. This must be either `r vector_or(clinical_breakpoints$type, documentation = TRUE)`.
#' * `AMR_capped_mic_handling` \cr A [character] to use in [as.sir()], to indicate how capped MIC values (`<`, `<=`, `>`, `>=`) should be interpreted. Must be one of `"none"`, `"conservative"`, `"standard"`, or `"lenient"` - the default is `"conservative"`. #' * `AMR_capped_mic_handling` \cr A [character] to use in [as.sir()], to indicate how capped MIC values (`<`, `<=`, `>`, `>=`) should be interpreted. Must be one of `"none"`, `"conservative"`, `"standard"`, or `"lenient"` - the default is `"conservative"`.
#' * `AMR_cleaning_regex` \cr A [regular expression][base::regex] (case-insensitive) to use in [as.mo()] and all [`mo_*`][mo_property()] functions, to clean the user input. The default is the outcome of [mo_cleaning_regex()], which removes texts between brackets and texts such as "species" and "serovar". #' * `AMR_cleaning_regex` \cr A [regular expression][base::regex] (case-insensitive) to use in [as.mo()] and all [`mo_*`][mo_property()] functions, to clean the user input. The default is the outcome of [mo_cleaning_regex()], which removes texts between brackets and texts such as "species" and "serovar".
#' * `AMR_custom_ab` \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in [add_custom_antimicrobials()]. #' * `AMR_custom_ab` \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in [add_custom_antimicrobials()].

View File

@@ -32,7 +32,7 @@
#' Use these functions to return a specific property of an antibiotic from the [antimicrobials] data set. All input values will be evaluated internally with [as.ab()]. #' Use these functions to return a specific property of an antibiotic from the [antimicrobials] data set. All input values will be evaluated internally with [as.ab()].
#' @param x Any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()]. #' @param x Any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()].
#' @param tolower A [logical] to indicate whether the first [character] of every output should be transformed to a lower case [character]. This will lead to e.g. "polymyxin B" and not "polymyxin b". #' @param tolower A [logical] to indicate whether the first [character] of every output should be transformed to a lower case [character]. This will lead to e.g. "polymyxin B" and not "polymyxin b".
#' @param property One of the column names of one of the [antimicrobials] data set: `vector_or(colnames(antimicrobials), sort = FALSE)`. #' @param property One of the column names of one of the [antimicrobials] data set: `r vector_or(colnames(antimicrobials), documentation = TRUE, sort = FALSE)`.
#' @param language Language of the returned text - the default is the current system language (see [get_AMR_locale()]) and can also be set with the package option [`AMR_locale`][AMR-options]. Use `language = NULL` or `language = ""` to prevent translation. #' @param language Language of the returned text - the default is the current system language (see [get_AMR_locale()]) and can also be set with the package option [`AMR_locale`][AMR-options]. Use `language = NULL` or `language = ""` to prevent translation.
#' @param administration Way of administration, either `"oral"` or `"iv"`. #' @param administration Way of administration, either `"oral"` or `"iv"`.
#' @param open Browse the URL using [utils::browseURL()]. #' @param open Browse the URL using [utils::browseURL()].

View File

@@ -48,8 +48,8 @@
#' - `carbapenems() + "GEN"` #' - `carbapenems() + "GEN"`
#' - `carbapenems() + c("", "GEN")` #' - `carbapenems() + c("", "GEN")`
#' - `carbapenems() + c("", aminoglycosides())` #' - `carbapenems() + c("", aminoglycosides())`
#' @param mo_transform A character to transform microorganism input - must be `"name"`, `"shortname"` (default), `"gramstain"`, or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input or `NA` to consider all microorganisms 'unknown'. #' @param mo_transform A character to transform microorganism input - must be `"name"`, `"shortname"` (default), `"gramstain"`, or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, documentation = TRUE)`. Can also be `NULL` to not transform the input or `NA` to consider all microorganisms 'unknown'.
#' @param ab_transform A character to transform antimicrobial input - must be one of the column names of the [antimicrobials] data set (defaults to `"name"`): `r vector_or(colnames(antimicrobials), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input. #' @param ab_transform A character to transform antimicrobial input - must be one of the column names of the [antimicrobials] data set (defaults to `"name"`): `r vector_or(colnames(antimicrobials), sort = FALSE, documentation = TRUE)`. Can also be `NULL` to not transform the input.
#' @param syndromic_group A column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*. #' @param syndromic_group A column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*.
#' @param add_total_n *(deprecated in favour of `formatting_type`)* A [logical] to indicate whether `n_tested` available numbers per pathogen should be added to the table (default is `TRUE`). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for *E. coli* 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200"). This option is unavailable when `wisca = TRUE`; in that case, use [retrieve_wisca_parameters()] to get the parameters used for WISCA. #' @param add_total_n *(deprecated in favour of `formatting_type`)* A [logical] to indicate whether `n_tested` available numbers per pathogen should be added to the table (default is `TRUE`). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for *E. coli* 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200"). This option is unavailable when `wisca = TRUE`; in that case, use [retrieve_wisca_parameters()] to get the parameters used for WISCA.
#' @param only_all_tested (for combination antibiograms): a [logical] to indicate that isolates must be tested for all antimicrobials, see *Details*. #' @param only_all_tested (for combination antibiograms): a [logical] to indicate that isolates must be tested for all antimicrobials, see *Details*.

View File

@@ -32,7 +32,7 @@
#' Use these functions to return a specific property of an antiviral drug from the [antivirals] data set. All input values will be evaluated internally with [as.av()]. #' Use these functions to return a specific property of an antiviral drug from the [antivirals] data set. All input values will be evaluated internally with [as.av()].
#' @param x Any (vector of) text that can be coerced to a valid antiviral drug code with [as.av()]. #' @param x Any (vector of) text that can be coerced to a valid antiviral drug code with [as.av()].
#' @param tolower A [logical] to indicate whether the first [character] of every output should be transformed to a lower case [character]. #' @param tolower A [logical] to indicate whether the first [character] of every output should be transformed to a lower case [character].
#' @param property One of the column names of one of the [antivirals] data set: `vector_or(colnames(antivirals), sort = FALSE)`. #' @param property One of the column names of one of the [antivirals] data set: `r vector_or(colnames(antivirals), documentation = TRUE, sort = FALSE)`.
#' @param language Language of the returned text - the default is system language (see [get_AMR_locale()]) and can also be set with the package option [`AMR_locale`][AMR-options]. Use `language = NULL` or `language = ""` to prevent translation. #' @param language Language of the returned text - the default is system language (see [get_AMR_locale()]) and can also be set with the package option [`AMR_locale`][AMR-options]. Use `language = NULL` or `language = ""` to prevent translation.
#' @param administration Way of administration, either `"oral"` or `"iv"`. #' @param administration Way of administration, either `"oral"` or `"iv"`.
#' @param open Browse the URL using [utils::browseURL()]. #' @param open Browse the URL using [utils::browseURL()].

View File

@@ -106,12 +106,12 @@
#' @format A [tibble][tibble::tibble] with `r format(nrow(microorganisms), big.mark = " ")` observations and `r ncol(microorganisms)` variables: #' @format A [tibble][tibble::tibble] with `r format(nrow(microorganisms), big.mark = " ")` observations and `r ncol(microorganisms)` variables:
#' - `mo`\cr ID of microorganism as used by this package. ***This is a unique identifier.*** #' - `mo`\cr ID of microorganism as used by this package. ***This is a unique identifier.***
#' - `fullname`\cr Full name, like `"Escherichia coli"`. For the taxonomic ranks genus, species and subspecies, this is the 'pasted' text of genus, species, and subspecies. For all taxonomic ranks higher than genus, this is the name of the taxon. ***This is a unique identifier.*** #' - `fullname`\cr Full name, like `"Escherichia coli"`. For the taxonomic ranks genus, species and subspecies, this is the 'pasted' text of genus, species, and subspecies. For all taxonomic ranks higher than genus, this is the name of the taxon. ***This is a unique identifier.***
#' - `status` \cr Status of the taxon, either `r vector_or(microorganisms$status)` #' - `status` \cr Status of the taxon, either `r vector_or(microorganisms$status, documentation = TRUE)`
#' - `kingdom`, `phylum`, `class`, `order`, `family`, `genus`, `species`, `subspecies`\cr Taxonomic rank of the microorganism. Note that for fungi, *phylum* is equal to their taxonomic *division*. Also, for fungi, *subkingdom* and *subdivision* were left out since they do not occur in the bacterial taxonomy. #' - `kingdom`, `phylum`, `class`, `order`, `family`, `genus`, `species`, `subspecies`\cr Taxonomic rank of the microorganism. Note that for fungi, *phylum* is equal to their taxonomic *division*. Also, for fungi, *subkingdom* and *subdivision* were left out since they do not occur in the bacterial taxonomy.
#' - `rank`\cr Text of the taxonomic rank of the microorganism, such as `"species"` or `"genus"` #' - `rank`\cr Text of the taxonomic rank of the microorganism, such as `"species"` or `"genus"`
#' - `ref`\cr Author(s) and year of related scientific publication. This contains only the *first surname* and year of the *latest* authors, e.g. "Wallis *et al.* 2006 *emend.* Smith and Jones 2018" becomes "Smith *et al.*, 2018". This field is directly retrieved from the source specified in the column `source`. Moreover, accents were removed to comply with CRAN that only allows ASCII characters. #' - `ref`\cr Author(s) and year of related scientific publication. This contains only the *first surname* and year of the *latest* authors, e.g. "Wallis *et al.* 2006 *emend.* Smith and Jones 2018" becomes "Smith *et al.*, 2018". This field is directly retrieved from the source specified in the column `source`. Moreover, accents were removed to comply with CRAN that only allows ASCII characters.
#' - `oxygen_tolerance` \cr Oxygen tolerance, either `r vector_or(microorganisms$oxygen_tolerance)`. These data were retrieved from BacDive (see *Source*). Items that contain "likely" are missing from BacDive and were extrapolated from other species within the same genus to guess the oxygen tolerance. Currently `r round(length(microorganisms$oxygen_tolerance[which(!is.na(microorganisms$oxygen_tolerance))]) / nrow(microorganisms[which(microorganisms$kingdom == "Bacteria"), ]) * 100, 1)`% of all `r format_included_data_number(nrow(microorganisms[which(microorganisms$kingdom == "Bacteria"), ]))` bacteria in the data set contain an oxygen tolerance. #' - `oxygen_tolerance` \cr Oxygen tolerance, either `r vector_or(microorganisms$oxygen_tolerance, documentation = TRUE)`. These data were retrieved from BacDive (see *Source*). Items that contain "likely" are missing from BacDive and were extrapolated from other species within the same genus to guess the oxygen tolerance. Currently `r round(length(microorganisms$oxygen_tolerance[which(!is.na(microorganisms$oxygen_tolerance))]) / nrow(microorganisms[which(microorganisms$kingdom == "Bacteria"), ]) * 100, 1)`% of all `r format_included_data_number(nrow(microorganisms[which(microorganisms$kingdom == "Bacteria"), ]))` bacteria in the data set contain an oxygen tolerance.
#' - `source`\cr Either `r vector_or(microorganisms$source)` (see *Source*) #' - `source`\cr Either `r vector_or(microorganisms$source, documentation = TRUE)` (see *Source*)
#' - `lpsn`\cr Identifier ('Record number') of `r TAXONOMY_VERSION$LPSN$name`. This will be the first/highest LPSN identifier to keep one identifier per row. For example, *Acetobacter ascendens* has LPSN Record number 7864 and 11011. Only the first is available in the `microorganisms` data set. ***This is a unique identifier***, though available for only `r format_included_data_number(sum(!is.na(microorganisms$lpsn)))` records. #' - `lpsn`\cr Identifier ('Record number') of `r TAXONOMY_VERSION$LPSN$name`. This will be the first/highest LPSN identifier to keep one identifier per row. For example, *Acetobacter ascendens* has LPSN Record number 7864 and 11011. Only the first is available in the `microorganisms` data set. ***This is a unique identifier***, though available for only `r format_included_data_number(sum(!is.na(microorganisms$lpsn)))` records.
#' - `lpsn_parent`\cr LPSN identifier of the parent taxon #' - `lpsn_parent`\cr LPSN identifier of the parent taxon
#' - `lpsn_renamed_to`\cr LPSN identifier of the currently valid taxon #' - `lpsn_renamed_to`\cr LPSN identifier of the currently valid taxon
@@ -222,8 +222,8 @@
#' - `date`\cr Date of receipt at the laboratory #' - `date`\cr Date of receipt at the laboratory
#' - `patient`\cr ID of the patient #' - `patient`\cr ID of the patient
#' - `age`\cr Age of the patient #' - `age`\cr Age of the patient
#' - `gender`\cr Gender of the patient, either `r vector_or(example_isolates$gender)` #' - `gender`\cr Gender of the patient, either `r vector_or(example_isolates$gender, documentation = TRUE)`
#' - `ward`\cr Ward type where the patient was admitted, either `r vector_or(example_isolates$ward)` #' - `ward`\cr Ward type where the patient was admitted, either `r vector_or(example_isolates$ward, documentation = TRUE)`
#' - `mo`\cr ID of microorganism created with [as.mo()], see also the [microorganisms] data set #' - `mo`\cr ID of microorganism created with [as.mo()], see also the [microorganisms] data set
#' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.sir))` different antimicrobials with class [`sir`] (see [as.sir()]); these column names occur in the [antimicrobials] data set and can be translated with [set_ab_names()] or [ab_name()] #' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.sir))` different antimicrobials with class [`sir`] (see [as.sir()]); these column names occur in the [antimicrobials] data set and can be translated with [set_ab_names()] or [ab_name()]
#' @inheritSection AMR Download Our Reference Data #' @inheritSection AMR Download Our Reference Data
@@ -292,9 +292,9 @@
#' Use [as.sir()] to transform MICs or disks measurements to SIR values. #' Use [as.sir()] to transform MICs or disks measurements to SIR values.
#' @format A [tibble][tibble::tibble] with `r format(nrow(clinical_breakpoints), big.mark = " ")` observations and `r ncol(clinical_breakpoints)` variables: #' @format A [tibble][tibble::tibble] with `r format(nrow(clinical_breakpoints), big.mark = " ")` observations and `r ncol(clinical_breakpoints)` variables:
#' - `guideline`\cr Name of the guideline #' - `guideline`\cr Name of the guideline
#' - `type`\cr Breakpoint type, either `r vector_or(clinical_breakpoints$type)` #' - `type`\cr Breakpoint type, either `r vector_or(clinical_breakpoints$type, documentation = TRUE)`
#' - `host`\cr Host of infectious agent. This is mostly useful for veterinary breakpoints and is either `r vector_or(clinical_breakpoints$host)` #' - `host`\cr Host of infectious agent. This is mostly useful for veterinary breakpoints and is either `r vector_or(clinical_breakpoints$host, documentation = TRUE)`
#' - `method`\cr Testing method, either `r vector_or(clinical_breakpoints$method)` #' - `method`\cr Testing method, either `r vector_or(clinical_breakpoints$method, documentation = TRUE)`
#' - `site`\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory" #' - `site`\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory"
#' - `mo`\cr Microbial ID, see [as.mo()] #' - `mo`\cr Microbial ID, see [as.mo()]
#' - `rank_index`\cr Taxonomic rank index of `mo` from 1 (subspecies/infraspecies) to 5 (unknown microorganism) #' - `rank_index`\cr Taxonomic rank index of `mo` from 1 (subspecies/infraspecies) to 5 (unknown microorganism)
@@ -307,7 +307,7 @@
#' - `is_SDD`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the intermediate range between "S" and "R" should be interpreted as "SDD", instead of "I". This currently applies to `r sum(clinical_breakpoints$is_SDD)` breakpoints. #' - `is_SDD`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the intermediate range between "S" and "R" should be interpreted as "SDD", instead of "I". This currently applies to `r sum(clinical_breakpoints$is_SDD)` breakpoints.
#' @details #' @details
#' ### Different Types of Breakpoints #' ### Different Types of Breakpoints
#' Supported types of breakpoints are `r vector_and(clinical_breakpoints$type, quote = FALSE)`. ECOFF (Epidemiological cut-off) values are used in antimicrobial susceptibility testing to differentiate between wild-type and non-wild-type strains of bacteria or fungi. #' Supported types of breakpoints are `r vector_and(clinical_breakpoints$type, quotes = FALSE)`. ECOFF (Epidemiological cut-off) values are used in antimicrobial susceptibility testing to differentiate between wild-type and non-wild-type strains of bacteria or fungi.
#' #'
#' The default is `"human"`, which can also be set with the package option [`AMR_breakpoint_type`][AMR-options]. Use [`as.sir(..., breakpoint_type = ...)`][as.sir()] to interpret raw data using a specific breakpoint type, e.g. `as.sir(..., breakpoint_type = "ECOFF")` to use ECOFFs. #' The default is `"human"`, which can also be set with the package option [`AMR_breakpoint_type`][AMR-options]. Use [`as.sir(..., breakpoint_type = ...)`][as.sir()] to interpret raw data using a specific breakpoint type, e.g. `as.sir(..., breakpoint_type = "ECOFF")` to use ECOFFs.
#' #'
@@ -350,10 +350,10 @@
#' @format A [tibble][tibble::tibble] with `r format(nrow(dosage), big.mark = " ")` observations and `r ncol(dosage)` variables: #' @format A [tibble][tibble::tibble] with `r format(nrow(dosage), big.mark = " ")` observations and `r ncol(dosage)` variables:
#' - `ab`\cr Antimicrobial ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available #' - `ab`\cr Antimicrobial ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
#' - `name`\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO #' - `name`\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO
#' - `type`\cr Type of the dosage, either `r vector_or(dosage$type)` #' - `type`\cr Type of the dosage, either `r vector_or(dosage$type, documentation = TRUE)`
#' - `dose`\cr Dose, such as "2 g" or "25 mg/kg" #' - `dose`\cr Dose, such as "2 g" or "25 mg/kg"
#' - `dose_times`\cr Number of times a dose must be administered #' - `dose_times`\cr Number of times a dose must be administered
#' - `administration`\cr Route of administration, either `r vector_or(dosage$administration)` #' - `administration`\cr Route of administration, either `r vector_or(dosage$administration, documentation = TRUE)`
#' - `notes`\cr Additional dosage notes #' - `notes`\cr Additional dosage notes
#' - `original_txt`\cr Original text in the PDF file of EUCAST #' - `original_txt`\cr Original text in the PDF file of EUCAST
#' - `eucast_version`\cr Version number of the EUCAST Clinical Breakpoints guideline to which these dosages apply, either `r vector_or(dosage$eucast_version, quotes = FALSE, sort = TRUE, reverse = TRUE)` #' - `eucast_version`\cr Version number of the EUCAST Clinical Breakpoints guideline to which these dosages apply, either `r vector_or(dosage$eucast_version, quotes = FALSE, sort = TRUE, reverse = TRUE)`

View File

@@ -64,16 +64,17 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' @param guideline A guideline name, either "EUCAST" (default) or "CLSI". This can be set with the package option [`AMR_guideline`][AMR-options]. #' @param guideline A guideline name, either "EUCAST" (default) or "CLSI". This can be set with the package option [`AMR_guideline`][AMR-options].
#' @param rules A [character] vector that specifies which rules should be applied. Must be one or more of `"breakpoints"`, `"expected_phenotypes"`, `"expert"`, `"other"`, `"custom"`, `"all"`, and defaults to `c("breakpoints", "expected_phenotypes")`. The default value can be set to another value using the package option [`AMR_interpretive_rules`][AMR-options]: `options(AMR_interpretive_rules = "all")`. If using `"custom"`, be sure to fill in argument `custom_rules` too. Custom rules can be created with [custom_eucast_rules()]. #' @param rules A [character] vector that specifies which rules should be applied. Must be one or more of `"breakpoints"`, `"expected_phenotypes"`, `"expert"`, `"other"`, `"custom"`, `"all"`, and defaults to `c("breakpoints", "expected_phenotypes")`. The default value can be set to another value using the package option [`AMR_interpretive_rules`][AMR-options]: `options(AMR_interpretive_rules = "all")`. If using `"custom"`, be sure to fill in argument `custom_rules` too. Custom rules can be created with [custom_eucast_rules()].
#' @param verbose A [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time. #' @param verbose A [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.
#' @param version_breakpoints The version number to use for the EUCAST Clinical Breakpoints guideline. Can be `r vector_or(names(EUCAST_VERSION_BREAKPOINTS), reverse = TRUE)`. #' @param version_breakpoints The version number to use for the EUCAST Clinical Breakpoints guideline. Can be `r vector_or(names(EUCAST_VERSION_BREAKPOINTS), documentation = TRUE, reverse = TRUE)`.
#' @param version_expected_phenotypes The version number to use for the EUCAST Expected Phenotypes. Can be `r vector_or(names(EUCAST_VERSION_EXPECTED_PHENOTYPES), reverse = TRUE)`. #' @param version_expected_phenotypes The version number to use for the EUCAST Expected Phenotypes. Can be `r vector_or(names(EUCAST_VERSION_EXPECTED_PHENOTYPES), documentation = TRUE, reverse = TRUE)`.
#' @param version_expertrules The version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be `r vector_or(names(EUCAST_VERSION_EXPERT_RULES), reverse = TRUE)`. #' @param version_expertrules The version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be `r vector_or(names(EUCAST_VERSION_EXPERT_RULES), documentation = TRUE, reverse = TRUE)`.
#' @param ampc_cephalosporin_resistance (only applies when `rules` contains `"expert"` or `"all"`) a [character] value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants - the default is `NA`. Currently only works when `version_expertrules` is `3.2` and higher; these versions of '*EUCAST Expert Rules on Enterobacterales*' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of `NA` (the default) for this argument will remove results for these three drugs, while e.g. a value of `"R"` will make the results for these drugs resistant. Use `NULL` or `FALSE` to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using `TRUE` is equal to using `"R"`. \cr For *EUCAST Expert Rules* v3.2, this rule applies to: `r vector_and(gsub("[^a-zA-Z ]+", "", unlist(strsplit(EUCAST_RULES_DF[which(EUCAST_RULES_DF$reference.version %in% c(3.2, 3.3) & EUCAST_RULES_DF$reference.rule %like% "ampc"), "this_value"][1], "|", fixed = TRUE))), quotes = "*")`. #' @param ampc_cephalosporin_resistance (only applies when `rules` contains `"expert"` or `"all"`) a [character] value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants - the default is `NA`. Currently only works when `version_expertrules` is `3.2` and higher; these versions of '*EUCAST Expert Rules on Enterobacterales*' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of `NA` (the default) for this argument will remove results for these three drugs, while e.g. a value of `"R"` will make the results for these drugs resistant. Use `NULL` or `FALSE` to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using `TRUE` is equal to using `"R"`. \cr For *EUCAST Expert Rules* v3.2, this rule applies to: `r vector_and(gsub("[^a-zA-Z ]+", "", unlist(strsplit(EUCAST_RULES_DF[which(EUCAST_RULES_DF$reference.version %in% c(3.2, 3.3) & EUCAST_RULES_DF$reference.rule %like% "ampc"), "this_value"][1], "|", fixed = TRUE))), quotes = "*")`.
#' @param ... Column names of antimicrobials. To automatically detect antimicrobial column names, do not provide any named arguments; [guess_ab_col()] will then be used for detection. To manually specify a column, provide its name (case-insensitive) as an argument, e.g. `AMX = "amoxicillin"`. To skip a specific antimicrobial, set it to `NULL`, e.g. `TIC = NULL` to exclude ticarcillin. If a manually defined column does not exist in the data, it will be skipped with a warning. #' @param ... Column names of antimicrobials. To automatically detect antimicrobial column names, do not provide any named arguments; [guess_ab_col()] will then be used for detection. To manually specify a column, provide its name (case-insensitive) as an argument, e.g. `AMX = "amoxicillin"`. To skip a specific antimicrobial, set it to `NULL`, e.g. `TIC = NULL` to exclude ticarcillin. If a manually defined column does not exist in the data, it will be skipped with a warning.
#' @param ab Any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()]. #' @param ab Any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()].
#' @param administration Route of administration, either `r vector_or(dosage$administration)`. #' @param administration Route of administration, either `r vector_or(dosage$administration, documentation = TRUE)`.
#' @param only_sir_columns A [logical] to indicate whether only antimicrobial columns must be included that were transformed to class [sir][as.sir()] on beforehand. Defaults to `FALSE` if no columns of `x` have a class [sir][as.sir()]. #' @param only_sir_columns A [logical] to indicate whether only antimicrobial columns must be included that were transformed to class [sir][as.sir()] on beforehand. Defaults to `FALSE` if no columns of `x` have a class [sir][as.sir()].
#' @param custom_rules Custom rules to apply, created with [custom_eucast_rules()]. #' @param custom_rules Custom rules to apply, created with [custom_eucast_rules()].
#' @param overwrite A [logical] indicating whether to overwrite existing SIR values (default: `FALSE`). When `FALSE`, only non-SIR values are modified (i.e., any value that is not already S, I or R). To ensure compliance with EUCAST guidelines, **this should remain** `FALSE`, as EUCAST notes often state that an organism "should be tested for susceptibility to individual agents or be reported resistant". #' @param overwrite A [logical] indicating whether to overwrite existing SIR values (default: `FALSE`). When `FALSE`, only non-SIR values are modified (i.e., any value that is not already S, I or R). To ensure compliance with EUCAST guidelines, **this should remain** `FALSE`, as EUCAST notes often state that an organism "should be tested for susceptibility to individual agents or be reported resistant".
#' @param add_if_missing A [logical] indicating whether rules should also be applied to missing (`NA`) values (default: `TRUE`). When `FALSE`, rules are only applied to cells that already contain an SIR value; cells with `NA` are left untouched. This is particularly useful when using `overwrite = TRUE` with custom rules and you want to update reported results without imputing values for untested drugs.
#' @inheritParams first_isolate #' @inheritParams first_isolate
#' @details #' @details
#' **Note:** This function does not translate MIC or disk values to SIR values. Use [as.sir()] for that. \cr #' **Note:** This function does not translate MIC or disk values to SIR values. Use [as.sir()] for that. \cr
@@ -170,6 +171,7 @@ interpretive_rules <- function(x,
only_sir_columns = any(is.sir(x)), only_sir_columns = any(is.sir(x)),
custom_rules = NULL, custom_rules = NULL,
overwrite = FALSE, overwrite = FALSE,
add_if_missing = TRUE,
...) { ...) {
meet_criteria(x, allow_class = "data.frame") meet_criteria(x, allow_class = "data.frame")
meet_criteria(col_mo, allow_class = "character", has_length = 1, is_in = colnames(x), allow_NULL = TRUE) meet_criteria(col_mo, allow_class = "character", has_length = 1, is_in = colnames(x), allow_NULL = TRUE)
@@ -184,6 +186,12 @@ interpretive_rules <- function(x,
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE) meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE)
meet_criteria(overwrite, allow_class = "logical", has_length = 1) meet_criteria(overwrite, allow_class = "logical", has_length = 1)
meet_criteria(add_if_missing, allow_class = "logical", has_length = 1)
stop_if(
!overwrite && !add_if_missing,
"Either set {.arg overwrite} or {.arg add_if_missing} to {.code TRUE}, or both."
)
stop_if( stop_if(
guideline == "CLSI", guideline == "CLSI",
@@ -533,7 +541,8 @@ interpretive_rules <- function(x,
warned = warned, warned = warned,
info = info, info = info,
verbose = verbose, verbose = verbose,
overwrite = overwrite overwrite = overwrite,
add_if_missing = add_if_missing
) )
n_added <- n_added + run_changes$added n_added <- n_added + run_changes$added
n_changed <- n_changed + run_changes$changed n_changed <- n_changed + run_changes$changed
@@ -575,7 +584,8 @@ interpretive_rules <- function(x,
warned = warned, warned = warned,
info = info, info = info,
verbose = verbose, verbose = verbose,
overwrite = overwrite overwrite = overwrite,
add_if_missing = add_if_missing
) )
n_added <- n_added + run_changes$added n_added <- n_added + run_changes$added
n_changed <- n_changed + run_changes$changed n_changed <- n_changed + run_changes$changed
@@ -595,7 +605,7 @@ interpretive_rules <- function(x,
} else { } else {
if (isTRUE(info)) { if (isTRUE(info)) {
cat("\n") cat("\n")
message_("Skipping inhibitor-inheritance rules defined by this AMR package: setting S to drug+inhibitor where drug is S, and setting R to drug where drug+inhibitor is R. Add \"other\" or \"all\" to the {.arg rules} argument to apply those rules.") message_("Skipping inhibitor-inheritance rules defined by this AMR package: setting S to drug+inhibitor where drug is S, and setting R to drug where drug+inhibitor is R. Add {.val other} or {.val all} to the {.arg rules} argument to apply those rules.")
} }
} }
@@ -609,7 +619,7 @@ interpretive_rules <- function(x,
# >>> Apply Official EUCAST rules <<< --------------------------------------------------- # >>> Apply Official EUCAST rules <<< ---------------------------------------------------
eucast_notification_shown <- FALSE eucast_notification_shown <- FALSE
if (!is.null(list(...)$eucast_rules_df)) { if (!is.null(list(...)$eucast_rules_df)) {
# this allows: eucast_rules(x, eucast_rules_df = AMR:::EUCAST_RULES_DF %>% filter(is.na(have_these_values))) # this allows: eucast_rules(x, eucast_rules_df = AMR:::EUCAST_RULES_DF |> filter(is.na(have_these_values)))
eucast_rules_df_total <- list(...)$eucast_rules_df eucast_rules_df_total <- list(...)$eucast_rules_df
} else { } else {
# otherwise internal data file, created in data-raw/_pre_commit_checks.R # otherwise internal data file, created in data-raw/_pre_commit_checks.R
@@ -862,7 +872,8 @@ interpretive_rules <- function(x,
warned = warned, warned = warned,
info = info, info = info,
verbose = verbose, verbose = verbose,
overwrite = overwrite overwrite = overwrite,
add_if_missing = add_if_missing
) )
n_added <- n_added + run_changes$added n_added <- n_added + run_changes$added
n_changed <- n_changed + run_changes$changed n_changed <- n_changed + run_changes$changed
@@ -932,7 +943,8 @@ interpretive_rules <- function(x,
warned = warned, warned = warned,
info = info, info = info,
verbose = verbose, verbose = verbose,
overwrite = overwrite overwrite = overwrite,
add_if_missing = add_if_missing
) )
n_added <- n_added + run_changes$added n_added <- n_added + run_changes$added
n_changed <- n_changed + run_changes$changed n_changed <- n_changed + run_changes$changed
@@ -1063,13 +1075,13 @@ interpretive_rules <- function(x,
warn_lacking_sir_class <- warn_lacking_sir_class[order(colnames(x.bak))] warn_lacking_sir_class <- warn_lacking_sir_class[order(colnames(x.bak))]
warn_lacking_sir_class <- warn_lacking_sir_class[!is.na(warn_lacking_sir_class)] warn_lacking_sir_class <- warn_lacking_sir_class[!is.na(warn_lacking_sir_class)]
warning_( warning_(
"in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: not all columns with antimicrobial results are of class {.cls sir}. Transform them on beforehand, e.g.:\n", "in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: not all columns with antimicrobial results are of class {.cls sir}. Transform them on beforehand, e.g.:\n\n",
" - ", highlight_code(paste0(x_deparsed, " %>% as.sir(", ifelse(length(warn_lacking_sir_class) == 1, "\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0(x_deparsed, " |> as.sir(", ifelse(length(warn_lacking_sir_class) == 1,
warn_lacking_sir_class, warn_lacking_sir_class,
paste0(warn_lacking_sir_class[1], ":", warn_lacking_sir_class[length(warn_lacking_sir_class)]) paste0(warn_lacking_sir_class[1], ":", warn_lacking_sir_class[length(warn_lacking_sir_class)])
), ")")), "\n", ), ")")), "\n\n",
" - ", highlight_code(paste0(x_deparsed, " %>% mutate_if(is_sir_eligible, as.sir)")), "\n", "\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0(x_deparsed, " |> mutate_if(is_sir_eligible, as.sir)")), "\n\n",
" - ", highlight_code(paste0(x_deparsed, " %>% mutate(across(where(is_sir_eligible), as.sir))")) "\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0(x_deparsed, " |> mutate(across(where(is_sir_eligible), as.sir))"))
) )
} }
@@ -1124,8 +1136,10 @@ edit_sir <- function(x,
warned, warned,
info, info,
verbose, verbose,
overwrite) { overwrite,
add_if_missing) {
cols <- unique(cols[!is.na(cols) & !is.null(cols)]) cols <- unique(cols[!is.na(cols) & !is.null(cols)])
rows <- unique(rows)
# for Verbose Mode, keep track of all changes and return them # for Verbose Mode, keep track of all changes and return them
track_changes <- list( track_changes <- list(
@@ -1152,32 +1166,50 @@ edit_sir <- function(x,
track_changes$sir_warn <- cols[!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.sir)] track_changes$sir_warn <- cols[!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.sir)]
} }
isNA <- is.na(new_edits[rows, cols]) isNA <- is.na(new_edits[rows, cols])
isSIR <- !isNA & (new_edits[rows, cols] == "S" | new_edits[rows, cols] == "I" | new_edits[rows, cols] == "R" | new_edits[rows, cols] == "SDD" | new_edits[rows, cols] == "NI" | new_edits[rows, cols] == "WT" | new_edits[rows, cols] == "NWT" | new_edits[rows, cols] == "NS") isSIR <- !isNA &
(new_edits[rows, cols] == "S" |
new_edits[rows, cols] == "I" |
new_edits[rows, cols] == "R" |
new_edits[rows, cols] == "SDD" |
new_edits[rows, cols] == "NI" |
new_edits[rows, cols] == "WT" |
new_edits[rows, cols] == "NWT" |
new_edits[rows, cols] == "NS")
non_SIR <- !isSIR non_SIR <- !isSIR
if (isFALSE(overwrite) && any(isSIR) && message_not_thrown_before("edit_sir.warning_overwrite")) { if (isFALSE(overwrite) && any(isSIR) && message_not_thrown_before("edit_sir.warning_overwrite")) {
warning_("Some values had SIR values and were not overwritten, since {.code overwrite = FALSE}.") warning_("in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: some columns had SIR values which were not overwritten, since {.code overwrite = FALSE}.")
} }
tryCatch( # determine which cells to modify based on overwrite and add_if_missing
# insert into original table
if (isTRUE(overwrite)) { if (isTRUE(overwrite)) {
new_edits[rows, cols] <- to if (isTRUE(add_if_missing)) {
apply_mask <- rep(TRUE, length(isSIR))
} else { } else {
new_edits[rows, cols][non_SIR] <- to apply_mask <- isSIR
}, }
} else {
# overwrite = FALSE, add_if_missing = TRUE: fill missing and placeholder cells only
apply_mask <- !isSIR
}
do_assign <- function() {
subset <- new_edits[rows, cols, drop = FALSE]
mask <- matrix(apply_mask, nrow = nrow(subset), ncol = ncol(subset))
subset[mask] <- to
new_edits[rows, cols] <<- subset
}
tryCatch(
do_assign(),
warning = function(w) { warning = function(w) {
if (w$message %like% "invalid factor level") { if (w$message %like% "invalid factor level") {
xyz <- vapply(FUN.VALUE = logical(1), cols, function(col) { vapply(FUN.VALUE = logical(1), cols, function(col) {
new_edits[, col] <<- factor( new_edits[, col] <<- factor(
x = as.character(pm_pull(new_edits, col)), x = as.character(pm_pull(new_edits, col)),
levels = unique(c(to, levels(pm_pull(new_edits, col)))) levels = unique(c(to, levels(pm_pull(new_edits, col))))
) )
TRUE TRUE
}) })
if (isTRUE(overwrite)) { suppressWarnings(do_assign())
suppressWarnings(new_edits[rows, cols] <<- to)
} else {
suppressWarnings(new_edits[rows, cols][non_SIR] <<- to)
}
warning_( warning_(
"in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: value \"", to, "\" added to the factor levels of column", "in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: value \"", to, "\" added to the factor levels of column",
ifelse(length(cols) == 1, "", "s"), ifelse(length(cols) == 1, "", "s"),
@@ -1185,7 +1217,7 @@ edit_sir <- function(x,
" because this value was not an existing factor level." " because this value was not an existing factor level."
) )
txt_warning() txt_warning()
warned <- FALSE warned <<- FALSE
} else { } else {
warning_("in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: ", w$message) warning_("in {.help [{.fun eucast_rules}](AMR::eucast_rules)}: ", w$message)
txt_warning() txt_warning()

4
R/mo.R
View File

@@ -792,7 +792,7 @@ print.mo <- function(x, print.shortnames = FALSE, ...) {
names(x) <- x_names names(x) <- x_names
if (!all(x %in% c(AMR_env$MO_lookup$mo, NA))) { if (!all(x %in% c(AMR_env$MO_lookup$mo, NA))) {
warning_( warning_(
"Some MO codes are from a previous AMR package version. ", "Some MO codes are from another AMR package version. ",
"Please update the MO codes with {.help [{.fun as.mo}](AMR::as.mo)}.", "Please update the MO codes with {.help [{.fun as.mo}](AMR::as.mo)}.",
call = FALSE call = FALSE
) )
@@ -826,7 +826,7 @@ as.data.frame.mo <- function(x, ...) {
add_MO_lookup_to_AMR_env() add_MO_lookup_to_AMR_env()
if (!all(x %in% c(AMR_env$MO_lookup$mo, NA))) { if (!all(x %in% c(AMR_env$MO_lookup$mo, NA))) {
warning_( warning_(
"The data contains old MO codes (from a previous AMR package version). ", "The data contains old MO codes (from another AMR package version). ",
"Please update your MO codes with {.help [{.fun as.mo}](AMR::as.mo)}." "Please update your MO codes with {.help [{.fun as.mo}](AMR::as.mo)}."
) )
} }

View File

@@ -31,7 +31,7 @@
#' #'
#' Use these functions to return a specific property of a microorganism based on the latest accepted taxonomy. All input values will be evaluated internally with [as.mo()], which makes it possible to use microbial abbreviations, codes and names as input. See *Examples*. #' Use these functions to return a specific property of a microorganism based on the latest accepted taxonomy. All input values will be evaluated internally with [as.mo()], which makes it possible to use microbial abbreviations, codes and names as input. See *Examples*.
#' @param x Any [character] (vector) that can be coerced to a valid microorganism code with [as.mo()]. Can be left blank for auto-guessing the column containing microorganism codes if used in a data set, see *Examples*. #' @param x Any [character] (vector) that can be coerced to a valid microorganism code with [as.mo()]. Can be left blank for auto-guessing the column containing microorganism codes if used in a data set, see *Examples*.
#' @param property One of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`, or must be `"shortname"`. #' @param property One of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, documentation = TRUE)`, or must be `"shortname"`.
#' @inheritParams as.mo #' @inheritParams as.mo
#' @param ... Other arguments passed on to [as.mo()], such as 'minimum_matching_score', 'ignore_pattern', and 'remove_from_input'. #' @param ... Other arguments passed on to [as.mo()], such as 'minimum_matching_score', 'ignore_pattern', and 'remove_from_input'.
#' @param ab Any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()]. #' @param ab Any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()].

View File

@@ -65,7 +65,7 @@ VALID_SIR_LEVELS <- c("S", "SDD", "I", "R", "NI", "WT", "NWT", "NS")
#' @param substitute_missing_r_breakpoint A [logical] to indicate that a missing clinical breakpoints for R (resistant) must be substituted with R - the default is `FALSE`. Some (especially CLSI) breakpoints only have a breakpoint for S, meaning that the outcome can only be `"S"` or `NA`. Setting this to `TRUE` will convert the `NA`s in these cases to `"R"`. Can also be set with the package option [`AMR_substitute_missing_r_breakpoint`][AMR-options]. #' @param substitute_missing_r_breakpoint A [logical] to indicate that a missing clinical breakpoints for R (resistant) must be substituted with R - the default is `FALSE`. Some (especially CLSI) breakpoints only have a breakpoint for S, meaning that the outcome can only be `"S"` or `NA`. Setting this to `TRUE` will convert the `NA`s in these cases to `"R"`. Can also be set with the package option [`AMR_substitute_missing_r_breakpoint`][AMR-options].
#' @param include_screening A [logical] to indicate that clinical breakpoints for screening are allowed - the default is `FALSE`. Can also be set with the package option [`AMR_include_screening`][AMR-options]. #' @param include_screening A [logical] to indicate that clinical breakpoints for screening are allowed - the default is `FALSE`. Can also be set with the package option [`AMR_include_screening`][AMR-options].
#' @param include_PKPD A [logical] to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is `TRUE`. Can also be set with the package option [`AMR_include_PKPD`][AMR-options]. #' @param include_PKPD A [logical] to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is `TRUE`. Can also be set with the package option [`AMR_include_PKPD`][AMR-options].
#' @param breakpoint_type The type of breakpoints to use, either `r vector_or(clinical_breakpoints$type)`. ECOFF stands for Epidemiological Cut-Off values. The default is `"human"`, which can also be set with the package option [`AMR_breakpoint_type`][AMR-options]. If `host` is set to values of veterinary species, this will automatically be set to `"animal"`. #' @param breakpoint_type The type of breakpoints to use, either `r vector_or(clinical_breakpoints$type, documentation = TRUE)`. ECOFF stands for Epidemiological Cut-Off values. The default is `"human"`, which can also be set with the package option [`AMR_breakpoint_type`][AMR-options]. If `host` is set to values of veterinary species, this will automatically be set to `"animal"`.
#' @param host A vector (or column name) with [character]s to indicate the host. Only useful for veterinary breakpoints, as it requires `breakpoint_type = "animal"`. The values can be any text resembling the animal species, even in any of the `r length(LANGUAGES_SUPPORTED)` supported languages of this package. For foreign languages, be sure to set the language with [set_AMR_locale()] (though it will be automatically guessed based on the system language). #' @param host A vector (or column name) with [character]s to indicate the host. Only useful for veterinary breakpoints, as it requires `breakpoint_type = "animal"`. The values can be any text resembling the animal species, even in any of the `r length(LANGUAGES_SUPPORTED)` supported languages of this package. For foreign languages, be sure to set the language with [set_AMR_locale()] (though it will be automatically guessed based on the system language).
#' @param language Language to convert values set in `host` when using animal breakpoints. Use one of these supported language names or [ISO 639-1 codes](https://en.wikipedia.org/wiki/ISO_639-1): `r vector_or(paste0(sapply(LANGUAGES_SUPPORTED_NAMES, function(x) x[[1]]), " (" , LANGUAGES_SUPPORTED, ")"), quotes = FALSE, sort = FALSE)`. #' @param language Language to convert values set in `host` when using animal breakpoints. Use one of these supported language names or [ISO 639-1 codes](https://en.wikipedia.org/wiki/ISO_639-1): `r vector_or(paste0(sapply(LANGUAGES_SUPPORTED_NAMES, function(x) x[[1]]), " (" , LANGUAGES_SUPPORTED, ")"), quotes = FALSE, sort = FALSE)`.
#' @param verbose A [logical] to indicate that all notes should be printed during interpretation of MIC values or disk diffusion values. #' @param verbose A [logical] to indicate that all notes should be printed during interpretation of MIC values or disk diffusion values.

View File

@@ -21,7 +21,6 @@
#' @export #' @export
#' @examples #' @examples
#' if (require("tidymodels")) { #' if (require("tidymodels")) {
#'
#' # The below approach formed the basis for this paper: DOI 10.3389/fmicb.2025.1582703 #' # The below approach formed the basis for this paper: DOI 10.3389/fmicb.2025.1582703
#' # Presence of ESBL genes was predicted based on raw MIC values. #' # Presence of ESBL genes was predicted based on raw MIC values.
#' #'
@@ -40,13 +39,10 @@
#' #'
#' # Create and prep a recipe with MIC log2 transformation #' # Create and prep a recipe with MIC log2 transformation
#' mic_recipe <- recipe(esbl ~ ., data = training_data) %>% #' mic_recipe <- recipe(esbl ~ ., data = training_data) %>%
#'
#' # Optionally remove non-predictive variables #' # Optionally remove non-predictive variables
#' remove_role(genus, old_role = "predictor") %>% #' remove_role(genus, old_role = "predictor") %>%
#'
#' # Apply the log2 transformation to all MIC predictors #' # Apply the log2 transformation to all MIC predictors
#' step_mic_log2(all_mic_predictors()) %>% #' step_mic_log2(all_mic_predictors()) %>%
#'
#' # And apply the preparation steps #' # And apply the preparation steps
#' prep() #' prep()
#' #'
@@ -67,13 +63,15 @@
#' bind_cols(out_testing) #' bind_cols(out_testing)
#' #'
#' # Evaluate predictions using standard classification metrics #' # Evaluate predictions using standard classification metrics
#' our_metrics <- metric_set(accuracy, #' our_metrics <- metric_set(
#' accuracy,
#' recall, #' recall,
#' precision, #' precision,
#' sensitivity, #' sensitivity,
#' specificity, #' specificity,
#' ppv, #' ppv,
#' npv) #' npv
#' )
#' metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class) #' metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class)
#' #'
#' # Show performance #' # Show performance

View File

@@ -32,7 +32,7 @@
#' This function filters a data set to include only the top *n* microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera. #' This function filters a data set to include only the top *n* microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.
#' @param x A data frame containing microbial data. #' @param x A data frame containing microbial data.
#' @param n An integer specifying the maximum number of unique values of the `property` to include in the output. #' @param n An integer specifying the maximum number of unique values of the `property` to include in the output.
#' @param property A character string indicating the microorganism property to use for filtering. Must be one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. If `NULL`, the raw values from `col_mo` will be used without transformation. When using `"species"` (default) or `"subpecies"`, the genus will be added to make sure each (sub)species still belongs to the right genus. #' @param property A character string indicating the microorganism property to use for filtering. Must be one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, documentation = TRUE)`. If `NULL`, the raw values from `col_mo` will be used without transformation. When using `"species"` (default) or `"subpecies"`, the genus will be added to make sure each (sub)species still belongs to the right genus.
#' @param n_for_each An optional integer specifying the maximum number of rows to retain for each value of the selected property. If `NULL`, all rows within the top *n* groups will be included. #' @param n_for_each An optional integer specifying the maximum number of rows to retain for each value of the selected property. If `NULL`, all rows within the top *n* groups will be included.
#' @param col_mo A character string indicating the column in `x` that contains microorganism names or codes. Defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()]. #' @param col_mo A character string indicating the column in `x` that contains microorganism names or codes. Defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()].
#' @param ... Additional arguments passed on to [mo_property()] when `property` is not `NULL`. #' @param ... Additional arguments passed on to [mo_property()] when `property` is not `NULL`.

View File

@@ -15,8 +15,10 @@ library(readr)
library(tidyr) library(tidyr)
# WHONET version of 16th Feb 2024 # WHONET version of 16th Feb 2024
whonet_breakpoints <- read_tsv("WHONET/Resources/Breakpoints.txt", na = c("", "NA", "-"), whonet_breakpoints <- read_tsv("WHONET/Resources/Breakpoints.txt",
show_col_types = FALSE, guess_max = Inf) %>% na = c("", "NA", "-"),
show_col_types = FALSE, guess_max = Inf
) %>%
filter(GUIDELINES %in% c("CLSI", "EUCAST")) filter(GUIDELINES %in% c("CLSI", "EUCAST"))
dim(whonet_breakpoints) dim(whonet_breakpoints)
@@ -59,9 +61,11 @@ whonet_breakpoints |>
```{r} ```{r}
whonet_breakpoints |> whonet_breakpoints |>
filter(HOST == "Cats", YEAR == 2023) |> filter(HOST == "Cats", YEAR == 2023) |>
mutate(MO = AMR::mo_shortname(ORGANISM_CODE), mutate(
MO = AMR::mo_shortname(ORGANISM_CODE),
AB = AMR::ab_name(WHONET_ABX_CODE), AB = AMR::ab_name(WHONET_ABX_CODE),
SITE_OF_INFECTION = substr(SITE_OF_INFECTION, 1, 25)) |> SITE_OF_INFECTION = substr(SITE_OF_INFECTION, 1, 25)
) |>
arrange(MO, AB) |> arrange(MO, AB) |>
select(MO, AB, SITE_OF_INFECTION) |> select(MO, AB, SITE_OF_INFECTION) |>
as.data.frame() as.data.frame()

View File

@@ -478,7 +478,8 @@ pre_commit_lst$AB_BETALACTAMS <- sort(c(
pre_commit_lst$AB_PENICILLINS, pre_commit_lst$AB_PENICILLINS,
pre_commit_lst$AB_CEPHALOSPORINS, pre_commit_lst$AB_CEPHALOSPORINS,
pre_commit_lst$AB_CARBAPENEMS, pre_commit_lst$AB_CARBAPENEMS,
pre_commit_lst$AB_MONOBACTAMS)) pre_commit_lst$AB_MONOBACTAMS
))
pre_commit_lst$AB_BETALACTAMASE_INHIBITORS <- antimicrobials %>% pre_commit_lst$AB_BETALACTAMASE_INHIBITORS <- antimicrobials %>%
filter(atc_group2 %like% "Beta-lactamase inhibitors" | name %like% "bactam") %>% filter(atc_group2 %like% "Beta-lactamase inhibitors" | name %like% "bactam") %>%
pull(ab) pull(ab)
@@ -496,7 +497,8 @@ for (grp in pre_commit_lst$DEFINED_AB_GROUPS[pre_commit_lst$DEFINED_AB_GROUPS %u
if (!fn_name %in% ls(envir = asNamespace("AMR"))) { if (!fn_name %in% ls(envir = asNamespace("AMR"))) {
stop("Group '", grp, "' has ", length(pre_commit_lst[[grp]]), stop("Group '", grp, "' has ", length(pre_commit_lst[[grp]]),
" members (", toString(ab_name(pre_commit_lst[[grp]], tolower = T)), ") but no corresponding function '", fn_name, "()' exists in the AMR namespace.", " members (", toString(ab_name(pre_commit_lst[[grp]], tolower = T)), ") but no corresponding function '", fn_name, "()' exists in the AMR namespace.",
call. = FALSE) call. = FALSE
)
} }
} }
} }
@@ -534,7 +536,8 @@ for (i in seq_along(group_map)) {
} }
# create priority list for ab_group() # create priority list for ab_group()
pre_commit_lst$ABX_PRIORITY_LIST <- c("Aminopenicillins", pre_commit_lst$ABX_PRIORITY_LIST <- c(
"Aminopenicillins",
"Isoxazolylpenicillins", "Isoxazolylpenicillins",
"Ureidopenicillins", "Ureidopenicillins",
"Oxazolidinones", "Oxazolidinones",
@@ -573,7 +576,8 @@ pre_commit_lst$ABX_PRIORITY_LIST <- c("Aminopenicillins",
"Beta-lactamase inhibitors", "Beta-lactamase inhibitors",
"Pleuromutilins", "Pleuromutilins",
"Aminocoumarins", "Aminocoumarins",
"Other") "Other"
)
if (!all(unlist(antimicrobials$group) %in% pre_commit_lst$ABX_PRIORITY_LIST)) { if (!all(unlist(antimicrobials$group) %in% pre_commit_lst$ABX_PRIORITY_LIST)) {
stop("Missing group(s) in priority list: ", paste(setdiff(unlist(antimicrobials$group), pre_commit_lst$ABX_PRIORITY_LIST), collapse = ", ")) stop("Missing group(s) in priority list: ", paste(setdiff(unlist(antimicrobials$group), pre_commit_lst$ABX_PRIORITY_LIST), collapse = ", "))
} }
@@ -589,17 +593,17 @@ pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(antivirals)
# Export to package as internal data ---- # Export to package as internal data ----
# usethis::use_data() must receive unquoted object names, which is not flexible at all. # usethis::use_data() must receive unquoted object names, which is not flexible at all.
# we'll use good old base::save() instead # we'll use good old base::save() instead
save(list = names(pre_commit_lst), save(
list = names(pre_commit_lst),
file = "R/sysdata.rda", file = "R/sysdata.rda",
envir = as.environment(pre_commit_lst), envir = as.environment(pre_commit_lst),
compress = "xz", compress = "xz",
version = 2, version = 2,
ascii = FALSE) ascii = FALSE
)
usethis::ui_done("Saved to {usethis::ui_value('R/sysdata.rda')}") usethis::ui_done("Saved to {usethis::ui_value('R/sysdata.rda')}")
# Export data sets to the repository in different formats ----------------- # Export data sets to the repository in different formats -----------------
for (pkg in c("haven", "openxlsx2", "arrow")) { for (pkg in c("haven", "openxlsx2", "arrow")) {
@@ -621,7 +625,9 @@ write_md5 <- function(object) {
} }
changed_md5 <- function(object) { changed_md5 <- function(object) {
path <- paste0("data-raw/", deparse(substitute(object)), ".md5") path <- paste0("data-raw/", deparse(substitute(object)), ".md5")
if (!file.exists(path)) return(TRUE) if (!file.exists(path)) {
return(TRUE)
}
tryCatch( tryCatch(
{ {
conn <- file(path) conn <- file(path)
@@ -759,11 +765,14 @@ devtools::load_all(quiet = TRUE)
suppressMessages(set_AMR_locale("English")) suppressMessages(set_AMR_locale("English"))
files_changed <- function(paths = "^(R|data)/") { files_changed <- function(paths = "^(R|data)/") {
tryCatch({ tryCatch(
{
changed_files <- system("git status", intern = TRUE) changed_files <- system("git status", intern = TRUE)
changed_files <- unlist(strsplit(changed_files, " ")) changed_files <- unlist(strsplit(changed_files, " "))
any(changed_files %like% paths[paths != "R/sysdata.rda"]) any(changed_files %like% paths[paths != "R/sysdata.rda"])
}, error = function(e) TRUE) },
error = function(e) TRUE
)
} }
# Update URLs ------------------------------------------------------------- # Update URLs -------------------------------------------------------------
@@ -801,8 +810,10 @@ if (files_changed()) {
# Style pkg --------------------------------------------------------------- # Style pkg ---------------------------------------------------------------
if (files_changed(paths = "^(R|tests)/")) { if (files_changed(paths = "^(R|tests)/")) {
usethis::ui_info("Styling package") usethis::ui_info("Styling package")
styler::style_pkg(include_roxygen_examples = FALSE, styler::style_pkg(
exclude_dirs = list.dirs(full.names = FALSE, recursive = FALSE)[!list.dirs(full.names = FALSE, recursive = FALSE) %in% c("R", "tests")]) include_roxygen_examples = FALSE,
exclude_dirs = list.dirs(full.names = FALSE, recursive = FALSE)[!list.dirs(full.names = FALSE, recursive = FALSE) %in% c("R", "tests")]
)
} }
# Document pkg ------------------------------------------------------------ # Document pkg ------------------------------------------------------------

View File

@@ -763,10 +763,12 @@ antimicrobials[which(antimicrobials$ab %in% c("CYC", "LNZ", "THA", "TZD")), "gro
# add efflux # add efflux
effl <- antimicrobials |> effl <- antimicrobials |>
filter(ab == "ACM") |> filter(ab == "ACM") |>
mutate(ab = as.character("EFF"), mutate(
ab = as.character("EFF"),
cid = NA_real_, cid = NA_real_,
name = "Efflux", name = "Efflux",
group = "Other") group = "Other"
)
antimicrobials <- antimicrobials |> antimicrobials <- antimicrobials |>
mutate(ab = as.character(ab)) |> mutate(ab = as.character(ab)) |>
bind_rows(effl) bind_rows(effl)
@@ -777,9 +779,11 @@ antimicrobials[which(antimicrobials$ab == "EFF"), "abbreviations"][[1]] <- list(
# add clindamycin inducible screening # add clindamycin inducible screening
clin <- antimicrobials |> clin <- antimicrobials |>
filter(ab == "FOX1") |> filter(ab == "FOX1") |>
mutate(ab = as.character("CLI-S"), mutate(
ab = as.character("CLI-S"),
name = "Clindamycin inducible screening", name = "Clindamycin inducible screening",
group = "Macrolides/lincosamides") group = "Macrolides/lincosamides"
)
antimicrobials <- antimicrobials |> antimicrobials <- antimicrobials |>
mutate(ab = as.character(ab)) |> mutate(ab = as.character(ab)) |>
bind_rows(clin) bind_rows(clin)
@@ -791,7 +795,8 @@ antimicrobials <- antimicrobials |>
bind_rows( bind_rows(
antimicrobials |> antimicrobials |>
filter(ab == "EFF") |> filter(ab == "EFF") |>
mutate(ab = "BLA-S", mutate(
ab = "BLA-S",
name = paste("Beta-lactamase", "screening test"), name = paste("Beta-lactamase", "screening test"),
cid = NA_real_, cid = NA_real_,
atc = list(character(0)), atc = list(character(0)),
@@ -803,10 +808,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "PEN") |> filter(ab == "PEN") |>
mutate(ab = "PEN-S", mutate(
ab = "PEN-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -818,10 +825,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "OXA") |> filter(ab == "OXA") |>
mutate(ab = "OXA-S", mutate(
ab = "OXA-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -833,10 +842,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "PEF") |> filter(ab == "PEF") |>
mutate(ab = "PEF-S", mutate(
ab = "PEF-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -848,10 +859,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "NAL") |> filter(ab == "NAL") |>
mutate(ab = "NAL-S", mutate(
ab = "NAL-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -863,10 +876,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "NOR") |> filter(ab == "NOR") |>
mutate(ab = "NOR-S", mutate(
ab = "NOR-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -878,10 +893,12 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))), loinc = list(character(0))
),
antimicrobials |> antimicrobials |>
filter(ab == "TCY") |> filter(ab == "TCY") |>
mutate(ab = "TCY-S", mutate(
ab = "TCY-S",
name = paste(name, "screening test"), name = paste(name, "screening test"),
cid = NA, cid = NA,
atc = list(character(0)), atc = list(character(0)),
@@ -893,7 +910,8 @@ antimicrobials <- antimicrobials |>
oral_units = NA_character_, oral_units = NA_character_,
iv_ddd = NA_real_, iv_ddd = NA_real_,
iv_units = NA_character_, iv_units = NA_character_,
loinc = list(character(0))) loinc = list(character(0))
)
) )
@@ -919,16 +937,20 @@ antimicrobials <- antimicrobials |>
antimicrobials |> antimicrobials |>
filter(ab == "FPE") |> filter(ab == "FPE") |>
mutate(ab = as.character(ab)) |> mutate(ab = as.character(ab)) |>
mutate(ab = "FTA", mutate(
ab = "FTA",
name = "Cefepime/taniborbactam", name = "Cefepime/taniborbactam",
cid = NA_real_), cid = NA_real_
),
antimicrobials |> antimicrobials |>
filter(ab == "TBP") |> filter(ab == "TBP") |>
mutate(ab = as.character(ab)) |> mutate(ab = as.character(ab)) |>
mutate(ab = "TAN", mutate(
ab = "TAN",
name = "Taniborbactam", name = "Taniborbactam",
cid = 76902493, cid = 76902493,
abbreviations = list("VNRX-5133")) abbreviations = list("VNRX-5133")
)
) )
antimicrobials <- antimicrobials |> antimicrobials <- antimicrobials |>
@@ -936,39 +958,51 @@ antimicrobials <- antimicrobials |>
bind_rows( bind_rows(
antimicrobials |> antimicrobials |>
filter(ab == "CTB") |> filter(ab == "CTB") |>
mutate(ab = "CTA", mutate(
ab = "CTA",
cid = NA_real_, cid = NA_real_,
name = "Ceftibuten/avibactam") |> name = "Ceftibuten/avibactam"
) |>
select(1:4), select(1:4),
antimicrobials |> antimicrobials |>
filter(ab == "KAC") |> filter(ab == "KAC") |>
mutate(ab = "KAS", mutate(
ab = "KAS",
cid = NA_real_, cid = NA_real_,
name = "Kasugamycin") |> name = "Kasugamycin"
) |>
select(1:4), select(1:4),
antimicrobials |> antimicrobials |>
filter(ab == "PRI") |> filter(ab == "PRI") |>
mutate(ab = "OST", mutate(
ab = "OST",
cid = NA_real_, cid = NA_real_,
name = "Ostreogrycin") |> name = "Ostreogrycin"
) |>
select(1:4), select(1:4),
antimicrobials |> antimicrobials |>
filter(ab == "PRI") |> filter(ab == "PRI") |>
mutate(ab = "THS", mutate(
ab = "THS",
cid = NA_real_, cid = NA_real_,
name = "Thiostrepton") |> name = "Thiostrepton"
) |>
select(1, 3), select(1, 3),
antimicrobials |> antimicrobials |>
filter(ab == "CLA1") |> filter(ab == "CLA1") |>
mutate(ab = "XER", mutate(
ab = "XER",
cid = NA_real_, cid = NA_real_,
name = "Xeruborbactam") |> name = "Xeruborbactam"
) |>
select(1:4), select(1:4),
antimicrobials |> antimicrobials |>
filter(ab == "BLM") |> filter(ab == "BLM") |>
mutate(ab = "ZOR", mutate(
ab = "ZOR",
cid = NA_real_, cid = NA_real_,
name = "Zorbamycin") |> name = "Zorbamycin"
) |>
select(1:4), select(1:4),
) )
@@ -977,9 +1011,11 @@ antimicrobials <- antimicrobials |>
bind_rows( bind_rows(
antimicrobials |> antimicrobials |>
filter(ab == "NOV") |> filter(ab == "NOV") |>
mutate(ab = "CLB", mutate(
ab = "CLB",
cid = 54706138, cid = 54706138,
name = "Clorobiocin") |> name = "Clorobiocin"
) |>
select(1:4), select(1:4),
) )
@@ -1055,8 +1091,10 @@ to_update <- 1:nrow(antimicrobials)
# or just the empty ones: # or just the empty ones:
to_update <- which(sapply(antimicrobials$atc, function(x) length(x[!is.na(x)])) == 0) to_update <- which(sapply(antimicrobials$atc, function(x) length(x[!is.na(x)])) == 0)
updated_atc <- lapply(seq_len(length(to_update)), updated_atc <- lapply(
function(x) NA_character_) seq_len(length(to_update)),
function(x) NA_character_
)
# this takes around 10 minutes for the whole table (some ABx are skipped and go faster) # this takes around 10 minutes for the whole table (some ABx are skipped and go faster)

View File

@@ -89,28 +89,36 @@ unmatched <- whonet_organisms |> filter(is.na(mo))
# generate the mo codes and add their names # generate the mo codes and add their names
message("Getting MO codes for WHONET input...") message("Getting MO codes for WHONET input...")
unmatched <- unmatched |> unmatched <- unmatched |>
mutate(mo = as.mo(gsub("(sero[a-z]*| nontypable| non[-][a-zA-Z]+|var[.]| not .*|sp[.],.*|, .*variant.*|, .*toxin.*|, microaer.*| beta-haem[.])", "", ORGANISM), mutate(
mo = as.mo(gsub("(sero[a-z]*| nontypable| non[-][a-zA-Z]+|var[.]| not .*|sp[.],.*|, .*variant.*|, .*toxin.*|, microaer.*| beta-haem[.])", "", ORGANISM),
minimum_matching_score = 0.55, minimum_matching_score = 0.55,
keep_synonyms = TRUE, keep_synonyms = TRUE,
language = "en"), language = "en"
mo = case_when(ORGANISM %like% "Anaerobic" & ORGANISM %like% "negative" ~ as.mo("B_ANAER-NEG"), ),
mo = case_when(
ORGANISM %like% "Anaerobic" & ORGANISM %like% "negative" ~ as.mo("B_ANAER-NEG"),
ORGANISM %like% "Anaerobic" & ORGANISM %like% "positive" ~ as.mo("B_ANAER-POS"), ORGANISM %like% "Anaerobic" & ORGANISM %like% "positive" ~ as.mo("B_ANAER-POS"),
ORGANISM %like% "Anaerobic" ~ as.mo("B_ANAER"), ORGANISM %like% "Anaerobic" ~ as.mo("B_ANAER"),
TRUE ~ mo), TRUE ~ mo
),
mo_name = mo_name(mo, mo_name = mo_name(mo,
keep_synonyms = TRUE, keep_synonyms = TRUE,
language = "en")) language = "en"
)
)
# check if coercion at least resembles the first part (genus) # check if coercion at least resembles the first part (genus)
unmatched <- unmatched |> unmatched <- unmatched |>
mutate( mutate(
first_part = sapply(ORGANISM, function(x) strsplit(gsub("[^a-zA-Z _-]+", "", x), " ")[[1]][1], USE.NAMES = FALSE), first_part = sapply(ORGANISM, function(x) strsplit(gsub("[^a-zA-Z _-]+", "", x), " ")[[1]][1], USE.NAMES = FALSE),
keep = mo_name %like_case% first_part | ORGANISM %like% "Gram " | ORGANISM == "Other" | ORGANISM %like% "anaerobic") |> keep = mo_name %like_case% first_part | ORGANISM %like% "Gram " | ORGANISM == "Other" | ORGANISM %like% "anaerobic"
) |>
arrange(keep) arrange(keep)
unmatched |> View() unmatched |> View()
unmatched <- unmatched |> unmatched <- unmatched |>
filter(keep == TRUE) filter(keep == TRUE)
organisms <- matched |> transmute(code = toupper(ORGANISM_CODE), group = SPECIES_GROUP, mo) |> organisms <- matched |>
transmute(code = toupper(ORGANISM_CODE), group = SPECIES_GROUP, mo) |>
bind_rows(unmatched |> transmute(code = toupper(ORGANISM_CODE), group = SPECIES_GROUP, mo)) |> bind_rows(unmatched |> transmute(code = toupper(ORGANISM_CODE), group = SPECIES_GROUP, mo)) |>
mutate(name = mo_name(mo, keep_synonyms = TRUE)) |> mutate(name = mo_name(mo, keep_synonyms = TRUE)) |>
arrange(code) arrange(code)
@@ -127,10 +135,16 @@ subspp <- organisms |>
filter(mo_species(mo, keep_synonyms = TRUE) == mo_subspecies(mo, keep_synonyms = TRUE) & filter(mo_species(mo, keep_synonyms = TRUE) == mo_subspecies(mo, keep_synonyms = TRUE) &
mo_species(mo, keep_synonyms = TRUE) != "" & mo_species(mo, keep_synonyms = TRUE) != "" &
mo_genus(mo, keep_synonyms = TRUE) != "Salmonella") |> mo_genus(mo, keep_synonyms = TRUE) != "Salmonella") |>
mutate(mo = as.mo(paste(mo_genus(mo, keep_synonyms = TRUE), mutate(
mo_species(mo, keep_synonyms = TRUE)), mo = as.mo(
keep_synonyms = TRUE), paste(
name = mo_name(mo, keep_synonyms = TRUE)) mo_genus(mo, keep_synonyms = TRUE),
mo_species(mo, keep_synonyms = TRUE)
),
keep_synonyms = TRUE
),
name = mo_name(mo, keep_synonyms = TRUE)
)
organisms <- organisms |> organisms <- organisms |>
filter(!code %in% subspp$code) |> filter(!code %in% subspp$code) |>
bind_rows(subspp) |> bind_rows(subspp) |>
@@ -138,10 +152,12 @@ organisms <- organisms |>
# add the groups # add the groups
organisms <- organisms |> organisms <- organisms |>
bind_rows(tibble(code = organisms |> filter(!is.na(group)) |> pull(group) |> unique(), bind_rows(tibble(
code = organisms |> filter(!is.na(group)) |> pull(group) |> unique(),
group = NA, group = NA,
mo = organisms |> filter(!is.na(group)) |> pull(group) |> unique() |> as.mo(keep_synonyms = TRUE), mo = organisms |> filter(!is.na(group)) |> pull(group) |> unique() |> as.mo(keep_synonyms = TRUE),
name = mo_name(mo, keep_synonyms = TRUE))) |> name = mo_name(mo, keep_synonyms = TRUE)
)) |>
arrange(code, group) |> arrange(code, group) |>
select(-group) |> select(-group) |>
distinct() distinct()
@@ -233,10 +249,14 @@ AMR::clinical_breakpoints |>
breakpoints <- whonet_breakpoints_raw |> breakpoints <- whonet_breakpoints_raw |>
mutate(code = toupper(ORGANISM_CODE)) |> mutate(code = toupper(ORGANISM_CODE)) |>
left_join(bind_rows(microorganisms.codes |> filter(!code %in% c("ALL", "GEN")), left_join(bind_rows(
microorganisms.codes |> filter(!code %in% c("ALL", "GEN")),
# GEN (Generic) and ALL (All) are PK/PD codes # GEN (Generic) and ALL (All) are PK/PD codes
data.frame(code = c("ALL", "GEN"), data.frame(
mo = rep(as.mo("UNKNOWN"), 2)))) code = c("ALL", "GEN"),
mo = rep(as.mo("UNKNOWN"), 2)
)
))
# these ones lack an MO name, they cannot be used: # these ones lack an MO name, they cannot be used:
unknown <- breakpoints |> unknown <- breakpoints |>
filter(is.na(mo)) |> filter(is.na(mo)) |>
@@ -253,8 +273,10 @@ breakpoints <- breakpoints |>
breakpoints |> breakpoints |>
filter(!WHONET_ABX_CODE %in% whonet_antibiotics_raw$WHONET_ABX_CODE) |> filter(!WHONET_ABX_CODE %in% whonet_antibiotics_raw$WHONET_ABX_CODE) |>
count(GUIDELINES, WHONET_ABX_CODE) |> count(GUIDELINES, WHONET_ABX_CODE) |>
mutate(ab = as.ab(WHONET_ABX_CODE, fast_mode = TRUE), mutate(
ab_name = ab_name(ab)) ab = as.ab(WHONET_ABX_CODE, fast_mode = TRUE),
ab_name = ab_name(ab)
)
# 2025-04-20: these codes are currently: CFC, ROX, FIX, and N/A. All have the right replacements in `antimicrobials`, so we can safely use as.ab() later on # 2025-04-20: these codes are currently: CFC, ROX, FIX, and N/A. All have the right replacements in `antimicrobials`, so we can safely use as.ab() later on
# the NAs are for M. tuberculosis, they are empty breakpoints # the NAs are for M. tuberculosis, they are empty breakpoints
breakpoints <- breakpoints |> breakpoints <- breakpoints |>
@@ -301,11 +323,15 @@ breakpoints_new <- breakpoints |>
distinct(guideline, type, host, ab, mo, method, site, breakpoint_S, .keep_all = TRUE) distinct(guideline, type, host, ab, mo, method, site, breakpoint_S, .keep_all = TRUE)
# fix reference table names # fix reference table names
breakpoints_new |> filter(guideline %like% "EUCAST", is.na(ref_tbl)) |> View() breakpoints_new |>
filter(guideline %like% "EUCAST", is.na(ref_tbl)) |>
View()
breakpoints_new <- breakpoints_new |> breakpoints_new <- breakpoints_new |>
mutate(ref_tbl = case_when(is.na(ref_tbl) & guideline %like% "EUCAST 202" ~ lead(ref_tbl), mutate(ref_tbl = case_when(
is.na(ref_tbl) & guideline %like% "EUCAST 202" ~ lead(ref_tbl),
is.na(ref_tbl) ~ "Unknown", is.na(ref_tbl) ~ "Unknown",
TRUE ~ ref_tbl)) TRUE ~ ref_tbl
))
# clean disk zones # clean disk zones
breakpoints_new[which(breakpoints_new$method == "DISK"), "breakpoint_S"] <- as.double(as.disk(breakpoints_new[which(breakpoints_new$method == "DISK"), "breakpoint_S", drop = TRUE])) breakpoints_new[which(breakpoints_new$method == "DISK"), "breakpoint_S"] <- as.double(as.disk(breakpoints_new[which(breakpoints_new$method == "DISK"), "breakpoint_S", drop = TRUE]))
@@ -324,8 +350,12 @@ m <- unique(as.double(as.mic(levels(as.mic(1)))))
# WHONET has no >1024 but instead uses 1025, 513, and 129, so as.mic() cannot be used to clean. # WHONET has no >1024 but instead uses 1025, 513, and 129, so as.mic() cannot be used to clean.
# instead, raise these one higher valid MIC factor level: # instead, raise these one higher valid MIC factor level:
breakpoints_new |> filter(method == "MIC" & (!breakpoint_S %in% c(m, NA))) |> distinct(breakpoint_S) breakpoints_new |>
breakpoints_new |> filter(method == "MIC" & (!breakpoint_R %in% c(m, NA))) |> distinct(breakpoint_R) filter(method == "MIC" & (!breakpoint_S %in% c(m, NA))) |>
distinct(breakpoint_S)
breakpoints_new |>
filter(method == "MIC" & (!breakpoint_R %in% c(m, NA))) |>
distinct(breakpoint_R)
breakpoints_new[which(breakpoints_new$breakpoint_R == 129), "breakpoint_R"] <- m[which(m == 128) + 1] breakpoints_new[which(breakpoints_new$breakpoint_R == 129), "breakpoint_R"] <- m[which(m == 128) + 1]
breakpoints_new[which(breakpoints_new$breakpoint_R == 257), "breakpoint_R"] <- m[which(m == 256) + 1] breakpoints_new[which(breakpoints_new$breakpoint_R == 257), "breakpoint_R"] <- m[which(m == 256) + 1]
breakpoints_new[which(breakpoints_new$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1] breakpoints_new[which(breakpoints_new$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1]
@@ -387,7 +417,9 @@ breakpoints_new <- breakpoints_new |> filter(!wrong)
# 2025-04-20/ fixed now # 2025-04-20/ fixed now
# WHONET sets for EUCAST 2026 TMP breakpoints for all Klebsiella, but this is now only for non-aerogenes species # WHONET sets for EUCAST 2026 TMP breakpoints for all Klebsiella, but this is now only for non-aerogenes species
kleb_spp <- microorganisms |> filter(rank == "species", genus == "Klebsiella", !species %in% c("", "aerogenes")) |> pull(mo) kleb_spp <- microorganisms |>
filter(rank == "species", genus == "Klebsiella", !species %in% c("", "aerogenes")) |>
pull(mo)
kleb_tmp_mic <- breakpoints_new |> kleb_tmp_mic <- breakpoints_new |>
filter(guideline == "EUCAST 2026", method == "MIC", ab == "TMP", mo == as.mo("Klebsiella")) |> filter(guideline == "EUCAST 2026", method == "MIC", ab == "TMP", mo == as.mo("Klebsiella")) |>
uncount(length(kleb_spp)) |> uncount(length(kleb_spp)) |>
@@ -398,8 +430,10 @@ kleb_tmp_disk <- breakpoints_new |>
mutate(mo = kleb_spp) mutate(mo = kleb_spp)
breakpoints_new <- breakpoints_new |> breakpoints_new <- breakpoints_new |>
filter(!(guideline == "EUCAST 2026" & method == "MIC" & ab == "TMP" & mo == as.mo("Klebsiella"))) |> filter(!(guideline == "EUCAST 2026" & method == "MIC" & ab == "TMP" & mo == as.mo("Klebsiella"))) |>
bind_rows(kleb_tmp_mic, bind_rows(
kleb_tmp_disk) kleb_tmp_mic,
kleb_tmp_disk
)
# WHONET contains wrong EUCAST breakpoints for enterococci/SXT: disk should be 23/23, not 21/50, and MIC should be 1/1, not 0.032/1 # WHONET contains wrong EUCAST breakpoints for enterococci/SXT: disk should be 23/23, not 21/50, and MIC should be 1/1, not 0.032/1
# applies to all previous years, since v11 (2011) # applies to all previous years, since v11 (2011)

View File

@@ -649,7 +649,9 @@ taxonomy_mycobank <- taxonomy_mycobank %>%
arrange(fullname) arrange(fullname)
taxonomy_mycobank %>% count(rank, sort = TRUE) taxonomy_mycobank %>% count(rank, sort = TRUE)
taxonomy_mycobank %>% filter(rank %like% "#") %>% count(rank) taxonomy_mycobank %>%
filter(rank %like% "#") %>%
count(rank)
taxonomy_mycobank3 <- taxonomy_mycobank taxonomy_mycobank3 <- taxonomy_mycobank
@@ -2546,7 +2548,9 @@ taxonomy %>%
arrange(mo) %>% arrange(mo) %>%
View() View()
# keep the firsts # keep the firsts
taxonomy <- taxonomy %>% arrange(mo) %>% distinct(mo, .keep_all = TRUE) taxonomy <- taxonomy %>%
arrange(mo) %>%
distinct(mo, .keep_all = TRUE)
# are fullnames unique? # are fullnames unique?
taxonomy %>% taxonomy %>%
@@ -2997,7 +3001,9 @@ taxonomy$rank[which(taxonomy$fullname %like% "unknown")] <- "(unknown rank)"
# this happened in early 2025, check that MO codes do not have repeated elements # this happened in early 2025, check that MO codes do not have repeated elements
# fixed it then like this: microorganisms$mo <- gsub("B_SCLLM_CNNM_LNSM_LNSM_LNSM_LNSM", "B_SCLLM_CNNM", microorganisms$mo) # fixed it then like this: microorganisms$mo <- gsub("B_SCLLM_CNNM_LNSM_LNSM_LNSM_LNSM", "B_SCLLM_CNNM", microorganisms$mo)
taxonomy |> filter(mo %like% "_.*_.*_.*_") |> View() taxonomy |>
filter(mo %like% "_.*_.*_.*_") |>
View()
fix_old_mos <- function(dataset) { fix_old_mos <- function(dataset) {
@@ -3085,7 +3091,9 @@ microorganisms <- taxonomy
# set class <mo> # set class <mo>
class(microorganisms$mo) <- c("mo", "character") class(microorganisms$mo) <- c("mo", "character")
microorganisms <- microorganisms %>% arrange(fullname) %>% df_remove_nonASCII() microorganisms <- microorganisms %>%
arrange(fullname) %>%
df_remove_nonASCII()
usethis::use_data( usethis::use_data(
microorganisms, microorganisms,
overwrite = TRUE, overwrite = TRUE,

View File

@@ -73,58 +73,87 @@ whonet_organisms <- whonet_organisms %>%
whonet_organisms %>% whonet_organisms %>%
filter(!is.na(SPECIES_GROUP)) %>% filter(!is.na(SPECIES_GROUP)) %>%
group_by(SPECIES_GROUP) %>% group_by(SPECIES_GROUP) %>%
summarise(complex = ORGANISM[ORGANISM %like% " (group|complex)"][1], summarise(
organisms = paste0(n(), ": ", paste(sort(unique(ORGANISM)), collapse = ", "))) %>% complex = ORGANISM[ORGANISM %like% " (group|complex)"][1],
organisms = paste0(n(), ": ", paste(sort(unique(ORGANISM)), collapse = ", "))
) %>%
filter(!SPECIES_GROUP %in% microorganisms.codes$code) filter(!SPECIES_GROUP %in% microorganisms.codes$code)
# create the species group data set ---- # create the species group data set ----
microorganisms.groups <- whonet_organisms %>% microorganisms.groups <- whonet_organisms %>%
# these will not be translated well # these will not be translated well
filter(!ORGANISM %in% c("Trueperella pyogenes-like bacteria", filter(!ORGANISM %in% c(
"Trueperella pyogenes-like bacteria",
"Mycobacterium suricattae", "Mycobacterium suricattae",
"Mycobacterium canetti")) %>% "Mycobacterium canetti"
)) %>%
filter(!is.na(SPECIES_GROUP), SPECIES_GROUP != ORGANISM_CODE) %>% filter(!is.na(SPECIES_GROUP), SPECIES_GROUP != ORGANISM_CODE) %>%
transmute(mo_group = as.mo(SPECIES_GROUP), transmute(
mo_group = as.mo(SPECIES_GROUP),
mo = ifelse(is.na(mo), mo = ifelse(is.na(mo),
as.character(as.mo(ORGANISM, keep_synonyms = TRUE, minimum_matching_score = 0)), as.character(as.mo(ORGANISM, keep_synonyms = TRUE, minimum_matching_score = 0)),
mo)) %>% mo
)
) %>%
# add our own CoNS and CoPS, WHONET does not strictly follow Becker et al. (2014, 2019, 2020) # add our own CoNS and CoPS, WHONET does not strictly follow Becker et al. (2014, 2019, 2020)
filter(mo_group != as.mo("CoNS")) %>% filter(mo_group != as.mo("CoNS")) %>%
bind_rows(tibble(mo_group = as.mo("CoNS"), mo = MO_CONS)) %>% bind_rows(tibble(mo_group = as.mo("CoNS"), mo = MO_CONS)) %>%
filter(mo_group != as.mo("CoPS")) %>% filter(mo_group != as.mo("CoPS")) %>%
bind_rows(tibble(mo_group = as.mo("CoPS"), mo = MO_COPS)) %>% bind_rows(tibble(mo_group = as.mo("CoPS"), mo = MO_COPS)) %>%
# at least all our Lancefield-grouped streptococci must be in the beta-haemolytic group: # at least all our Lancefield-grouped streptococci must be in the beta-haemolytic group:
bind_rows(tibble(mo_group = as.mo("Beta-haemolytic streptococcus"), bind_rows(tibble(
mo = c(MO_LANCEFIELD, mo_group = as.mo("Beta-haemolytic streptococcus"),
microorganisms %>% filter(fullname %like% "^Streptococcus Group") %>% pull(mo)))) %>% mo = c(
MO_LANCEFIELD,
microorganisms %>% filter(fullname %like% "^Streptococcus Group") %>% pull(mo)
)
)) %>%
# and per Streptococcus group as well: # and per Streptococcus group as well:
# group A - S. pyogenes # group A - S. pyogenes
bind_rows(tibble(mo_group = as.mo("Streptococcus Group A"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_PYGN(_|$)")])) %>% mo_group = as.mo("Streptococcus Group A"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_PYGN(_|$)")]
)) %>%
# group B - S. agalactiae # group B - S. agalactiae
bind_rows(tibble(mo_group = as.mo("Streptococcus Group B"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_AGLC(_|$)")])) %>% mo_group = as.mo("Streptococcus Group B"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_AGLC(_|$)")]
)) %>%
# group C - all subspecies within S. dysgalactiae and S. equi (such as S. equi zooepidemicus) # group C - all subspecies within S. dysgalactiae and S. equi (such as S. equi zooepidemicus)
bind_rows(tibble(mo_group = as.mo("Streptococcus Group C"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(DYSG|EQUI)(_|$)")])) %>% mo_group = as.mo("Streptococcus Group C"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(DYSG|EQUI)(_|$)")]
)) %>%
# group F - Milleri group == S. anginosus group, which incl. S. anginosus, S. constellatus, S. intermedius # group F - Milleri group == S. anginosus group, which incl. S. anginosus, S. constellatus, S. intermedius
bind_rows(tibble(mo_group = as.mo("Streptococcus Group F"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(ANGN|CNST|INTR)(_|$)")])) %>% mo_group = as.mo("Streptococcus Group F"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(ANGN|CNST|INTR)(_|$)")]
)) %>%
# group G - S. dysgalactiae and S. canis (though dysgalactiae is also group C and will be matched there) # group G - S. dysgalactiae and S. canis (though dysgalactiae is also group C and will be matched there)
bind_rows(tibble(mo_group = as.mo("Streptococcus Group G"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(DYSG|CANS)(_|$)")])) %>% mo_group = as.mo("Streptococcus Group G"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(DYSG|CANS)(_|$)")]
)) %>%
# group H - S. sanguinis # group H - S. sanguinis
bind_rows(tibble(mo_group = as.mo("Streptococcus Group H"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_SNGN(_|$)")])) %>% mo_group = as.mo("Streptococcus Group H"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_SNGN(_|$)")]
)) %>%
# group K - S. salivarius, incl. S. salivarius salivariuss and S. salivarius thermophilus # group K - S. salivarius, incl. S. salivarius salivariuss and S. salivarius thermophilus
bind_rows(tibble(mo_group = as.mo("Streptococcus Group K"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_SLVR(_|$)")])) %>% mo_group = as.mo("Streptococcus Group K"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_SLVR(_|$)")]
)) %>%
# group L - only S. dysgalactiae # group L - only S. dysgalactiae
bind_rows(tibble(mo_group = as.mo("Streptococcus Group L"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_DYSG(_|$)")])) %>% mo_group = as.mo("Streptococcus Group L"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_DYSG(_|$)")]
)) %>%
# and for EUCAST: Strep group A, B, C, G # and for EUCAST: Strep group A, B, C, G
bind_rows(tibble(mo_group = as.mo("Streptococcus Group A, B, C, G"), bind_rows(tibble(
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(PYGN|AGLC|DYSG|EQUI|CANS|GRPA|GRPB|GRPC|GRPG)(_|$)")])) %>% mo_group = as.mo("Streptococcus Group A, B, C, G"),
mo = microorganisms$mo[which(microorganisms$mo %like% "^B_STRPT_(PYGN|AGLC|DYSG|EQUI|CANS|GRPA|GRPB|GRPC|GRPG)(_|$)")]
)) %>%
# HACEK is: # HACEK is:
# - Haemophilus species # - Haemophilus species
# - Aggregatibacter species # - Aggregatibacter species
@@ -143,21 +172,29 @@ microorganisms.groups <- whonet_organisms %>%
# Citrobacter freundii complex in the NCBI Taxonomy Browser: # Citrobacter freundii complex in the NCBI Taxonomy Browser:
# https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=1344959 # https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=1344959
filter(mo_group != "B_CTRBC_FRND-C") %>% filter(mo_group != "B_CTRBC_FRND-C") %>%
bind_rows(tibble(mo_group = as.mo("B_CTRBC_FRND-C"), bind_rows(tibble(
mo = paste("Citrobacter", c("freundii", "braakii", "gillenii", "murliniae", "portucalensis", "sedlakii", "werkmanii", "youngae")) %>% as.mo(keep_synonyms = TRUE))) %>% mo_group = as.mo("B_CTRBC_FRND-C"),
mo = paste("Citrobacter", c("freundii", "braakii", "gillenii", "murliniae", "portucalensis", "sedlakii", "werkmanii", "youngae")) %>% as.mo(keep_synonyms = TRUE)
)) %>%
# Klebsiella pneumoniae complex # Klebsiella pneumoniae complex
filter(mo_group != "B_KLBSL_PNMN-C") %>% filter(mo_group != "B_KLBSL_PNMN-C") %>%
bind_rows(tibble(mo_group = as.mo("B_KLBSL_PNMN-C"), bind_rows(tibble(
mo = paste("Klebsiella", c("africana", "pneumoniae", "quasipneumoniae", "quasivariicola", "variicola")) %>% as.mo(keep_synonyms = TRUE))) %>% mo_group = as.mo("B_KLBSL_PNMN-C"),
mo = paste("Klebsiella", c("africana", "pneumoniae", "quasipneumoniae", "quasivariicola", "variicola")) %>% as.mo(keep_synonyms = TRUE)
)) %>%
# Yersinia pseudotuberculosis complex in the NCBI Taxonomy Browser: # Yersinia pseudotuberculosis complex in the NCBI Taxonomy Browser:
# https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=1649845 # https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=1649845
filter(mo_group != "B_YERSN_PSDT-C") %>% filter(mo_group != "B_YERSN_PSDT-C") %>%
bind_rows(tibble(mo_group = as.mo("B_YERSN_PSDT-C"), bind_rows(tibble(
mo = paste("Yersinia", c("pseudotuberculosis", "pestis", "similis", "wautersii")) %>% as.mo(keep_synonyms = TRUE))) %>% mo_group = as.mo("B_YERSN_PSDT-C"),
mo = paste("Yersinia", c("pseudotuberculosis", "pestis", "similis", "wautersii")) %>% as.mo(keep_synonyms = TRUE)
)) %>%
# RGM are Rapidly-growing Mycobacteria, see https://pubmed.ncbi.nlm.nih.gov/28084211/ # RGM are Rapidly-growing Mycobacteria, see https://pubmed.ncbi.nlm.nih.gov/28084211/
filter(mo_group != "B_MYCBC_RGM") %>% filter(mo_group != "B_MYCBC_RGM") %>%
bind_rows(tibble(mo_group = as.mo("B_MYCBC_RGM"), bind_rows(tibble(
mo = paste("Mycobacterium", c( "abscessus abscessus", "abscessus bolletii", "abscessus massiliense", "agri", "aichiense", "algericum", "alvei", "anyangense", "arabiense", "aromaticivorans", "aubagnense", "aubagnense", "aurum", "austroafricanum", "bacteremicum", "boenickei", "bourgelatii", "brisbanense", "brumae", "canariasense", "celeriflavum", "chelonae", "chitae", "chlorophenolicum", "chubuense", "confluentis", "cosmeticum", "crocinum", "diernhoferi", "duvalii", "elephantis", "fallax", "flavescens", "fluoranthenivorans", "fortuitum", "franklinii", "frederiksbergense", "gadium", "gilvum", "goodii", "hassiacum", "hippocampi", "hodleri", "holsaticum", "houstonense", "immunogenum", "insubricum", "iranicum", "komossense", "litorale", "llatzerense", "madagascariense", "mageritense", "monacense", "moriokaense", "mucogenicum", "mucogenicum", "murale", "neoaurum", "neworleansense", "novocastrense", "obuense", "pallens", "parafortuitum", "peregrinum", "phlei", "phocaicum", "phocaicum", "porcinum", "poriferae", "psychrotolerans", "pyrenivorans", "rhodesiae", "rufum", "rutilum", "salmoniphilum", "sediminis", "senegalense", "septicum", "setense", "smegmatis", "sphagni", "thermoresistibile", "tokaiense", "vaccae", "vanbaalenii", "wolinskyi")) %>% as.mo(keep_synonyms = TRUE))) mo_group = as.mo("B_MYCBC_RGM"),
mo = paste("Mycobacterium", c("abscessus abscessus", "abscessus bolletii", "abscessus massiliense", "agri", "aichiense", "algericum", "alvei", "anyangense", "arabiense", "aromaticivorans", "aubagnense", "aubagnense", "aurum", "austroafricanum", "bacteremicum", "boenickei", "bourgelatii", "brisbanense", "brumae", "canariasense", "celeriflavum", "chelonae", "chitae", "chlorophenolicum", "chubuense", "confluentis", "cosmeticum", "crocinum", "diernhoferi", "duvalii", "elephantis", "fallax", "flavescens", "fluoranthenivorans", "fortuitum", "franklinii", "frederiksbergense", "gadium", "gilvum", "goodii", "hassiacum", "hippocampi", "hodleri", "holsaticum", "houstonense", "immunogenum", "insubricum", "iranicum", "komossense", "litorale", "llatzerense", "madagascariense", "mageritense", "monacense", "moriokaense", "mucogenicum", "mucogenicum", "murale", "neoaurum", "neworleansense", "novocastrense", "obuense", "pallens", "parafortuitum", "peregrinum", "phlei", "phocaicum", "phocaicum", "porcinum", "poriferae", "psychrotolerans", "pyrenivorans", "rhodesiae", "rufum", "rutilum", "salmoniphilum", "sediminis", "senegalense", "septicum", "setense", "smegmatis", "sphagni", "thermoresistibile", "tokaiense", "vaccae", "vanbaalenii", "wolinskyi")) %>% as.mo(keep_synonyms = TRUE)
))
# add subspecies to all species # add subspecies to all species
for (group in unique(microorganisms.groups$mo_group)) { for (group in unique(microorganisms.groups$mo_group)) {
@@ -175,8 +212,10 @@ for (group in unique(microorganisms.groups$mo_group)) {
# add full names, arrange and clean # add full names, arrange and clean
microorganisms.groups <- microorganisms.groups %>% microorganisms.groups <- microorganisms.groups %>%
mutate(mo_group_name = mo_name(mo_group, keep_synonyms = TRUE, language = NULL), mutate(
mo_name = mo_name(mo, keep_synonyms = TRUE, language = NULL)) %>% mo_group_name = mo_name(mo_group, keep_synonyms = TRUE, language = NULL),
mo_name = mo_name(mo, keep_synonyms = TRUE, language = NULL)
) %>%
arrange(mo_group_name, mo_name) %>% arrange(mo_group_name, mo_name) %>%
filter(mo_group != mo) %>% filter(mo_group != mo) %>%
distinct() %>% distinct() %>%

View File

@@ -68,9 +68,11 @@ new_ab <- complete_tbl |>
) |> ) |>
mutate(name = paste0(substr(toupper(name), 1, 1), substr(name, 2, 999))) |> mutate(name = paste0(substr(toupper(name), 1, 1), substr(name, 2, 999))) |>
mutate(name = gsub(" and ", "/", name)) |> mutate(name = gsub(" and ", "/", name)) |>
filter(name %unlike% "^Combinations", filter(
name %unlike% "^Combinations",
name %unlike% "/beta[-]lactamase inhibitor", name %unlike% "/beta[-]lactamase inhibitor",
name %unlike% "combinations") |> name %unlike% "combinations"
) |>
arrange(name) arrange(name)
new_atcs <- new_ab |> new_atcs <- new_ab |>

View File

@@ -487,7 +487,10 @@ codes$lev_pct <- codes$lev / nchar(codes$name)
View(codes) View(codes)
import <- codes |> filter(lev <= 10 | name_gen == "PENICILLIN") |> as_tibble() |> mutate(ab = as.ab(ab_name, fast_mode = TRUE)) import <- codes |>
filter(lev <= 10 | name_gen == "PENICILLIN") |>
as_tibble() |>
mutate(ab = as.ab(ab_name, fast_mode = TRUE))
for (i in seq_len(NROW(import))) { for (i in seq_len(NROW(import))) {
# put them in the abbreviations # put them in the abbreviations

View File

@@ -1056,8 +1056,10 @@ import$mo <- as.mo(import$mo_name)
microorganisms.codes <- microorganisms.codes |> microorganisms.codes <- microorganisms.codes |>
bind_rows( bind_rows(
tibble(code = toupper(import$code), tibble(
mo = import$mo) |> code = toupper(import$code),
mo = import$mo
) |>
distinct() distinct()
) |> ) |>
arrange(code) arrange(code)
@@ -1065,4 +1067,3 @@ class(microorganisms.codes$mo) <- c("mo", "character")
usethis::use_data(microorganisms.codes, overwrite = TRUE, compress = "xz", version = 2) usethis::use_data(microorganisms.codes, overwrite = TRUE, compress = "xz", version = 2)
rm(microorganisms.codes) rm(microorganisms.codes)
devtools::load_all() devtools::load_all()

View File

@@ -4,12 +4,14 @@ df <- example_isolates |>
top_n_microorganisms(10) top_n_microorganisms(10)
out_new <- df |> antibiogram(c("TZP", "TZP+GEN", "TZP+TOB"), wisca = TRUE, syndromic_group = "ward") out_new <- df |> antibiogram(c("TZP", "TZP+GEN", "TZP+TOB"), wisca = TRUE, syndromic_group = "ward")
out_nonwisca <- df |> antibiogram(c("TZP","TZP+GEN","TZP+TOB"), out_nonwisca <- df |>
antibiogram(c("TZP", "TZP+GEN", "TZP+TOB"),
syndromic_group = "ward", syndromic_group = "ward",
mo_transform = function(x) "", mo_transform = function(x) "",
digits = 1, digits = 1,
minimum = 10, minimum = 10,
formatting_type = 14) |> formatting_type = 14
) |>
as_tibble() |> as_tibble() |>
select(-Pathogen) select(-Pathogen)
@@ -17,7 +19,3 @@ out_nonwisca <- df |> antibiogram(c("TZP","TZP+GEN","TZP+TOB"),
# parameters_amr.R: number of first isolates are determined on the whole data set, while Klebsiella is aggregated afterwards (=duplicates on genus level) # parameters_amr.R: number of first isolates are determined on the whole data set, while Klebsiella is aggregated afterwards (=duplicates on genus level)
source("~/Downloads/estimate_definition_amr.R") source("~/Downloads/estimate_definition_amr.R")

View File

@@ -12,7 +12,7 @@ This is an overview of all the package-specific options you can set in the \code
\itemize{ \itemize{
\item \code{AMR_antibiogram_formatting_type} \cr A \link{numeric} (1-22) to use in \code{\link[=antibiogram]{antibiogram()}}, to indicate which formatting type to use. \item \code{AMR_antibiogram_formatting_type} \cr A \link{numeric} (1-22) to use in \code{\link[=antibiogram]{antibiogram()}}, to indicate which formatting type to use.
\item \code{AMR_breakpoint_type} \cr A \link{character} to use in \code{\link[=as.sir]{as.sir()}}, to indicate which breakpoint type to use. This must be either {.val ECOFF}, {.val animal}, or {.val human}. \item \code{AMR_breakpoint_type} \cr A \link{character} to use in \code{\link[=as.sir]{as.sir()}}, to indicate which breakpoint type to use. This must be either \code{"ECOFF"}, \code{"animal"}, or \code{"human"}.
\item \code{AMR_capped_mic_handling} \cr A \link{character} to use in \code{\link[=as.sir]{as.sir()}}, to indicate how capped MIC values (\code{<}, \code{<=}, \code{>}, \code{>=}) should be interpreted. Must be one of \code{"none"}, \code{"conservative"}, \code{"standard"}, or \code{"lenient"} - the default is \code{"conservative"}. \item \code{AMR_capped_mic_handling} \cr A \link{character} to use in \code{\link[=as.sir]{as.sir()}}, to indicate how capped MIC values (\code{<}, \code{<=}, \code{>}, \code{>=}) should be interpreted. Must be one of \code{"none"}, \code{"conservative"}, \code{"standard"}, or \code{"lenient"} - the default is \code{"conservative"}.
\item \code{AMR_cleaning_regex} \cr A \link[base:regex]{regular expression} (case-insensitive) to use in \code{\link[=as.mo]{as.mo()}} and all \code{\link[=mo_property]{mo_*}} functions, to clean the user input. The default is the outcome of \code{\link[=mo_cleaning_regex]{mo_cleaning_regex()}}, which removes texts between brackets and texts such as "species" and "serovar". \item \code{AMR_cleaning_regex} \cr A \link[base:regex]{regular expression} (case-insensitive) to use in \code{\link[=as.mo]{as.mo()}} and all \code{\link[=mo_property]{mo_*}} functions, to clean the user input. The default is the outcome of \code{\link[=mo_cleaning_regex]{mo_cleaning_regex()}}, which removes texts between brackets and texts such as "species" and "serovar".
\item \code{AMR_custom_ab} \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}}. \item \code{AMR_custom_ab} \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}}.

View File

@@ -67,7 +67,7 @@ set_ab_names(data, ..., property = "name", language = get_AMR_locale(),
\item{open}{Browse the URL using \code{\link[utils:browseURL]{utils::browseURL()}}.} \item{open}{Browse the URL using \code{\link[utils:browseURL]{utils::browseURL()}}.}
\item{property}{One of the column names of one of the \link{antimicrobials} data set: \code{vector_or(colnames(antimicrobials), sort = FALSE)}.} \item{property}{One of the column names of one of the \link{antimicrobials} data set: \code{"ab"}, \code{"cid"}, \code{"name"}, \code{"group"}, \code{"atc"}, \code{"atc_group1"}, \code{"atc_group2"}, \code{"abbreviations"}, \code{"synonyms"}, \code{"oral_ddd"}, \code{"oral_units"}, \code{"iv_ddd"}, \code{"iv_units"}, or \code{"loinc"}.}
\item{data}{A \link{data.frame} of which the columns need to be renamed, or a \link{character} vector of column names.} \item{data}{A \link{data.frame} of which the columns need to be renamed, or a \link{character} vector of column names.}

View File

@@ -68,9 +68,9 @@ retrieve_wisca_parameters(wisca_model, ...)
} }
}} }}
\item{mo_transform}{A character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: {.val mo}, {.val fullname}, {.val status}, {.val kingdom}, {.val phylum}, {.val class}, {.val order}, {.val family}, {.val genus}, {.val species}, {.val subspecies}, {.val rank}, {.val ref}, {.val oxygen_tolerance}, {.val source}, {.val lpsn}, {.val lpsn_parent}, {.val lpsn_renamed_to}, {.val mycobank}, {.val mycobank_parent}, {.val mycobank_renamed_to}, {.val gbif}, {.val gbif_parent}, {.val gbif_renamed_to}, {.val prevalence}, or {.val snomed}. Can also be \code{NULL} to not transform the input or \code{NA} to consider all microorganisms 'unknown'.} \item{mo_transform}{A character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, or \code{"snomed"}. Can also be \code{NULL} to not transform the input or \code{NA} to consider all microorganisms 'unknown'.}
\item{ab_transform}{A character to transform antimicrobial input - must be one of the column names of the \link{antimicrobials} data set (defaults to \code{"name"}): {.val ab}, {.val cid}, {.val name}, {.val group}, {.val atc}, {.val atc_group1}, {.val atc_group2}, {.val abbreviations}, {.val synonyms}, {.val oral_ddd}, {.val oral_units}, {.val iv_ddd}, {.val iv_units}, or {.val loinc}. Can also be \code{NULL} to not transform the input.} \item{ab_transform}{A character to transform antimicrobial input - must be one of the column names of the \link{antimicrobials} data set (defaults to \code{"name"}): \code{"ab"}, \code{"cid"}, \code{"name"}, \code{"group"}, \code{"atc"}, \code{"atc_group1"}, \code{"atc_group2"}, \code{"abbreviations"}, \code{"synonyms"}, \code{"oral_ddd"}, \code{"oral_units"}, \code{"iv_ddd"}, \code{"iv_units"}, or \code{"loinc"}. Can also be \code{NULL} to not transform the input.}
\item{syndromic_group}{A column name of \code{x}, or values calculated to split rows of \code{x}, e.g. by using \code{\link[=ifelse]{ifelse()}} or \code{\link[dplyr:case-and-replace-when]{case_when()}}. See \emph{Examples}.} \item{syndromic_group}{A column name of \code{x}, or values calculated to split rows of \code{x}, e.g. by using \code{\link[=ifelse]{ifelse()}} or \code{\link[dplyr:case-and-replace-when]{case_when()}}. See \emph{Examples}.}

View File

@@ -157,7 +157,7 @@ not_intrinsic_resistant(only_sir_columns = FALSE, col_mo = NULL,
\item{col_mo}{Column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{Column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{version_expected_phenotypes}{The version number to use for the EUCAST Expected Phenotypes. Can be {.val 1.2}.} \item{version_expected_phenotypes}{The version number to use for the EUCAST Expected Phenotypes. Can be \code{"1.2"}.}
} }
\value{ \value{
When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"amr_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter. When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"amr_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter.

View File

@@ -138,7 +138,7 @@ The default \code{"conservative"} setting ensures cautious handling of uncertain
\item{include_PKPD}{A \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.} \item{include_PKPD}{A \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.}
\item{breakpoint_type}{The type of breakpoints to use, either {.val ECOFF}, {.val animal}, or {.val human}. ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.} \item{breakpoint_type}{The type of breakpoints to use, either \code{"ECOFF"}, \code{"animal"}, or \code{"human"}. ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.}
\item{host}{A vector (or column name) with \link{character}s to indicate the host. Only useful for veterinary breakpoints, as it requires \code{breakpoint_type = "animal"}. The values can be any text resembling the animal species, even in any of the 28 supported languages of this package. For foreign languages, be sure to set the language with \code{\link[=set_AMR_locale]{set_AMR_locale()}} (though it will be automatically guessed based on the system language).} \item{host}{A vector (or column name) with \link{character}s to indicate the host. Only useful for veterinary breakpoints, as it requires \code{breakpoint_type = "animal"}. The values can be any text resembling the animal species, even in any of the 28 supported languages of this package. For foreign languages, be sure to set the language with \code{\link[=set_AMR_locale]{set_AMR_locale()}} (though it will be automatically guessed based on the system language).}

View File

@@ -52,7 +52,7 @@ av_property(x, property = "name", language = get_AMR_locale(), ...)
\item{open}{Browse the URL using \code{\link[utils:browseURL]{utils::browseURL()}}.} \item{open}{Browse the URL using \code{\link[utils:browseURL]{utils::browseURL()}}.}
\item{property}{One of the column names of one of the \link{antivirals} data set: \code{vector_or(colnames(antivirals), sort = FALSE)}.} \item{property}{One of the column names of one of the \link{antivirals} data set: \code{"av"}, \code{"name"}, \code{"atc"}, \code{"cid"}, \code{"atc_group"}, \code{"synonyms"}, \code{"oral_ddd"}, \code{"oral_units"}, \code{"iv_ddd"}, \code{"iv_units"}, or \code{"loinc"}.}
} }
\value{ \value{
\itemize{ \itemize{

View File

@@ -8,9 +8,9 @@
A \link[tibble:tibble]{tibble} with 45 730 observations and 14 variables: A \link[tibble:tibble]{tibble} with 45 730 observations and 14 variables:
\itemize{ \itemize{
\item \code{guideline}\cr Name of the guideline \item \code{guideline}\cr Name of the guideline
\item \code{type}\cr Breakpoint type, either {.val ECOFF}, {.val animal}, or {.val human} \item \code{type}\cr Breakpoint type, either \code{"ECOFF"}, \code{"animal"}, or \code{"human"}
\item \code{host}\cr Host of infectious agent. This is mostly useful for veterinary breakpoints and is either {.val ECOFF}, {.val aquatic}, {.val cats}, {.val cattle}, {.val dogs}, {.val horse}, {.val human}, {.val poultry}, or {.val swine} \item \code{host}\cr Host of infectious agent. This is mostly useful for veterinary breakpoints and is either \code{"ECOFF"}, \code{"aquatic"}, \code{"cats"}, \code{"cattle"}, \code{"dogs"}, \code{"horse"}, \code{"human"}, \code{"poultry"}, or \code{"swine"}
\item \code{method}\cr Testing method, either {.val DISK} or {.val MIC} \item \code{method}\cr Testing method, either \code{"DISK"} or \code{"MIC"}
\item \code{site}\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory" \item \code{site}\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory"
\item \code{mo}\cr Microbial ID, see \code{\link[=as.mo]{as.mo()}} \item \code{mo}\cr Microbial ID, see \code{\link[=as.mo]{as.mo()}}
\item \code{rank_index}\cr Taxonomic rank index of \code{mo} from 1 (subspecies/infraspecies) to 5 (unknown microorganism) \item \code{rank_index}\cr Taxonomic rank index of \code{mo} from 1 (subspecies/infraspecies) to 5 (unknown microorganism)

View File

@@ -61,7 +61,7 @@ eucast_rules(df,
\subsection{Using taxonomic properties in rules}{ \subsection{Using taxonomic properties in rules}{
There is one exception in columns used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", and "snomed". Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}: There is one exception in columns used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, and \code{"snomed"}. Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{y <- custom_eucast_rules( \if{html}{\out{<div class="sourceCode r">}}\preformatted{y <- custom_eucast_rules(
TZP == "S" & genus == "Klebsiella" ~ aminopenicillins == "S", TZP == "S" & genus == "Klebsiella" ~ aminopenicillins == "S",

View File

@@ -9,10 +9,10 @@ A \link[tibble:tibble]{tibble} with 759 observations and 9 variables:
\itemize{ \itemize{
\item \code{ab}\cr Antimicrobial ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available \item \code{ab}\cr Antimicrobial ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
\item \code{name}\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO \item \code{name}\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO
\item \code{type}\cr Type of the dosage, either {.val high_dosage}, {.val standard_dosage}, or {.val uncomplicated_uti} \item \code{type}\cr Type of the dosage, either \code{"high_dosage"}, \code{"standard_dosage"}, or \code{"uncomplicated_uti"}
\item \code{dose}\cr Dose, such as "2 g" or "25 mg/kg" \item \code{dose}\cr Dose, such as "2 g" or "25 mg/kg"
\item \code{dose_times}\cr Number of times a dose must be administered \item \code{dose_times}\cr Number of times a dose must be administered
\item \code{administration}\cr Route of administration, either {.val }, {.val im}, {.val iv}, {.val oral}, or NA \item \code{administration}\cr Route of administration, either \code{""}, \code{"im"}, \code{"iv"}, \code{"oral"}, or NA
\item \code{notes}\cr Additional dosage notes \item \code{notes}\cr Additional dosage notes
\item \code{original_txt}\cr Original text in the PDF file of EUCAST \item \code{original_txt}\cr Original text in the PDF file of EUCAST
\item \code{eucast_version}\cr Version number of the EUCAST Clinical Breakpoints guideline to which these dosages apply, either 15, 14, 13.1, 12, or 11 \item \code{eucast_version}\cr Version number of the EUCAST Clinical Breakpoints guideline to which these dosages apply, either 15, 14, 13.1, 12, or 11

View File

@@ -10,8 +10,8 @@ A \link[tibble:tibble]{tibble} with 2 000 observations and 46 variables:
\item \code{date}\cr Date of receipt at the laboratory \item \code{date}\cr Date of receipt at the laboratory
\item \code{patient}\cr ID of the patient \item \code{patient}\cr ID of the patient
\item \code{age}\cr Age of the patient \item \code{age}\cr Age of the patient
\item \code{gender}\cr Gender of the patient, either {.val F} or {.val M} \item \code{gender}\cr Gender of the patient, either \code{"F"} or \code{"M"}
\item \code{ward}\cr Ward type where the patient was admitted, either {.val Clinical}, {.val ICU}, or {.val Outpatient} \item \code{ward}\cr Ward type where the patient was admitted, either \code{"Clinical"}, \code{"ICU"}, or \code{"Outpatient"}
\item \code{mo}\cr ID of microorganism created with \code{\link[=as.mo]{as.mo()}}, see also the \link{microorganisms} data set \item \code{mo}\cr ID of microorganism created with \code{\link[=as.mo]{as.mo()}}, see also the \link{microorganisms} data set
\item \code{PEN:RIF}\cr 40 different antimicrobials with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}); these column names occur in the \link{antimicrobials} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}} \item \code{PEN:RIF}\cr 40 different antimicrobials with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}); these column names occur in the \link{antimicrobials} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}}
} }

View File

@@ -27,7 +27,7 @@ interpretive_rules(x, col_mo = NULL, info = interactive(),
verbose = FALSE, version_breakpoints = 16, verbose = FALSE, version_breakpoints = 16,
version_expected_phenotypes = 1.2, version_expertrules = 3.3, version_expected_phenotypes = 1.2, version_expertrules = 3.3,
ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)), ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)),
custom_rules = NULL, overwrite = FALSE, ...) custom_rules = NULL, overwrite = FALSE, add_if_missing = TRUE, ...)
eucast_rules(x, col_mo = NULL, info = interactive(), eucast_rules(x, col_mo = NULL, info = interactive(),
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
@@ -52,11 +52,11 @@ eucast_dosage(ab, administration = "iv", version_breakpoints = 15)
\item{verbose}{A \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.} \item{verbose}{A \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.}
\item{version_breakpoints}{The version number to use for the EUCAST Clinical Breakpoints guideline. Can be {.val 16.0}, {.val 15.0}, {.val 14.0}, {.val 13.1}, {.val 12.0}, {.val 11.0}, or {.val 10.0}.} \item{version_breakpoints}{The version number to use for the EUCAST Clinical Breakpoints guideline. Can be \code{"16.0"}, \code{"15.0"}, \code{"14.0"}, \code{"13.1"}, \code{"12.0"}, \code{"11.0"}, or \code{"10.0"}.}
\item{version_expected_phenotypes}{The version number to use for the EUCAST Expected Phenotypes. Can be {.val 1.2}.} \item{version_expected_phenotypes}{The version number to use for the EUCAST Expected Phenotypes. Can be \code{"1.2"}.}
\item{version_expertrules}{The version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be {.val 3.3}, {.val 3.2}, or {.val 3.1}.} \item{version_expertrules}{The version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be \code{"3.3"}, \code{"3.2"}, or \code{"3.1"}.}
\item{ampc_cephalosporin_resistance}{(only applies when \code{rules} contains \code{"expert"} or \code{"all"}) a \link{character} value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants - the default is \code{NA}. Currently only works when \code{version_expertrules} is \code{3.2} and higher; these versions of '\emph{EUCAST Expert Rules on Enterobacterales}' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of \code{NA} (the default) for this argument will remove results for these three drugs, while e.g. a value of \code{"R"} will make the results for these drugs resistant. Use \code{NULL} or \code{FALSE} to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using \code{TRUE} is equal to using \code{"R"}. \cr For \emph{EUCAST Expert Rules} v3.2, this rule applies to: \emph{Citrobacter braakii}, \emph{Citrobacter freundii}, \emph{Citrobacter gillenii}, \emph{Citrobacter murliniae}, \emph{Citrobacter rodenticum}, \emph{Citrobacter sedlakii}, \emph{Citrobacter werkmanii}, \emph{Citrobacter youngae}, \emph{Enterobacter}, \emph{Hafnia alvei}, \emph{Klebsiella aerogenes}, \emph{Morganella morganii}, \emph{Providencia}, and \emph{Serratia}.} \item{ampc_cephalosporin_resistance}{(only applies when \code{rules} contains \code{"expert"} or \code{"all"}) a \link{character} value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants - the default is \code{NA}. Currently only works when \code{version_expertrules} is \code{3.2} and higher; these versions of '\emph{EUCAST Expert Rules on Enterobacterales}' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of \code{NA} (the default) for this argument will remove results for these three drugs, while e.g. a value of \code{"R"} will make the results for these drugs resistant. Use \code{NULL} or \code{FALSE} to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using \code{TRUE} is equal to using \code{"R"}. \cr For \emph{EUCAST Expert Rules} v3.2, this rule applies to: \emph{Citrobacter braakii}, \emph{Citrobacter freundii}, \emph{Citrobacter gillenii}, \emph{Citrobacter murliniae}, \emph{Citrobacter rodenticum}, \emph{Citrobacter sedlakii}, \emph{Citrobacter werkmanii}, \emph{Citrobacter youngae}, \emph{Enterobacter}, \emph{Hafnia alvei}, \emph{Klebsiella aerogenes}, \emph{Morganella morganii}, \emph{Providencia}, and \emph{Serratia}.}
@@ -66,11 +66,13 @@ eucast_dosage(ab, administration = "iv", version_breakpoints = 15)
\item{overwrite}{A \link{logical} indicating whether to overwrite existing SIR values (default: \code{FALSE}). When \code{FALSE}, only non-SIR values are modified (i.e., any value that is not already S, I or R). To ensure compliance with EUCAST guidelines, \strong{this should remain} \code{FALSE}, as EUCAST notes often state that an organism "should be tested for susceptibility to individual agents or be reported resistant".} \item{overwrite}{A \link{logical} indicating whether to overwrite existing SIR values (default: \code{FALSE}). When \code{FALSE}, only non-SIR values are modified (i.e., any value that is not already S, I or R). To ensure compliance with EUCAST guidelines, \strong{this should remain} \code{FALSE}, as EUCAST notes often state that an organism "should be tested for susceptibility to individual agents or be reported resistant".}
\item{add_if_missing}{A \link{logical} indicating whether rules should also be applied to missing (\code{NA}) values (default: \code{TRUE}). When \code{FALSE}, rules are only applied to cells that already contain an SIR value; cells with \code{NA} are left untouched. This is particularly useful when using \code{overwrite = TRUE} with custom rules and you want to update reported results without imputing values for untested drugs.}
\item{...}{Column names of antimicrobials. To automatically detect antimicrobial column names, do not provide any named arguments; \code{\link[=guess_ab_col]{guess_ab_col()}} will then be used for detection. To manually specify a column, provide its name (case-insensitive) as an argument, e.g. \code{AMX = "amoxicillin"}. To skip a specific antimicrobial, set it to \code{NULL}, e.g. \code{TIC = NULL} to exclude ticarcillin. If a manually defined column does not exist in the data, it will be skipped with a warning.} \item{...}{Column names of antimicrobials. To automatically detect antimicrobial column names, do not provide any named arguments; \code{\link[=guess_ab_col]{guess_ab_col()}} will then be used for detection. To manually specify a column, provide its name (case-insensitive) as an argument, e.g. \code{AMX = "amoxicillin"}. To skip a specific antimicrobial, set it to \code{NULL}, e.g. \code{TIC = NULL} to exclude ticarcillin. If a manually defined column does not exist in the data, it will be skipped with a warning.}
\item{ab}{Any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}.} \item{ab}{Any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}.}
\item{administration}{Route of administration, either {.val }, {.val im}, {.val iv}, {.val oral}, or NA.} \item{administration}{Route of administration, either \code{""}, \code{"im"}, \code{"iv"}, \code{"oral"}, or NA.}
} }
\value{ \value{
The input of \code{x}, possibly with edited values of antimicrobials. Or, if \code{verbose = TRUE}, a \link{data.frame} with all original and new values of the affected bug-drug combinations. The input of \code{x}, possibly with edited values of antimicrobials. Or, if \code{verbose = TRUE}, a \link{data.frame} with all original and new values of the affected bug-drug combinations.

View File

@@ -9,12 +9,12 @@ A \link[tibble:tibble]{tibble} with 78 679 observations and 26 variables:
\itemize{ \itemize{
\item \code{mo}\cr ID of microorganism as used by this package. \emph{\strong{This is a unique identifier.}} \item \code{mo}\cr ID of microorganism as used by this package. \emph{\strong{This is a unique identifier.}}
\item \code{fullname}\cr Full name, like \code{"Escherichia coli"}. For the taxonomic ranks genus, species and subspecies, this is the 'pasted' text of genus, species, and subspecies. For all taxonomic ranks higher than genus, this is the name of the taxon. \emph{\strong{This is a unique identifier.}} \item \code{fullname}\cr Full name, like \code{"Escherichia coli"}. For the taxonomic ranks genus, species and subspecies, this is the 'pasted' text of genus, species, and subspecies. For all taxonomic ranks higher than genus, this is the name of the taxon. \emph{\strong{This is a unique identifier.}}
\item \code{status} \cr Status of the taxon, either {.val accepted}, {.val not validly published}, {.val synonym}, or {.val unknown} \item \code{status} \cr Status of the taxon, either \code{"accepted"}, \code{"not validly published"}, \code{"synonym"}, or \code{"unknown"}
\item \code{kingdom}, \code{phylum}, \code{class}, \code{order}, \code{family}, \code{genus}, \code{species}, \code{subspecies}\cr Taxonomic rank of the microorganism. Note that for fungi, \emph{phylum} is equal to their taxonomic \emph{division}. Also, for fungi, \emph{subkingdom} and \emph{subdivision} were left out since they do not occur in the bacterial taxonomy. \item \code{kingdom}, \code{phylum}, \code{class}, \code{order}, \code{family}, \code{genus}, \code{species}, \code{subspecies}\cr Taxonomic rank of the microorganism. Note that for fungi, \emph{phylum} is equal to their taxonomic \emph{division}. Also, for fungi, \emph{subkingdom} and \emph{subdivision} were left out since they do not occur in the bacterial taxonomy.
\item \code{rank}\cr Text of the taxonomic rank of the microorganism, such as \code{"species"} or \code{"genus"} \item \code{rank}\cr Text of the taxonomic rank of the microorganism, such as \code{"species"} or \code{"genus"}
\item \code{ref}\cr Author(s) and year of related scientific publication. This contains only the \emph{first surname} and year of the \emph{latest} authors, e.g. "Wallis \emph{et al.} 2006 \emph{emend.} Smith and Jones 2018" becomes "Smith \emph{et al.}, 2018". This field is directly retrieved from the source specified in the column \code{source}. Moreover, accents were removed to comply with CRAN that only allows ASCII characters. \item \code{ref}\cr Author(s) and year of related scientific publication. This contains only the \emph{first surname} and year of the \emph{latest} authors, e.g. "Wallis \emph{et al.} 2006 \emph{emend.} Smith and Jones 2018" becomes "Smith \emph{et al.}, 2018". This field is directly retrieved from the source specified in the column \code{source}. Moreover, accents were removed to comply with CRAN that only allows ASCII characters.
\item \code{oxygen_tolerance} \cr Oxygen tolerance, either {.val aerobe}, {.val anaerobe}, {.val anaerobe/microaerophile}, {.val facultative anaerobe}, {.val likely facultative anaerobe}, {.val microaerophile}, or NA. These data were retrieved from BacDive (see \emph{Source}). Items that contain "likely" are missing from BacDive and were extrapolated from other species within the same genus to guess the oxygen tolerance. Currently 68.3\% of all ~39 000 bacteria in the data set contain an oxygen tolerance. \item \code{oxygen_tolerance} \cr Oxygen tolerance, either \code{"aerobe"}, \code{"anaerobe"}, \code{"anaerobe/microaerophile"}, \code{"facultative anaerobe"}, \code{"likely facultative anaerobe"}, \code{"microaerophile"}, or NA. These data were retrieved from BacDive (see \emph{Source}). Items that contain "likely" are missing from BacDive and were extrapolated from other species within the same genus to guess the oxygen tolerance. Currently 68.3\% of all ~39 000 bacteria in the data set contain an oxygen tolerance.
\item \code{source}\cr Either {.val GBIF}, {.val LPSN}, {.val Manually added}, {.val MycoBank}, or {.val manually added} (see \emph{Source}) \item \code{source}\cr Either \code{"GBIF"}, \code{"LPSN"}, \code{"Manually added"}, \code{"MycoBank"}, or \code{"manually added"} (see \emph{Source})
\item \code{lpsn}\cr Identifier ('Record number') of List of Prokaryotic names with Standing in Nomenclature (LPSN). This will be the first/highest LPSN identifier to keep one identifier per row. For example, \emph{Acetobacter ascendens} has LPSN Record number 7864 and 11011. Only the first is available in the \code{microorganisms} data set. \emph{\strong{This is a unique identifier}}, though available for only ~33 000 records. \item \code{lpsn}\cr Identifier ('Record number') of List of Prokaryotic names with Standing in Nomenclature (LPSN). This will be the first/highest LPSN identifier to keep one identifier per row. For example, \emph{Acetobacter ascendens} has LPSN Record number 7864 and 11011. Only the first is available in the \code{microorganisms} data set. \emph{\strong{This is a unique identifier}}, though available for only ~33 000 records.
\item \code{lpsn_parent}\cr LPSN identifier of the parent taxon \item \code{lpsn_parent}\cr LPSN identifier of the parent taxon
\item \code{lpsn_renamed_to}\cr LPSN identifier of the currently valid taxon \item \code{lpsn_renamed_to}\cr LPSN identifier of the currently valid taxon

View File

@@ -165,7 +165,7 @@ The default is \code{FALSE}, which will return a note if outdated taxonomic name
\item{open}{Browse the URL using \code{\link[utils:browseURL]{browseURL()}}.} \item{open}{Browse the URL using \code{\link[utils:browseURL]{browseURL()}}.}
\item{property}{One of the column names of the \link{microorganisms} data set: {.val mo}, {.val fullname}, {.val status}, {.val kingdom}, {.val phylum}, {.val class}, {.val order}, {.val family}, {.val genus}, {.val species}, {.val subspecies}, {.val rank}, {.val ref}, {.val oxygen_tolerance}, {.val source}, {.val lpsn}, {.val lpsn_parent}, {.val lpsn_renamed_to}, {.val mycobank}, {.val mycobank_parent}, {.val mycobank_renamed_to}, {.val gbif}, {.val gbif_parent}, {.val gbif_renamed_to}, {.val prevalence}, or {.val snomed}, or must be \code{"shortname"}.} \item{property}{One of the column names of the \link{microorganisms} data set: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, or \code{"snomed"}, or must be \code{"shortname"}.}
} }
\value{ \value{
\itemize{ \itemize{

View File

@@ -137,7 +137,7 @@ labels_sir_count(position = NULL, x = "antibiotic",
\item{include_PKPD}{A \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.} \item{include_PKPD}{A \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.}
\item{breakpoint_type}{The type of breakpoints to use, either {.val ECOFF}, {.val animal}, or {.val human}. ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.} \item{breakpoint_type}{The type of breakpoints to use, either \code{"ECOFF"}, \code{"animal"}, or \code{"human"}. ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.}
\item{facet}{Variable to split plots by, either \code{"interpretation"} (default) or \code{"antibiotic"} or a grouping variable.} \item{facet}{Variable to split plots by, either \code{"interpretation"} (default) or \code{"antibiotic"} or a grouping variable.}

View File

@@ -12,7 +12,7 @@ top_n_microorganisms(x, n, property = "species", n_for_each = NULL,
\item{n}{An integer specifying the maximum number of unique values of the \code{property} to include in the output.} \item{n}{An integer specifying the maximum number of unique values of the \code{property} to include in the output.}
\item{property}{A character string indicating the microorganism property to use for filtering. Must be one of the column names of the \link{microorganisms} data set: {.val mo}, {.val fullname}, {.val status}, {.val kingdom}, {.val phylum}, {.val class}, {.val order}, {.val family}, {.val genus}, {.val species}, {.val subspecies}, {.val rank}, {.val ref}, {.val oxygen_tolerance}, {.val source}, {.val lpsn}, {.val lpsn_parent}, {.val lpsn_renamed_to}, {.val mycobank}, {.val mycobank_parent}, {.val mycobank_renamed_to}, {.val gbif}, {.val gbif_parent}, {.val gbif_renamed_to}, {.val prevalence}, or {.val snomed}. If \code{NULL}, the raw values from \code{col_mo} will be used without transformation. When using \code{"species"} (default) or \code{"subpecies"}, the genus will be added to make sure each (sub)species still belongs to the right genus.} \item{property}{A character string indicating the microorganism property to use for filtering. Must be one of the column names of the \link{microorganisms} data set: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, or \code{"snomed"}. If \code{NULL}, the raw values from \code{col_mo} will be used without transformation. When using \code{"species"} (default) or \code{"subpecies"}, the genus will be added to make sure each (sub)species still belongs to the right genus.}
\item{n_for_each}{An optional integer specifying the maximum number of rows to retain for each value of the selected property. If \code{NULL}, all rows within the top \emph{n} groups will be included.} \item{n_for_each}{An optional integer specifying the maximum number of rows to retain for each value of the selected property. If \code{NULL}, all rows within the top \emph{n} groups will be included.}

View File

@@ -268,7 +268,8 @@ To create a traditional antibiogram, simply state which antibiotics should be us
```{r trad} ```{r trad}
antibiogram(example_isolates, antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems())) antibiotics = c(aminoglycosides(), carbapenems())
)
``` ```
Notice that the `antibiogram()` function automatically prints in the right format when using Quarto or R Markdown (such as this page), and even applies italics for taxonomic names (by using `italicise_taxonomy()` internally). Notice that the `antibiogram()` function automatically prints in the right format when using Quarto or R Markdown (such as this page), and even applies italics for taxonomic names (by using `italicise_taxonomy()` internally).
@@ -280,7 +281,8 @@ antibiogram(example_isolates,
mo_transform = "gramstain", mo_transform = "gramstain",
antibiotics = aminoglycosides(), antibiotics = aminoglycosides(),
ab_transform = "name", ab_transform = "name",
language = "es") language = "es"
)
``` ```
### Combined Antibiogram ### Combined Antibiogram
@@ -290,7 +292,8 @@ To create a combined antibiogram, use antibiotic codes or names with a plus `+`
```{r comb} ```{r comb}
combined_ab <- antibiogram(example_isolates, combined_ab <- antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"), antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
ab_transform = NULL) ab_transform = NULL
)
combined_ab combined_ab
``` ```
@@ -301,7 +304,8 @@ To create a syndromic antibiogram, the `syndromic_group` argument must be used.
```{r synd} ```{r synd}
antibiogram(example_isolates, antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()), antibiotics = c(aminoglycosides(), carbapenems()),
syndromic_group = "ward") syndromic_group = "ward"
)
``` ```
### Weighted-Incidence Syndromic Combination Antibiogram (WISCA) ### Weighted-Incidence Syndromic Combination Antibiogram (WISCA)
@@ -310,8 +314,10 @@ To create a **Weighted-Incidence Syndromic Combination Antibiogram (WISCA)**, si
```{r wisca} ```{r wisca}
example_isolates %>% example_isolates %>%
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"), wisca(
minimum = 10) # Recommended threshold: ≥30 antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
minimum = 10
) # Recommended threshold: ≥30
``` ```
WISCA uses a **Bayesian decision model** to integrate data from multiple pathogens, improving empirical therapy guidance, especially for low-incidence infections. It is **pathogen-agnostic**, meaning results are syndrome-based rather than stratified by microorganism. WISCA uses a **Bayesian decision model** to integrate data from multiple pathogens, improving empirical therapy guidance, especially for low-incidence infections. It is **pathogen-agnostic**, meaning results are syndrome-based rather than stratified by microorganism.
@@ -323,8 +329,10 @@ For **patient- or syndrome-specific WISCA**, run the function on a grouped `tibb
```{r wisca_grouped} ```{r wisca_grouped}
example_isolates %>% example_isolates %>%
top_n_microorganisms(n = 10) %>% top_n_microorganisms(n = 10) %>%
group_by(age_group = age_groups(age, c(25, 50, 75)), group_by(
gender) %>% age_group = age_groups(age, c(25, 50, 75)),
gender
) %>%
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN")) wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
``` ```
@@ -381,15 +389,19 @@ We can visualise MIC distributions and their SIR interpretations using `ggplot2`
# add a group # add a group
my_data$group <- rep(c("A", "B", "C", "D"), each = 25) my_data$group <- rep(c("A", "B", "C", "D"), each = 25)
ggplot(my_data, ggplot(
aes(x = group, y = MIC, colour = SIR)) + my_data,
aes(x = group, y = MIC, colour = SIR)
) +
geom_jitter(width = 0.2, size = 2) + geom_jitter(width = 0.2, size = 2) +
geom_boxplot(fill = NA, colour = "grey40") + geom_boxplot(fill = NA, colour = "grey40") +
scale_y_mic() + scale_y_mic() +
scale_colour_sir() + scale_colour_sir() +
labs(title = "MIC Distribution and SIR Interpretation", labs(
title = "MIC Distribution and SIR Interpretation",
x = "Sample Groups", x = "Sample Groups",
y = "MIC (mg/L)") y = "MIC (mg/L)"
)
``` ```
This plot provides an intuitive way to assess susceptibility patterns across different groups while incorporating clinical breakpoints. This plot provides an intuitive way to assess susceptibility patterns across different groups while incorporating clinical breakpoints.

View File

@@ -68,13 +68,19 @@ data <- example_isolates %>%
# select AB results dynamically # select AB results dynamically
select(mo, aminoglycosides(), betalactams()) %>% select(mo, aminoglycosides(), betalactams()) %>%
# replace NAs with NI (not-interpretable) # replace NAs with NI (not-interpretable)
mutate(across(where(is.sir), mutate(
~replace_na(.x, "NI")), across(
where(is.sir),
~ replace_na(.x, "NI")
),
# make factors of SIR columns # make factors of SIR columns
across(where(is.sir), across(
as.integer), where(is.sir),
as.integer
),
# get Gramstain of microorganisms # get Gramstain of microorganisms
mo = as.factor(mo_gramstain(mo))) %>% mo = as.factor(mo_gramstain(mo))
) %>%
# drop NAs - the ones without a Gramstain (fungi, etc.) # drop NAs - the ones without a Gramstain (fungi, etc.)
drop_na() drop_na()
``` ```
@@ -341,9 +347,11 @@ library(ggplot2)
ggplot(predictions, aes(x = esbl, fill = .pred_class)) + ggplot(predictions, aes(x = esbl, fill = .pred_class)) +
geom_bar(position = "stack") + geom_bar(position = "stack") +
labs(title = "Predicted vs Actual ESBL Status", labs(
title = "Predicted vs Actual ESBL Status",
x = "Actual ESBL", x = "Actual ESBL",
y = "Count") + y = "Count"
) +
theme_minimal() theme_minimal()
``` ```
@@ -351,18 +359,27 @@ And plot the certainties too - how certain were the actual predictions?
```{r} ```{r}
predictions %>% predictions %>%
mutate(certainty = ifelse(.pred_class == "FALSE", mutate(
certainty = ifelse(.pred_class == "FALSE",
.pred_FALSE, .pred_FALSE,
.pred_TRUE), .pred_TRUE
correct = ifelse(esbl == .pred_class, "Right", "Wrong")) %>% ),
ggplot(aes(x = seq_len(nrow(predictions)), correct = ifelse(esbl == .pred_class, "Right", "Wrong")
) %>%
ggplot(aes(
x = seq_len(nrow(predictions)),
y = certainty, y = certainty,
colour = correct)) + colour = correct
scale_colour_manual(values = c(Right = "green3", Wrong = "red2"), )) +
name = "Correct?") + scale_colour_manual(
values = c(Right = "green3", Wrong = "red2"),
name = "Correct?"
) +
geom_point() + geom_point() +
scale_y_continuous(labels = function(x) paste0(x * 100, "%"), scale_y_continuous(
limits = c(0.5, 1)) + labels = function(x) paste0(x * 100, "%"),
limits = c(0.5, 1)
) +
theme_minimal() theme_minimal()
``` ```
@@ -399,13 +416,18 @@ library(tidymodels)
# Transform dataset # Transform dataset
data_time <- example_isolates %>% data_time <- example_isolates %>%
top_n_microorganisms(n = 10) %>% # Filter on the top #10 species top_n_microorganisms(n = 10) %>% # Filter on the top #10 species
mutate(year = as.integer(format(date, "%Y")), # Extract year from date mutate(
gramstain = mo_gramstain(mo)) %>% # Get taxonomic names year = as.integer(format(date, "%Y")), # Extract year from date
gramstain = mo_gramstain(mo)
) %>% # Get taxonomic names
group_by(year, gramstain) %>% group_by(year, gramstain) %>%
summarise(across(c(AMX, AMC, CIP), summarise(
across(c(AMX, AMC, CIP),
function(x) resistance(x, minimum = 0), function(x) resistance(x, minimum = 0),
.names = "res_{.col}"), .names = "res_{.col}"
.groups = "drop") %>% ),
.groups = "drop"
) %>%
filter(!is.na(res_AMX) & !is.na(res_AMC) & !is.na(res_CIP)) # Drop missing values filter(!is.na(res_AMX) & !is.na(res_AMC) & !is.na(res_CIP)) # Drop missing values
data_time data_time
@@ -514,9 +536,11 @@ library(ggplot2)
ggplot(predictions_time, aes(x = year)) + ggplot(predictions_time, aes(x = year)) +
geom_point(aes(y = res_AMX, color = "Actual")) + geom_point(aes(y = res_AMX, color = "Actual")) +
geom_line(aes(y = .pred, color = "Predicted")) + geom_line(aes(y = .pred, color = "Predicted")) +
labs(title = "Predicted vs Actual AMX Resistance Over Time", labs(
title = "Predicted vs Actual AMX Resistance Over Time",
x = "Year", x = "Year",
y = "Resistance Proportion") + y = "Resistance Proportion"
) +
theme_minimal() theme_minimal()
``` ```
@@ -525,13 +549,17 @@ Additionally, we can visualise resistance trends in `ggplot2` and directly add l
```{r} ```{r}
ggplot(data_time, aes(x = year, y = res_AMX, color = gramstain)) + ggplot(data_time, aes(x = year, y = res_AMX, color = gramstain)) +
geom_line() + geom_line() +
labs(title = "AMX Resistance Trends", labs(
title = "AMX Resistance Trends",
x = "Year", x = "Year",
y = "Resistance Proportion") + y = "Resistance Proportion"
) +
# add a linear model directly in ggplot2: # add a linear model directly in ggplot2:
geom_smooth(method = "lm", geom_smooth(
method = "lm",
formula = y ~ x, formula = y ~ x,
alpha = 0.25) + alpha = 0.25
) +
theme_minimal() theme_minimal()
``` ```

View File

@@ -147,14 +147,16 @@ data$syndrome <- ifelse(data$mo %like% "coli", "UTI", "No UTI")
```{r} ```{r}
wisca(data, wisca(data,
antimicrobials = c("AMC", "CIP", "GEN")) antimicrobials = c("AMC", "CIP", "GEN")
)
``` ```
### Use combination regimens ### Use combination regimens
```{r} ```{r}
wisca(data, wisca(data,
antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN")) antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN")
)
``` ```
### Stratify by syndrome ### Stratify by syndrome
@@ -162,7 +164,8 @@ wisca(data,
```{r} ```{r}
wisca(data, wisca(data,
antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN"), antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN"),
syndromic_group = "syndrome") syndromic_group = "syndrome"
)
``` ```
The `AMR` package is available in `r length(AMR:::LANGUAGES_SUPPORTED)` languages, which can all be used for the `wisca()` function too: The `AMR` package is available in `r length(AMR:::LANGUAGES_SUPPORTED)` languages, which can all be used for the `wisca()` function too:
@@ -171,7 +174,8 @@ The `AMR` package is available in `r length(AMR:::LANGUAGES_SUPPORTED)` language
wisca(data, wisca(data,
antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN"), antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN"),
syndromic_group = gsub("UTI", "UCI", data$syndrome), syndromic_group = gsub("UTI", "UCI", data$syndrome),
language = "Spanish") language = "Spanish"
)
``` ```