1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 23:21:56 +02:00

23 Commits

Author SHA1 Message Date
a2cbbf470e AMR v2.1.0 pre-release 2023-07-16 16:18:53 +02:00
7a4628b73f Added C. freundii complex and Y. pseudotuberculosis complex 2023-07-14 10:49:06 +02:00
fd480d1a9a console hyperlink fix 2023-07-14 09:50:13 +02:00
08f7256852 include unit tests again 2023-07-13 12:45:14 +01:00
ddd01f9410 test to remove unit tests from build 2023-07-13 09:42:37 +01:00
eff164ecb1 indicate unique identifiers 2023-07-12 21:26:32 +02:00
ea2a4652e9 mouse-hover fixes 2023-07-12 15:27:43 +01:00
e1b4f99f4f breakpoints fixes 2023-07-12 15:20:04 +01:00
0c46f61260 MO group fixes 2023-07-12 15:04:48 +01:00
9cf054903b version bump 2023-07-12 11:42:29 +01:00
7cd9ca274c add strep groups to ABCG 2023-07-12 11:41:25 +01:00
66eeeb4b88 cleanup 2023-07-11 14:29:40 +02:00
8df1cd8d97 interpretation fixes 2023-07-11 09:50:45 +02:00
5e1221bceb unit test 2023-07-10 19:04:12 +02:00
dab20c09f6 unit test 2023-07-10 18:30:26 +02:00
1b499bf012 fixes 2023-07-10 17:02:28 +02:00
a4e2e25e3f reftbl in plots, speedup for as.sir() and mo_validate 2023-07-10 16:43:46 +02:00
70c601ca11 breakpoints UTI interpretation fix 2023-07-10 13:41:52 +02:00
3829311dd3 random() fix 2023-07-08 21:00:49 +02:00
acb534102b new species groups, updated clinical breakpoints 2023-07-08 17:30:05 +02:00
2d97cca6d9 fix reference_df endless loop 2023-06-26 13:52:02 +02:00
1d9ee39cc7 fix for mo codes 2023-06-22 15:24:18 +02:00
f065945d7b Update clinical breakpoints and fix some as.mo() bugs (#117)
* Updates clinical breakpoints EUCAST/CLSI 2023, fixes #102, fixes #112, fixes #113, fixes #114, fixes #115
* docs
* implement ecoffs
* unit tests
2023-06-22 15:10:59 +02:00
220 changed files with 46656 additions and 29037 deletions

View File

@ -33,7 +33,6 @@
^vignettes/other_pkg.*\.Rmd$ ^vignettes/other_pkg.*\.Rmd$
^vignettes/PCA\.Rmd$ ^vignettes/PCA\.Rmd$
^vignettes/resistance_predict\.Rmd$ ^vignettes/resistance_predict\.Rmd$
^vignettes/SPSS\.Rmd$
^vignettes/WHONET\.Rmd$ ^vignettes/WHONET\.Rmd$
^logo.svg$ ^logo.svg$
^CRAN-SUBMISSION$ ^CRAN-SUBMISSION$

View File

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -49,7 +49,7 @@ jobs:
# Test all old versions of R >= 3.0, we support them all! # Test all old versions of R >= 3.0, we support them all!
# For these old versions, dependencies and vignettes will not be checked. # For these old versions, dependencies and vignettes will not be checked.
# For recent R versions, see check-recent.yaml (r-lib and tidyverse support the latest 5 major R releases). # For recent R versions, see check-recent.yaml (r-lib and tidyverse support the latest 5 major R releases).
- {os: windows-latest, r: '3.5', allowfail: true} # - {os: windows-latest, r: '3.5', allowfail: true} # always fails, horrible with UTF-8
- {os: ubuntu-latest, r: '3.4', allowfail: false} - {os: ubuntu-latest, r: '3.4', allowfail: false}
- {os: ubuntu-latest, r: '3.3', allowfail: false} - {os: ubuntu-latest, r: '3.3', allowfail: false}
- {os: ubuntu-latest, r: '3.2', allowfail: false} - {os: ubuntu-latest, r: '3.2', allowfail: false}

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,3 +1,3 @@
Version: 2.0.0 Version: 2.1.0
Date: 2023-03-12 12:42:08 UTC Date: 2023-07-16 07:05:11 UTC
SHA: 80cfc503c29ad48806e526b97d4570600bbd5420 SHA: 7a4628b73f91aad903f841c4275c8a68eea318b8

View File

@ -1,12 +1,12 @@
Package: AMR Package: AMR
Version: 2.0.0.9023 Version: 2.1.0
Date: 2023-05-27 Date: 2023-07-16
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
using evidence-based methods, as described in <doi:10.18637/jss.v104.i03>. using evidence-based methods, as described in <doi:10.18637/jss.v104.i03>.
Authors@R: c( Authors@R: c(
person(family = "Berends", c("Matthijs", "S."), role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7620-1800"), email = "m.berends@certe.nl"), person(family = "Berends", c("Matthijs", "S."), role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7620-1800"), email = "m.s.berends@umcg.nl"),
person(family = "Luz", c("Christian", "F."), role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-5809-5995")), person(family = "Luz", c("Christian", "F."), role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-5809-5995")),
person(family = "Souverein", c("Dennis"), role = c("aut", "ctb"), comment = c(ORCID = "0000-0003-0455-0336")), person(family = "Souverein", c("Dennis"), role = c("aut", "ctb"), comment = c(ORCID = "0000-0003-0455-0336")),
person(family = "Hassing", c("Erwin", "E.", "A."), role = c("aut", "ctb")), person(family = "Hassing", c("Erwin", "E.", "A."), role = c("aut", "ctb")),
@ -38,6 +38,7 @@ Enhances:
tidyselect, tidyselect,
tsibble tsibble
Suggests: Suggests:
cli,
curl, curl,
data.table, data.table,
dplyr, dplyr,

25
NEWS.md
View File

@ -1,19 +1,38 @@
# AMR 2.0.0.9023 # AMR 2.1.0
## Changed ## New
* Regarding clinical breakpoints:
* Clinical breakpoints and intrinsic resistance of EUCAST 2023 and CLSI 2023 have been added to the `clinical_breakpoints` data set for usage in `as.sir()`. EUCAST 2023 (v13.0) is now the new default guideline for all MIC and disks diffusion interpretations
* The EUCAST dosage guideline of v13.0 has been added to the `dosage` data set
* The `clinical_breakpoints` data set now also contains epidemiological cut-off (ECOFF) values and CLSI animal breakpoints. These two new breakpoint types can be used for MIC/disk interpretation using `as.sir(..., breakpoint_type = "ECOFF")` or`as.sir(..., breakpoint_type = "animal")`, which is an important new addition for veterinary microbiology.
* Added support for 30 species groups / complexes. They are gathered in a new data set `microorganisms.groups` and are used in clinical breakpoint interpretation. For example, CLSI 2023 contains breakpoints for the RGM group (Rapidly Growing Mycobacterium, containing over 80 species) which is now supported by our package.
* Added oxygen tolerance from BacDive to over 25,000 bacteria in the `microorganisms` data set * Added oxygen tolerance from BacDive to over 25,000 bacteria in the `microorganisms` data set
* Added `mo_oxygen_tolerance()` to retrieve the values * Added `mo_oxygen_tolerance()` to retrieve the values
* Added `mo_is_anaerobic()` to determine which genera/species are obligate anaerobic bacteria * Added `mo_is_anaerobic()` to determine which genera/species are obligate anaerobic bacteria
* Added LPSN and GBIF identifiers, and oxygen tolerance to `mo_info()` * Added LPSN and GBIF identifiers, and oxygen tolerance to `mo_info()`
* Added SAS Transport files (file extension `.xpt`) to [our download page](https://msberends.github.io/AMR/articles/datasets.html) to use in SAS software * Added SAS Transport files (file extension `.xpt`) to [our download page](https://msberends.github.io/AMR/articles/datasets.html) to use in SAS software
* Added microbial codes for Gram-negative/positive anaerobic bacteria * Added microbial codes for Gram-negative/positive anaerobic bacteria
## Changed
* Updated algorithm of `as.mo()` by giving more weight to fungi
* Fixed clinical breakpoints errors introduced by the source we import the rules from
* `mo_rank()` now returns `NA` for 'unknown' microorganisms (`B_ANAER`, `B_ANAER-NEG`, `B_ANAER-POS`, `B_GRAMN`, `B_GRAMP`, `F_FUNGUS`, `F_YEAST`, and `UNKNOWN`) * `mo_rank()` now returns `NA` for 'unknown' microorganisms (`B_ANAER`, `B_ANAER-NEG`, `B_ANAER-POS`, `B_GRAMN`, `B_GRAMP`, `F_FUNGUS`, `F_YEAST`, and `UNKNOWN`)
* When printing microorganism or antibiotic codes in a tibble, a mouse-hover now shows the full name of the code
* Plots for MIC and disk diffusion values:
* Now have settable arguments for breakpoint type and PK/PD, like `as.sir()`
* Will now contain the name of the guideline table in the subtitle of the plot
* Fixed formatting for `sir_interpretation_history()` * Fixed formatting for `sir_interpretation_history()`
* Fixed some WHONET codes for microorganisms and consequently a couple of entries in `clinical_breakpoints` * Fixed some WHONET codes for microorganisms and consequently a couple of entries in `clinical_breakpoints`
* Fixed a bug for `as.mo()` that led to coercion of `NA` values when using custom microorganism codes * Fixed a bug for `as.mo()` that led to coercion of `NA` values when using custom microorganism codes
* Fixed usage of `icu_exclude` in `first_isolates()` * Fixed usage of `icu_exclude` in `first_isolates()`
* Improved `as.mo()` algorithm for searching on only species names * Improved `as.mo()` algorithm:
* Now allows searching on only species names
* Fix for using the `keep_synonyms` argument when using MO codes as input
* Fix for using the `minimum_matching_score` argument
* Updated the code table in `microorganisms.codes` * Updated the code table in `microorganisms.codes`
* Fixed an endless loop if using `reference_df` in `as.mo()`
* Fixed bug for indicating UTIs in `as.sir()`
* Greatly improved speed of `as.sir()`
# AMR 2.0.0 # AMR 2.0.0

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -36,7 +36,7 @@
#' #'
#' This work was published in the Journal of Statistical Software (Volume 104(3); \doi{jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}). #' This work was published in the Journal of Statistical Software (Volume 104(3); \doi{jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}).
#' #'
#' After installing this package, R knows [**`r format_included_data_number(AMR::microorganisms)` microorganisms**](https://msberends.github.io/AMR/reference/microorganisms.html) (updated `r format(TAXONOMY_VERSION$GBIF$accessed_date, "%B %Y")`) and all [**`r format_included_data_number(nrow(AMR::antibiotics) + nrow(AMR::antivirals))` antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl). #' After installing this package, R knows [**`r format_included_data_number(AMR::microorganisms)` microorganisms**](https://msberends.github.io/AMR/reference/microorganisms.html) (updated `r format(TAXONOMY_VERSION$GBIF$accessed_date, "%B %Y")`) and all [**`r format_included_data_number(nrow(AMR::antibiotics) + nrow(AMR::antivirals))` antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl).
#' #'
#' The `AMR` package is available in `r vector_and(vapply(FUN.VALUE = character(1), LANGUAGES_SUPPORTED_NAMES, function(x) x$exonym), quotes = FALSE, sort = FALSE)`. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages. #' The `AMR` package is available in `r vector_and(vapply(FUN.VALUE = character(1), LANGUAGES_SUPPORTED_NAMES, function(x) x$exonym), quotes = FALSE, sort = FALSE)`. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
#' @section Reference Data Publicly Available: #' @section Reference Data Publicly Available:

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -30,6 +30,12 @@
# add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and clinical_breakpoints # add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and clinical_breakpoints
# (sourcing "data-raw/_pre_commit_hook.R" will process the TSV file) # (sourcing "data-raw/_pre_commit_hook.R" will process the TSV file)
EUCAST_VERSION_BREAKPOINTS <- list( EUCAST_VERSION_BREAKPOINTS <- list(
# "13.0" = list(
# version_txt = "v13.0",
# year = 2023,
# title = "'EUCAST Clinical Breakpoint Tables'",
# url = "https://www.eucast.org/clinical_breakpoints/"
# ),
"12.0" = list( "12.0" = list(
version_txt = "v12.0", version_txt = "v12.0",
year = 2022, year = 2022,
@ -50,25 +56,33 @@ EUCAST_VERSION_BREAKPOINTS <- list(
) )
) )
EUCAST_VERSION_EXPERT_RULES <- list( EUCAST_VERSION_EXPERT_RULES <- list(
"3.1" = list( "3.3" = list(
version_txt = "v3.1", version_txt = "v3.3",
year = 2016, year = 2021,
title = "'EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes'", title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/" url = "https://www.eucast.org/expert_rules_and_expected_phenotypes"
), ),
"3.2" = list( "3.2" = list(
version_txt = "v3.2", version_txt = "v3.2",
year = 2020, year = 2020,
title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'", title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/" url = "https://www.eucast.org/expert_rules_and_expected_phenotypes"
), ),
"3.3" = list( "3.1" = list(
version_txt = "v3.3", version_txt = "v3.1",
year = 2021, year = 2016,
title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'", title = "'EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/" url = "https://www.eucast.org/expert_rules_and_expected_phenotypes"
) )
) )
# EUCAST_VERSION_RESISTANTPHENOTYPES <- list(
# "1.2" = list(
# version_txt = "v1.2",
# year = 2023,
# title = "'Expected Resistant Phenotypes'",
# url = "https://www.eucast.org/expert_rules_and_expected_phenotypes"
# )
# )
TAXONOMY_VERSION <- list( TAXONOMY_VERSION <- list(
GBIF = list( GBIF = list(

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -501,9 +501,25 @@ word_wrap <- function(...,
} }
# format backticks # format backticks
if (pkg_is_available("cli") &&
tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE) &&
tryCatch(getExportedValue("isAvailable", ns = asNamespace("rstudioapi"))(), error = function(e) return(FALSE)) &&
tryCatch(getExportedValue("versionInfo", ns = asNamespace("rstudioapi"))()$version > "2023.6.0.0", error = function(e) return(FALSE))) {
# we are in a recent version of RStudio, so do something nice: add links to our help pages in the console.
parts <- strsplit(msg, "`", fixed = TRUE)[[1]]
cmds <- parts %in% paste0(ls(envir = asNamespace("AMR")), "()")
# functions with a dot are not allowed: https://github.com/rstudio/rstudio/issues/11273#issuecomment-1156193252
# lead them to the help page of our package
parts[cmds & parts %like% "[.]"] <- font_url(url = paste0("ide:help:AMR::", gsub("()", "", parts[cmds & parts %like% "[.]"], fixed = TRUE)),
txt = parts[cmds & parts %like% "[.]"])
# otherwise, give a 'click to run' popup
parts[cmds & parts %unlike% "[.]"] <- font_url(url = paste0("ide:run:AMR::", parts[cmds & parts %unlike% "[.]"]),
txt = parts[cmds & parts %unlike% "[.]"])
msg <- paste0(parts, collapse = "`")
}
msg <- gsub("`(.+?)`", font_grey_bg("\\1"), msg) msg <- gsub("`(.+?)`", font_grey_bg("\\1"), msg)
# clean introduced whitespace between fullstops # clean introduced whitespace in between fullstops
msg <- gsub("[.] +[.]", "..", msg) msg <- gsub("[.] +[.]", "..", msg)
# remove extra space that was introduced (e.g. "Smith et al. , 2022") # remove extra space that was introduced (e.g. "Smith et al. , 2022")
msg <- gsub(". ,", ".,", msg, fixed = TRUE) msg <- gsub(". ,", ".,", msg, fixed = TRUE)
@ -1182,20 +1198,20 @@ is_dark <- function() {
} }
isTRUE(AMR_env$is_dark_theme) isTRUE(AMR_env$is_dark_theme)
} }
font_black <- function(..., collapse = " ") { font_black <- function(..., collapse = " ", adapt = TRUE) {
before <- "\033[38;5;232m" before <- "\033[38;5;232m"
after <- "\033[39m" after <- "\033[39m"
if (is_dark()) { if (isTRUE(adapt) && is_dark()) {
# white # white
before <- "\033[37m" before <- "\033[37m"
after <- "\033[39m" after <- "\033[39m"
} }
try_colour(..., before = before, after = after, collapse = collapse) try_colour(..., before = before, after = after, collapse = collapse)
} }
font_white <- function(..., collapse = " ") { font_white <- function(..., collapse = " ", adapt = TRUE) {
before <- "\033[37m" before <- "\033[37m"
after <- "\033[39m" after <- "\033[39m"
if (is_dark()) { if (isTRUE(adapt) && is_dark()) {
# black # black
before <- "\033[38;5;232m" before <- "\033[38;5;232m"
after <- "\033[39m" after <- "\033[39m"
@ -1237,24 +1253,24 @@ font_grey_bg <- function(..., collapse = " ") {
} }
font_red_bg <- function(..., collapse = " ") { font_red_bg <- function(..., collapse = " ") {
# this is #ed553b (picked to be colourblind-safe with other SIR colours) # this is #ed553b (picked to be colourblind-safe with other SIR colours)
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;203m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;203m", after = "\033[49m", collapse = collapse)
} }
font_orange_bg <- function(..., collapse = " ") { font_orange_bg <- function(..., collapse = " ") {
# this is #f6d55c (picked to be colourblind-safe with other SIR colours) # this is #f6d55c (picked to be colourblind-safe with other SIR colours)
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;222m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;222m", after = "\033[49m", collapse = collapse)
} }
font_yellow_bg <- function(..., collapse = " ") { font_yellow_bg <- function(..., collapse = " ") {
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;228m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;228m", after = "\033[49m", collapse = collapse)
} }
font_green_bg <- function(..., collapse = " ") { font_green_bg <- function(..., collapse = " ") {
# this is #3caea3 (picked to be colourblind-safe with other SIR colours) # this is #3caea3 (picked to be colourblind-safe with other SIR colours)
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;79m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;79m", after = "\033[49m", collapse = collapse)
} }
font_purple_bg <- function(..., collapse = " ") { font_purple_bg <- function(..., collapse = " ") {
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;89m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;89m", after = "\033[49m", collapse = collapse)
} }
font_rose_bg <- function(..., collapse = " ") { font_rose_bg <- function(..., collapse = " ") {
try_colour(font_black(..., collapse = collapse), before = "\033[48;5;217m", after = "\033[49m", collapse = collapse) try_colour(font_black(..., collapse = collapse, adapt = FALSE), before = "\033[48;5;217m", after = "\033[49m", collapse = collapse)
} }
font_na <- function(..., collapse = " ") { font_na <- function(..., collapse = " ") {
font_red(..., collapse = collapse) font_red(..., collapse = collapse)
@ -1283,7 +1299,7 @@ font_stripstyle <- function(x) {
x x
} }
progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) { progress_ticker <- function(n = 1, n_min = 0, print = TRUE, clear = TRUE, title = "", only_bar_percent = FALSE, ...) {
if (print == FALSE || n < n_min) { if (print == FALSE || n < n_min) {
# create fake/empty object # create fake/empty object
pb <- list() pb <- list()
@ -1299,9 +1315,11 @@ progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) {
progress_bar <- import_fn("progress_bar", "progress", error_on_fail = FALSE) progress_bar <- import_fn("progress_bar", "progress", error_on_fail = FALSE)
if (!is.null(progress_bar)) { if (!is.null(progress_bar)) {
# so we use progress::progress_bar # so we use progress::progress_bar
# a close() method was also added, see below this function # a close()-method was also added, see below for that
pb <- progress_bar$new( pb <- progress_bar$new(
format = "[:bar] :percent (:current/:total,:eta)", format = paste0(title,
ifelse(only_bar_percent == TRUE, "[:bar] :percent", "[:bar] :percent (:current/:total,:eta)")),
clear = clear,
total = n total = n
) )
} else { } else {
@ -1487,11 +1505,11 @@ add_MO_lookup_to_AMR_env <- function() {
MO_lookup$kingdom_index <- NA_real_ MO_lookup$kingdom_index <- NA_real_
MO_lookup[which(MO_lookup$kingdom == "Bacteria" | MO_lookup$mo == "UNKNOWN"), "kingdom_index"] <- 1 MO_lookup[which(MO_lookup$kingdom == "Bacteria" | MO_lookup$mo == "UNKNOWN"), "kingdom_index"] <- 1
MO_lookup[which(MO_lookup$kingdom == "Fungi"), "kingdom_index"] <- 2 MO_lookup[which(MO_lookup$kingdom == "Fungi"), "kingdom_index"] <- 1.25
MO_lookup[which(MO_lookup$kingdom == "Protozoa"), "kingdom_index"] <- 3 MO_lookup[which(MO_lookup$kingdom == "Protozoa"), "kingdom_index"] <- 1.5
MO_lookup[which(MO_lookup$kingdom == "Archaea"), "kingdom_index"] <- 4 MO_lookup[which(MO_lookup$kingdom == "Archaea"), "kingdom_index"] <- 2
# all the rest # all the rest
MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5 MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 3
# the fullname lowercase, important for the internal algorithms in as.mo() # the fullname lowercase, important for the internal algorithms in as.mo()
MO_lookup$fullname_lower <- tolower(trimws(paste( MO_lookup$fullname_lower <- tolower(trimws(paste(
@ -1517,6 +1535,10 @@ trimws2 <- function(..., whitespace = "[\u0009\u000A\u000B\u000C\u000D\u0020\u00
trimws(..., whitespace = whitespace) trimws(..., whitespace = whitespace)
} }
totitle <- function(x) {
gsub("^(.)", "\\U\\1", x, perl = TRUE)
}
readRDS_AMR <- function(file, refhook = NULL) { readRDS_AMR <- function(file, refhook = NULL) {
# this is readRDS with remote file support # this is readRDS with remote file support
con <- file(file) con <- file(file)
@ -1527,19 +1549,17 @@ readRDS_AMR <- function(file, refhook = NULL) {
# Faster data.table implementations ---- # Faster data.table implementations ----
match <- function(x, table, ...) { match <- function(x, table, ...) {
chmatch <- import_fn("chmatch", "data.table", error_on_fail = FALSE) if (!is.null(AMR_env$chmatch) && inherits(x, "character") && inherits(table, "character")) {
if (!is.null(chmatch) && is.character(x) && is.character(table)) {
# data.table::chmatch() is much faster than base::match() for character # data.table::chmatch() is much faster than base::match() for character
chmatch(x, table, ...) AMR_env$chmatch(x, table, ...)
} else { } else {
base::match(x, table, ...) base::match(x, table, ...)
} }
} }
`%in%` <- function(x, table) { `%in%` <- function(x, table) {
chin <- import_fn("%chin%", "data.table", error_on_fail = FALSE) if (!is.null(AMR_env$chin) && inherits(x, "character") && inherits(table, "character")) {
if (!is.null(chin) && is.character(x) && is.character(table)) {
# data.table::`%chin%`() is much faster than base::`%in%`() for character # data.table::`%chin%`() is much faster than base::`%in%`() for character
chin(x, table) AMR_env$chin(x, table)
} else { } else {
base::`%in%`(x, table) base::`%in%`(x, table)
} }

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -37,6 +37,7 @@
#' * `AMR_guideline` \cr Used for setting the default guideline for interpreting MIC values and disk diffusion diameters with [as.sir()]. Can be only the guideline name (e.g., `"CLSI"`) or the name with a year (e.g. `"CLSI 2019"`). The default to the latest implemented EUCAST guideline, currently \code{"`r clinical_breakpoints$guideline[1]`"}. Supported guideline are currently EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). #' * `AMR_guideline` \cr Used for setting the default guideline for interpreting MIC values and disk diffusion diameters with [as.sir()]. Can be only the guideline name (e.g., `"CLSI"`) or the name with a year (e.g. `"CLSI 2019"`). The default to the latest implemented EUCAST guideline, currently \code{"`r clinical_breakpoints$guideline[1]`"}. Supported guideline are currently EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`).
#' * `AMR_ignore_pattern` \cr A [regular expression][base::regex] to ignore (i.e., make `NA`) any match given in [as.mo()] and all [`mo_*`][mo_property()] functions. #' * `AMR_ignore_pattern` \cr A [regular expression][base::regex] to ignore (i.e., make `NA`) any match given in [as.mo()] and all [`mo_*`][mo_property()] functions.
#' * `AMR_include_PKPD` \cr A [logical] to use in [as.sir()], to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is `TRUE`. #' * `AMR_include_PKPD` \cr A [logical] to use in [as.sir()], to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is `TRUE`.
#' * `AMR_ecoff` \cr A [logical] use in [as.sir()], to indicate that ECOFF (Epidemiological Cut-Off) values must be used - the default is `FALSE`.
#' * `AMR_include_screening` \cr A [logical] to use in [as.sir()], to indicate that clinical breakpoints for screening are allowed - the default is `FALSE`. #' * `AMR_include_screening` \cr A [logical] to use in [as.sir()], to indicate that clinical breakpoints for screening are allowed - the default is `FALSE`.
#' * `AMR_keep_synonyms` \cr A [logical] to use in [as.mo()] and all [`mo_*`][mo_property()] functions, to indicate if old, previously valid taxonomic names must be preserved and not be corrected to currently accepted names. The default is `FALSE`. #' * `AMR_keep_synonyms` \cr A [logical] to use in [as.mo()] and all [`mo_*`][mo_property()] functions, to indicate if old, previously valid taxonomic names must be preserved and not be corrected to currently accepted names. The default is `FALSE`.
#' * `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".

13
R/ab.R
View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -545,6 +545,13 @@ is.ab <- function(x) {
pillar_shaft.ab <- function(x, ...) { pillar_shaft.ab <- function(x, ...) {
out <- trimws(format(x)) out <- trimws(format(x))
out[is.na(x)] <- font_na(NA) out[is.na(x)] <- font_na(NA)
# add the names to the drugs as mouse-over!
if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) {
out[!is.na(x)] <- font_url(url = paste0(x[!is.na(x)], ": ", ab_name(x[!is.na(x)])),
txt = out[!is.na(x)])
}
create_pillar_column(out, align = "left", min_width = 4) create_pillar_column(out, align = "left", min_width = 4)
} }

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -620,7 +620,7 @@ administrable_iv <- function(only_sir_columns = FALSE, ...) {
#' @rdname antibiotic_class_selectors #' @rdname antibiotic_class_selectors
#' @inheritParams eucast_rules #' @inheritParams eucast_rules
#' @details The [not_intrinsic_resistant()] function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of *E. coli* and *K. pneumoniae* and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies `r format_eucast_version_nr(names(EUCAST_VERSION_EXPERT_RULES[length(EUCAST_VERSION_EXPERT_RULES)]))` to determine intrinsic resistance, using the [eucast_rules()] function internally. Because of this determination, this function is quite slow in terms of performance. #' @details The [not_intrinsic_resistant()] function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of *E. coli* and *K. pneumoniae* and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies `r format_eucast_version_nr(names(EUCAST_VERSION_EXPERT_RULES[1]))` to determine intrinsic resistance, using the [eucast_rules()] function internally. Because of this determination, this function is quite slow in terms of performance.
#' @export #' @export
not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ...) { not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

6
R/av.R
View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -32,9 +32,9 @@
#' Two data sets containing all antibiotics/antimycotics and antivirals. Use [as.ab()] or one of the [`ab_*`][ab_property()] functions to retrieve values from the [antibiotics] data set. Three identifiers are included in this data set: an antibiotic ID (`ab`, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (`atc`) as defined by the WHO, and a Compound ID (`cid`) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes. #' Two data sets containing all antibiotics/antimycotics and antivirals. Use [as.ab()] or one of the [`ab_*`][ab_property()] functions to retrieve values from the [antibiotics] data set. Three identifiers are included in this data set: an antibiotic ID (`ab`, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (`atc`) as defined by the WHO, and a Compound ID (`cid`) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes.
#' @format #' @format
#' ### For the [antibiotics] data set: a [tibble][tibble::tibble] with `r nrow(antibiotics)` observations and `r ncol(antibiotics)` variables: #' ### For the [antibiotics] data set: a [tibble][tibble::tibble] with `r nrow(antibiotics)` observations and `r ncol(antibiotics)` variables:
#' - `ab`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available #' - `ab`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. *This is a unique identifier.*
#' - `cid`\cr Compound ID as found in PubChem #' - `cid`\cr Compound ID as found in PubChem. *This is a unique identifier.*
#' - `name`\cr Official name as used by WHONET/EARS-Net or the WHO #' - `name`\cr Official name as used by WHONET/EARS-Net or the WHO. *This is a unique identifier.*
#' - `group`\cr A short and concise group name, based on WHONET and WHOCC definitions #' - `group`\cr A short and concise group name, based on WHONET and WHOCC definitions
#' - `atc`\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC, like `J01CR02` #' - `atc`\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC, like `J01CR02`
#' - `atc_group1`\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like `"Macrolides, lincosamides and streptogramins"` #' - `atc_group1`\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like `"Macrolides, lincosamides and streptogramins"`
@ -48,10 +48,10 @@
#' - `loinc`\cr All LOINC codes (Logical Observation Identifiers Names and Codes) associated with the name of the antimicrobial drug. Use [ab_loinc()] to retrieve them quickly, see [ab_property()]. #' - `loinc`\cr All LOINC codes (Logical Observation Identifiers Names and Codes) associated with the name of the antimicrobial drug. Use [ab_loinc()] to retrieve them quickly, see [ab_property()].
#' #'
#' ### For the [antivirals] data set: a [tibble][tibble::tibble] with `r nrow(antivirals)` observations and `r ncol(antivirals)` variables: #' ### For the [antivirals] data set: a [tibble][tibble::tibble] with `r nrow(antivirals)` observations and `r ncol(antivirals)` variables:
#' - `av`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available #' - `av`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. *This is a unique identifier.*
#' - `name`\cr Official name as used by WHONET/EARS-Net or the WHO #' - `name`\cr Official name as used by WHONET/EARS-Net or the WHO. *This is a unique identifier.*
#' - `atc`\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC #' - `atc`\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC
#' - `cid`\cr Compound ID as found in PubChem #' - `cid`\cr Compound ID as found in PubChem. *This is a unique identifier.*
#' - `atc_group`\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC #' - `atc_group`\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC
#' - `synonyms`\cr Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID #' - `synonyms`\cr Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID
#' - `oral_ddd`\cr Defined Daily Dose (DDD), oral treatment #' - `oral_ddd`\cr Defined Daily Dose (DDD), oral treatment
@ -86,8 +86,8 @@
#' #'
#' A data set containing the full microbial taxonomy (**last updated: `r documentation_date(max(TAXONOMY_VERSION$GBIF$accessed_date, TAXONOMY_VERSION$LPSN$accessed_date))`**) of `r nr2char(length(unique(microorganisms$kingdom[!microorganisms$kingdom %like% "unknown"])))` kingdoms from the List of Prokaryotic names with Standing in Nomenclature (LPSN) and the Global Biodiversity Information Facility (GBIF). This data set is the backbone of this `AMR` package. MO codes can be looked up using [as.mo()]. #' A data set containing the full microbial taxonomy (**last updated: `r documentation_date(max(TAXONOMY_VERSION$GBIF$accessed_date, TAXONOMY_VERSION$LPSN$accessed_date))`**) of `r nr2char(length(unique(microorganisms$kingdom[!microorganisms$kingdom %like% "unknown"])))` kingdoms from the List of Prokaryotic names with Standing in Nomenclature (LPSN) and the Global Biodiversity Information Facility (GBIF). This data set is the backbone of this `AMR` package. MO codes can be looked up using [as.mo()].
#' @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 #' - `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. #' - `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)`
#' - `kingdom`, `phylum`, `class`, `order`, `family`, `genus`, `species`, `subspecies`\cr Taxonomic rank of the microorganism #' - `kingdom`, `phylum`, `class`, `order`, `family`, `genus`, `species`, `subspecies`\cr Taxonomic rank of the microorganism
#' - `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"`
@ -122,8 +122,7 @@
#' For convenience, some entries were added manually: #' For convenience, some entries were added manually:
#' #'
#' - `r format_included_data_number(microorganisms[which(microorganisms$source == "manually added" & microorganisms$genus == "Salmonella"), , drop = FALSE])` entries of *Salmonella*, such as the city-like serovars and groups A to H #' - `r format_included_data_number(microorganisms[which(microorganisms$source == "manually added" & microorganisms$genus == "Salmonella"), , drop = FALSE])` entries of *Salmonella*, such as the city-like serovars and groups A to H
#' - `r format_included_data_number(microorganisms[which(microorganisms$source == "manually added" & microorganisms$genus == "Streptococcus"), , drop = FALSE])` entries of *Streptococcus*, such as the beta-haemolytic groups A to K, viridans, and milleri #' - `r format_included_data_number(length(which(microorganisms$rank == "species group")))` species groups (such as the beta-haemolytic *Streptococcus* groups A to K, coagulase-negative *Staphylococcus* (CoNS), *Mycobacterium tuberculosis* complex, etc.), of which the group compositions are stored in the [microorganisms.groups] data set
#' - 2 entries of *Staphylococcus* (coagulase-negative (CoNS) and coagulase-positive (CoPS))
#' - 1 entry of *Blastocystis* (*B. hominis*), although it officially does not exist (Noel *et al.* 2005, PMID 15634993) #' - 1 entry of *Blastocystis* (*B. hominis*), although it officially does not exist (Noel *et al.* 2005, PMID 15634993)
#' - 1 entry of *Moraxella* (*M. catarrhalis*), which was formally named *Branhamella catarrhalis* (Catlin, 1970) though this change was never accepted within the field of clinical microbiology #' - 1 entry of *Moraxella* (*M. catarrhalis*), which was formally named *Branhamella catarrhalis* (Catlin, 1970) though this change was never accepted within the field of clinical microbiology
#' - 8 other 'undefined' entries (unknown, unknown Gram-negatives, unknown Gram-positives, unknown yeast, unknown fungus, and unknown anaerobic Gram-pos/Gram-neg bacteria) #' - 8 other 'undefined' entries (unknown, unknown Gram-negatives, unknown Gram-positives, unknown yeast, unknown fungus, and unknown anaerobic Gram-pos/Gram-neg bacteria)
@ -148,16 +147,16 @@
#' * Grimont *et al.* (2007). Antigenic Formulae of the Salmonella Serovars, 9th Edition. WHO Collaborating Centre for Reference and Research on *Salmonella* (WHOCC-SALM). #' * Grimont *et al.* (2007). Antigenic Formulae of the Salmonella Serovars, 9th Edition. WHO Collaborating Centre for Reference and Research on *Salmonella* (WHOCC-SALM).
#' #'
#' * Bartlett *et al.* (2022). **A comprehensive list of bacterial pathogens infecting humans** *Microbiology* 168:001269; \doi{10.1099/mic.0.001269} #' * Bartlett *et al.* (2022). **A comprehensive list of bacterial pathogens infecting humans** *Microbiology* 168:001269; \doi{10.1099/mic.0.001269}
#' @seealso [as.mo()], [mo_property()], [microorganisms.codes], [intrinsic_resistant] #' @seealso [as.mo()], [mo_property()], [microorganisms.groups], [microorganisms.codes], [intrinsic_resistant]
#' @examples #' @examples
#' microorganisms #' microorganisms
"microorganisms" "microorganisms"
#' Data Set with `r format(nrow(microorganisms.codes), big.mark = " ")` Common Microorganism Codes #' Data Set with `r format(nrow(microorganisms.codes), big.mark = " ")` Common Microorganism Codes
#' #'
#' A data set containing commonly used codes for microorganisms, from laboratory systems and WHONET. Define your own with [set_mo_source()]. They will all be searched when using [as.mo()] and consequently all the [`mo_*`][mo_property()] functions. #' A data set containing commonly used codes for microorganisms, from laboratory systems and [WHONET](https://whonet.org). Define your own with [set_mo_source()]. They will all be searched when using [as.mo()] and consequently all the [`mo_*`][mo_property()] functions.
#' @format A [tibble][tibble::tibble] with `r format(nrow(microorganisms.codes), big.mark = " ")` observations and `r ncol(microorganisms.codes)` variables: #' @format A [tibble][tibble::tibble] with `r format(nrow(microorganisms.codes), big.mark = " ")` observations and `r ncol(microorganisms.codes)` variables:
#' - `code`\cr Commonly used code of a microorganism #' - `code`\cr Commonly used code of a microorganism. *This is a unique identifier.*
#' - `mo`\cr ID of the microorganism in the [microorganisms] data set #' - `mo`\cr ID of the microorganism in the [microorganisms] data set
#' @details #' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw).
@ -175,6 +174,24 @@
#' mo_is_intrinsic_resistant("eco", ab = "vancomycin") #' mo_is_intrinsic_resistant("eco", ab = "vancomycin")
"microorganisms.codes" "microorganisms.codes"
#' Data Set with `r format(nrow(microorganisms.groups), big.mark = " ")` Microorganisms In Species Groups
#'
#' A data set containing species groups and microbiological complexes, which are used in [the clinical breakpoints table][clinical_breakpoints].
#' @format A [tibble][tibble::tibble] with `r format(nrow(microorganisms.groups), big.mark = " ")` observations and `r ncol(microorganisms.groups)` variables:
#' - `mo_group`\cr ID of the species group / microbiological complex
#' - `mo`\cr ID of the microorganism belonging in the species group / microbiological complex
#' - `mo_group_name`\cr Name of the species group / microbiological complex, as retrieved with [mo_name()]
#' - `mo_name`\cr Name of the microorganism belonging in the species group / microbiological complex, as retrieved with [mo_name()]
#' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw).
#' @seealso [as.mo()] [microorganisms]
#' @examples
#' microorganisms.groups
#'
#' # these are all species in the Bacteroides fragilis group, as per WHONET:
#' microorganisms.groups[microorganisms.groups$mo_group == "B_BCTRD_FRGL-C", ]
"microorganisms.groups"
#' Data Set with `r format(nrow(example_isolates), big.mark = " ")` Example Isolates #' Data Set with `r format(nrow(example_isolates), big.mark = " ")` Example Isolates
#' #'
#' A data set containing `r format(nrow(example_isolates), big.mark = " ")` microbial isolates with their full antibiograms. This data set contains randomised fictitious data, but reflects reality and can be used to practise AMR data analysis. For examples, please read [the tutorial on our website](https://msberends.github.io/AMR/articles/AMR.html). #' A data set containing `r format(nrow(example_isolates), big.mark = " ")` microbial isolates with their full antibiograms. This data set contains randomised fictitious data, but reflects reality and can be used to practise AMR data analysis. For examples, please read [the tutorial on our website](https://msberends.github.io/AMR/articles/AMR.html).
@ -248,20 +265,33 @@
#' Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. Currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). Use [as.sir()] to transform MICs or disks measurements to SIR values. #' Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. Currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). 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
#' - `method`\cr Either `r vector_or(clinical_breakpoints$method)` #' - `type`\cr Breakpoint type, either `r vector_or(clinical_breakpoints$type)`
#' - `site`\cr Body site, e.g. "Oral" or "Respiratory" #' - `method`\cr Testing method, either `r vector_or(clinical_breakpoints$method)`
#' - `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)
#' - `ab`\cr Antibiotic ID, see [as.ab()] #' - `ab`\cr Antibiotic code as used by this package, EARS-Net and WHONET, see [as.ab()]
#' - `ref_tbl`\cr Info about where the guideline rule can be found #' - `ref_tbl`\cr Info about where the guideline rule can be found
#' - `disk_dose`\cr Dose of the used disk diffusion method #' - `disk_dose`\cr Dose of the used disk diffusion method
#' - `breakpoint_S`\cr Lowest MIC value or highest number of millimetres that leads to "S" #' - `breakpoint_S`\cr Lowest MIC value or highest number of millimetres that leads to "S"
#' - `breakpoint_R`\cr Highest MIC value or lowest number of millimetres that leads to "R" #' - `breakpoint_R`\cr Highest MIC value or lowest number of millimetres that leads to "R"
#' - `uti`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the rule applies to a urinary tract infection (UTI) #' - `uti`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the rule applies to a urinary tract infection (UTI)
#' @details #' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' ### 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.
#' They **allow for machine reading EUCAST and CLSI guidelines**, which is almost impossible with the MS Excel and PDF files distributed by EUCAST and CLSI. #'
#' The default is `"human"`, which can also be set with the [package option][AMR-options] [`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.
#'
#' ### Imported from WHONET
#' Clinical breakpoints in this package were validated through and imported from [WHONET](https://whonet.org), a free desktop Windows application developed and supported by the WHO Collaborating Centre for Surveillance of Antimicrobial Resistance. More can be read on [their website](https://whonet.org). The developers of WHONET and this `AMR` package have been in contact about sharing their work. We highly appreciate their development on the WHONET software.
#'
#' ### Response from CLSI and EUCAST
#' The CEO of CLSI and the chairman of EUCAST have endorsed the work and public use of this `AMR` package (and consequently the use of their breakpoints) in June 2023, when future development of distributing clinical breakpoints was discussed in a meeting between CLSI, EUCAST, the WHO, and developers of WHONET and the `AMR` package.
#'
#' ### Download
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). They allow for machine reading EUCAST and CLSI guidelines, which is almost impossible with the MS Excel and PDF files distributed by EUCAST and CLSI, though initiatives have started to overcome these burdens.
#'
#' **NOTE:** this `AMR` package (and the WHONET software as well) contains internal methods to apply the guidelines, which is rather complex. For example, some breakpoints must be applied on certain species groups (which are in case of this package available through the [microorganisms.groups] data set). It is important that this is considered when using the breakpoints for own use.
#' @seealso [intrinsic_resistant] #' @seealso [intrinsic_resistant]
#' @examples #' @examples
#' clinical_breakpoints #' clinical_breakpoints
@ -296,11 +326,8 @@
#' - `administration`\cr Route of administration, either `r vector_or(dosage$administration)` #' - `administration`\cr Route of administration, either `r vector_or(dosage$administration)`
#' - `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 #' - `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)`
#' @details #' @details
#' This data set is based on `r format_eucast_version_nr(12.0)` and `r format_eucast_version_nr(11.0)`.
#'
#' ### Direct download
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw).
#' @examples #' @examples
#' dosage #' dosage

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -70,7 +70,7 @@
#' # interpret whole data set, pretend to be all from urinary tract infections: #' # interpret whole data set, pretend to be all from urinary tract infections:
#' as.sir(df, uti = TRUE) #' as.sir(df, uti = TRUE)
as.disk <- function(x, na.rm = FALSE) { as.disk <- function(x, na.rm = FALSE) {
meet_criteria(x, allow_class = c("disk", "character", "numeric", "integer"), allow_NA = TRUE) meet_criteria(x, allow_NA = TRUE)
meet_criteria(na.rm, allow_class = "logical", has_length = 1) meet_criteria(na.rm, allow_class = "logical", has_length = 1)
if (!is.disk(x)) { if (!is.disk(x)) {

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -63,8 +63,9 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' @param info a [logical] to indicate whether progress should be printed to the console - the default is only print while in interactive sessions #' @param info a [logical] to indicate whether progress should be printed to the console - the default is only print while in interactive sessions
#' @param rules a [character] vector that specifies which rules should be applied. Must be one or more of `"breakpoints"`, `"expert"`, `"other"`, `"custom"`, `"all"`, and defaults to `c("breakpoints", "expert")`. The default value can be set to another value using the [package option][AMR-options] [`AMR_eucastrules`][AMR-options]: `options(AMR_eucastrules = "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"`, `"expert"`, `"other"`, `"custom"`, `"all"`, and defaults to `c("breakpoints", "expert")`. The default value can be set to another value using the [package option][AMR-options] [`AMR_eucastrules`][AMR-options]: `options(AMR_eucastrules = "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 either `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), reverse = TRUE)`.
#' @param version_expertrules the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be either `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), reverse = TRUE)`.
# @param version_resistant_phenotypes the version number to use for the EUCAST Expected Resistant Phenotypes. Can be `r vector_or(names(EUCAST_VERSION_RESISTANTPHENOTYPES), reverse = TRUE)`.
#' @param ampc_cephalosporin_resistance 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 version 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 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 version 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 name of an antibiotic, see section *Antibiotics* below #' @param ... column name of an antibiotic, see section *Antibiotics* below
#' @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()]
@ -167,6 +168,7 @@ eucast_rules <- function(x,
verbose = FALSE, verbose = FALSE,
version_breakpoints = 12.0, version_breakpoints = 12.0,
version_expertrules = 3.3, version_expertrules = 3.3,
# TODO version_resistant_phenotypes = 1.2,
ampc_cephalosporin_resistance = NA, ampc_cephalosporin_resistance = NA,
only_sir_columns = FALSE, only_sir_columns = FALSE,
custom_rules = NULL, custom_rules = NULL,
@ -178,6 +180,7 @@ eucast_rules <- function(x,
meet_criteria(verbose, allow_class = "logical", has_length = 1) meet_criteria(verbose, allow_class = "logical", has_length = 1)
meet_criteria(version_breakpoints, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_BREAKPOINTS))) meet_criteria(version_breakpoints, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_BREAKPOINTS)))
meet_criteria(version_expertrules, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_EXPERT_RULES))) meet_criteria(version_expertrules, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_EXPERT_RULES)))
# meet_criteria(version_resistant_phenotypes, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_RESISTANTPHENOTYPES)))
meet_criteria(ampc_cephalosporin_resistance, allow_class = c("logical", "character", "sir"), has_length = 1, allow_NA = TRUE, allow_NULL = TRUE) meet_criteria(ampc_cephalosporin_resistance, allow_class = c("logical", "character", "sir"), has_length = 1, allow_NA = TRUE, allow_NULL = TRUE)
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)
@ -205,7 +208,8 @@ eucast_rules <- function(x,
breakpoints_info <- EUCAST_VERSION_BREAKPOINTS[[which(as.double(names(EUCAST_VERSION_BREAKPOINTS)) == version_breakpoints)]] breakpoints_info <- EUCAST_VERSION_BREAKPOINTS[[which(as.double(names(EUCAST_VERSION_BREAKPOINTS)) == version_breakpoints)]]
expertrules_info <- EUCAST_VERSION_EXPERT_RULES[[which(as.double(names(EUCAST_VERSION_EXPERT_RULES)) == version_expertrules)]] expertrules_info <- EUCAST_VERSION_EXPERT_RULES[[which(as.double(names(EUCAST_VERSION_EXPERT_RULES)) == version_expertrules)]]
# resistantphenotypes_info <- EUCAST_VERSION_RESISTANTPHENOTYPES[[which(as.double(names(EUCAST_VERSION_RESISTANTPHENOTYPES)) == version_resistant_phenotypes)]]
# support old setting (until AMR v1.3.0) # support old setting (until AMR v1.3.0)
if (missing(rules) && !is.null(getOption("AMR.eucast_rules"))) { if (missing(rules) && !is.null(getOption("AMR.eucast_rules"))) {
rules <- getOption("AMR.eucast_rules") rules <- getOption("AMR.eucast_rules")

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -52,7 +52,7 @@
#' #'
#' * `guideline = "CMI2012"` (default) #' * `guideline = "CMI2012"` (default)
#' #'
#' Magiorakos AP, Srinivasan A *et al.* "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance." Clinical Microbiology and Infection (2012) ([link](https://www.clinicalmicrobiologyandinfection.com/article/S1198-743X(14)61632-3/fulltext)) #' Magiorakos AP, Srinivasan A *et al.* "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance." Clinical Microbiology and Infection (2012) (\doi{10.1111/j.1469-0691.2011.03570.x})
#' #'
#' * `guideline = "EUCAST3.3"` (or simply `guideline = "EUCAST"`) #' * `guideline = "EUCAST3.3"` (or simply `guideline = "EUCAST"`)
#' #'

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -165,7 +165,7 @@ valid_mic_levels <- c(
#' autoplot(mic_data, mo = "E. coli", ab = "cipro", language = "uk") # Ukrainian #' autoplot(mic_data, mo = "E. coli", ab = "cipro", language = "uk") # Ukrainian
#' } #' }
as.mic <- function(x, na.rm = FALSE) { as.mic <- function(x, na.rm = FALSE) {
meet_criteria(x, allow_class = c("mic", "character", "numeric", "integer", "factor"), allow_NA = TRUE) meet_criteria(x, allow_NA = TRUE)
meet_criteria(na.rm, allow_class = "logical", has_length = 1) meet_criteria(na.rm, allow_class = "logical", has_length = 1)
if (is.mic(x)) { if (is.mic(x)) {

372
R/mo.R
View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -134,6 +134,10 @@
#' "Ureaplasmium urealytica", #' "Ureaplasmium urealytica",
#' "Ureaplazma urealitycium" #' "Ureaplazma urealitycium"
#' )) #' ))
#'
#' # input will get cleaned up with the input given in the `cleaning_regex` argument,
#' # which defaults to `mo_cleaning_regex()`:
#' cat(mo_cleaning_regex(), "\n")
#' #'
#' as.mo("Streptococcus group A") #' as.mo("Streptococcus group A")
#' #'
@ -169,38 +173,34 @@ as.mo <- function(x,
meet_criteria(cleaning_regex, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(cleaning_regex, allow_class = "character", has_length = 1, allow_NULL = TRUE)
language <- validate_language(language) language <- validate_language(language)
meet_criteria(info, allow_class = "logical", has_length = 1) meet_criteria(info, allow_class = "logical", has_length = 1)
add_MO_lookup_to_AMR_env() add_MO_lookup_to_AMR_env()
if (tryCatch(all(x %in% c(AMR_env$MO_lookup$mo, NA)) && if (tryCatch(all(x %in% c(AMR_env$MO_lookup$mo, NA)), error = function(e) FALSE) &&
isFALSE(Becker) && isFALSE(Becker) &&
isFALSE(Lancefield), error = function(e) FALSE)) { isFALSE(Lancefield) &&
isTRUE(keep_synonyms)) {
# don't look into valid MO codes, just return them # don't look into valid MO codes, just return them
# is.mo() won't work - MO codes might change between package versions # is.mo() won't work - MO codes might change between package versions
return(set_clean_class(x, new_class = c("mo", "character"))) return(set_clean_class(x, new_class = c("mo", "character")))
} }
# start off with replaced language-specific non-ASCII characters with ASCII characters # start off with replaced language-specific non-ASCII characters with ASCII characters
x <- parse_and_convert(x) x <- parse_and_convert(x)
# replace mo codes used in older package versions # replace mo codes used in older package versions
x <- replace_old_mo_codes(x, property = "mo") x <- replace_old_mo_codes(x, property = "mo")
# ignore cases that match the ignore pattern # ignore cases that match the ignore pattern
x <- replace_ignore_pattern(x, ignore_pattern) x <- replace_ignore_pattern(x, ignore_pattern)
x_lower <- tolower(x) x_lower <- tolower(x)
complexes <- x[trimws2(x_lower) %like_case% " (complex|group)$"]
if (length(complexes) > 0 && identical(cleaning_regex, mo_cleaning_regex()) && !any(AMR_env$MO_lookup$fullname[which(AMR_env$MO_lookup$source == "Added by user")] %like% "(group|complex)", na.rm = TRUE)) {
warning_("in `as.mo()`: 'complex' and 'group' were ignored from the input in ", length(complexes), " case", ifelse(length(complexes) > 1, "s", ""), ", as they are currently not supported.\nYou can add your own microorganism with `add_custom_microorganisms()`.", call = FALSE)
}
# WHONET: xxx = no growth # WHONET: xxx = no growth
x[x_lower %in% c("", "xxx", "na", "nan")] <- NA_character_ x[x_lower %in% c("", "xxx", "na", "nan")] <- NA_character_
out <- rep(NA_character_, length(x)) out <- rep(NA_character_, length(x))
# below we use base R's match(), known for powering '%in%', and incredibly fast! # below we use base R's match(), known for powering '%in%', and incredibly fast!
# From reference_df ---- # From reference_df ----
reference_df <- repair_reference_df(reference_df) reference_df <- repair_reference_df(reference_df)
if (!is.null(reference_df)) { if (!is.null(reference_df)) {
@ -232,33 +232,33 @@ as.mo <- function(x,
" for ", vector_and(x[is.na(old) & !is.na(new)]), ". Run `mo_reset_session()` to reset this. This note will be shown once per session for this input." " for ", vector_and(x[is.na(old) & !is.na(new)]), ". Run `mo_reset_session()` to reset this. This note will be shown once per session for this input."
) )
} }
# For all other input ---- # For all other input ----
if (any(is.na(out) & !is.na(x))) { if (any(is.na(out) & !is.na(x))) {
# reset uncertainties # reset uncertainties
AMR_env$mo_uncertainties <- AMR_env$mo_uncertainties[0, ] AMR_env$mo_uncertainties <- AMR_env$mo_uncertainties[0, ]
AMR_env$mo_failures <- NULL AMR_env$mo_failures <- NULL
# Laboratory systems: remove (translated) entries like "no growth", "not E. coli", etc. # Laboratory systems: remove (translated) entries like "no growth", "not E. coli", etc.
x[trimws2(x) %like% translate_into_language("no .*growth", language = language)] <- NA_character_ x[trimws2(x) %like% translate_into_language("no .*growth", language = language)] <- NA_character_
x[trimws2(x) %like% paste0("^(", translate_into_language("no|not", language = language), ") ")] <- NA_character_ x[trimws2(x) %like% paste0("^(", translate_into_language("no|not", language = language), ") ")] <- NA_character_
# groups are in our taxonomic table with a capital G # groups are in our taxonomic table with a capital G
x <- gsub(" group( |$)", " Group\\1", x, perl = TRUE) x <- gsub(" group( |$)", " Group\\1", x, perl = TRUE)
# run over all unique leftovers # run over all unique leftovers
x_unique <- unique(x[is.na(out) & !is.na(x)]) x_unique <- unique(x[is.na(out) & !is.na(x)])
# set up progress bar # set up progress bar
progress <- progress_ticker(n = length(x_unique), n_min = 10, print = info) progress <- progress_ticker(n = length(x_unique), n_min = 10, print = info)
on.exit(close(progress)) on.exit(close(progress))
msg <- character(0) msg <- character(0)
# run it # run it
x_coerced <- vapply(FUN.VALUE = character(1), x_unique, function(x_search) { x_coerced <- vapply(FUN.VALUE = character(1), x_unique, function(x_search) {
progress$tick() progress$tick()
# some required cleaning steps # some required cleaning steps
x_out <- trimws2(x_search) x_out <- trimws2(x_search)
# this applies the `cleaning_regex` argument, which defaults to mo_cleaning_regex() # this applies the `cleaning_regex` argument, which defaults to mo_cleaning_regex()
@ -266,28 +266,30 @@ as.mo <- function(x,
x_out <- trimws2(gsub(" +", " ", x_out, perl = TRUE)) x_out <- trimws2(gsub(" +", " ", x_out, perl = TRUE))
x_search_cleaned <- x_out x_search_cleaned <- x_out
x_out <- tolower(x_out) x_out <- tolower(x_out)
# when x_search_cleaned are only capitals (such as in codes), make them lowercase to increase matching score
x_search_cleaned[x_search_cleaned == toupper(x_search_cleaned)] <- x_out[x_search_cleaned == toupper(x_search_cleaned)]
# first check if cleaning led to an exact result, case-insensitive # first check if cleaning led to an exact result, case-insensitive
if (x_out %in% AMR_env$MO_lookup$fullname_lower) { if (x_out %in% AMR_env$MO_lookup$fullname_lower) {
return(as.character(AMR_env$MO_lookup$mo[match(x_out, AMR_env$MO_lookup$fullname_lower)])) return(as.character(AMR_env$MO_lookup$mo[match(x_out, AMR_env$MO_lookup$fullname_lower)]))
} }
# input must not be too short # input must not be too short
if (nchar(x_out) < 3) { if (nchar(x_out) < 3) {
return("UNKNOWN") return("UNKNOWN")
} }
# take out the parts, split by space # take out the parts, split by space
x_parts <- strsplit(gsub("-", " ", x_out, fixed = TRUE), " ", fixed = TRUE)[[1]] x_parts <- strsplit(gsub("-", " ", x_out, fixed = TRUE), " ", fixed = TRUE)[[1]]
# do a pre-match on first character (and if it contains a space, first chars of first two terms) # do a pre-match on first character (and if it contains a space, first chars of first two terms)
if (length(x_parts) %in% c(2, 3)) { if (length(x_parts) %in% c(2, 3)) {
# for genus + species + subspecies # for genus + species + subspecies
if (nchar(gsub("[^a-z]", "", x_parts[1], perl = TRUE)) <= 3) { if (nchar(gsub("[^a-z]", "", x_parts[1], perl = TRUE)) <= 3) {
filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) & filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) &
(AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) | (AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) |
AMR_env$MO_lookup$subspecies_first == substr(x_parts[2], 1, 1) | AMR_env$MO_lookup$subspecies_first == substr(x_parts[2], 1, 1) |
AMR_env$MO_lookup$subspecies_first == substr(x_parts[3], 1, 1))) AMR_env$MO_lookup$subspecies_first == substr(x_parts[3], 1, 1)))
} else { } else {
filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) | filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) |
AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) | AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) |
@ -297,15 +299,19 @@ as.mo <- function(x,
} else if (length(x_parts) > 3) { } else if (length(x_parts) > 3) {
first_chars <- paste0("(^| )[", paste(substr(x_parts, 1, 1), collapse = ""), "]") first_chars <- paste0("(^| )[", paste(substr(x_parts, 1, 1), collapse = ""), "]")
filtr <- which(AMR_env$MO_lookup$full_first %like_case% first_chars) filtr <- which(AMR_env$MO_lookup$full_first %like_case% first_chars)
} else if (nchar(x_out) == 3) {
# no space and 3 characters - probably a code such as SAU or ECO
msg <<- c(msg, paste0("Input \"", x_search, "\" was assumed to be a microorganism code - tried to match on \"", totitle(substr(x_out, 1, 1)), AMR_env$dots, " ", substr(x_out, 2, 3), AMR_env$dots, "\""))
filtr <- which(AMR_env$MO_lookup$fullname_lower %like_case% paste0("(^| )", substr(x_out, 1, 1), ".* ", substr(x_out, 2, 3)))
} else if (nchar(x_out) == 4) { } else if (nchar(x_out) == 4) {
# no space and 4 characters - probably a code such as STAU or ESCO # no space and 4 characters - probably a code such as STAU or ESCO
msg <- c(msg, paste0("Input \"", x_search, "\" was assumed to be a microorganism code - tried to match on ", vector_and(c(substr(x_out, 1, 2), substr(x_out, 3, 4)), sort = FALSE))) msg <<- c(msg, paste0("Input \"", x_search, "\" was assumed to be a microorganism code - tried to match on \"", totitle(substr(x_out, 1, 2)), AMR_env$dots, " ", substr(x_out, 3, 4), AMR_env$dots, "\""))
filtr <- which(AMR_env$MO_lookup$fullname_lower %like_case% paste0("(^| )", substr(x_out, 1, 2), ".* ", substr(x_out, 3, 4))) filtr <- which(AMR_env$MO_lookup$fullname_lower %like_case% paste0("(^| )", substr(x_out, 1, 2), ".* ", substr(x_out, 3, 4)))
} else if (nchar(x_out) <= 6) { } else if (nchar(x_out) <= 6) {
# no space and 5-6 characters - probably a code such as STAAUR or ESCCOL # no space and 5-6 characters - probably a code such as STAAUR or ESCCOL
first_part <- paste0(substr(x_out, 1, 2), "[a-z]*", substr(x_out, 3, 3)) first_part <- paste0(substr(x_out, 1, 2), "[a-z]*", substr(x_out, 3, 3))
second_part <- substr(x_out, 4, nchar(x_out)) second_part <- substr(x_out, 4, nchar(x_out))
msg <- c(msg, paste0("Input \"", x_search, "\" was assumed to be a microorganism code - tried to match on ", vector_and(c(gsub("[a-z]*", "(...)", first_part, fixed = TRUE), second_part), sort = FALSE))) msg <<- c(msg, paste0("Input \"", x_search, "\" was assumed to be a microorganism code - tried to match on \"", gsub("[a-z]*", AMR_env$dots, totitle(first_part), fixed = TRUE), " ", second_part, AMR_env$dots, "\""))
filtr <- which(AMR_env$MO_lookup$fullname_lower %like_case% paste0("(^| )", first_part, ".* ", second_part)) filtr <- which(AMR_env$MO_lookup$fullname_lower %like_case% paste0("(^| )", first_part, ".* ", second_part))
} else { } else {
# for genus or species or subspecies # for genus or species or subspecies
@ -318,7 +324,7 @@ as.mo <- function(x,
} else { } else {
mo_to_search <- AMR_env$MO_lookup$fullname[filtr] mo_to_search <- AMR_env$MO_lookup$fullname[filtr]
} }
AMR_env$mo_to_search <- mo_to_search AMR_env$mo_to_search <- mo_to_search
# determine the matching score on the original search value # determine the matching score on the original search value
m <- mo_matching_score(x = x_search_cleaned, n = mo_to_search) m <- mo_matching_score(x = x_search_cleaned, n = mo_to_search)
@ -328,15 +334,19 @@ as.mo <- function(x,
minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$prevalence[match(mo_to_search, AMR_env$MO_lookup$fullname)] minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$prevalence[match(mo_to_search, AMR_env$MO_lookup$fullname)]
# correct back for kingdom # correct back for kingdom
minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$kingdom_index[match(mo_to_search, AMR_env$MO_lookup$fullname)] minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$kingdom_index[match(mo_to_search, AMR_env$MO_lookup$fullname)]
minimum_matching_score_current <- pmax(minimum_matching_score_current, m)
if (length(x_parts) > 1 && all(m <= 0.55, na.rm = TRUE)) {
# if the highest score is 0.5, we have nothing serious - 0.5 is the lowest for pathogenic group 1
# make everything NA so the results will get removed below
# (we added length(x_parts) > 1 to exclude microbial codes from this rule, such as "STAU")
m[seq_len(length(m))] <- NA_real_
}
} else { } else {
# minimum_matching_score was set, so remove everything below it
m[m < minimum_matching_score] <- NA_real_
minimum_matching_score_current <- minimum_matching_score minimum_matching_score_current <- minimum_matching_score
} }
if (sum(m >= minimum_matching_score_current) > 10) {
# at least 10 are left over, make the ones under `m` NA
m[m < minimum_matching_score_current] <- NA_real_
}
top_hits <- mo_to_search[order(m, decreasing = TRUE, na.last = NA)] # na.last = NA will remove the NAs top_hits <- mo_to_search[order(m, decreasing = TRUE, na.last = NA)] # na.last = NA will remove the NAs
if (length(top_hits) == 0) { if (length(top_hits) == 0) {
warning_("No hits found for \"", x_search, "\" with minimum_matching_score = ", ifelse(is.null(minimum_matching_score), paste0("NULL (=", round(min(minimum_matching_score_current, na.rm = TRUE), 3), ")"), minimum_matching_score), ". Try setting this value lower or even to 0.", call = FALSE) warning_("No hits found for \"", x_search, "\" with minimum_matching_score = ", ifelse(is.null(minimum_matching_score), paste0("NULL (=", round(min(minimum_matching_score_current, na.rm = TRUE), 3), ")"), minimum_matching_score), ". Try setting this value lower or even to 0.", call = FALSE)
@ -369,12 +379,12 @@ as.mo <- function(x,
# the actual result: # the actual result:
as.character(result_mo) as.character(result_mo)
}) })
# remove progress bar from console # remove progress bar from console
close(progress) close(progress)
# expand from unique again # expand from unique again
out[is.na(out)] <- x_coerced[match(x[is.na(out)], x_unique)] out[is.na(out)] <- x_coerced[match(x[is.na(out)], x_unique)]
# Throw note about uncertainties ---- # Throw note about uncertainties ----
if (isTRUE(info) && NROW(AMR_env$mo_uncertainties) > 0) { if (isTRUE(info) && NROW(AMR_env$mo_uncertainties) > 0) {
if (message_not_thrown_before("as.mo", "uncertainties", AMR_env$mo_uncertainties$original_input)) { if (message_not_thrown_before("as.mo", "uncertainties", AMR_env$mo_uncertainties$original_input)) {
@ -397,14 +407,14 @@ as.mo <- function(x,
"Microorganism translation was uncertain for ", examples, "Microorganism translation was uncertain for ", examples,
". Run `mo_uncertainties()` to review ", plural[2], ", or use `add_custom_microorganisms()` to add custom entries." ". Run `mo_uncertainties()` to review ", plural[2], ", or use `add_custom_microorganisms()` to add custom entries."
)) ))
for (m in msg) { for (m in msg) {
message_(m) message_(m)
} }
} }
} }
} # end of loop over all yet unknowns } # end of loop over all yet unknowns
# Keep or replace synonyms ---- # Keep or replace synonyms ----
lpsn_matches <- AMR_env$MO_lookup$lpsn_renamed_to[match(out, AMR_env$MO_lookup$mo)] lpsn_matches <- AMR_env$MO_lookup$lpsn_renamed_to[match(out, AMR_env$MO_lookup$mo)]
lpsn_matches[!lpsn_matches %in% AMR_env$MO_lookup$lpsn] <- NA lpsn_matches[!lpsn_matches %in% AMR_env$MO_lookup$lpsn] <- NA
@ -427,14 +437,14 @@ as.mo <- function(x,
# keep synonyms is TRUE, so check if any do have synonyms # keep synonyms is TRUE, so check if any do have synonyms
warning_("Function `as.mo()` returned ", nr2char(length(unique(AMR_env$mo_renamed$old))), " old taxonomic name", ifelse(length(unique(AMR_env$mo_renamed$old)) > 1, "s", ""), ". Use `as.mo(..., keep_synonyms = FALSE)` to clean the input to currently accepted taxonomic names, or set the R option `AMR_keep_synonyms` to `FALSE`. This warning will be shown once per session.", call = FALSE) warning_("Function `as.mo()` returned ", nr2char(length(unique(AMR_env$mo_renamed$old))), " old taxonomic name", ifelse(length(unique(AMR_env$mo_renamed$old)) > 1, "s", ""), ". Use `as.mo(..., keep_synonyms = FALSE)` to clean the input to currently accepted taxonomic names, or set the R option `AMR_keep_synonyms` to `FALSE`. This warning will be shown once per session.", call = FALSE)
} }
# Apply Becker ---- # Apply Becker ----
if (isTRUE(Becker) || Becker == "all") { if (isTRUE(Becker) || Becker == "all") {
# warn when species found that are not in: # warn when species found that are not in:
# - Becker et al. 2014, PMID 25278577 # - Becker et al. 2014, PMID 25278577
# - Becker et al. 2019, PMID 30872103 # - Becker et al. 2019, PMID 30872103
# - Becker et al. 2020, PMID 32056452 # - Becker et al. 2020, PMID 32056452
# comment below code if all staphylococcal species are categorised as CoNS/CoPS # comment below code if all staphylococcal species are categorised as CoNS/CoPS
post_Becker <- paste( post_Becker <- paste(
"Staphylococcus", "Staphylococcus",
@ -443,13 +453,13 @@ as.mo <- function(x,
if (any(out %in% AMR_env$MO_lookup$mo[match(post_Becker, AMR_env$MO_lookup$fullname)])) { if (any(out %in% AMR_env$MO_lookup$mo[match(post_Becker, AMR_env$MO_lookup$fullname)])) {
if (message_not_thrown_before("as.mo", "becker")) { if (message_not_thrown_before("as.mo", "becker")) {
warning_("in `as.mo()`: Becker ", font_italic("et al."), " (2014, 2019, 2020) does not contain these species named after their publication: ", warning_("in `as.mo()`: Becker ", font_italic("et al."), " (2014, 2019, 2020) does not contain these species named after their publication: ",
vector_and(font_italic(gsub("Staphylococcus", "S.", post_Becker, fixed = TRUE), collapse = NULL), quotes = FALSE), vector_and(font_italic(gsub("Staphylococcus", "S.", post_Becker, fixed = TRUE), collapse = NULL), quotes = FALSE),
". Categorisation to CoNS/CoPS was taken from the original scientific publication(s).", ". Categorisation to CoNS/CoPS was taken from the original scientific publication(s).",
immediate = TRUE, call = FALSE immediate = TRUE, call = FALSE
) )
} }
} }
# 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_hook.R # 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_hook.R
out[out %in% MO_CONS] <- "B_STPHY_CONS" out[out %in% MO_CONS] <- "B_STPHY_CONS"
out[out %in% MO_COPS] <- "B_STPHY_COPS" out[out %in% MO_COPS] <- "B_STPHY_COPS"
@ -457,11 +467,11 @@ as.mo <- function(x,
out[out == "B_STPHY_AURS"] <- "B_STPHY_COPS" out[out == "B_STPHY_AURS"] <- "B_STPHY_COPS"
} }
} }
# Apply Lancefield ---- # Apply Lancefield ----
if (isTRUE(Lancefield) || Lancefield == "all") { if (isTRUE(Lancefield) || Lancefield == "all") {
# (using `%like_case%` to also match subspecies) # (using `%like_case%` to also match subspecies)
# group A - S. pyogenes # group A - S. pyogenes
out[out %like_case% "^B_STRPT_PYGN(_|$)"] <- "B_STRPT_GRPA" out[out %like_case% "^B_STRPT_PYGN(_|$)"] <- "B_STRPT_GRPA"
# group B - S. agalactiae # group B - S. agalactiae
@ -472,27 +482,27 @@ as.mo <- function(x,
# group D - all enterococci # group D - all enterococci
out[out %like_case% "^B_ENTRC(_|$)"] <- "B_STRPT_GRPD" out[out %like_case% "^B_ENTRC(_|$)"] <- "B_STRPT_GRPD"
} }
# group F - S. anginosus, incl. S. anginosus anginosus and S. anginosus whileyi # group F - Milleri group == S. anginosus group, which incl. S. anginosus, S. constellatus, S. intermedius
out[out %like_case% "^B_STRPT_ANGN(_|$)"] <- "B_STRPT_GRPF" out[out %like_case% "^B_STRPT_(ANGN|CNST|INTR)(_|$)"] <- "B_STRPT_GRPF"
# 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)
out[out %like_case% "^B_STRPT_(DYSG|CANS)(_|$)"] <- "B_STRPT_GRPG" out[out %like_case% "^B_STRPT_(DYSG|CANS)(_|$)"] <- "B_STRPT_GRPG"
# group H - S. sanguinis # group H - S. sanguinis
out[out %like_case% "^B_STRPT_SNGN(_|$)"] <- "B_STRPT_GRPH" out[out %like_case% "^B_STRPT_SNGN(_|$)"] <- "B_STRPT_GRPH"
# group K - S. salivarius, incl. S. salivarius salivariuss and S. salivarius thermophilus # group K - S. salivarius, incl. S. salivarius salivarius and S. salivarius thermophilus
out[out %like_case% "^B_STRPT_SLVR(_|$)"] <- "B_STRPT_GRPK" out[out %like_case% "^B_STRPT_SLVR(_|$)"] <- "B_STRPT_GRPK"
# group L - only S. dysgalactiae which is also group C & G, so ignore it here # group L - only S. dysgalactiae which is also group C & G, so ignore it here
} }
# All unknowns ---- # All unknowns ----
out[is.na(out) & !is.na(x)] <- "UNKNOWN" out[is.na(out) & !is.na(x)] <- "UNKNOWN"
AMR_env$mo_failures <- unique(x[out == "UNKNOWN" & !x %in% c("UNKNOWN", "con") & !x %like_case% "^[(]unknown [a-z]+[)]$" & !is.na(x)]) AMR_env$mo_failures <- unique(x[out == "UNKNOWN" & !toupper(x) %in% c("UNKNOWN", "CON", "UNK") & !x %like_case% "^[(]unknown [a-z]+[)]$" & !is.na(x)])
if (length(AMR_env$mo_failures) > 0) { if (length(AMR_env$mo_failures) > 0) {
warning_("The following input could not be coerced and was returned as \"UNKNOWN\": ", vector_and(AMR_env$mo_failures, quotes = TRUE), ".\nYou can retrieve this list with `mo_failures()`.", call = FALSE) warning_("The following input could not be coerced and was returned as \"UNKNOWN\": ", vector_and(AMR_env$mo_failures, quotes = TRUE), ".\nYou can retrieve this list with `mo_failures()`.", call = FALSE)
} }
# Return class ---- # Return class ----
set_clean_class(out, set_clean_class(out,
new_class = c("mo", "character") new_class = c("mo", "character")
) )
} }
@ -515,13 +525,13 @@ mo_uncertainties <- function() {
mo_renamed <- function() { mo_renamed <- function() {
add_MO_lookup_to_AMR_env() add_MO_lookup_to_AMR_env()
x <- AMR_env$mo_renamed x <- AMR_env$mo_renamed
x$new <- synonym_mo_to_accepted_mo(x$old) x$new <- synonym_mo_to_accepted_mo(x$old)
mo_old <- AMR_env$MO_lookup$fullname[match(x$old, AMR_env$MO_lookup$mo)] mo_old <- AMR_env$MO_lookup$fullname[match(x$old, AMR_env$MO_lookup$mo)]
mo_new <- AMR_env$MO_lookup$fullname[match(x$new, AMR_env$MO_lookup$mo)] mo_new <- AMR_env$MO_lookup$fullname[match(x$new, AMR_env$MO_lookup$mo)]
ref_old <- AMR_env$MO_lookup$ref[match(x$old, AMR_env$MO_lookup$mo)] ref_old <- AMR_env$MO_lookup$ref[match(x$old, AMR_env$MO_lookup$mo)]
ref_new <- AMR_env$MO_lookup$ref[match(x$new, AMR_env$MO_lookup$mo)] ref_new <- AMR_env$MO_lookup$ref[match(x$new, AMR_env$MO_lookup$mo)]
df_renamed <- data.frame( df_renamed <- data.frame(
old = mo_old, old = mo_old,
new = mo_new, new = mo_new,
@ -555,14 +565,17 @@ mo_reset_session <- function() {
#' @rdname as.mo #' @rdname as.mo
#' @export #' @export
mo_cleaning_regex <- function() { mo_cleaning_regex <- function() {
parts_to_remove <- c("e?spp([^a-z]+|$)", "e?ssp([^a-z]+|$)", "e?ss([^a-z]+|$)", "e?sp([^a-z]+|$)", "e?subsp", "sube?species", "e?species",
"biovar[a-z]*", "biotype", "serovar[a-z]*", "var([^a-z]+|$)", "serogr.?up[a-z]*",
"titer", "dummy", "Ig[ADEGM]")
paste0( paste0(
"(", "(",
"[^A-Za-z- \\(\\)\\[\\]{}]+", "[^A-Za-z- \\(\\)\\[\\]{}]+",
"|", "|",
"([({]|\\[).+([})]|\\])", "([({]|\\[).+([})]|\\])",
"|", "|(^| )(",
"(^| )(e?spp|e?ssp|e?ss|e?sp|e?subsp|sube?species|biovar|biotype|serovar|var|serogr.?up|e?species)[.]*( |$|(complex|group)$))" paste0(parts_to_remove[order(1 - nchar(parts_to_remove))], collapse = "|"),
) "))")
} }
# UNDOCUMENTED METHODS ---------------------------------------------------- # UNDOCUMENTED METHODS ----------------------------------------------------
@ -570,35 +583,35 @@ mo_cleaning_regex <- function() {
# will be exported using s3_register() in R/zzz.R # will be exported using s3_register() in R/zzz.R
pillar_shaft.mo <- function(x, ...) { pillar_shaft.mo <- function(x, ...) {
add_MO_lookup_to_AMR_env() add_MO_lookup_to_AMR_env()
out <- format(x) out <- trimws(format(x))
# grey out the kingdom (part until first "_") # grey out the kingdom (part until first "_")
out[!is.na(x)] <- gsub("^([A-Z]+_)(.*)", paste0(font_subtle("\\1"), "\\2"), out[!is.na(x)], perl = TRUE) out[!is.na(x)] <- gsub("^([A-Z]+_)(.*)", paste0(font_subtle("\\1"), "\\2"), out[!is.na(x)], perl = TRUE)
# and grey out every _ # and grey out every _
out[!is.na(x)] <- gsub("_", font_subtle("_"), out[!is.na(x)]) out[!is.na(x)] <- gsub("_", font_subtle("_"), out[!is.na(x)])
# markup NA and UNKNOWN # markup NA and UNKNOWN
out[is.na(x)] <- font_na(" NA") out[is.na(x)] <- font_na(" NA")
out[x == "UNKNOWN"] <- font_na(" UNKNOWN") out[x == "UNKNOWN"] <- font_na(" UNKNOWN")
# markup manual codes # markup manual codes
out[x %in% AMR_env$MO_lookup$mo & !x %in% AMR::microorganisms$mo] <- font_blue(out[x %in% AMR_env$MO_lookup$mo & !x %in% AMR::microorganisms$mo], collapse = NULL) out[x %in% AMR_env$MO_lookup$mo & !x %in% AMR::microorganisms$mo] <- font_blue(out[x %in% AMR_env$MO_lookup$mo & !x %in% AMR::microorganisms$mo], collapse = NULL)
df <- tryCatch(get_current_data(arg_name = "x", call = 0), df <- tryCatch(get_current_data(arg_name = "x", call = 0),
error = function(e) NULL error = function(e) NULL
) )
if (!is.null(df)) { if (!is.null(df)) {
mo_cols <- vapply(FUN.VALUE = logical(1), df, is.mo) mo_cols <- vapply(FUN.VALUE = logical(1), df, is.mo)
} else { } else {
mo_cols <- NULL mo_cols <- NULL
} }
all_mos <- c(AMR_env$MO_lookup$mo, NA) all_mos <- c(AMR_env$MO_lookup$mo, NA)
if (!all(x %in% all_mos) || if (!all(x %in% all_mos) ||
(!is.null(df) && !all(unlist(df[, which(mo_cols), drop = FALSE]) %in% all_mos))) { (!is.null(df) && !all(unlist(df[, which(mo_cols), drop = FALSE]) %in% all_mos))) {
# markup old mo codes # markup old mo codes
out[!x %in% all_mos] <- font_italic( out[!x %in% all_mos] <- font_italic(
font_na(x[!x %in% all_mos], font_na(x[!x %in% all_mos],
collapse = NULL collapse = NULL
), ),
collapse = NULL collapse = NULL
) )
@ -614,15 +627,22 @@ pillar_shaft.mo <- function(x, ...) {
call = FALSE call = FALSE
) )
} }
# add the names to the bugs as mouse-over!
if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) {
out[!x %in% c("UNKNOWN", NA)] <- font_url(url = paste0(x[!x %in% c("UNKNOWN", NA)], ": ",
mo_name(x[!x %in% c("UNKNOWN", NA)], keep_synonyms = TRUE)),
txt = out[!x %in% c("UNKNOWN", NA)])
}
# make it always fit exactly # make it always fit exactly
max_char <- max(nchar(x)) max_char <- max(nchar(x))
if (is.na(max_char)) { if (is.na(max_char)) {
max_char <- 12 max_char <- 12
} }
create_pillar_column(out, create_pillar_column(out,
align = "left", align = "left",
width = max_char + ifelse(any(x %in% c(NA, "UNKNOWN")), 2, 0) width = max_char + ifelse(any(x %in% c(NA, "UNKNOWN")), 2, 0)
) )
} }
@ -645,21 +665,21 @@ freq.mo <- function(x, ...) {
.add_header = list( .add_header = list(
`Gram-negative` = paste0( `Gram-negative` = paste0(
format(sum(grams == "Gram-negative", na.rm = TRUE), format(sum(grams == "Gram-negative", na.rm = TRUE),
big.mark = " ", big.mark = " ",
decimal.mark = "." decimal.mark = "."
), ),
" (", percentage(sum(grams == "Gram-negative", na.rm = TRUE) / length(grams), " (", percentage(sum(grams == "Gram-negative", na.rm = TRUE) / length(grams),
digits = digits digits = digits
), ),
")" ")"
), ),
`Gram-positive` = paste0( `Gram-positive` = paste0(
format(sum(grams == "Gram-positive", na.rm = TRUE), format(sum(grams == "Gram-positive", na.rm = TRUE),
big.mark = " ", big.mark = " ",
decimal.mark = "." decimal.mark = "."
), ),
" (", percentage(sum(grams == "Gram-positive", na.rm = TRUE) / length(grams), " (", percentage(sum(grams == "Gram-positive", na.rm = TRUE) / length(grams),
digits = digits digits = digits
), ),
")" ")"
), ),
@ -815,41 +835,41 @@ rep.mo <- function(x, ...) {
print.mo_uncertainties <- function(x, n = 10, ...) { print.mo_uncertainties <- function(x, n = 10, ...) {
more_than_50 <- FALSE more_than_50 <- FALSE
if (NROW(x) == 0) { if (NROW(x) == 0) {
cat(word_wrap("No uncertainties to show. Only uncertainties of the last call of `as.mo()` or any `mo_*()` function are stored.\n\n", add_fn = font_blue)) cat(word_wrap("No uncertainties to show. Only uncertainties of the last call to `as.mo()` or any `mo_*()` function are stored.\n\n", add_fn = font_blue))
return(invisible(NULL)) return(invisible(NULL))
} else if (NROW(x) > 50) { } else if (NROW(x) > 50) {
more_than_50 <- TRUE more_than_50 <- TRUE
x <- x[1:50, , drop = FALSE] x <- x[1:50, , drop = FALSE]
} }
cat(word_wrap("Matching scores are based on the resemblance between the input and the full taxonomic name, and the pathogenicity in humans. See `?mo_matching_score`.\n\n", add_fn = font_blue)) cat(word_wrap("Matching scores are based on the resemblance between the input and the full taxonomic name, and the pathogenicity in humans. See `?mo_matching_score`.\n\n", add_fn = font_blue))
add_MO_lookup_to_AMR_env() add_MO_lookup_to_AMR_env()
col_red <- function(x) font_rose_bg(font_black(x, collapse = NULL), collapse = NULL) col_red <- function(x) font_rose_bg(x, collapse = NULL)
col_orange <- function(x) font_orange_bg(font_black(x, collapse = NULL), collapse = NULL) col_orange <- function(x) font_orange_bg(x, collapse = NULL)
col_yellow <- function(x) font_yellow_bg(font_black(x, collapse = NULL), collapse = NULL) col_yellow <- function(x) font_yellow_bg(x, collapse = NULL)
col_green <- function(x) font_green_bg(font_black(x, collapse = NULL), collapse = NULL) col_green <- function(x) font_green_bg(x, collapse = NULL)
if (has_colour()) { if (has_colour()) {
cat(word_wrap("Colour keys: ", cat(word_wrap("Colour keys: ",
col_red(" 0.000-0.499 "), col_red(" 0.000-0.549 "),
col_orange(" 0.500-0.599 "), col_orange(" 0.550-0.649 "),
col_yellow(" 0.600-0.699 "), col_yellow(" 0.650-0.749 "),
col_green(" 0.700-1.000"), col_green(" 0.750-1.000"),
add_fn = font_blue add_fn = font_blue
), font_green_bg(" "), "\n", sep = "") ), font_green_bg(" "), "\n", sep = "")
} }
score_set_colour <- function(text, scores) { score_set_colour <- function(text, scores) {
# set colours to scores # set colours to scores
text[scores >= 0.7] <- col_green(text[scores >= 0.7]) text[scores >= 0.75] <- col_green(text[scores >= 0.75])
text[scores >= 0.6 & scores < 0.7] <- col_yellow(text[scores >= 0.6 & scores < 0.7]) text[scores >= 0.65 & scores < 0.75] <- col_yellow(text[scores >= 0.65 & scores < 0.75])
text[scores >= 0.5 & scores < 0.6] <- col_orange(text[scores >= 0.5 & scores < 0.6]) text[scores >= 0.55 & scores < 0.65] <- col_orange(text[scores >= 0.55 & scores < 0.65])
text[scores < 0.5] <- col_red(text[scores < 0.5]) text[scores < 0.55] <- col_red(text[scores < 0.55])
text text
} }
txt <- "" txt <- ""
any_maxed_out <- FALSE any_maxed_out <- FALSE
for (i in seq_len(nrow(x))) { for (i in seq_len(nrow(x))) {
@ -861,15 +881,15 @@ print.mo_uncertainties <- function(x, n = 10, ...) {
} }
scores <- mo_matching_score(x = x[i, ]$input, n = candidates) scores <- mo_matching_score(x = x[i, ]$input, n = candidates)
n_candidates <- length(candidates) n_candidates <- length(candidates)
candidates_formatted <- italicise(candidates) candidates_formatted <- italicise(candidates)
scores_formatted <- trimws(formatC(round(scores, 3), format = "f", digits = 3)) scores_formatted <- trimws(formatC(round(scores, 3), format = "f", digits = 3))
scores_formatted <- score_set_colour(scores_formatted, scores) scores_formatted <- score_set_colour(scores_formatted, scores)
# sort on descending scores # sort on descending scores
candidates_formatted <- candidates_formatted[order(1 - scores)] candidates_formatted <- candidates_formatted[order(1 - scores)]
scores_formatted <- scores_formatted[order(1 - scores)] scores_formatted <- scores_formatted[order(1 - scores)]
candidates <- word_wrap( candidates <- word_wrap(
paste0( paste0(
"Also matched: ", "Also matched: ",
@ -887,42 +907,42 @@ print.mo_uncertainties <- function(x, n = 10, ...) {
} else { } else {
candidates <- "" candidates <- ""
} }
score <- mo_matching_score( score <- mo_matching_score(
x = x[i, ]$input, x = x[i, ]$input,
n = x[i, ]$fullname n = x[i, ]$fullname
) )
score_formatted <- trimws(formatC(round(score, 3), format = "f", digits = 3)) score_formatted <- trimws(formatC(round(score, 3), format = "f", digits = 3))
txt <- paste(txt, txt <- paste(txt,
paste0( paste0(
paste0( paste0(
"", strrep(font_grey("-"), times = getOption("width", 100)), "\n", "", strrep(font_grey("-"), times = getOption("width", 100)), "\n",
'"', x[i, ]$original_input, '"', '"', x[i, ]$original_input, '"',
" -> ", " -> ",
paste0( paste0(
font_bold(italicise(x[i, ]$fullname)), font_bold(italicise(x[i, ]$fullname)),
" (", x[i, ]$mo, ", ", score_set_colour(score_formatted, score), ")" " (", x[i, ]$mo, ", ", score_set_colour(score_formatted, score), ")"
) )
), ),
collapse = "\n" collapse = "\n"
), ),
# Add note if result was coerced to accepted taxonomic name # Add note if result was coerced to accepted taxonomic name
ifelse(x[i, ]$keep_synonyms == FALSE & x[i, ]$mo %in% AMR_env$MO_lookup$mo[which(AMR_env$MO_lookup$status == "synonym")], ifelse(x[i, ]$keep_synonyms == FALSE & x[i, ]$mo %in% AMR_env$MO_lookup$mo[which(AMR_env$MO_lookup$status == "synonym")],
paste0( paste0(
strrep(" ", nchar(x[i, ]$original_input) + 6), strrep(" ", nchar(x[i, ]$original_input) + 6),
font_red(paste0("This old taxonomic name was converted to ", font_italic(AMR_env$MO_lookup$fullname[match(synonym_mo_to_accepted_mo(x[i, ]$mo), AMR_env$MO_lookup$mo)], collapse = NULL), " (", synonym_mo_to_accepted_mo(x[i, ]$mo), ")."), collapse = NULL) font_red(paste0("This old taxonomic name was converted to ", font_italic(AMR_env$MO_lookup$fullname[match(synonym_mo_to_accepted_mo(x[i, ]$mo), AMR_env$MO_lookup$mo)], collapse = NULL), " (", synonym_mo_to_accepted_mo(x[i, ]$mo), ")."), collapse = NULL)
), ),
"" ""
), ),
candidates, candidates,
sep = "\n" sep = "\n"
) )
txt <- gsub("[\n]+", "\n", txt) txt <- gsub("[\n]+", "\n", txt)
# remove first and last break # remove first and last break
txt <- gsub("(^[\n]|[\n]$)", "", txt) txt <- gsub("(^[\n]|[\n]$)", "", txt)
txt <- paste0("\n", txt, "\n") txt <- paste0("\n", txt, "\n")
} }
cat(txt) cat(txt)
if (isTRUE(any_maxed_out)) { if (isTRUE(any_maxed_out)) {
cat(font_blue(word_wrap("\nOnly the first ", n, " other matches of each record are shown. Run `print(mo_uncertainties(), n = ...)` to view more entries, or save `mo_uncertainties()` to an object."))) cat(font_blue(word_wrap("\nOnly the first ", n, " other matches of each record are shown. Run `print(mo_uncertainties(), n = ...)` to view more entries, or save `mo_uncertainties()` to an object.")))
@ -940,19 +960,19 @@ print.mo_renamed <- function(x, extra_txt = "", n = 25, ...) {
cat(word_wrap("No renamed taxonomy to show. Only renamed taxonomy of the last call of `as.mo()` or any `mo_*()` function are stored.\n", add_fn = font_blue)) cat(word_wrap("No renamed taxonomy to show. Only renamed taxonomy of the last call of `as.mo()` or any `mo_*()` function are stored.\n", add_fn = font_blue))
return(invisible(NULL)) return(invisible(NULL))
} }
x$ref_old[!is.na(x$ref_old)] <- paste0(" (", gsub("et al.", font_italic("et al."), x$ref_old[!is.na(x$ref_old)], fixed = TRUE), ")") x$ref_old[!is.na(x$ref_old)] <- paste0(" (", gsub("et al.", font_italic("et al."), x$ref_old[!is.na(x$ref_old)], fixed = TRUE), ")")
x$ref_new[!is.na(x$ref_new)] <- paste0(" (", gsub("et al.", font_italic("et al."), x$ref_new[!is.na(x$ref_new)], fixed = TRUE), ")") x$ref_new[!is.na(x$ref_new)] <- paste0(" (", gsub("et al.", font_italic("et al."), x$ref_new[!is.na(x$ref_new)], fixed = TRUE), ")")
x$ref_old[is.na(x$ref_old)] <- " (author unknown)" x$ref_old[is.na(x$ref_old)] <- " (author unknown)"
x$ref_new[is.na(x$ref_new)] <- " (author unknown)" x$ref_new[is.na(x$ref_new)] <- " (author unknown)"
rows <- seq_len(min(NROW(x), n)) rows <- seq_len(min(NROW(x), n))
message_( message_(
"The following microorganism", ifelse(NROW(x) > 1, "s were", " was"), " taxonomically renamed", extra_txt, ":\n", "The following microorganism", ifelse(NROW(x) > 1, "s were", " was"), " taxonomically renamed", extra_txt, ":\n",
paste0(" ", AMR_env$bullet_icon, " ", font_italic(x$old[rows], collapse = NULL), x$ref_old[rows], paste0(" ", AMR_env$bullet_icon, " ", font_italic(x$old[rows], collapse = NULL), x$ref_old[rows],
" -> ", font_italic(x$new[rows], collapse = NULL), x$ref_new[rows], " -> ", font_italic(x$new[rows], collapse = NULL), x$ref_new[rows],
collapse = "\n" collapse = "\n"
), ),
ifelse(NROW(x) > n, paste0("\n\nOnly the first ", n, " (out of ", NROW(x), ") are shown. Run `print(mo_renamed(), n = ...)` to view more entries (might be slow), or save `mo_renamed()` to an object."), "") ifelse(NROW(x) > n, paste0("\n\nOnly the first ", n, " (out of ", NROW(x), ") are shown. Run `print(mo_renamed(), n = ...)` to view more entries (might be slow), or save `mo_renamed()` to an object."), "")
) )
@ -964,51 +984,52 @@ convert_colloquial_input <- function(x) {
x.bak <- trimws2(x) x.bak <- trimws2(x)
x <- trimws2(tolower(x)) x <- trimws2(tolower(x))
out <- rep(NA_character_, length(x)) out <- rep(NA_character_, length(x))
# Streptococci, like GBS = Group B Streptococci (B_STRPT_GRPB) # Streptococci, like GBS = Group B Streptococci (B_STRPT_GRPB)
out[x %like_case% "^g[abcdefghijkl]s$"] <- gsub("g([abcdefghijkl])s", out[x %like_case% "^g[abcdefghijkl]s$"] <- gsub("g([abcdefghijkl])s",
"B_STRPT_GRP\\U\\1", "B_STRPT_GRP\\U\\1",
x[x %like_case% "^g[abcdefghijkl]s$"], x[x %like_case% "^g[abcdefghijkl]s$"],
perl = TRUE perl = TRUE
) )
# Streptococci in different languages, like "estreptococos grupo B" # Streptococci in different languages, like "estreptococos grupo B"
out[x %like_case% "strepto[ck]o[ck].* [abcdefghijkl]$"] <- gsub(".*e?strepto[ck]o[ck].* ([abcdefghijkl])$", out[x %like_case% "strepto[ck]o[ck][a-zA-Z ]* [abcdefghijkl]$"] <- gsub(".*e?strepto[ck]o[ck].* ([abcdefghijkl])$",
"B_STRPT_GRP\\U\\1", "B_STRPT_GRP\\U\\1",
x[x %like_case% "strepto[ck]o[ck].* [abcdefghijkl]$"], x[x %like_case% "strepto[ck]o[ck][a-zA-Z ]* [abcdefghijkl]$"],
perl = TRUE perl = TRUE
) )
out[x %like_case% "strep[a-z]* group [abcdefghijkl]$"] <- gsub(".* ([abcdefghijkl])$", out[x %like_case% "strep[a-z]* group [abcdefghijkl]$"] <- gsub(".* ([abcdefghijkl])$",
"B_STRPT_GRP\\U\\1", "B_STRPT_GRP\\U\\1",
x[x %like_case% "strep[a-z]* group [abcdefghijkl]$"], x[x %like_case% "strep[a-z]* group [abcdefghijkl]$"],
perl = TRUE perl = TRUE
) )
out[x %like_case% "group [abcdefghijkl] strepto[ck]o[ck]"] <- gsub(".*group ([abcdefghijkl]) strepto[ck]o[ck].*", out[x %like_case% "group [abcdefghijkl] strepto[ck]o[ck]"] <- gsub(".*group ([abcdefghijkl]) strepto[ck]o[ck].*",
"B_STRPT_GRP\\U\\1", "B_STRPT_GRP\\U\\1",
x[x %like_case% "group [abcdefghijkl] strepto[ck]o[ck]"], x[x %like_case% "group [abcdefghijkl] strepto[ck]o[ck]"],
perl = TRUE perl = TRUE
) )
out[x %like_case% "ha?emoly.*strep"] <- "B_STRPT_HAEM" out[x %like_case% "ha?emoly.*strep"] <- "B_STRPT_HAEM"
out[x %like_case% "(strepto.* [abcg, ]{2,4}$)"] <- "B_STRPT_ABCG"
out[x %like_case% "(strepto.* mil+er+i|^mgs[^a-z]*$)"] <- "B_STRPT_MILL" out[x %like_case% "(strepto.* mil+er+i|^mgs[^a-z]*$)"] <- "B_STRPT_MILL"
out[x %like_case% "mil+er+i gr"] <- "B_STRPT_MILL" out[x %like_case% "mil+er+i gr"] <- "B_STRPT_MILL"
out[x %like_case% "((strepto|^s).* viridans|^vgs[^a-z]*$)"] <- "B_STRPT_VIRI" out[x %like_case% "((strepto|^s).* viridans|^vgs[^a-z]*$)"] <- "B_STRPT_VIRI"
out[x %like_case% "(viridans.* (strepto|^s).*|^vgs[^a-z]*$)"] <- "B_STRPT_VIRI" out[x %like_case% "(viridans.* (strepto|^s).*|^vgs[^a-z]*$)"] <- "B_STRPT_VIRI"
# Salmonella in different languages, like "Salmonella grupo B" # Salmonella in different languages, like "Salmonella grupo B"
out[x %like_case% "salmonella.* [abcdefgh]$"] <- gsub(".*salmonella.* ([abcdefgh])$", out[x %like_case% "salmonella.* [abcdefgh]$"] <- gsub(".*salmonella.* ([abcdefgh])$",
"B_SLMNL_GRP\\U\\1", "B_SLMNL_GRP\\U\\1",
x[x %like_case% "salmonella.* [abcdefgh]$"], x[x %like_case% "salmonella.* [abcdefgh]$"],
perl = TRUE perl = TRUE
) )
out[x %like_case% "group [abcdefgh] salmonella"] <- gsub(".*group ([abcdefgh]) salmonella*", out[x %like_case% "group [abcdefgh] salmonella"] <- gsub(".*group ([abcdefgh]) salmonella*",
"B_SLMNL_GRP\\U\\1", "B_SLMNL_GRP\\U\\1",
x[x %like_case% "group [abcdefgh] salmonella"], x[x %like_case% "group [abcdefgh] salmonella"],
perl = TRUE perl = TRUE
) )
# CoNS/CoPS in different languages (support for German, Dutch, Spanish, Portuguese) # CoNS/CoPS in different languages (support for German, Dutch, Spanish, Portuguese)
out[x %like_case% "([ck]oagulas[ea].negatie?[vf]|^[ck]o?ns[^a-z]*$)"] <- "B_STPHY_CONS" out[x %like_case% "([ck]oagulas[ea].negatie?[vf]|^[ck]o?ns[^a-z]*$)"] <- "B_STPHY_CONS"
out[x %like_case% "([ck]oagulas[ea].positie?[vf]|^[ck]o?ps[^a-z]*$)"] <- "B_STPHY_COPS" out[x %like_case% "([ck]oagulas[ea].positie?[vf]|^[ck]o?ps[^a-z]*$)"] <- "B_STPHY_COPS"
# Gram stains # Gram stains
out[x %like_case% "gram[ -]?neg.*"] <- "B_GRAMN" out[x %like_case% "gram[ -]?neg.*"] <- "B_GRAMN"
out[x %like_case% "( |^)gram[-]( |$)"] <- "B_GRAMN" out[x %like_case% "( |^)gram[-]( |$)"] <- "B_GRAMN"
@ -1018,22 +1039,29 @@ out[x %like_case% "^g[abcdefghijkl]s$"] <- gsub("g([abcdefghijkl])s",
out[x %like_case% "anaerob[a-z]+ .*gram[ -]?pos.*"] <- "B_ANAER-POS" out[x %like_case% "anaerob[a-z]+ .*gram[ -]?pos.*"] <- "B_ANAER-POS"
out[is.na(out) & x %like_case% "anaerob[a-z]+ (micro)?.*organism"] <- "B_ANAER" out[is.na(out) & x %like_case% "anaerob[a-z]+ (micro)?.*organism"] <- "B_ANAER"
# coryneform bacteria
out[x %like_case% "^coryneform"] <- "B_CORYNF"
# yeasts and fungi # yeasts and fungi
out[x %like_case% "^yeast?"] <- "F_YEAST" out[x %like_case% "^yeast?"] <- "F_YEAST"
out[x %like_case% "^fung(us|i)"] <- "F_FUNGUS" out[x %like_case% "^fung(us|i)"] <- "F_FUNGUS"
# trivial names known to the field # trivial names known to the field
out[x %like_case% "meningo[ck]o[ck]"] <- "B_NESSR_MNNG" out[x %like_case% "meningo[ck]o[ck]"] <- "B_NESSR_MNNG"
out[x %like_case% "gono[ck]o[ck]"] <- "B_NESSR_GNRR" out[x %like_case% "gono[ck]o[ck]"] <- "B_NESSR_GNRR"
out[x %like_case% "pneumo[ck]o[ck]"] <- "B_STRPT_PNMN" out[x %like_case% "pneumo[ck]o[ck]"] <- "B_STRPT_PNMN"
out[x %like_case% "hacek"] <- "B_HACEK"
out[x %like_case% "haemophilus" & x %like_case% "aggregatibacter" & x %like_case% "cardiobacterium" & x %like_case% "eikenella" & x %like_case% "kingella"] <- "B_HACEK"
out[x %like_case% "slow.* grow.* mycobact"] <- "B_MYCBC_SGM"
out[x %like_case% "rapid.* grow.* mycobact"] <- "B_MYCBC_RGM"
# unexisting names (con is the WHONET code for contamination) # unexisting names (con is the WHONET code for contamination)
out[x %in% c("con", "other", "none", "unknown") | x %like_case% "virus"] <- "UNKNOWN" out[x %in% c("con", "other", "none", "unknown") | x %like_case% "virus"] <- "UNKNOWN"
# WHONET has a lot of E. coli and Vibrio cholerae names # WHONET has a lot of E. coli and Vibrio cholerae names
out[x %like_case% "escherichia coli"] <- "B_ESCHR_COLI" out[x %like_case% "escherichia coli"] <- "B_ESCHR_COLI"
out[x %like_case% "vibrio cholerae"] <- "B_VIBRI_CHLR" out[x %like_case% "vibrio cholerae"] <- "B_VIBRI_CHLR"
out out
} }
@ -1125,7 +1153,7 @@ replace_old_mo_codes <- function(x, property) {
name <- gsub(" .*", " ", name, fixed = TRUE) name <- gsub(" .*", " ", name, fixed = TRUE)
name <- paste0("^", name) name <- paste0("^", name)
results <- AMR_env$MO_lookup$mo[AMR_env$MO_lookup$kingdom %like_case% kingdom & results <- AMR_env$MO_lookup$mo[AMR_env$MO_lookup$kingdom %like_case% kingdom &
AMR_env$MO_lookup$fullname_lower %like_case% name] AMR_env$MO_lookup$fullname_lower %like_case% name]
if (length(results) > 1) { if (length(results) > 1) {
all_direct_matches <<- FALSE all_direct_matches <<- FALSE
} }
@ -1162,8 +1190,8 @@ replace_old_mo_codes <- function(x, property) {
"to ", ifelse(n_solved == 1, "a ", ""), "to ", ifelse(n_solved == 1, "a ", ""),
"currently used MO code", ifelse(n_solved == 1, "", "s"), "currently used MO code", ifelse(n_solved == 1, "", "s"),
ifelse(n_unsolved > 0, ifelse(n_unsolved > 0,
paste0(" and ", n_unsolved, " old MO code", ifelse(n_unsolved == 1, "", "s"), " could not be updated."), paste0(" and ", n_unsolved, " old MO code", ifelse(n_unsolved == 1, "", "s"), " could not be updated."),
"." "."
) )
) )
} }
@ -1192,21 +1220,21 @@ repair_reference_df <- function(reference_df) {
# has valid own reference_df # has valid own reference_df
reference_df <- reference_df %pm>% reference_df <- reference_df %pm>%
pm_filter(!is.na(mo)) pm_filter(!is.na(mo))
# keep only first two columns, second must be mo # keep only first two columns, second must be mo
if (colnames(reference_df)[1] == "mo") { if (colnames(reference_df)[1] == "mo") {
reference_df <- reference_df %pm>% pm_select(2, "mo") reference_df <- reference_df %pm>% pm_select(2, "mo")
} else { } else {
reference_df <- reference_df %pm>% pm_select(1, "mo") reference_df <- reference_df %pm>% pm_select(1, "mo")
} }
# remove factors, just keep characters # remove factors, just keep characters
colnames(reference_df)[1] <- "x" colnames(reference_df)[1] <- "x"
reference_df[, "x"] <- as.character(reference_df[, "x", drop = TRUE]) reference_df[, "x"] <- as.character(reference_df[, "x", drop = TRUE])
reference_df[, "mo"] <- as.character(reference_df[, "mo", drop = TRUE]) reference_df[, "mo"] <- as.character(reference_df[, "mo", drop = TRUE])
# some MO codes might be old # some MO codes might be old
reference_df[, "mo"] <- as.mo(reference_df[, "mo", drop = TRUE]) reference_df[, "mo"] <- as.mo(reference_df[, "mo", drop = TRUE], reference_df = NULL)
reference_df reference_df
} }
@ -1226,10 +1254,10 @@ synonym_mo_to_accepted_mo <- function(x, fill_in_accepted = FALSE) {
x_lpsn <- AMR_env$MO_lookup$lpsn_renamed_to[match(x, AMR_env$MO_lookup$mo)] x_lpsn <- AMR_env$MO_lookup$lpsn_renamed_to[match(x, AMR_env$MO_lookup$mo)]
x_gbif[!x_gbif %in% AMR_env$MO_lookup$gbif] <- NA x_gbif[!x_gbif %in% AMR_env$MO_lookup$gbif] <- NA
x_lpsn[!x_lpsn %in% AMR_env$MO_lookup$lpsn] <- NA x_lpsn[!x_lpsn %in% AMR_env$MO_lookup$lpsn] <- NA
out <- ifelse(is.na(x_lpsn), out <- ifelse(is.na(x_lpsn),
AMR_env$MO_lookup$mo[match(x_gbif, AMR_env$MO_lookup$gbif)], AMR_env$MO_lookup$mo[match(x_gbif, AMR_env$MO_lookup$gbif)],
AMR_env$MO_lookup$mo[match(x_lpsn, AMR_env$MO_lookup$lpsn)] AMR_env$MO_lookup$mo[match(x_lpsn, AMR_env$MO_lookup$lpsn)]
) )
if (isTRUE(fill_in_accepted)) { if (isTRUE(fill_in_accepted)) {
x_accepted <- which(AMR_env$MO_lookup$status[match(x, AMR_env$MO_lookup$mo)] == "accepted") x_accepted <- which(AMR_env$MO_lookup$status[match(x, AMR_env$MO_lookup$mo)] == "accepted")

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -50,7 +50,7 @@
#' * \eqn{l_n} is the length of \eqn{n}; #' * \eqn{l_n} is the length of \eqn{n};
#' * \eqn{lev} is the [Levenshtein distance function](https://en.wikipedia.org/wiki/Levenshtein_distance) (counting any insertion as 1, and any deletion or substitution as 2) that is needed to change \eqn{x} into \eqn{n}; #' * \eqn{lev} is the [Levenshtein distance function](https://en.wikipedia.org/wiki/Levenshtein_distance) (counting any insertion as 1, and any deletion or substitution as 2) that is needed to change \eqn{x} into \eqn{n};
#' * \eqn{p_n} is the human pathogenic prevalence group of \eqn{n}, as described below; #' * \eqn{p_n} is the human pathogenic prevalence group of \eqn{n}, as described below;
#' * \eqn{k_n} is the taxonomic kingdom of \eqn{n}, set as Bacteria = 1, Fungi = 2, Protozoa = 3, Archaea = 4, others = 5. #' * \eqn{k_n} is the taxonomic kingdom of \eqn{n}, set as Bacteria = 1, Fungi = 1.25, Protozoa = 1.5, Archaea = 2, others = 3.
#' #'
#' The grouping into human pathogenic prevalence \eqn{p} is based on recent work from Bartlett *et al.* (2022, \doi{10.1099/mic.0.001269}) who extensively studied medical-scientific literature to categorise all bacterial species into these groups: #' The grouping into human pathogenic prevalence \eqn{p} is based on recent work from Bartlett *et al.* (2022, \doi{10.1099/mic.0.001269}) who extensively studied medical-scientific literature to categorise all bacterial species into these groups:
#' #'
@ -62,7 +62,7 @@
#' - Any genus present in the **established** list also has `prevalence = 1.0` in the [microorganisms] data set; #' - Any genus present in the **established** list also has `prevalence = 1.0` in the [microorganisms] data set;
#' - Any other genus present in the **putative** list has `prevalence = 1.25` in the [microorganisms] data set; #' - Any other genus present in the **putative** list has `prevalence = 1.25` in the [microorganisms] data set;
#' - Any other species or subspecies of which the genus is present in the two aforementioned groups, has `prevalence = 1.5` in the [microorganisms] data set; #' - Any other species or subspecies of which the genus is present in the two aforementioned groups, has `prevalence = 1.5` in the [microorganisms] data set;
#' - Any *non-bacterial* genus, species or subspecies of which the genus is present in the following list, has `prevalence = 1.5` in the [microorganisms] data set: `r vector_or(MO_PREVALENT_GENERA, quotes = "*")`; #' - Any *non-bacterial* genus, species or subspecies of which the genus is present in the following list, has `prevalence = 1.25` in the [microorganisms] data set: `r vector_or(MO_PREVALENT_GENERA, quotes = "*")`;
#' - All other records have `prevalence = 2.0` in the [microorganisms] data set. #' - All other records have `prevalence = 2.0` in the [microorganisms] data set.
#' #'
#' When calculating the matching score, all characters in \eqn{x} and \eqn{n} are ignored that are other than A-Z, a-z, 0-9, spaces and parentheses. #' When calculating the matching score, all characters in \eqn{x} and \eqn{n} are ignored that are other than A-Z, a-z, 0-9, spaces and parentheses.

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -427,22 +427,13 @@ mo_pathogenicity <- function(x, language = get_AMR_locale(), keep_synonyms = get
kngd <- AMR_env$MO_lookup$kingdom[match(x.mo, AMR_env$MO_lookup$mo)] kngd <- AMR_env$MO_lookup$kingdom[match(x.mo, AMR_env$MO_lookup$mo)]
rank <- AMR_env$MO_lookup$rank[match(x.mo, AMR_env$MO_lookup$mo)] rank <- AMR_env$MO_lookup$rank[match(x.mo, AMR_env$MO_lookup$mo)]
out <- factor( out <- factor(case_when_AMR(prev == 1 & kngd == "Bacteria" & rank != "genus" ~ "Pathogenic",
ifelse(prev == 1 & kngd == "Bacteria" & rank != "genus", (prev < 2 & kngd == "Fungi") ~ "Potentially pathogenic",
"Pathogenic", prev == 2 & kngd == "Bacteria" ~ "Non-pathogenic",
ifelse(prev < 2 & kngd == "Fungi", kngd == "Bacteria" ~ "Potentially pathogenic",
"Potentially pathogenic", TRUE ~ "Unknown"),
ifelse(prev == 2 & kngd == "Bacteria", levels = c("Pathogenic", "Potentially pathogenic", "Non-pathogenic", "Unknown"),
"Non-pathogenic", ordered = TRUE
ifelse(kngd == "Bacteria",
"Potentially pathogenic",
"Unknown"
)
)
)
),
levels = c("Pathogenic", "Potentially pathogenic", "Non-pathogenic", "Unknown"),
ordered = TRUE
) )
load_mo_uncertainties(metadata) load_mo_uncertainties(metadata)
@ -922,26 +913,36 @@ mo_validate <- function(x, property, language, keep_synonyms = keep_synonyms, ..
Lancefield <- FALSE Lancefield <- FALSE
} }
has_Becker_or_Lancefield <- Becker %in% c(TRUE, "all") || Lancefield %in% c(TRUE, "all") has_Becker_or_Lancefield <- Becker %in% c(TRUE, "all") || Lancefield %in% c(TRUE, "all")
# get microorganisms data set, but remove synonyms if keep_synonyms is FALSE if (isFALSE(has_Becker_or_Lancefield) && isTRUE(keep_synonyms) && all(x %in% c(AMR_env$MO_lookup$mo, NA))) {
mo_data_check <- AMR_env$MO_lookup[which(AMR_env$MO_lookup$status %in% if (isTRUE(keep_synonyms)) c("synonym", "accepted") else "accepted"), , drop = FALSE] # fastest way to get properties
if (property == "snomed") {
if (all(x %in% c(mo_data_check$mo, NA)) && !has_Becker_or_Lancefield) { x <- lapply(x, function(y) unlist(AMR_env$MO_lookup$snomed[match(y, AMR_env$MO_lookup$mo)]))
# do nothing, just don't run the other if-else's } else {
} else if (all(x %in% c(unlist(mo_data_check[[property]]), NA)) && !has_Becker_or_Lancefield) { x <- AMR_env$MO_lookup[[property]][match(x, AMR_env$MO_lookup$mo)]
# no need to do anything, just return it }
return(x)
} else { } else {
# we need to get MO codes now # get microorganisms data set, but remove synonyms if keep_synonyms is FALSE
x <- replace_old_mo_codes(x, property = property) mo_data_check <- AMR_env$MO_lookup[which(AMR_env$MO_lookup$status %in% if (isTRUE(keep_synonyms)) c("synonym", "accepted") else "accepted"), , drop = FALSE]
x <- as.mo(x, language = language, keep_synonyms = keep_synonyms, ...)
} if (all(x %in% c(mo_data_check$mo, NA)) && !has_Becker_or_Lancefield) {
# do nothing, just don't run the other if-else's
# get property reeaaally fast using match() } else if (all(x %in% c(unlist(mo_data_check[[property]]), NA)) && !has_Becker_or_Lancefield) {
if (property == "snomed") { # no need to do anything, just return it
x <- lapply(x, function(y) unlist(AMR_env$MO_lookup$snomed[match(y, AMR_env$MO_lookup$mo)])) return(x)
} else { } else {
x <- AMR_env$MO_lookup[[property]][match(x, AMR_env$MO_lookup$mo)] # we need to get MO codes now
x <- replace_old_mo_codes(x, property = property)
x <- as.mo(x, language = language, keep_synonyms = keep_synonyms, ...)
}
# get property reeaaally fast using match()
if (property == "snomed") {
x <- lapply(x, function(y) unlist(AMR_env$MO_lookup$snomed[match(y, AMR_env$MO_lookup$mo)]))
} else {
x <- AMR_env$MO_lookup[[property]][match(x, AMR_env$MO_lookup$mo)]
}
} }
if (property == "mo") { if (property == "mo") {

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -40,6 +40,7 @@
#' @param colours_SIR colours to use for filling in the bars, must be a vector of three values (in the order S, I and R). The default colours are colour-blind friendly. #' @param colours_SIR colours to use for filling in the bars, must be a vector of three values (in the order S, I and R). The default colours are colour-blind friendly.
#' @param language language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant' - the default is system language (see [get_AMR_locale()]) and can be overwritten by setting the [package option][AMR-options] [`AMR_locale`][AMR-options], e.g. `options(AMR_locale = "de")`, see [translate]. Use `language = NULL` or `language = ""` to prevent translation. #' @param language language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant' - the default is system language (see [get_AMR_locale()]) and can be overwritten by setting the [package option][AMR-options] [`AMR_locale`][AMR-options], e.g. `options(AMR_locale = "de")`, see [translate]. Use `language = NULL` or `language = ""` to prevent translation.
#' @param expand a [logical] to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled. #' @param expand a [logical] to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled.
#' @inheritParams as.sir
#' @details #' @details
#' The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases. #' The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases.
#' #'
@ -93,6 +94,8 @@ plot.mic <- function(x,
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(), language = get_AMR_locale(),
expand = TRUE, expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
@ -123,7 +126,9 @@ plot.mic <- function(x,
colours_SIR = colours_SIR, colours_SIR = colours_SIR,
fn = as.mic, fn = as.mic,
language = language, language = language,
type = "MIC", method = "MIC",
include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
barplot(x, barplot(x,
@ -224,6 +229,8 @@ autoplot.mic <- function(object,
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(), language = get_AMR_locale(),
expand = TRUE, expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
stop_ifnot_installed("ggplot2") stop_ifnot_installed("ggplot2")
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
@ -256,7 +263,9 @@ autoplot.mic <- function(object,
colours_SIR = colours_SIR, colours_SIR = colours_SIR,
fn = as.mic, fn = as.mic,
language = language, language = language,
type = "MIC", method = "MIC",
include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
df <- as.data.frame(x, stringsAsFactors = TRUE) df <- as.data.frame(x, stringsAsFactors = TRUE)
@ -327,6 +336,8 @@ plot.disk <- function(x,
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(), language = get_AMR_locale(),
expand = TRUE, expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(ylab, allow_class = "character", has_length = 1)
@ -357,7 +368,9 @@ plot.disk <- function(x,
colours_SIR = colours_SIR, colours_SIR = colours_SIR,
fn = as.disk, fn = as.disk,
language = language, language = language,
type = "disk", method = "disk",
include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
@ -458,6 +471,8 @@ autoplot.disk <- function(object,
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(), language = get_AMR_locale(),
expand = TRUE, expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
stop_ifnot_installed("ggplot2") stop_ifnot_installed("ggplot2")
meet_criteria(title, allow_class = "character", allow_NULL = TRUE) meet_criteria(title, allow_class = "character", allow_NULL = TRUE)
@ -490,7 +505,9 @@ autoplot.disk <- function(object,
colours_SIR = colours_SIR, colours_SIR = colours_SIR,
fn = as.disk, fn = as.disk,
language = language, language = language,
type = "disk", method = "disk",
include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
df <- as.data.frame(x, stringsAsFactors = TRUE) df <- as.data.frame(x, stringsAsFactors = TRUE)
@ -744,38 +761,45 @@ plot_name_of_I <- function(guideline) {
} }
} }
plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, fn, language, type, ...) { plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, fn, language, method, breakpoint_type, include_PKPD, ...) {
guideline <- get_guideline(guideline, AMR::clinical_breakpoints) guideline <- get_guideline(guideline, AMR::clinical_breakpoints)
# store previous interpretations to backup
sir_history <- AMR_env$sir_interpretation_history
# and clear previous interpretations
AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE]
if (!is.null(mo) && !is.null(ab)) { if (!is.null(mo) && !is.null(ab)) {
# interpret and give colour based on MIC values # interpret and give colour based on MIC values
mo <- as.mo(mo) mo <- as.mo(mo)
moname <- mo_name(mo, language = language) moname <- mo_name(mo, language = language)
ab <- as.ab(ab) ab <- as.ab(ab)
abname <- ab_name(ab, language = language) abname <- ab_name(ab, language = language)
sir <- suppressWarnings(suppressMessages(as.sir(fn(names(x)), mo = mo, ab = ab, guideline = guideline, include_screening = FALSE, include_PKPD = TRUE, ...))) sir <- suppressWarnings(suppressMessages(as.sir(fn(names(x)), mo = mo, ab = ab, guideline = guideline, include_screening = FALSE, include_PKPD = include_PKPD, breakpoint_type = breakpoint_type, ...)))
guideline_txt <- guideline guideline_txt <- guideline
if (all(is.na(sir))) { if (all(is.na(sir))) {
sir_screening <- suppressWarnings(suppressMessages(as.sir(fn(names(x)), mo = mo, ab = ab, guideline = guideline, include_screening = TRUE, include_PKPD = TRUE, ...))) sir_screening <- suppressWarnings(suppressMessages(as.sir(fn(names(x)), mo = mo, ab = ab, guideline = guideline, include_screening = TRUE, include_PKPD = include_PKPD, breakpoint_type = breakpoint_type, ...)))
if (!all(is.na(sir_screening))) { if (!all(is.na(sir_screening))) {
message_( message_(
"Only ", guideline, " ", type, " interpretations found for ", "Only ", guideline, " ", method, " interpretations found for ",
ab_name(ab, language = NULL, tolower = TRUE), " in ", italicise(moname), " for screening" ab_name(ab, language = NULL, tolower = TRUE), " in ", italicise(moname), " for screening"
) )
sir <- sir_screening sir <- sir_screening
guideline_txt <- paste0("(Screen, ", guideline_txt, ")") guideline_txt <- paste0("(Screen, ", guideline_txt, ")")
} else { } else {
message_( message_(
"No ", guideline, " ", type, " interpretations found for ", "No ", guideline, " ", method, " interpretations found for ",
ab_name(ab, language = NULL, tolower = TRUE), " in ", italicise(moname) ab_name(ab, language = NULL, tolower = TRUE), " in ", italicise(moname)
) )
guideline_txt <- "" guideline_txt <- paste0("(", guideline_txt, ")")
} }
} else { } else {
if (isTRUE(list(...)$uti)) { if (isTRUE(list(...)$uti)) {
guideline_txt <- paste("UTIs,", guideline_txt) guideline_txt <- paste("UTIs,", guideline_txt)
} }
guideline_txt <- paste0("(", guideline_txt, ")") ref_tbl <- paste0('"', unique(AMR_env$sir_interpretation_history$ref_table), '"', collapse = "/")
guideline_txt <- paste0("(", guideline_txt, ": ", ref_tbl, ")")
} }
cols <- character(length = length(sir)) cols <- character(length = length(sir))
cols[is.na(sir)] <- "#BEBEBE" cols[is.na(sir)] <- "#BEBEBE"
@ -787,5 +811,9 @@ plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, f
cols <- "#BEBEBE" cols <- "#BEBEBE"
sub <- NULL sub <- NULL
} }
# restore previous interpretations to backup
AMR_env$sir_interpretation_history <- sir_history
list(cols = cols, count = as.double(x), sub = sub, guideline = guideline) list(cols = cols, count = as.double(x), sub = sub, guideline = guideline)
} }

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -94,13 +94,14 @@ random_sir <- function(size = NULL, prob_SIR = c(0.33, 0.33, 0.33), ...) {
sample(as.sir(c("S", "I", "R")), size = size, replace = TRUE, prob = prob_SIR) sample(as.sir(c("S", "I", "R")), size = size, replace = TRUE, prob = prob_SIR)
} }
random_exec <- function(type, size, mo = NULL, ab = NULL) { random_exec <- function(method_type, size, mo = NULL, ab = NULL) {
df <- AMR::clinical_breakpoints %pm>% df <- AMR::clinical_breakpoints %pm>%
pm_filter(guideline %like% "EUCAST") %pm>% pm_filter(guideline %like% "EUCAST") %pm>%
pm_arrange(pm_desc(guideline)) %pm>% pm_arrange(pm_desc(guideline)) %pm>%
subset(guideline == max(guideline) & subset(guideline == max(guideline) &
method == type) method == method_type &
type == "human")
if (!is.null(mo)) { if (!is.null(mo)) {
mo_coerced <- as.mo(mo) mo_coerced <- as.mo(mo)
mo_include <- c( mo_include <- c(
@ -114,7 +115,7 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) {
if (nrow(df_new) > 0) { if (nrow(df_new) > 0) {
df <- df_new df <- df_new
} else { } else {
warning_("in `random_", tolower(type), "()`: no rows found that match mo '", mo, "', ignoring argument `mo`") warning_("in `random_", tolower(method_type), "()`: no rows found that match mo '", mo, "', ignoring argument `mo`")
} }
} }
@ -125,22 +126,22 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) {
if (nrow(df_new) > 0) { if (nrow(df_new) > 0) {
df <- df_new df <- df_new
} else { } else {
warning_("in `random_", tolower(type), "()`: no rows found that match ab '", ab, "', ignoring argument `ab`") warning_("in `random_", tolower(method_type), "()`: no rows found that match ab '", ab, "' (", ab_name(ab_coerced, tolower = TRUE, language = NULL), "), ignoring argument `ab`")
} }
} }
if (type == "MIC") { if (method_type == "MIC") {
# set range # set range
mic_range <- c(0.001, 0.002, 0.005, 0.010, 0.025, 0.0625, 0.125, 0.250, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256) mic_range <- c(0.001, 0.002, 0.005, 0.010, 0.025, 0.0625, 0.125, 0.250, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256)
# get highest/lowest +/- random 1 to 3 higher factors of two # get highest/lowest +/- random 1 to 3 higher factors of two
max_range <- mic_range[min( max_range <- mic_range[min(
length(mic_range), length(mic_range),
which(mic_range == max(df$breakpoint_R)) + sample(c(1:3), 1) which(mic_range == max(df$breakpoint_R, na.rm = TRUE)) + sample(c(1:3), 1)
)] )]
min_range <- mic_range[max( min_range <- mic_range[max(
1, 1,
which(mic_range == min(df$breakpoint_S)) - sample(c(1:3), 1) which(mic_range == min(df$breakpoint_S, na.rm = TRUE)) - sample(c(1:3), 1)
)] )]
mic_range_new <- mic_range[mic_range <= max_range & mic_range >= min_range] mic_range_new <- mic_range[mic_range <= max_range & mic_range >= min_range]
@ -156,10 +157,10 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) {
out[out == max(out)] <- paste0(">=", out[out == max(out)]) out[out == max(out)] <- paste0(">=", out[out == max(out)])
} }
return(out) return(out)
} else if (type == "DISK") { } else if (method_type == "DISK") {
set_range <- seq( set_range <- seq(
from = as.integer(min(df$breakpoint_R) / 1.25), from = as.integer(min(df$breakpoint_R, na.rm = TRUE) / 1.25),
to = as.integer(max(df$breakpoint_S) * 1.25), to = as.integer(max(df$breakpoint_S, na.rm = TRUE) * 1.25),
by = 1 by = 1
) )
out <- sample(set_range, size = size, replace = TRUE) out <- sample(set_range, size = size, replace = TRUE)

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

230
R/sir.R
View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -30,6 +30,8 @@
#' Translate MIC and Disk Diffusion to SIR, or Clean Existing SIR Data #' Translate MIC and Disk Diffusion to SIR, or Clean Existing SIR Data
#' #'
#' @description Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing SIR values. This transforms the input to a new class [`sir`], which is an ordered [factor] with levels `S < I < R`. #' @description Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing SIR values. This transforms the input to a new class [`sir`], which is an ordered [factor] with levels `S < I < R`.
#'
#' Currently available **breakpoint guidelines** are EUCAST `r min(as.integer(gsub("[^0-9]", "", subset(AMR::clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(AMR::clinical_breakpoints, guideline %like% "EUCAST")$guideline)))` and CLSI `r min(as.integer(gsub("[^0-9]", "", subset(AMR::clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(AMR::clinical_breakpoints, guideline %like% "CLSI")$guideline)))`, and available **breakpoint types** are `r vector_and(clinical_breakpoints$type)`.
#' #'
#' All breakpoints used for interpretation are publicly available in the [clinical_breakpoints] data set. #' All breakpoints used for interpretation are publicly available in the [clinical_breakpoints] data set.
#' @rdname as.sir #' @rdname as.sir
@ -43,10 +45,13 @@
#' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`. #' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`.
#' @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-options] [`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-options] [`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-options] [`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-options] [`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-options] [`AMR_breakpoint_type`][AMR-options].
#' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [clinical_breakpoints] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [clinical_breakpoints] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set. #' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [clinical_breakpoints] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [clinical_breakpoints] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set.
#' @param threshold maximum fraction of invalid antimicrobial interpretations of `x`, see *Examples* #' @param threshold maximum fraction of invalid antimicrobial interpretations of `x`, see *Examples*
#' @param ... for using on a [data.frame]: names of columns to apply [as.sir()] on (supports tidy selection such as `column1:column4`). Otherwise: arguments passed on to methods. #' @param ... for using on a [data.frame]: names of columns to apply [as.sir()] on (supports tidy selection such as `column1:column4`). Otherwise: arguments passed on to methods.
#' @details #' @details
#' *Note: The clinical breakpoints in this package were validated through and imported from [WHONET](https://whonet.org) and the public use of this `AMR` package has been endorsed by CLSI and EUCAST, please see [clinical_breakpoints] for more information.*
#'
#' ### How it Works #' ### How it Works
#' #'
#' The [as.sir()] function works in four ways: #' The [as.sir()] function works in four ways:
@ -100,7 +105,7 @@
#' #'
#' The function [is_sir_eligible()] returns `TRUE` when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and `FALSE` otherwise. The threshold of 5% can be set with the `threshold` argument. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector. #' The function [is_sir_eligible()] returns `TRUE` when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and `FALSE` otherwise. The threshold of 5% can be set with the `threshold` argument. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector.
#' @section Interpretation of SIR: #' @section Interpretation of SIR:
#' In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (<https://www.eucast.org/newsiandr/>): #' In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (<https://www.eucast.org/newsiandr>):
#' #'
#' - **S - Susceptible, standard dosing regimen**\cr #' - **S - Susceptible, standard dosing regimen**\cr
#' A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. #' A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.
@ -428,6 +433,7 @@ as.sir.mic <- function(x,
reference_data = AMR::clinical_breakpoints, reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE), include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE), include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
as_sir_method( as_sir_method(
method_short = "mic", method_short = "mic",
@ -442,6 +448,7 @@ as.sir.mic <- function(x,
reference_data = reference_data, reference_data = reference_data,
include_screening = include_screening, include_screening = include_screening,
include_PKPD = include_PKPD, include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
} }
@ -457,6 +464,7 @@ as.sir.disk <- function(x,
reference_data = AMR::clinical_breakpoints, reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE), include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE), include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
as_sir_method( as_sir_method(
method_short = "disk", method_short = "disk",
@ -471,6 +479,7 @@ as.sir.disk <- function(x,
reference_data = reference_data, reference_data = reference_data,
include_screening = include_screening, include_screening = include_screening,
include_PKPD = include_PKPD, include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
... ...
) )
} }
@ -486,7 +495,8 @@ as.sir.data.frame <- function(x,
add_intrinsic_resistance = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints, reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE), include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE)) { include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human")) {
meet_criteria(x, allow_class = "data.frame") # will also check for dimensions > 0 meet_criteria(x, allow_class = "data.frame") # will also check for dimensions > 0
meet_criteria(col_mo, allow_class = "character", is_in = colnames(x), allow_NULL = TRUE) meet_criteria(col_mo, allow_class = "character", is_in = colnames(x), allow_NULL = TRUE)
meet_criteria(guideline, allow_class = "character", has_length = 1) meet_criteria(guideline, allow_class = "character", has_length = 1)
@ -494,6 +504,9 @@ as.sir.data.frame <- function(x,
meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1) meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1)
meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1) meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1)
meet_criteria(reference_data, allow_class = "data.frame") meet_criteria(reference_data, allow_class = "data.frame")
meet_criteria(include_screening, allow_class = "logical", has_length = 1)
meet_criteria(include_PKPD, allow_class = "logical", has_length = 1)
meet_criteria(breakpoint_type, allow_class = "character", is_in = reference_data$type, has_length = 1)
x.bak <- x x.bak <- x
for (i in seq_len(ncol(x))) { for (i in seq_len(ncol(x))) {
@ -625,6 +638,7 @@ as.sir.data.frame <- function(x,
reference_data = reference_data, reference_data = reference_data,
include_screening = include_screening, include_screening = include_screening,
include_PKPD = include_PKPD, include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
is_data.frame = TRUE is_data.frame = TRUE
) )
} else if (types[i] == "disk") { } else if (types[i] == "disk") {
@ -642,6 +656,7 @@ as.sir.data.frame <- function(x,
reference_data = reference_data, reference_data = reference_data,
include_screening = include_screening, include_screening = include_screening,
include_PKPD = include_PKPD, include_PKPD = include_PKPD,
breakpoint_type = breakpoint_type,
is_data.frame = TRUE is_data.frame = TRUE
) )
} else if (types[i] == "sir") { } else if (types[i] == "sir") {
@ -711,6 +726,7 @@ as_sir_method <- function(method_short,
reference_data, reference_data,
include_screening, include_screening,
include_PKPD, include_PKPD,
breakpoint_type,
...) { ...) {
meet_criteria(x, allow_NA = TRUE, .call_depth = -2) meet_criteria(x, allow_NA = TRUE, .call_depth = -2)
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE, .call_depth = -2) meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE, .call_depth = -2)
@ -723,7 +739,14 @@ as_sir_method <- function(method_short,
meet_criteria(include_screening, allow_class = "logical", has_length = 1, .call_depth = -2) meet_criteria(include_screening, allow_class = "logical", has_length = 1, .call_depth = -2)
meet_criteria(include_PKPD, allow_class = "logical", has_length = 1, .call_depth = -2) meet_criteria(include_PKPD, allow_class = "logical", has_length = 1, .call_depth = -2)
check_reference_data(reference_data, .call_depth = -2) check_reference_data(reference_data, .call_depth = -2)
meet_criteria(breakpoint_type, allow_class = "character", is_in = reference_data$type, has_length = 1, .call_depth = -2)
guideline_coerced <- get_guideline(guideline, reference_data)
if (message_not_thrown_before("as.sir", "sir_interpretation_history")) {
message_("Run `sir_interpretation_history()` afterwards to retrieve a logbook with all the details of the breakpoint interpretations. Note that some microorganisms might not have breakpoints for each antimicrobial drug in ", guideline_coerced, ".\n\n")
}
# for dplyr's across() # for dplyr's across()
cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE) cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE)
if (!is.null(cur_column_dplyr) && tryCatch(is.data.frame(get_current_data("ab", call = 0)), error = function(e) FALSE)) { if (!is.null(cur_column_dplyr) && tryCatch(is.data.frame(get_current_data("ab", call = 0)), error = function(e) FALSE)) {
@ -776,11 +799,10 @@ as_sir_method <- function(method_short,
mo.bak <- mo mo.bak <- mo
} }
# be sure to take current taxonomy, as the 'clinical_breakpoints' data set only contains current taxonomy # be sure to take current taxonomy, as the 'clinical_breakpoints' data set only contains current taxonomy
mo <- suppressWarnings(suppressMessages(as.mo(mo, keep_synonyms = FALSE, inf0 = FALSE))) mo <- suppressWarnings(suppressMessages(as.mo(mo, keep_synonyms = FALSE, info = FALSE)))
guideline_coerced <- get_guideline(guideline, reference_data)
if (is.na(ab)) { if (is.na(ab)) {
message_("Returning NAs for unknown drug: '", font_bold(ab.bak), message_("Returning NAs for unknown antibiotic: '", font_bold(ab.bak),
"'. Rename this column to a drug name or code, and check the output with `as.ab()`.", "'. Rename this column to a valid name or code, and check the output with `as.ab()`.",
add_fn = font_red, add_fn = font_red,
as_note = FALSE as_note = FALSE
) )
@ -817,25 +839,25 @@ as_sir_method <- function(method_short,
), agent_name, ")" ), agent_name, ")"
) )
} }
message_("=> Interpreting ", method_long, " of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""),
agent_formatted, # this intro text will also be printed in the progress bar in the `progress` package is installed
mo_var_found, intro_txt <- paste0("Interpreting ", method_long, ": ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""),
" according to ", ifelse(identical(reference_data, AMR::clinical_breakpoints), agent_formatted,
font_bold(guideline_coerced), mo_var_found,
"manually defined 'reference_data'" ifelse(identical(reference_data, AMR::clinical_breakpoints),
), paste0(", ", font_bold(guideline_coerced)),
"... ", ""),
appendLF = FALSE, "... ")
as_note = FALSE message_(intro_txt, appendLF = FALSE, as_note = FALSE)
)
msg_note <- function(messages) { msg_note <- function(messages) {
messages <- unique(messages)
for (i in seq_len(length(messages))) { for (i in seq_len(length(messages))) {
messages[i] <- word_wrap(extra_indent = 5, messages[i]) messages[i] <- word_wrap(extra_indent = 5, messages[i])
} }
message( message(
font_green(font_bold(" Note:\n")), font_yellow_bg(paste0(" NOTE", ifelse(length(messages) > 1, "S", ""), " \n")),
paste0(" ", font_black(AMR_env$bullet_icon), " ", font_black(messages, collapse = NULL), collapse = "\n") paste0(" ", font_black(AMR_env$bullet_icon), " ", font_black(messages, collapse = NULL), collapse = "\n")
) )
} }
@ -857,13 +879,13 @@ as_sir_method <- function(method_short,
# when as.sir.disk is called directly # when as.sir.disk is called directly
df$values <- as.disk(df$values) df$values <- as.disk(df$values)
} }
df_unique <- unique(df[ , c("mo", "uti"), drop = FALSE])
rise_warning <- FALSE rise_warning <- FALSE
rise_note <- FALSE rise_note <- FALSE
method_coerced <- toupper(method) method_coerced <- toupper(method)
ab_coerced <- ab ab_coerced <- as.ab(ab)
mo_coerced <- mo
if (identical(reference_data, AMR::clinical_breakpoints)) { if (identical(reference_data, AMR::clinical_breakpoints)) {
breakpoints <- reference_data %pm>% breakpoints <- reference_data %pm>%
subset(guideline == guideline_coerced & method == method_coerced & ab == ab_coerced) subset(guideline == guideline_coerced & method == method_coerced & ab == ab_coerced)
@ -877,6 +899,9 @@ as_sir_method <- function(method_short,
subset(method == method_coerced & ab == ab_coerced) subset(method == method_coerced & ab == ab_coerced)
} }
breakpoints <- breakpoints %pm>%
subset(type == breakpoint_type)
if (isFALSE(include_screening)) { if (isFALSE(include_screening)) {
# remove screening rules from the breakpoints table # remove screening rules from the breakpoints table
breakpoints <- breakpoints %pm>% breakpoints <- breakpoints %pm>%
@ -891,11 +916,12 @@ as_sir_method <- function(method_short,
msgs <- character(0) msgs <- character(0)
if (nrow(breakpoints) == 0) { if (nrow(breakpoints) == 0) {
# apparently no breakpoints found # apparently no breakpoints found
msg_note(paste0( message(
"No ", method_coerced, " breakpoints available for ", paste0(font_rose_bg(" WARNING "), "\n"),
suppressMessages(suppressWarnings(ab_name(ab_coerced, language = NULL, tolower = TRUE))), font_black(paste0(" ", AMR_env$bullet_icon, " No ", method_coerced, " breakpoints available for ",
" (", ab_coerced, ")" suppressMessages(suppressWarnings(ab_name(ab_coerced, language = NULL, tolower = TRUE))),
)) " (", ab_coerced, ").")))
load_mo_uncertainties(metadata_mo) load_mo_uncertainties(metadata_mo)
return(rep(NA_sir_, nrow(df))) return(rep(NA_sir_, nrow(df)))
} }
@ -904,33 +930,42 @@ as_sir_method <- function(method_short,
any_is_intrinsic_resistant <- FALSE any_is_intrinsic_resistant <- FALSE
add_intrinsic_resistance_to_AMR_env() add_intrinsic_resistance_to_AMR_env()
} }
p <- progress_ticker(n = nrow(df_unique), n_min = 10, title = font_blue(intro_txt), only_bar_percent = TRUE)
has_progress_bar <- !is.null(import_fn("progress_bar", "progress", error_on_fail = FALSE)) && nrow(df_unique) >= 10
on.exit(close(p))
# run the rules # run the rules
for (mo_unique in unique(df$mo)) { for (i in seq_len(nrow(df_unique))) {
rows <- which(df$mo == mo_unique) p$tick()
mo_current <- df_unique[i, "mo", drop = TRUE]
uti_current <- df_unique[i, "uti", drop = TRUE]
if (is.na(uti_current)) {
# no preference, so no filter on UTIs
rows <- which(df$mo == mo_current)
} else {
rows <- which(df$mo == mo_current & df$uti == uti_current)
}
values <- df[rows, "values", drop = TRUE] values <- df[rows, "values", drop = TRUE]
uti <- df[rows, "uti", drop = TRUE]
new_sir <- rep(NA_sir_, length(rows)) new_sir <- rep(NA_sir_, length(rows))
# find different mo properties # find different mo properties, as fast as possible
mo_current_genus <- as.mo(mo_genus(mo_unique, language = NULL)) mo_current_genus <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$genus[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
mo_current_family <- as.mo(mo_family(mo_unique, language = NULL)) mo_current_family <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$family[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
mo_current_order <- as.mo(mo_order(mo_unique, language = NULL)) mo_current_order <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$order[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
mo_current_class <- as.mo(mo_class(mo_unique, language = NULL)) mo_current_class <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$class[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
if (mo_genus(mo_unique, language = NULL) == "Staphylococcus") { mo_current_rank <- AMR_env$MO_lookup$rank[match(mo_current, AMR_env$MO_lookup$mo)]
mo_current_becker <- as.mo(mo_unique, Becker = TRUE) mo_current_name <- AMR_env$MO_lookup$fullname[match(mo_current, AMR_env$MO_lookup$mo)]
if (mo_current %in% AMR::microorganisms.groups$mo) {
# get the species group (might be more than 1 entry)
mo_current_species_group <- AMR::microorganisms.groups$mo_group[which(AMR::microorganisms.groups$mo == mo_current)]
} else { } else {
mo_current_becker <- mo_unique mo_current_species_group <- NULL
} }
if (mo_genus(mo_unique, language = NULL) == "Streptococcus") { mo_current_other <- structure("UNKNOWN", class = c("mo", "character"))
mo_current_lancefield <- as.mo(mo_unique, Lancefield = TRUE)
} else {
mo_current_lancefield <- mo_unique
}
mo_current_other <- as.mo("UNKNOWN")
# formatted for notes # formatted for notes
mo_formatted <- suppressMessages(suppressWarnings(mo_fullname(mo_unique, language = NULL, keep_synonyms = FALSE))) mo_formatted <- mo_current_name
if (!mo_rank(mo_unique) %in% c("kingdom", "phylum", "class", "order")) { if (!mo_current_rank %in% c("kingdom", "phylum", "class", "order")) {
mo_formatted <- font_italic(mo_formatted) mo_formatted <- font_italic(mo_formatted)
} }
ab_formatted <- paste0( ab_formatted <- paste0(
@ -942,46 +977,54 @@ as_sir_method <- function(method_short,
# (this will prefer species breakpoints over order breakpoints) # (this will prefer species breakpoints over order breakpoints)
breakpoints_current <- breakpoints %pm>% breakpoints_current <- breakpoints %pm>%
subset(mo %in% c( subset(mo %in% c(
mo_current_genus, mo_current_family, mo_current, mo_current_genus, mo_current_family,
mo_current_order, mo_current_class, mo_current_order, mo_current_class,
mo_current_becker, mo_current_lancefield, mo_current_species_group,
mo_current_other mo_current_other
)) ))
if (any(uti, na.rm = TRUE)) { if (is.na(unique(uti_current))) {
breakpoints_current <- breakpoints_current %pm>% breakpoints_current <- breakpoints_current %pm>%
# this will put UTI = FALSE first, then UTI = TRUE, then UTI = NA
pm_arrange(rank_index, uti) # 'uti' is a column in data set 'clinical_breakpoints'
} else if (unique(uti_current) == TRUE) {
breakpoints_current <- breakpoints_current %pm>%
subset(uti == TRUE) %pm>%
# be as specific as possible (i.e. prefer species over genus): # be as specific as possible (i.e. prefer species over genus):
# the below `pm_desc(uti)` will put `TRUE` on top and FALSE on bottom pm_arrange(rank_index)
pm_arrange(rank_index, pm_desc(uti)) # 'uti' is a column in data set 'clinical_breakpoints' } else if (unique(uti_current) == FALSE) {
} else {
breakpoints_current <- breakpoints_current %pm>% breakpoints_current <- breakpoints_current %pm>%
# sort UTI = FALSE first, then UTI = TRUE subset(uti == FALSE) %pm>%
pm_arrange(rank_index, uti) # be as specific as possible (i.e. prefer species over genus):
pm_arrange(rank_index)
} }
# throw notes for different body sites # throw notes for different body sites
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_coerced)) { site <- breakpoints_current[1L, "site", drop = FALSE] # this is the one we'll take
if (is.na(site)) {
site <- paste0("an unspecified body site")
} else {
site <- paste0("body site '", site, "'")
}
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti_current %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_coerced)) {
# only UTI breakpoints available # only UTI breakpoints available
warning_("in `as.sir()`: interpretation of ", font_bold(ab_formatted), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms, thus assuming `uti = TRUE`. See `?as.sir`.") warning_("in `as.sir()`: interpretation of ", font_bold(ab_formatted), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms, thus assuming `uti = TRUE`. See `?as.sir`.")
rise_warning <- TRUE rise_warning <- TRUE
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_unique, ab_coerced)) { } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti_current)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_current, ab_coerced)) {
# both UTI and Non-UTI breakpoints available # both UTI and Non-UTI breakpoints available
msgs <- c(msgs, paste0("Breakpoints for UTI ", font_underline("and"), " non-UTI available for ", ab_formatted, " in ", mo_formatted, " - assuming non-UTI. Use argument `uti` to set which isolates are from urine. See `?as.sir`.")) msgs <- c(msgs, paste0("Breakpoints for UTI ", font_underline("and"), " non-UTI available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, ". Use argument `uti` to set which isolates are from urine. See `?as.sir`."))
breakpoints_current <- breakpoints_current %pm>% breakpoints_current <- breakpoints_current %pm>%
pm_filter(uti == FALSE) pm_filter(uti == FALSE)
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_unique, ab_coerced)) { } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_current, ab_coerced)) {
# breakpoints for multiple body sites available # breakpoints for multiple body sites available
site <- breakpoints_current[1L, "site", drop = FALSE] # this is the one we'll take
if (is.na(site)) {
site <- paste0("an unspecified body site")
} else {
site <- paste0("body site '", site, "'")
}
msgs <- c(msgs, paste0("Multiple breakpoints available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, ".")) msgs <- c(msgs, paste0("Multiple breakpoints available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, "."))
} else if (nrow(breakpoints_current) == 0) {
# # do not note - it's already in the header before the interpretation starts
next
} }
# first check if mo is intrinsic resistant # first check if mo is intrinsic resistant
if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_unique, ab_coerced) %in% AMR_env$intrinsic_resistant) { if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_current, ab_coerced) %in% AMR_env$intrinsic_resistant) {
msgs <- c(msgs, paste0("Intrinsic resistance applied for ", ab_formatted, " in ", mo_formatted, "")) msgs <- c(msgs, paste0("Intrinsic resistance applied for ", ab_formatted, " in ", mo_formatted, ""))
new_sir <- rep(as.sir("R"), length(rows)) new_sir <- rep(as.sir("R"), length(rows))
} else if (nrow(breakpoints_current) == 0) { } else if (nrow(breakpoints_current) == 0) {
@ -992,10 +1035,10 @@ as_sir_method <- function(method_short,
breakpoints_current <- breakpoints_current[1L, , drop = FALSE] breakpoints_current <- breakpoints_current[1L, , drop = FALSE]
if (any(breakpoints_current$mo == "UNKNOWN", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "PK.*PD", na.rm = TRUE)) { if (any(breakpoints_current$mo == "UNKNOWN", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "PK.*PD", na.rm = TRUE)) {
msgs <- c(msgs, "(Some) PK/PD breakpoints were applied - use `include_PKPD = FALSE` to prevent this") msgs <- c(msgs, "Some PK/PD breakpoints were applied - use `include_PKPD = FALSE` to prevent this")
} }
if (any(breakpoints_current$site %like% "screen", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "screen", na.rm = TRUE)) { if (any(breakpoints_current$site %like% "screen", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "screen", na.rm = TRUE)) {
msgs <- c(msgs, "(Some) screening breakpoints were applied - use `include_screening = FALSE` to prevent this") msgs <- c(msgs, "Some screening breakpoints were applied - use `include_screening = FALSE` to prevent this")
} }
if (method == "mic") { if (method == "mic") {
@ -1029,16 +1072,17 @@ as_sir_method <- function(method_short,
data.frame( data.frame(
datetime = rep(Sys.time(), length(rows)), datetime = rep(Sys.time(), length(rows)),
index = rows, index = rows,
ab_input = rep(ab.bak, length(rows)), ab_user = rep(ab.bak, length(rows)),
ab_guideline = rep(ab_coerced, length(rows)), mo_user = rep(mo.bak[match(mo_current, df$mo)][1], length(rows)),
mo_input = rep(mo.bak[match(mo_unique, df$mo)][1], length(rows)), ab = rep(ab_coerced, length(rows)),
mo_guideline = rep(breakpoints_current[, "mo", drop = TRUE], length(rows)), mo = rep(breakpoints_current[, "mo", drop = TRUE], length(rows)),
guideline = rep(guideline_coerced, length(rows)),
ref_table = rep(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)),
method = rep(method_coerced, length(rows)),
input = as.double(values), input = as.double(values),
outcome = as.sir(new_sir), outcome = as.sir(new_sir),
method = rep(method_coerced, length(rows)),
breakpoint_S_R = rep(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)), breakpoint_S_R = rep(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)),
guideline = rep(guideline_coerced, length(rows)),
ref_table = rep(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)),
uti = rep(breakpoints_current[, "uti", drop = TRUE], length(rows)),
stringsAsFactors = FALSE stringsAsFactors = FALSE
) )
) )
@ -1046,11 +1090,18 @@ as_sir_method <- function(method_short,
df[rows, "result"] <- new_sir df[rows, "result"] <- new_sir
} }
close(p)
# printing messages
if (has_progress_bar == TRUE) {
# the progress bar has overwritten the intro text, so:
message_(intro_txt, appendLF = FALSE, as_note = FALSE)
}
if (isTRUE(rise_warning)) { if (isTRUE(rise_warning)) {
message(font_yellow(font_bold(" * WARNING *"))) message(font_rose_bg(" WARNING "))
} else if (length(msgs) == 0) { } else if (length(msgs) == 0) {
message(font_green(" OK.")) message(font_green_bg(" OK "))
} else { } else {
msg_note(sort(msgs)) msg_note(sort(msgs))
} }
@ -1066,22 +1117,17 @@ as_sir_method <- function(method_short,
sir_interpretation_history <- function(clean = FALSE) { sir_interpretation_history <- function(clean = FALSE) {
meet_criteria(clean, allow_class = "logical", has_length = 1) meet_criteria(clean, allow_class = "logical", has_length = 1)
out.bak <- AMR_env$sir_interpretation_history out <- AMR_env$sir_interpretation_history
out <- out.bak
if (NROW(out) == 0) { if (NROW(out) == 0) {
message_("No results to return. Run `as.sir()` on MIC values or disk diffusion zones first to see a 'logbook' data set here.") message_("No results to return. Run `as.sir()` on MIC values or disk diffusion zones first to see a 'logbook' data set here.")
return(invisible(NULL)) return(invisible(NULL))
} }
out$ab_guideline <- as.ab(out$ab_guideline)
out$mo_guideline <- as.mo(out$mo_guideline)
out$outcome <- as.sir(out$outcome) out$outcome <- as.sir(out$outcome)
# keep stored for next use # keep stored for next use
if (isTRUE(clean)) { if (isTRUE(clean)) {
AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE] AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE]
} else {
AMR_env$sir_interpretation_history <- out.bak
} }
# sort descending on time # sort descending on time
out <- out[order(out$datetime, decreasing = TRUE), , drop = FALSE] out <- out[order(out$datetime, decreasing = TRUE), , drop = FALSE]
@ -1101,7 +1147,11 @@ pillar_shaft.sir <- function(x, ...) {
out[is.na(x)] <- font_grey(" NA") out[is.na(x)] <- font_grey(" NA")
out[x == "S"] <- font_green_bg(" S ") out[x == "S"] <- font_green_bg(" S ")
out[x == "I"] <- font_orange_bg(" I ") out[x == "I"] <- font_orange_bg(" I ")
out[x == "R"] <- font_red_bg(" R ") if (is_dark()) {
out[x == "R"] <- font_red_bg(" R ")
} else {
out[x == "R"] <- font_rose_bg(" R ")
}
} }
create_pillar_column(out, align = "left", width = 5) create_pillar_column(out, align = "left", width = 5)
} }

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

39
R/zzz.R
View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -58,34 +58,35 @@ AMR_env$av_previously_coerced <- data.frame(
AMR_env$sir_interpretation_history <- data.frame( AMR_env$sir_interpretation_history <- data.frame(
datetime = Sys.time()[0], datetime = Sys.time()[0],
index = integer(0), index = integer(0),
ab_input = character(0), ab_user = character(0),
ab_guideline = set_clean_class(character(0), c("ab", "character")), mo_user = character(0),
mo_input = character(0), ab = set_clean_class(character(0), c("ab", "character")),
mo_guideline = set_clean_class(character(0), c("mo", "character")), mo = set_clean_class(character(0), c("mo", "character")),
guideline = character(0),
ref_table = character(0),
method = character(0),
input = double(0), input = double(0),
outcome = NA_sir_[0], outcome = NA_sir_[0],
method = character(0),
breakpoint_S_R = character(0), breakpoint_S_R = character(0),
guideline = character(0),
ref_table = character(0),
stringsAsFactors = FALSE stringsAsFactors = FALSE
) )
AMR_env$custom_ab_codes <- character(0) AMR_env$custom_ab_codes <- character(0)
AMR_env$custom_mo_codes <- character(0) AMR_env$custom_mo_codes <- character(0)
AMR_env$is_dark_theme <- NULL AMR_env$is_dark_theme <- NULL
AMR_env$chmatch <- import_fn("chmatch", "data.table", error_on_fail = FALSE)
AMR_env$chin <- import_fn("%chin%", "data.table", error_on_fail = FALSE)
# determine info icon for messages # determine info icon for messages
utf8_supported <- isTRUE(base::l10n_info()$`UTF-8`) if (pkg_is_available("cli")) {
is_latex <- tryCatch(import_fn("is_latex_output", "knitr", error_on_fail = FALSE)(), # let cli do the determination of supported symbols
error = function(e) FALSE AMR_env$info_icon <- import_fn("symbol", "cli")$info
) AMR_env$bullet_icon <- import_fn("symbol", "cli")$bullet
if (utf8_supported && !is_latex) { AMR_env$dots <- import_fn("symbol", "cli")$ellipsis
# \u2139 is a symbol officially named 'information source'
AMR_env$info_icon <- "\u2139"
AMR_env$bullet_icon <- "\u2022"
} else { } else {
AMR_env$info_icon <- "i" AMR_env$info_icon <- "i"
AMR_env$bullet_icon <- "*" AMR_env$bullet_icon <- "*"
AMR_env$dots <- "..."
} }
.onLoad <- function(lib, pkg) { .onLoad <- function(lib, pkg) {
@ -184,7 +185,7 @@ if (utf8_supported && !is_latex) {
try(loadNamespace("tibble"), silent = TRUE) try(loadNamespace("tibble"), silent = TRUE)
} }
# reference data - they have additional to improve algorithm speed # reference data - they have additional data to improve algorithm speed
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB) # they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP) AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP) AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -233,6 +233,7 @@ reference:
- "`example_isolates`" - "`example_isolates`"
- "`microorganisms`" - "`microorganisms`"
- "`microorganisms.codes`" - "`microorganisms.codes`"
- "`microorganisms.groups`"
- "`antibiotics`" - "`antibiotics`"
- "`intrinsic_resistant`" - "`intrinsic_resistant`"
- "`dosage`" - "`dosage`"

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,3 +1,5 @@
The email address of the maintainer has changed - not the person.
As with all previous >20 releases, some CHECKs might return a NOTE for *just* hitting the installation size limit, though its size has been brought down to a minimum in collaboration with CRAN maintainers previously. As with all previous >20 releases, some CHECKs might return a NOTE for *just* hitting the installation size limit, though its size has been brought down to a minimum in collaboration with CRAN maintainers previously.
We consider this a high-impact package: it was published in the Journal of Statistical Software (2022), is including in a CRAN Task View (Epidemiology), and is according to download stats used in almost all countries in the world. If there is anything to note, please let us know up-front without directly archiving the current version. That said, we continually unit test our package extensively and have no reason to assume that anything is wrong. We consider this a high-impact package: it was published in the Journal of Statistical Software (2022), is including in a CRAN Task View (Epidemiology), and is according to download stats used in almost all countries in the world. If there is anything to note, please let us know up-front without directly archiving the current version. That said, we continually unit test our package extensively and have no reason to assume that anything is wrong.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #
@ -365,7 +365,7 @@ if (changed_md5(clin_break)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}")) usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}"))
write_md5(clin_break) write_md5(clin_break)
try(saveRDS(clin_break, "data-raw/clinical_breakpoints.rds", version = 2, compress = "xz"), silent = TRUE) try(saveRDS(clin_break, "data-raw/clinical_breakpoints.rds", version = 2, compress = "xz"), silent = TRUE)
try(write.table(clin_break, "data-raw/clinical_breakpoints.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE) try(write.table(clinical_breakpoints, "data-raw/clinical_breakpoints.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
try(haven::write_xpt(clin_break, "data-raw/clinical_breakpoints.xpt"), silent = TRUE) try(haven::write_xpt(clin_break, "data-raw/clinical_breakpoints.xpt"), silent = TRUE)
try(haven::write_sav(clin_break, "data-raw/clinical_breakpoints.sav"), silent = TRUE) try(haven::write_sav(clin_break, "data-raw/clinical_breakpoints.sav"), silent = TRUE)
try(haven::write_dta(clin_break, "data-raw/clinical_breakpoints.dta"), silent = TRUE) try(haven::write_dta(clin_break, "data-raw/clinical_breakpoints.dta"), silent = TRUE)
@ -392,6 +392,32 @@ if (changed_md5(microorganisms)) {
try(arrow::write_parquet(microorganisms, "data-raw/microorganisms.parquet"), silent = TRUE) try(arrow::write_parquet(microorganisms, "data-raw/microorganisms.parquet"), silent = TRUE)
} }
if (changed_md5(microorganisms.codes)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms.codes')} to {usethis::ui_value('data-raw/')}"))
write_md5(microorganisms.codes)
try(saveRDS(microorganisms.codes, "data-raw/microorganisms.codes.rds", version = 2, compress = "xz"), silent = TRUE)
try(write.table(microorganisms.codes, "data-raw/microorganisms.codes.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
try(haven::write_xpt(microorganisms.codes, "data-raw/microorganisms.codes.xpt"), silent = TRUE)
try(haven::write_sav(microorganisms.codes, "data-raw/microorganisms.codes.sav"), silent = TRUE)
try(haven::write_dta(microorganisms.codes, "data-raw/microorganisms.codes.dta"), silent = TRUE)
try(openxlsx::write.xlsx(microorganisms.codes, "data-raw/microorganisms.codes.xlsx"), silent = TRUE)
try(arrow::write_feather(microorganisms.codes, "data-raw/microorganisms.codes.feather"), silent = TRUE)
try(arrow::write_parquet(microorganisms.codes, "data-raw/microorganisms.codes.parquet"), silent = TRUE)
}
if (changed_md5(microorganisms.groups)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms.groups')} to {usethis::ui_value('data-raw/')}"))
write_md5(microorganisms.groups)
try(saveRDS(microorganisms.groups, "data-raw/microorganisms.groups.rds", version = 2, compress = "xz"), silent = TRUE)
try(write.table(microorganisms.groups, "data-raw/microorganisms.groups.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
try(haven::write_xpt(microorganisms.groups, "data-raw/microorganisms.groups.xpt"), silent = TRUE)
try(haven::write_sav(microorganisms.groups, "data-raw/microorganisms.groups.sav"), silent = TRUE)
try(haven::write_dta(microorganisms.groups, "data-raw/microorganisms.groups.dta"), silent = TRUE)
try(openxlsx::write.xlsx(microorganisms.groups, "data-raw/microorganisms.groups.xlsx"), silent = TRUE)
try(arrow::write_feather(microorganisms.groups, "data-raw/microorganisms.groups.feather"), silent = TRUE)
try(arrow::write_parquet(microorganisms.groups, "data-raw/microorganisms.groups.parquet"), silent = TRUE)
}
ab <- dplyr::mutate_if(antibiotics, ~ !is.numeric(.), as.character) ab <- dplyr::mutate_if(antibiotics, ~ !is.numeric(.), as.character)
if (changed_md5(ab)) { if (changed_md5(ab)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('antibiotics')} to {usethis::ui_value('data-raw/')}")) usethis::ui_info(paste0("Saving {usethis::ui_value('antibiotics')} to {usethis::ui_value('data-raw/')}"))

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
0a9ea3545d68b95108a28096d975388f b0c1c3ddb9f8a23aedff6208e9f8d32a

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
9a9fad0100acf4738f3f66b25ed3d8ef cf0833ed69cfd2b6afb5b6d18cf2df26

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,171 @@
"ab" "name" "type" "dose" "dose_times" "administration" "notes" "original_txt" "eucast_version" "ab" "name" "type" "dose" "dose_times" "administration" "notes" "original_txt" "eucast_version"
"AMK" "Amikacin" "standard_dosage" "25-30 mg/kg" 1 "iv" "" "25-30 mg/kg x 1 iv" 13
"AMX" "Amoxicillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 13
"AMX" "Amoxicillin" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3-4 iv" 13
"AMX" "Amoxicillin" "high_dosage" "0.75-1 g" 3 "oral" "" "0.75-1 g x 3 oral" 13
"AMX" "Amoxicillin" "standard_dosage" "0.5 g" 3 "oral" "" "0.5 g x 3 oral" 13
"AMX" "Amoxicillin" "uncomplicated_uti" "0.5 g" 3 "oral" "" "0.5 g x 3 oral" 13
"AMC" "Amoxicillin/clavulanic acid" "high_dosage" "2 g + 0.2 g" 3 "iv" "" "(2 g amoxicillin + 0.2 g clavulanic acid) x 3 iv" 13
"AMC" "Amoxicillin/clavulanic acid" "standard_dosage" "1 g + 0.2 g" 3 "iv" "" "(1 g amoxicillin + 0.2 g clavulanic acid) x 3-4 iv" 13
"AMC" "Amoxicillin/clavulanic acid" "high_dosage" "0.875 g + 0.125 g" 3 "oral" "" "(0.875 g amoxicillin + 0.125 g clavulanic acid) x 3 oral" 13
"AMC" "Amoxicillin/clavulanic acid" "standard_dosage" "0.5 g + 0.125 g" 3 "oral" "" "(0.5 g amoxicillin + 0.125 g clavulanic acid) x 3 oral" 13
"AMC" "Amoxicillin/clavulanic acid" "uncomplicated_uti" "0.5 g + 0.125 g" 3 "oral" "" "(0.5 g amoxicillin + 0.125 g clavulanic acid) x 3 oral" 13
"AMP" "Ampicillin" "high_dosage" "2 g" 4 "iv" "" "2 g x 4 iv" 13
"AMP" "Ampicillin" "standard_dosage" "2 g" 3 "iv" "" "2 g x 3 iv" 13
"SAM" "Ampicillin/sulbactam" "high_dosage" "2 g + 1 g" 4 "iv" "" "(2 g ampicillin + 1 g sulbactam) x 4 iv" 13
"SAM" "Ampicillin/sulbactam" "standard_dosage" "2 g + 1 g" 3 "iv" "" "(2 g ampicillin + 1 g sulbactam) x 3 iv" 13
"AZM" "Azithromycin" "standard_dosage" "0.5 g" 1 "iv" "" "0.5 g x 1 iv" 13
"AZM" "Azithromycin" "standard_dosage" "0.5 g" 1 "oral" "" "0.5 g x 1 oral" 13
"ATM" "Aztreonam" "high_dosage" "2 g" 4 "iv" "" "2 g x 4 iv" 13
"ATM" "Aztreonam" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3 iv" 13
"PEN" "Benzylpenicillin" "high_dosage" "1.2 g" 4 "iv" "" "1.2 g (2 MU) x 4-6 iv" 13
"PEN" "Benzylpenicillin" "standard_dosage" "0.6 g" 4 "iv" "" "0.6 g (1 MU) x 4 iv" 13
"CEC" "Cefaclor" "high_dosage" "1 g" 3 "oral" "" "1 g x 3 oral" 13
"CEC" "Cefaclor" "standard_dosage" "0.25-0.5 g" 3 "oral" "" "0.25-0.5 g x 3 oral" 13
"CFR" "Cefadroxil" "standard_dosage" "0.5-1 g" 2 "oral" "" "0.5-1 g x 2 oral" 13
"CFR" "Cefadroxil" "uncomplicated_uti" "0.5-1 g" 2 "oral" "" "0.5-1 g x 2 oral" 13
"LEX" "Cefalexin" "standard_dosage" "0.25-1 g" 2 "oral" "" "0.25-1 g x 2-3 oral" 13
"LEX" "Cefalexin" "uncomplicated_uti" "0.25-1 g" 2 "oral" "" "0.25-1 g x 2-3 oral" 13
"CZO" "Cefazolin" "high_dosage" "2 g" 3 "iv" "" "2 g x 3 iv" 13
"CZO" "Cefazolin" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3 iv" 13
"FEP" "Cefepime" "high_dosage" "2 g" 3 "iv" "" "2 g x 3 iv" 13
"FEP" "Cefepime" "standard_dosage" "2 g" 2 "iv" "" "2 g x 2 iv" 13
"FDC" "Cefiderocol" "standard_dosage" "2 g" 3 "iv" "over 3 hours" "2 g x 3 iv over 3 hours" 13
"CFM" "Cefixime" "standard_dosage" "0.2-0.4 g" 2 "oral" "" "0.2-0.4 g x 2 oral" 13
"CFM" "Cefixime" "uncomplicated_uti" "0.2-0.4 g" 2 "oral" "" "0.2-0.4 g x 2 oral" 13
"CTX" "Cefotaxime" "high_dosage" "2 g" 3 "iv" "" "2 g x 3 iv" 13
"CTX" "Cefotaxime" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3 iv" 13
"CPD" "Cefpodoxime" "standard_dosage" "0.1-0.2 g" 2 "oral" "" "0.1-0.2 g x 2 oral" 13
"CPD" "Cefpodoxime" "uncomplicated_uti" "0.1-0.2 g" 2 "oral" "" "0.1-0.2 g x 2 oral" 13
"CPT" "Ceftaroline" "high_dosage" "0.6 g" 3 "iv" "over 2 hours" "0.6 g x 3 iv over 2 hours" 13
"CPT" "Ceftaroline" "standard_dosage" "0.6 g" 2 "iv" "over 1 hour" "0.6 g x 2 iv over 1 hour" 13
"CAZ" "Ceftazidime" "high_dosage" "1 g" 6 "iv" "" "1 g x 6 iv" 13
"CAZ" "Ceftazidime" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3 iv" 13
"CZA" "Ceftazidime/avibactam" "standard_dosage" "2 g + 0.5 g" 3 "iv" "over 2 hours" "(2 g ceftazidime + 0.5 g avibactam) x 3 iv over 2 hours" 13
"CTB" "Ceftibuten" "standard_dosage" "0.4 g" 1 "oral" "" "0.4 g x 1 oral" 13
"BPR" "Ceftobiprole" "standard_dosage" "0.5 g" 3 "iv" "over 2 hours" "0.5 g x 3 iv over 2 hours" 13
"CZT" "Ceftolozane/tazobactam" "standard_dosage" "1 g + 0.5 g" 3 "iv" "over 1 hour" "(1 g ceftolozane + 0.5 g tazobactam) x 3 iv over 1 hour" 13
"CZT" "Ceftolozane/tazobactam" "standard_dosage" "2 g + 1 g" 3 "iv" "over 1 hour" "(2 g ceftolozane + 1 g tazobactam) x 3 iv over 1 hour" 13
"CRO" "Ceftriaxone" "high_dosage" "4 g" 1 "iv" "" "4 g x 1 iv" 13
"CRO" "Ceftriaxone" "standard_dosage" "2 g" 1 "iv" "" "2 g x 1 iv" 13
"CXM" "Cefuroxime" "high_dosage" "1.5 g" 3 "iv" "" "1.5 g x 3 iv" 13
"CXM" "Cefuroxime" "standard_dosage" "0.75 g" 3 "iv" "" "0.75 g x 3 iv" 13
"CXM" "Cefuroxime" "high_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2 oral" 13
"CXM" "Cefuroxime" "standard_dosage" "0.25 g" 2 "oral" "" "0.25 g x 2 oral" 13
"CXM" "Cefuroxime" "uncomplicated_uti" "0.25 g" 2 "oral" "" "0.25 g x 2 oral" 13
"CHL" "Chloramphenicol" "high_dosage" "2 g" 4 "iv" "" "2 g x 4 iv" 13
"CHL" "Chloramphenicol" "standard_dosage" "1 g" 4 "iv" "" "1 g x 4 iv" 13
"CHL" "Chloramphenicol" "high_dosage" "2 g" 4 "oral" "" "2 g x 4 oral" 13
"CHL" "Chloramphenicol" "standard_dosage" "1 g" 4 "oral" "" "1 g x 4 oral" 13
"CIP" "Ciprofloxacin" "high_dosage" "0.4 g" 3 "iv" "" "0.4 g x 3 iv" 13
"CIP" "Ciprofloxacin" "standard_dosage" "0.4 g" 2 "iv" "" "0.4 g x 2 iv" 13
"CIP" "Ciprofloxacin" "high_dosage" "0.75 g" 2 "oral" "" "0.75 g x 2 oral" 13
"CIP" "Ciprofloxacin" "standard_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2 oral" 13
"CLR" "Clarithromycin" "high_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2 oral" 13
"CLR" "Clarithromycin" "standard_dosage" "0.25 g" 2 "oral" "" "0.25 g x 2 oral" 13
"CLI" "Clindamycin" "high_dosage" "0.9 g" 3 "iv" "" "0.9 g x 3 iv" 13
"CLI" "Clindamycin" "standard_dosage" "0.6 g" 3 "iv" "" "0.6 g x 3 iv" 13
"CLI" "Clindamycin" "high_dosage" "0.3 g" 4 "oral" "" "0.3 g x 4 oral" 13
"CLI" "Clindamycin" "standard_dosage" "0.3 g" 2 "oral" "" "0.3 g x 2 oral" 13
"CLO" "Cloxacillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 13
"CLO" "Cloxacillin" "standard_dosage" "1 g" 4 "iv" "" "1 g x 4 iv" 13
"CLO" "Cloxacillin" "high_dosage" "1 g" 4 "oral" "" "1 g x 4 oral" 13
"CLO" "Cloxacillin" "standard_dosage" "0.5 g" 4 "oral" "" "0.5 g x 4 oral" 13
"COL" "Colistin" "standard_dosage" "4.5 MU" 2 "iv" "loading dose of 9 MU" "4.5 MU x 2 iv with a loading dose of 9 MU" 13
"DAL" "Dalbavancin" "standard_dosage" "1 g" 1 "iv" "over 30 minutes on day 8" "1 g x 1 iv over 30 minutes on day 1 If needed, 0.5 g x 1 iv over 30 minutes on day 8" 13
"DAP" "Daptomycin" "standard_dosage" "4 mg/kg" 1 "iv" "" "4 mg/kg x 1 iv" 13
"DAP" "Daptomycin" "standard_dosage" "6 mg/kg" 1 "iv" "" "6 mg/kg x 1 iv" 13
"DFX" "Delafloxacin" "standard_dosage" "0.3 g" 2 "iv" "" "0.3 g x 2 iv" 13
"DFX" "Delafloxacin" "standard_dosage" "0.45 g" 2 "oral" "" "0.45 g x 2 oral" 13
"DIC" "Dicloxacillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 13
"DIC" "Dicloxacillin" "standard_dosage" "1 g" 4 "iv" "" "1 g x 4 iv" 13
"DIC" "Dicloxacillin" "high_dosage" "2 g" 4 "oral" "" "2 g x 4 oral" 13
"DIC" "Dicloxacillin" "standard_dosage" "0.5-1 g" 4 "oral" "" "0.5-1 g x 4 oral" 13
"DOR" "Doripenem" "high_dosage" "1 g" 3 "iv" "over 1 hour" "1 g x 3 iv over 1 hour" 13
"DOR" "Doripenem" "standard_dosage" "0.5 g" 3 "iv" "over 1 hour" "0.5 g x 3 iv over 1 hour" 13
"DOX" "Doxycycline" "high_dosage" "0.2 g" 1 "oral" "" "0.2 g x 1 oral" 13
"DOX" "Doxycycline" "standard_dosage" "0.1 g" 1 "oral" "" "0.1 g x 1 oral" 13
"ERV" "Eravacycline" "standard_dosage" "1 mg/kg" 2 "iv" "" "1 mg/kg x 2 iv" 13
"ETP" "Ertapenem" "standard_dosage" "1 g" 1 "iv" "over 30 minutes" "1 g x 1 iv over 30 minutes" 13
"ERY" "Erythromycin" "high_dosage" "1 g" 4 "iv" "" "1 g x 4 iv" 13
"ERY" "Erythromycin" "standard_dosage" "0.5 g" 2 "iv" "" "0.5 g x 2-4 iv" 13
"ERY" "Erythromycin" "high_dosage" "1 g" 4 "oral" "" "1 g x 4 oral" 13
"ERY" "Erythromycin" "standard_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2-4 oral" 13
"FDX" "Fidaxomicin" "standard_dosage" "0.2 g" 2 "oral" "" "0.2 g x 2 oral" 13
"FLC" "Flucloxacillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 13
"FLC" "Flucloxacillin" "standard_dosage" "2 g" 4 "iv" "" "2 g x 4 iv (or 1 g x 6 iv)" 13
"FLC" "Flucloxacillin" "high_dosage" "1 g" 4 "oral" "" "1 g x 4 oral" 13
"FLC" "Flucloxacillin" "standard_dosage" "1 g" 3 "oral" "" "1 g x 3 oral" 13
"FOS" "Fosfomycin" "high_dosage" "8 g" 3 "iv" "" "8 g x 3 iv" 13
"FOS" "Fosfomycin" "standard_dosage" "4 g" 3 "iv" "" "4 g x 3 iv" 13
"FUS" "Fusidic acid" "high_dosage" "0.5 g" 3 "iv" "" "0.5 g x 3 iv" 13
"FUS" "Fusidic acid" "standard_dosage" "0.5 g" 2 "iv" "" "0.5 g x 2 iv" 13
"FUS" "Fusidic acid" "high_dosage" "0.5 g" 3 "oral" "" "0.5 g x 3 oral" 13
"FUS" "Fusidic acid" "standard_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2 oral" 13
"GEN" "Gentamicin" "standard_dosage" "6-7 mg/kg" 1 "iv" "" "6-7 mg/kg x 1 iv" 13
"IPM" "Imipenem" "high_dosage" "1 g" 4 "iv" "over 30 minutes" "1 g x 4 iv over 30 minutes" 13
"IPM" "Imipenem" "standard_dosage" "0.5 g" 4 "iv" "over 30 minutes" "0.5 g x 4 iv over 30 minutes" 13
"IMR" "Imipenem/relebactam" "standard_dosage" "0.5 g + 0.25 g" 4 "iv" "over 30 minutes" "(0.5 g imipenem + 0.25 g relebactam) x 4 iv over 30 minutes" 13
"IMR" "Imipenem/relebactam" "standard_dosage" "0.5 g + 0.25 g" 4 "iv" "over 30 minutes" "(0.5 g imipenem + 0.25 g relebactam) x 4 iv over 30 minutes" 13
"LMU" "Lefamulin" "standard_dosage" "0.15 g" 2 "iv" "or 0.6 g x 2 oral" "0.15 g x 2 iv or 0.6 g x 2 oral" 13
"LMU" "Lefamulin" "standard_dosage" "0.6 g" 2 "oral" "" "0.6 g x 2 oral" 13
"LVX" "Levofloxacin" "high_dosage" "0.5 g" 2 "iv" "" "0.5 g x 2 iv" 13
"LVX" "Levofloxacin" "standard_dosage" "0.5 g" 1 "iv" "" "0.5 g x 1 iv" 13
"LVX" "Levofloxacin" "high_dosage" "0.5 g" 2 "oral" "" "0.5 g x 2 oral" 13
"LVX" "Levofloxacin" "standard_dosage" "0.5 g" 1 "oral" "" "0.5 g x 1 oral" 13
"LNZ" "Linezolid" "standard_dosage" "0.6 g" 2 "iv" "" "0.6 g x 2 iv" 13
"LNZ" "Linezolid" "standard_dosage" "0.6 g" 2 "oral" "" "0.6 g x 2 oral" 13
"MEM" "Meropenem" "high_dosage" "2 g" 3 "iv" "over 3 hours" "2 g x 3 iv over 3 hours" 13
"MEM" "Meropenem" "standard_dosage" "1 g" 3 "iv" "over 30 minutes" "1 g x 3 iv over 30 minutes" 13
"MEV" "Meropenem/vaborbactam" "standard_dosage" "2 g + 2 g" 3 "iv" "over 3 hours" "(2 g meropenem + 2 g vaborbactam) x 3 iv over 3 hours" 13
"MTR" "Metronidazole" "high_dosage" "0.5 g" 3 "iv" "" "0.5 g x 3 iv" 13
"MTR" "Metronidazole" "standard_dosage" "0.4 g" 3 "iv" "" "0.4 g x 3 iv" 13
"MTR" "Metronidazole" "high_dosage" "0.5 g" 3 "oral" "" "0.5 g x 3 oral" 13
"MTR" "Metronidazole" "standard_dosage" "0.4 g" 3 "oral" "" "0.4 g x 3 oral" 13
"MNO" "Minocycline" "standard_dosage" "0.1 g" 2 "oral" "" "0.1 g x 2 oral" 13
"MFX" "Moxifloxacin" "standard_dosage" "0.4 g" 1 "iv" "" "0.4 g x 1 iv" 13
"MFX" "Moxifloxacin" "standard_dosage" "0.4 g" 1 "oral" "" "0.4 g x 1 oral" 13
"OFX" "Ofloxacin" "high_dosage" "0.4 g" 2 "iv" "" "0.4 g x 2 iv" 13
"OFX" "Ofloxacin" "standard_dosage" "0.2 g" 2 "iv" "" "0.2 g x 2 iv" 13
"OFX" "Ofloxacin" "high_dosage" "0.4 g" 2 "oral" "" "0.4 g x 2 oral" 13
"OFX" "Ofloxacin" "standard_dosage" "0.2 g" 2 "oral" "" "0.2 g x 2 oral" 13
"ORI" "Oritavancin" "standard_dosage" "1.2 g" 1 "iv" "" "1.2 g x 1 (single dose) iv over 3 hours" 13
"OXA" "Oxacillin" "high_dosage" "1 g" 6 "iv" "" "1 g x 6 iv" 13
"OXA" "Oxacillin" "standard_dosage" "1 g" 4 "iv" "" "1 g x 4 iv" 13
"PHN" "Phenoxymethylpenicillin" "standard_dosage" "0.5-2 g" 3 "oral" "" "0.5-2 g x 3-4 oral" 13
"PIP" "Piperacillin" "high_dosage" "4 g" 4 "iv" "" "4 g x 4 iv by extended 3-hour infusion" 13
"PIP" "Piperacillin" "standard_dosage" "4 g" 4 "iv" "" "4 g x 4 iv" 13
"TZP" "Piperacillin/tazobactam" "high_dosage" "4 g + 0.5 g" 4 "iv" "" "(4 g piperacillin + 0.5 g tazobactam) x 4 iv by extended 3-hour infusion" 13
"TZP" "Piperacillin/tazobactam" "standard_dosage" "4 g + 0.5 g" 4 "iv" "" "(4 g piperacillin + 0.5 g tazobactam) x 4 iv 30-minute infusion or x 3 iv by extended 4-hour infusion" 13
"QDA" "Quinupristin/dalfopristin" "high_dosage" "7.5 mg/kg" 3 "iv" "" "7.5 mg/kg x 3 iv" 13
"QDA" "Quinupristin/dalfopristin" "standard_dosage" "7.5 mg/kg" 2 "iv" "" "7.5 mg/kg x 2 iv" 13
"RIF" "Rifampicin" "standard_dosage" "0.6 g" 1 "iv" "" "0.6 g x 1 iv" 13
"RIF" "Rifampicin" "standard_dosage" "0.6 g" 1 "oral" "" "0.6 g x 1 oral" 13
"RXT" "Roxithromycin" "standard_dosage" "0.15 g" 2 "oral" "" "0.15 g x 2 oral" 13
"SPT" "Spectinomycin" "standard_dosage" "2 g" 1 "im" "" "2 g x 1 im" 13
"TZD" "Tedizolid" "standard_dosage" "0.2 g" 1 "iv" "" "0.2 g x 1 iv" 13
"TZD" "Tedizolid" "standard_dosage" "0.2 g" 1 "oral" "" "0.2 g x 1 oral" 13
"TEC" "Teicoplanin" "high_dosage" "0.8 g" 1 "iv" "" "0.8 g x 1 iv" 13
"TEC" "Teicoplanin" "standard_dosage" "0.4 g" 1 "iv" "" "0.4 g x 1 iv" 13
"TLV" "Telavancin" "standard_dosage" "10 mg/kg" 1 "iv" "over 1 hour" "10 mg/kg x 1 iv over 1 hour" 13
"TLT" "Telithromycin" "standard_dosage" "0.8 g" 1 "oral" "" "0.8 g x 1 oral" 13
"TEM" "Temocillin" "high_dosage" "2 g" 3 "iv" "" "2 g x 3 iv" 13
"TEM" "Temocillin" "standard_dosage" "2 g" 2 "iv" "" "2 g x 2 iv" 13
"TCY" "Tetracycline" "high_dosage" "0.5 g" 4 "oral" "" "0.5 g x 4 oral" 13
"TCY" "Tetracycline" "standard_dosage" "0.25 g" 4 "oral" "" "0.25 g x 4 oral" 13
"TIC" "Ticarcillin" "high_dosage" "3 g" 6 "iv" "" "3 g x 6 iv" 13
"TIC" "Ticarcillin" "standard_dosage" "3 g" 4 "iv" "" "3 g x 4 iv" 13
"TCC" "Ticarcillin/clavulanic acid" "high_dosage" "3 g + 0.1 g" 6 "iv" "" "(3 g ticarcillin + 0.1 g clavulanic acid) x 6 iv" 13
"TCC" "Ticarcillin/clavulanic acid" "standard_dosage" "3 g + 0.1-0.2 g" 4 "iv" "" "(3 g ticarcillin + 0.1-0.2 g clavulanic acid) x 4 iv" 13
"TGC" "Tigecycline" "standard_dosage" "0.1 g" "loading dose followed by 50 mg x 2 iv" "0.1 g loading dose followed by 50 mg x 2 iv" 13
"TOB" "Tobramycin" "standard_dosage" "6-7 mg/kg" 1 "iv" "" "6-7 mg/kg x 1 iv" 13
"SXT" "Trimethoprim/sulfamethoxazole" "high_dosage" "0.24 g + 1.2 g" 2 "oral" "" "(0.24 g trimethoprim + 1.2 g sulfamethoxazole) x 2 oral" 13
"SXT" "Trimethoprim/sulfamethoxazole" "high_dosage" "0.24 g + 1.2 g" 2 "oral" "" "(0.24 g trimethoprim + 1.2 g sulfamethoxazole) x 2 oral or (0.24 g trimethoprim + 1.2 g sulfamethoxazole) x 2 iv" 13
"SXT" "Trimethoprim/sulfamethoxazole" "standard_dosage" "0.16 g + 0.8 g" 2 "oral" "" "(0.16 g trimethoprim + 0.8 g sulfamethoxazole) x 2 oral" 13
"SXT" "Trimethoprim/sulfamethoxazole" "standard_dosage" "0.16 g + 0.8 g" 2 "oral" "" "(0.16 g trimethoprim + 0.8 g sulfamethoxazole) x 2 oral or (0.16 g trimethoprim + 0.8 g sulfamethoxazole) x 2 iv" 13
"SXT" "Trimethoprim/sulfamethoxazole" "uncomplicated_uti" "0.16 g + 0.8 g" 2 "oral" "" "(0.16 g trimethoprim + 0.8 g sulfamethoxazole) x 2 oral" 13
"SXT" "Trimethoprim/sulfamethoxazole" "uncomplicated_uti" "0.16 g + 0.8 g" 2 "oral" "" "(0.16 g trimethoprim + 0.8 g sulfamethoxazole) x 2 oral" 13
"VAN" "Vancomycin" "standard_dosage" "1 g" 2 "iv" "" "1 g x 2 iv or 2 g x 1 by continuous infusion" 13
"AMK" "Amikacin" "standard_dosage" "25-30 mg/kg" 1 "iv" "" "25-30 mg/kg x 1 iv" 12 "AMK" "Amikacin" "standard_dosage" "25-30 mg/kg" 1 "iv" "" "25-30 mg/kg x 1 iv" 12
"AMX" "Amoxicillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 12 "AMX" "Amoxicillin" "high_dosage" "2 g" 6 "iv" "" "2 g x 6 iv" 12
"AMX" "Amoxicillin" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3-4 iv" 12 "AMX" "Amoxicillin" "standard_dosage" "1 g" 3 "iv" "" "1 g x 3-4 iv" 12

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,11 @@
# ==================================================================== # # ==================================================================== #
# TITLE # # TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data # # AMR: An R Package for Working with Antimicrobial Resistance Data #
# # # #
# SOURCE # # SOURCE CODE: #
# https://github.com/msberends/AMR # # https://github.com/msberends/AMR #
# # # #
# CITE AS # # PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # # Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance # # (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. # # Data. Journal of Statistical Software, 104(3), 1-31. #

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More