Browse Source

new antibiotics

new-mo-algorithm
parent
commit
68cc7ef0d0
  1. 5
      DESCRIPTION
  2. 30
      NAMESPACE
  3. 18
      NEWS.md
  4. 242
      R/ab.R
  5. 185
      R/ab_property.R
  6. 162
      R/abname.R
  7. 2
      R/age.R
  8. 112
      R/atc.R
  9. 107
      R/atc_property.R
  10. 55
      R/count.R
  11. 148
      R/data.R
  12. 64
      R/deprecated.R
  13. 92
      R/disk.R
  14. 556
      R/eucast_rules.R
  15. 9
      R/filter_ab_class.R
  16. 10
      R/first_isolate.R
  17. 17
      R/freq.R
  18. 51
      R/get_locale.R
  19. 31
      R/ggplot_rsi.R
  20. 10
      R/globals.R
  21. 96
      R/guess_ab_col.R
  22. 73
      R/key_antibiotics.R
  23. 465
      R/mdro.R
  24. 24
      R/mic.R
  25. 322
      R/misc.R
  26. 16
      R/mo.R
  27. 6
      R/mo_history.R
  28. 246
      R/mo_property.R
  29. 124
      R/portion.R
  30. 6
      R/resistance_predict.R
  31. 213
      R/rsi.R
  32. 5
      R/rsi_calc.R
  33. 1
      R/zzz.R
  34. 11
      _pkgdown.yml
  35. BIN
      data/antibiotics.rda
  36. BIN
      data/microorganisms.codes.rda
  37. BIN
      data/microorganisms.old.rda
  38. BIN
      data/microorganisms.rda
  39. BIN
      data/rsi_translation.rda
  40. BIN
      data/septic_patients.rda
  41. 4
      docs/LICENSE-text.html
  42. 497
      docs/articles/AMR.html
  43. BIN
      docs/articles/AMR_files/figure-html/plot 1-1.png
  44. BIN
      docs/articles/AMR_files/figure-html/plot 3-1.png
  45. BIN
      docs/articles/AMR_files/figure-html/plot 4-1.png
  46. BIN
      docs/articles/AMR_files/figure-html/plot 5-1.png
  47. 25
      docs/articles/SPSS.html
  48. 17
      docs/articles/ab_property.html
  49. 84
      docs/articles/benchmarks.html
  50. BIN
      docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png
  51. 6
      docs/articles/index.html
  52. 102
      docs/articles/resistance_predict.html
  53. BIN
      docs/articles/resistance_predict_files/figure-html/unnamed-chunk-4-1.png
  54. BIN
      docs/articles/resistance_predict_files/figure-html/unnamed-chunk-5-1.png
  55. BIN
      docs/articles/resistance_predict_files/figure-html/unnamed-chunk-5-2.png
  56. BIN
      docs/articles/resistance_predict_files/figure-html/unnamed-chunk-6-1.png
  57. BIN
      docs/articles/resistance_predict_files/figure-html/unnamed-chunk-7-1.png
  58. 4
      docs/authors.html
  59. 4
      docs/extra.js
  60. 14
      docs/index.html
  61. 280
      docs/news/index.html
  62. 2
      docs/pkgdown.yml
  63. 24
      docs/reference/AMR-deprecated.html
  64. 132
      docs/reference/ab_property.html
  65. 10
      docs/reference/age_groups.html
  66. 50
      docs/reference/antibiotics.html
  67. 365
      docs/reference/as.ab.html
  68. 22
      docs/reference/as.atc.html
  69. 343
      docs/reference/as.disk.html
  70. 20
      docs/reference/as.mic.html
  71. 6
      docs/reference/as.mo.html
  72. 61
      docs/reference/as.rsi.html
  73. 4
      docs/reference/catalogue_of_life.html
  74. 4
      docs/reference/catalogue_of_life_version.html
  75. 56
      docs/reference/count.html
  76. 203
      docs/reference/eucast_rules.html
  77. 8
      docs/reference/filter_ab_class.html
  78. 14
      docs/reference/first_isolate.html
  79. 8
      docs/reference/freq.html
  80. 40
      docs/reference/ggplot_rsi.html
  81. 8
      docs/reference/guess_ab_col.html
  82. 58
      docs/reference/index.html
  83. 30
      docs/reference/key_antibiotics.html
  84. 417
      docs/reference/mdro.html
  85. 4
      docs/reference/microorganisms.codes.html
  86. 4
      docs/reference/microorganisms.html
  87. 4
      docs/reference/microorganisms.old.html
  88. 48
      docs/reference/mo_property.html
  89. 79
      docs/reference/portion.html
  90. 10
      docs/reference/resistance_predict.html
  91. 311
      docs/reference/rsi_translation.html
  92. 336
      docs/reference/translate.html
  93. 21
      docs/sitemap.xml
  94. 10
      index.md
  95. 356
      inst/eucast/eucast_rules.tsv
  96. 21
      inst/rstudio/addins.dcf
  97. 456
      inst/translations.tsv
  98. 35
      man/AMR-deprecated.Rd
  99. 110
      man/ab_property.Rd
  100. 74
      man/abname.Rd
  101. Some files were not shown because too many files have changed in this diff Show More

5
DESCRIPTION

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
Package: AMR
Version: 0.6.1.9002
Date: 2019-04-11
Version: 0.6.1.9003
Date: 2019-05-10
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(
@ -53,6 +53,7 @@ Imports: @@ -53,6 +53,7 @@ Imports:
knitr (>= 1.0.0),
microbenchmark,
rlang (>= 0.3.1),
scales,
tidyr (>= 0.7.0)
Suggests:
covr (>= 3.0.1),

30
NAMESPACE

@ -1,11 +1,16 @@ @@ -1,11 +1,16 @@
# Generated by roxygen2: do not edit by hand
S3method(as.data.frame,ab)
S3method(as.data.frame,atc)
S3method(as.data.frame,frequency_tbl)
S3method(as.data.frame,mo)
S3method(as.double,mic)
S3method(as.integer,mic)
S3method(as.numeric,mic)
S3method(as.rsi,data.frame)
S3method(as.rsi,default)
S3method(as.rsi,disk)
S3method(as.rsi,mic)
S3method(as.vector,frequency_tbl)
S3method(as_tibble,frequency_tbl)
S3method(barplot,mic)
@ -22,14 +27,17 @@ S3method(plot,frequency_tbl) @@ -22,14 +27,17 @@ S3method(plot,frequency_tbl)
S3method(plot,mic)
S3method(plot,resistance_predict)
S3method(plot,rsi)
S3method(print,ab)
S3method(print,atc)
S3method(print,catalogue_of_life_version)
S3method(print,disk)
S3method(print,frequency_tbl)
S3method(print,mic)
S3method(print,mo)
S3method(print,mo_renamed)
S3method(print,mo_uncertainties)
S3method(print,rsi)
S3method(pull,ab)
S3method(pull,atc)
S3method(pull,mo)
S3method(select,frequency_tbl)
@ -41,24 +49,26 @@ S3method(summary,mo) @@ -41,24 +49,26 @@ S3method(summary,mo)
S3method(summary,rsi)
export("%like%")
export(ab_atc)
export(ab_certe)
export(ab_atc_group1)
export(ab_atc_group2)
export(ab_cid)
export(ab_ddd)
export(ab_group)
export(ab_name)
export(ab_official)
export(ab_property)
export(ab_synonyms)
export(ab_tradenames)
export(ab_trivial_nl)
export(ab_umcg)
export(abname)
export(age)
export(age_groups)
export(anti_join_microorganisms)
export(as.ab)
export(as.atc)
export(as.disk)
export(as.mic)
export(as.mo)
export(as.rsi)
export(atc_certe)
export(atc_ddd)
export(atc_groups)
export(atc_name)
export(atc_official)
export(atc_online_ddd)
@ -67,7 +77,6 @@ export(atc_online_property) @@ -67,7 +77,6 @@ export(atc_online_property)
export(atc_property)
export(atc_tradenames)
export(atc_trivial_nl)
export(atc_umcg)
export(availability)
export(brmo)
export(catalogue_of_life_version)
@ -109,7 +118,9 @@ export(ggplot_rsi_predict) @@ -109,7 +118,9 @@ export(ggplot_rsi_predict)
export(guess_ab_col)
export(header)
export(inner_join_microorganisms)
export(is.ab)
export(is.atc)
export(is.disk)
export(is.mic)
export(is.mo)
export(is.rsi)
@ -156,7 +167,6 @@ export(ratio) @@ -156,7 +167,6 @@ export(ratio)
export(read.4D)
export(resistance_predict)
export(right_join_microorganisms)
export(rsi)
export(rsi_predict)
export(scale_rsi_colours)
export(scale_y_percent)
@ -165,6 +175,7 @@ export(set_mo_source) @@ -165,6 +175,7 @@ export(set_mo_source)
export(skewness)
export(theme_rsi)
export(top_freq)
exportMethods(as.data.frame.ab)
exportMethods(as.data.frame.atc)
exportMethods(as.data.frame.frequency_tbl)
exportMethods(as.data.frame.mo)
@ -187,14 +198,17 @@ exportMethods(kurtosis.matrix) @@ -187,14 +198,17 @@ exportMethods(kurtosis.matrix)
exportMethods(plot.frequency_tbl)
exportMethods(plot.mic)
exportMethods(plot.rsi)
exportMethods(print.ab)
exportMethods(print.atc)
exportMethods(print.catalogue_of_life_version)
exportMethods(print.disk)
exportMethods(print.frequency_tbl)
exportMethods(print.mic)
exportMethods(print.mo)
exportMethods(print.mo_renamed)
exportMethods(print.mo_uncertainties)
exportMethods(print.rsi)
exportMethods(pull.ab)
exportMethods(pull.atc)
exportMethods(pull.mo)
exportMethods(select.frequency_tbl)

18
NEWS.md

@ -1,9 +1,24 @@ @@ -1,9 +1,24 @@
# AMR 0.6.1.9001
**Note: latest development version**
#### New
* Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use `as.rsi()` on an MIC value (created with `as.mic()`), a disk diffusion value (created with the new `as.disk()`) or on a complete date set containing columns with MIC or disk diffusion values.
#### Changed
* Removed deprecated functions `guess_mo()`, `guess_atc()`, `EUCAST_rules()`, `interpretive_reading()`
* Completely reworked the `antibiotics` data set:
* All entries now have 3 different identifiers: a human readable EARS-Net code (`ab`, used by ECDC and WHONET), an ATC code (`atc`, used by WHO), and a CID code (`cid`, Compound ID, used by PubChem)
* Based on the Compound ID, more than a thousand official brand names have been added from many different countries
* All references to antibiotics in our package now use EARS-Net codes, like `AMX` for amoxicillin
* Functions `atc_certe`, `ab_umcg` and `atc_trivial_nl` have been removed
* All `atc_*` functions are superceded by `ab_*` functions
* All output will be translated by using an included, local translation file that can be found after install with:
```r
system.file("translations.tsv", package = "AMR")
```
Please create an issue in one of our repositories if you want additions in this file.
* Improved intelligence of looking up antibiotic tables in data set using `guess_ab_col()`
* Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function
* Removed deprecated functions `guess_mo()`, `guess_atc()`, `EUCAST_rules()`, `interpretive_reading()`, `rsi()`
* Frequency tables of microbial IDs speed improvement
* Removed all hardcoded EUCAST rules and replaced them with a new reference file: `./inst/eucast/eucast.tsv`.
* Added ceftazidim intrinsic resistance to *Streptococci*
@ -11,6 +26,7 @@ @@ -11,6 +26,7 @@
* Fix for `freq()` for when all values are `NA`.
#### Other
* Support for R 3.6.0
* Prevented [staged install](https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html) in R 3.6.0 and later by adding `StagedInstall: false` to the DESCRIPTION file
# AMR 0.6.1

242
R/ab.R

@ -0,0 +1,242 @@ @@ -0,0 +1,242 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Transform to antibiotic ID
#'
#' Use this function to determine the antibiotic code of one or more antibiotics. The data set \code{\link{antibiotics}} will be searched for abbreviations, official names and synonyms (brand names).
#' @param x character vector to determine to antibiotic ID
#' @rdname as.ab
#' @keywords atc
#' @inheritSection WHOCC WHOCC
#' @export
#' @importFrom dplyr %>% filter slice pull
#' @details Use the \code{\link{ab_property}} functions to get properties based on the returned ATC code, see Examples.
#'
#' In the ATC classification system, the active substances are classified in a hierarchy with five different levels. The system has fourteen main anatomical/pharmacological groups or 1st levels. Each ATC main group is divided into 2nd levels which could be either pharmacological or therapeutic groups. The 3rd and 4th levels are chemical, pharmacological or therapeutic subgroups and the 5th level is the chemical substance. The 2nd, 3rd and 4th levels are often used to identify pharmacological subgroups when that is considered more appropriate than therapeutic or chemical subgroups.
#' Source: \url{https://www.whocc.no/atc/structure_and_principles/}
#' @section Source:
#' World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
#'
#' WHONET 2019 software: \url{http://www.whonet.org/software.html}
#'
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
#' @return Character (vector) with class \code{"act"}. Unknown values will return \code{NA}.
#' @seealso \code{\link{antibiotics}} for the dataframe that is being used to determine ATCs.
#' @inheritSection AMR Read more on our website!
#' @examples
#' # These examples all return "ERY", the ID of Erythromycin:
#' as.ab("J01FA01")
#' as.ab("J 01 FA 01")
#' as.ab("Erythromycin")
#' as.ab("eryt")
#' as.ab(" eryt 123")
#' as.ab("ERYT")
#' as.ab("ERY")
#' as.ab("erytromicine") # spelled wrong
#' as.ab("Erythrocin") # trade name
#' as.ab("Romycin") # trade name
#'
#' # Use ab_* functions to get a specific properties (see ?ab_property);
#' # they use as.ab() internally:
#' ab_name("J01FA01") # "Erythromycin"
#' ab_name("eryt") # "Erythromycin"
as.ab <- function(x) {
if (is.ab(x)) {
return(x)
}
x_bak <- x
# remove suffices
x_bak_clean <- gsub("_(mic|rsi)$", "", x)
# remove disk concentrations, like LVX_NM -> LVX
x_bak_clean <- gsub("_[A-Z]{2}[0-9_]{0,3}$", "", x_bak_clean)
# clean rest of it
x_bak_clean <- gsub("[^a-zA-Z0-9/-]", "", x_bak_clean)
# keep only a-z when it's not an ATC code or only numbers
x_bak_clean[!x_bak_clean %like% "^([A-Z][0-9]{2}[A-Z]{2}[0-9]{2}|[0-9]+)$"] <- gsub("[^a-zA-Z]+",
"",
x_bak_clean[!x_bak_clean %like% "^([A-Z][0-9]{2}[A-Z]{2}[0-9]{2}|[0-9]+)$"])
x <- unique(x_bak_clean)
x_new <- rep(NA_character_, length(x))
x_unknown <- character(0)
for (i in 1:length(x)) {
if (is.na(x[i]) | is.null(x[i])) {
next
}
if (identical(x[i], "")) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
next
}
# exact AB code
found <- AMR::antibiotics[which(AMR::antibiotics$ab == toupper(x[i])),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# exact ATC code
found <- AMR::antibiotics[which(AMR::antibiotics$atc == toupper(x[i])),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# exact CID code
found <- AMR::antibiotics[which(AMR::antibiotics$cid == x[i]),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# exact name
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) == toupper(x[i])),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# exact synonym
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
function(s) if (toupper(x[i]) %in% toupper(s)) {
TRUE
} else {
FALSE
}))
found <- AMR::antibiotics$ab[synonym_found == TRUE]
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# exact abbreviation
abbr_found <- unlist(lapply(AMR::antibiotics$abbreviations,
function(a) if (toupper(x[i]) %in% toupper(a)) {
TRUE
} else {
FALSE
}))
found <- AMR::antibiotics$ab[abbr_found == TRUE]
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# first >=4 characters of name
if (nchar(x[i]) >= 4) {
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) %like% paste0("^", x[i])),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
}
# allow characters that resemble others, but only continue when having more than 3 characters
if (nchar(x[i]) <= 3) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
next
}
x_spelling <- x[i]
x_spelling <- gsub("[iy]+", "[iy]+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("[sz]+", "[sz]+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("(c|k|q|qu)+", "(c|k|q|qu)+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("(ph|f|v)+", "(ph|f|v)+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("(th|t)+", "(th|t)+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("a+", "a+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("e+", "e+", x_spelling, ignore.case = TRUE)
x_spelling <- gsub("o+", "o+", x_spelling, ignore.case = TRUE)
# allow any ending of -in/-ine and -im/-ime
x_spelling <- gsub("(\\[iy\\]\\+(n|m)|\\[iy\\]\\+(n|m)e\\+)$", "[iy]+(n|m)e*", x_spelling, ignore.case = TRUE)
# allow any ending of -ol/-ole
x_spelling <- gsub("(o\\+l|o\\+le\\+)$", "o+le*", x_spelling, ignore.case = TRUE)
# try if name starts with it
found <- AMR::antibiotics[which(AMR::antibiotics$name %like% paste0("^", x_spelling)),]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# and try if any synonym starts with it
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
function(s) if (any(s %like% paste0("^", x_spelling))) {
TRUE
} else {
FALSE
}))
found <- AMR::antibiotics$ab[synonym_found == TRUE]
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
# not found
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
}
if (length(x_unknown) > 0) {
warning("These values could not be coerced to a valid antibiotic ID: ",
paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ', '),
".",
call. = FALSE)
}
x_result <- data.frame(x = x_bak_clean, stringsAsFactors = FALSE) %>%
left_join(data.frame(x = x, x_new = x_new, stringsAsFactors = FALSE), by = "x") %>%
pull(x_new)
structure(.Data = x_result,
class = "ab")
}
#' @rdname as.atc
#' @export
is.ab <- function(x) {
identical(class(x), "ab")
}
#' @exportMethod print.ab
#' @export
#' @noRd
print.ab <- function(x, ...) {
cat("Class 'ab'\n")
print.default(as.character(x), quote = FALSE)
}
#' @exportMethod as.data.frame.ab
#' @export
#' @noRd
as.data.frame.ab <- function (x, ...) {
# same as as.data.frame.character but with removed stringsAsFactors
nm <- paste(deparse(substitute(x), width.cutoff = 500L),
collapse = " ")
if (!"nm" %in% names(list(...))) {
as.data.frame.vector(x, ..., nm = nm)
} else {
as.data.frame.vector(x, ...)
}
}
#' @exportMethod pull.ab
#' @export
#' @importFrom dplyr pull
#' @noRd
pull.ab <- function(.data, ...) {
pull(as.data.frame(.data), ...)
}

185
R/ab_property.R

@ -0,0 +1,185 @@ @@ -0,0 +1,185 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Property of an antibiotic
#'
#' Use these functions to return a specific property of an antibiotic from the \code{\link{antibiotics}} data set. All input values will be evaluated internally with \code{\link{as.ab}}.
#' @param x any (vector of) text that can be coerced to a valid microorganism code with \code{\link{as.ab}}
#' @param tolower logical to indicate whether the first character of every output should be transformed to a lower case character. This will lead to e.g. "polymyxin B" and not "polymyxin b".
#' @param property one of the column names of one of the \code{\link{antibiotics}} data set
#' @param language language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.
#' @param administration way of administration, either \code{"oral"} or \code{"iv"}
#' @param units a logical to indicate whether the units instead of the DDDs itself must be returned, see Examples
#' @param ... other parameters passed on to \code{\link{as.ab}}
#' @details All output will be \link{translate}d where possible.
#' @inheritSection as.ab Source
#' @rdname ab_property
#' @name ab_property
#' @return \itemize{
#' \item{An \code{integer} in case of \code{ab_cid}}
#' \item{A named \code{list} in case of multiple \code{ab_synonyms}}
#' \item{A \code{double} in case of \code{ab_ddd}}
#' \item{A \code{character} in all other cases}
#' }
#' @export
#' @seealso \code{\link{antibiotics}}
#' @inheritSection AMR Read more on our website!
#' @examples
#' # all properties:
#' ab_name("AMX") # "Amoxicillin"
#' ab_atc("AMX") # J01CA04 (ATC code from the WHO)
#' ab_cid("AMX") # 33613 (Compound ID from PubChem)
#'
#' ab_synonyms("AMX") # a list with brand names of amoxicillin
#' ab_tradenames("AMX") # same
#'
#' ab_group("AMX") # "Beta-lactams/penicillins"
#' ab_atc_group1("AMX") # "Beta-lactam antibacterials, penicillins"
#' ab_atc_group2("AMX") # "Penicillins with extended spectrum"
#'
#' ab_name(x = c("AMC", "PLB")) # "Amoxicillin/clavulanic acid" "Polymyxin B"
#' ab_name(x = c("AMC", "PLB"),
#' tolower = TRUE) # "amoxicillin/clavulanic acid" "polymyxin B"
#'
#' ab_ddd("AMX", "oral") # 1
#' ab_ddd("AMX", "oral", units = TRUE) # "g"
#' ab_ddd("AMX", "iv") # 1
#' ab_ddd("AMX", "iv", units = TRUE) # "g"
#'
#' # all ab_* functions use as.ab() internally:
#' ab_name("Fluclox") # "Flucloxacillin"
#' ab_name("fluklox") # "Flucloxacillin"
#' ab_name("floxapen") # "Flucloxacillin"
#' ab_name(21319) # "Flucloxacillin" (using CID)
#' ab_name("J01CF05") # "Flucloxacillin" (using ATC)
ab_name <- function(x, language = get_locale(), tolower = FALSE, ...) {
x <- ab_validate(x = x, property = "name", ...)
res <- t(x, language = language)
if (tolower == TRUE) {
# use perl to only transform the first character
# as we want "polymyxin B", not "polymyxin b"
res <- gsub("^([A-Z])", "\\L\\1", res, perl = TRUE)
}
res
}
#' @rdname ab_property
#' @export
ab_atc <- function(x, ...) {
ab_validate(x = x, property = "atc", ...)
}
#' @rdname ab_property
#' @export
ab_cid <- function(x, ...) {
ab_validate(x = x, property = "cid", ...)
}
#' @rdname ab_property
#' @export
ab_synonyms <- function(x, ...) {
syns <- ab_validate(x = x, property = "synonyms", ...)
names(syns) <- x
if (length(syns) == 1) {
unname(unlist(syns))
} else {
syns
}
}
#' @rdname ab_property
#' @export
ab_tradenames <- function(x, ...) {
ab_synonyms(x, ...)
}
#' @rdname ab_property
#' @export
ab_group <- function(x, ...) {
ab_validate(x = x, property = "group", ...)
}
#' @rdname ab_property
#' @export
ab_atc_group1 <- function(x, ...) {
ab_validate(x = x, property = "atc_group1", ...)
}
#' @rdname ab_property
#' @export
ab_atc_group2 <- function(x, ...) {
ab_validate(x = x, property = "atc_group2", ...)
}
#' @rdname ab_property
#' @export
ab_ddd <- function(x, administration = "oral", units = FALSE, ...) {
if (!administration %in% c("oral", "iv")) {
stop("`administration` must be 'oral' or 'iv'", call. = FALSE)
}
ddd_prop <- administration
if (units == TRUE) {
ddd_prop <- paste0(ddd_prop, "_units")
} else {
ddd_prop <- paste0(ddd_prop, "_ddd")
}
ab_validate(x = x, property = ddd_prop, ...)
}
#' @rdname ab_property
#' @export
ab_property <- function(x, property = 'name', language = get_locale(), ...) {
if (length(property) != 1L) {
stop("'property' must be of length 1.")
}
if (!property %in% colnames(AMR::antibiotics)) {
stop("invalid property: '", property, "' - use a column name of the `antibiotics` data set")
}
t(ab_validate(x = x, property = property, ...), language = language)
}
ab_validate <- function(x, property, ...) {
if (!"AMR" %in% base::.packages()) {
library("AMR")
# check onLoad() in R/zzz.R: data tables are created there.
}
# try to catch an error when inputting an invalid parameter
# so the 'call.' can be set to FALSE
tryCatch(x[1L] %in% AMR::antibiotics[1, property],
error = function(e) stop(e$message, call. = FALSE))
if (!all(x %in% AMR::antibiotics[, property])) {
x <- data.frame(ab = as.ab(x), stringsAsFactors = FALSE) %>%
left_join(antibiotics %>% select(c("ab", property)), by = "ab") %>%
pull(property)
}
if (property %in% c("ab", "atc")) {
return(structure(x, class = property))
} else if (property == "cid") {
return(as.integer(x))
} else if (property %like% "ddd") {
return(as.double(x))
} else {
return(x)
}
}

162
R/abname.R

@ -1,162 +0,0 @@ @@ -1,162 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Name of an antibiotic
#'
#' Convert antibiotic codes to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{antibiotics}}.
#' @param abcode a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"}
#' @param from,to type to transform from and to. See \code{\link{antibiotics}} for its column names. WIth \code{from = "guess"} the from will be guessed from \code{"atc"}, \code{"certe"} and \code{"umcg"}. When using \code{to = "atc"}, the ATC code will be searched using \code{\link{as.atc}}.
#' @param textbetween text to put between multiple returned texts
#' @param tolower return output as lower case with function \code{\link{tolower}}.
#' @details \strong{The \code{\link{ab_property}} functions are faster and more concise}, but do not support concatenated strings, like \code{abname("AMCL+GENT"}.
#' @keywords ab antibiotics
#' @source \code{\link{antibiotics}}
#' @inheritSection WHOCC WHOCC
#' @export
#' @importFrom dplyr %>% pull
#' @inheritSection AMR Read more on our website!
#' @examples
#' abname("AMCL")
#' # "Amoxicillin and beta-lactamase inhibitor"
#'
#' # It is quite flexible at default (having `from = "guess"`)
#' abname(c("amox", "J01CA04", "Trimox", "dispermox", "Amoxil"))
#' # "Amoxicillin" "Amoxicillin" "Amoxicillin" "Amoxicillin" "Amoxicillin"
#'
#' # Multiple antibiotics can be combined with "+".
#' # The second antibiotic will be set to lower case when `tolower` was not set:
#' abname("AMCL+GENT", textbetween = "/")
#' # "amoxicillin and enzyme inhibitor/gentamicin"
#'
#' abname(c("AMCL", "GENT"))
#' # "Amoxicillin and beta-lactamase inhibitor" "Gentamicin"
#'
#' abname("AMCL", to = "trivial_nl")
#' # "Amoxicilline/clavulaanzuur"
#'
#' abname("AMCL", to = "atc")
#' # "J01CR02"
#'
#' # specific codes for University Medical Center Groningen (UMCG):
#' abname("J01CR02", from = "atc", to = "umcg")
#' # "AMCL"
#'
#' # specific codes for Certe:
#' abname("J01CR02", from = "atc", to = "certe")
#' # "amcl"
abname <- function(abcode,
from = c("guess", "atc", "certe", "umcg"),
to = 'official',
textbetween = ' + ',
tolower = FALSE) {
if (length(to) != 1L) {
stop('`to` must be of length 1', call. = FALSE)
}
if (to == "atc") {
return(as.character(as.atc(abcode)))
}
abx <- AMR::antibiotics
from <- from[1]
colnames(abx) <- colnames(abx) %>% tolower()
from <- from %>% tolower()
to <- to %>% tolower()
if (!(from %in% colnames(abx) | from == "guess") |
!to %in% colnames(abx)) {
stop(paste0('Invalid `from` or `to`. Choose one of ',
colnames(abx) %>% paste(collapse = ", "), '.'), call. = FALSE)
}
abcode <- as.character(abcode)
abcode.bak <- abcode
for (i in 1:length(abcode)) {
if (abcode[i] %like% "[+]") {
# support for multiple ab's with +
parts <- trimws(strsplit(abcode[i], split = "+", fixed = TRUE)[[1]])
ab1 <- abname(parts[1], from = from, to = to)
ab2 <- abname(parts[2], from = from, to = to)
if (missing(tolower)) {
ab2 <- tolower(ab2)
}
abcode[i] <- paste0(ab1, textbetween, ab2)
next
}
if (from %in% c("atc", "guess")) {
if (abcode[i] %in% abx$atc) {
abcode[i] <- abx[which(abx$atc == abcode[i]),] %>% pull(to) %>% .[1]
next
}
}
if (from %in% c("certe", "guess")) {
if (abcode[i] %in% abx$certe) {
abcode[i] <- abx[which(abx$certe == abcode[i]),] %>% pull(to) %>% .[1]
next
}
}
if (from %in% c("umcg", "guess")) {
if (abcode[i] %in% abx$umcg) {
abcode[i] <- abx[which(abx$umcg == abcode[i]),] %>% pull(to) %>% .[1]
next
}
}
if (from %in% c("trade_name", "guess")) {
if (abcode[i] %in% abx$trade_name) {
abcode[i] <- abx[which(abx$trade_name == abcode[i]),] %>% pull(to) %>% .[1]
next
}
if (sum(abx$trade_name %like% abcode[i]) > 0) {
abcode[i] <- abx[which(abx$trade_name %like% abcode[i]),] %>% pull(to) %>% .[1]
next
}
}
if (from != "guess") {
# when not found, try any `from`
abcode[i] <- abx[which(abx[,from] == abcode[i]),] %>% pull(to) %>% .[1]
}
if (is.na(abcode[i]) | length(abcode[i] == 0)) {
# try as.atc
try(suppressWarnings(
abcode[i] <- as.atc(abcode[i])
), silent = TRUE)
if (is.na(abcode[i])) {
# still not found
abcode[i] <- abcode.bak[i]
warning('Code "', abcode.bak[i], '" not found in antibiotics list.', call. = FALSE)
} else {
# fill in the found ATC code
abcode[i] <- abname(abcode[i], from = "atc", to = to)
}
}
}
if (tolower == TRUE) {
abcode <- abcode %>% tolower()
}
abcode
}

2
R/age.R

@ -112,7 +112,7 @@ age <- function(x, reference = Sys.Date()) { @@ -112,7 +112,7 @@ age <- function(x, reference = Sys.Date()) {
#' mo == as.mo("E. coli")) %>%
#' group_by(age_group = age_groups(age)) %>%
#' select(age_group,
#' cipr) %>%
#' CIP) %>%
#' ggplot_rsi(x = "age_group")
age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
if (is.character(split_at)) {

112
R/atc.R

@ -44,118 +44,8 @@ @@ -44,118 +44,8 @@
#' as.atc(" eryt 123")
#' as.atc("ERYT")
#' as.atc("ERY")
#' as.atc("Erythrocin") # Trade name
#' as.atc("Eryzole") # Trade name
#' as.atc("Pediamycin") # Trade name
#'
#' # Use ab_* functions to get a specific property based on an ATC code
#' Cipro <- as.atc("cipro") # returns `J01MA02`
#' atc_official(Cipro) # returns "Ciprofloxacin"
#' atc_umcg(Cipro) # returns "CIPR", the code used in the UMCG
as.atc <- function(x) {
x.new <- rep(NA_character_, length(x))
x <- trimws(x, which = "both")
# keep only a-z when it's not an ATC code
x[!x %like% "[A-Z][0-9]{2}[A-Z]{2}[0-9]{2}"] <- gsub("[^a-zA-Z]+", "", x[!x %like% "[A-Z][0-9]{2}[A-Z]{2}[0-9]{2}"])
x.bak <- x
x <- unique(x)
failures <- character(0)
for (i in 1:length(x)) {
if (is.na(x[i]) | is.null(x[i]) | identical(x[i], "")) {
x.new[i] <- x[i]
next
}
fail <- TRUE
# first try atc
found <- AMR::antibiotics[which(AMR::antibiotics$atc == x[i]),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try ATC in ATC code form, even if it does not exist in the antibiotics data set YET
if (length(found) == 0 & x[i] %like% '[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]') {
warning("ATC code ", x[i], " is not yet in the `antibiotics` data set.")
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- x[i]
}
# try abbreviation of EARS-Net/WHONET
found <- AMR::antibiotics[which(tolower(AMR::antibiotics$ears_net) == tolower(x[i])),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try abbreviation of certe and glims
found <- AMR::antibiotics[which(tolower(AMR::antibiotics$certe) == tolower(x[i])),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
found <- AMR::antibiotics[which(tolower(AMR::antibiotics$umcg) == tolower(x[i])),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try exact official name
found <- AMR::antibiotics[which(tolower(AMR::antibiotics$official) == tolower(x[i])),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try exact official Dutch
found <- AMR::antibiotics[which(tolower(AMR::antibiotics$official_nl) == tolower(x[i])),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try trade name
found <- AMR::antibiotics[which(paste0("(", AMR::antibiotics$trade_name, ")") %like% x[i]),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# try abbreviation
found <- AMR::antibiotics[which(paste0("(", AMR::antibiotics$abbr, ")") %like% x[i]),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
# nothing helped, try first chars of official name, but only if nchar > 4 (cipro, nitro, fosfo)
if (nchar(x[i]) > 4) {
found <- AMR::antibiotics[which(AMR::antibiotics$official %like% paste0("^", substr(x[i], 1, 5))),]$atc
if (length(found) > 0) {
fail <- FALSE
x.new[is.na(x.new) & x.bak == x[i]] <- found[1L]
}
}
# not found
if (fail == TRUE) {
failures <- c(failures, x[i])
}
}
failures <- failures[!failures %in% c(NA, NULL, NaN)]
if (length(failures) > 0) {
warning("These values could not be coerced to a valid atc: ",
paste('"', unique(failures), '"', sep = "", collapse = ', '),
".",
call. = FALSE)
}
class(x.new) <- "atc"
x.new
ab_atc(x)
}
#' @rdname as.atc

107
R/atc_property.R

@ -1,107 +0,0 @@ @@ -1,107 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Property of an antibiotic
#'
#' Use these functions to return a specific property of an antibiotic from the \code{\link{antibiotics}} data set, based on their ATC code. Get such a code with \code{\link{as.atc}}.
#' @param x a (vector of a) valid \code{\link{atc}} code or any text that can be coerced to a valid atc with \code{\link{as.atc}}
#' @param property one of the column names of one of the \code{\link{antibiotics}} data set, like \code{"atc"} and \code{"official"}
#' @param language language of the returned text, defaults to English (\code{"en"}) and can be set with \code{\link{getOption}("AMR_locale")}. Either one of \code{"en"} (English) or \code{"nl"} (Dutch).
#' @rdname atc_property
#' @return A vector of values. In case of \code{atc_tradenames}, if \code{x} is of length one, a vector will be returned. Otherwise a \code{\link{list}}, with \code{x} as names.
#' @export
#' @importFrom dplyr %>% left_join pull
#' @seealso \code{\link{antibiotics}}
#' @inheritSection AMR Read more on our website!
#' @examples
#' as.atc("amcl") # J01CR02
#' atc_name("amcl") # Amoxicillin and beta-lactamase inhibitor
#' atc_name("amcl", "nl") # Amoxicilline met enzymremmer
#' atc_trivial_nl("amcl") # Amoxicilline/clavulaanzuur
#' atc_certe("amcl") # amcl
#' atc_umcg("amcl") # AMCL
atc_property <- function(x, property = 'official') {
property <- property[1]
if (!property %in% colnames(AMR::antibiotics)) {
stop("invalid property: ", property, " - use a column name of the `antibiotics` data set")
}
if (!is.atc(x)) {
x <- as.atc(x) # this will give a warning if x cannot be coerced
}
suppressWarnings(
data.frame(atc = x, stringsAsFactors = FALSE) %>%
left_join(AMR::antibiotics, by = "atc") %>%
pull(property)
)
}
#' @rdname atc_property
#' @export
atc_official <- function(x, language = NULL) {
if (is.null(language)) {
language <- getOption("AMR_locale", default = "en")[1L]
} else {
language <- tolower(language[1])
}
if (language %in% c("en", "")) {
atc_property(x, "official")
} else if (language == "nl") {
atc_property(x, "official_nl")
} else {
stop("Unsupported language: '", language, "' - use one of: 'en', 'nl'", call. = FALSE)
}
}
#' @rdname atc_property
#' @export
atc_name <- atc_official
#' @rdname atc_property
#' @export
atc_trivial_nl <- function(x) {
atc_property(x, "trivial_nl")
}
#' @rdname atc_property
#' @export
atc_certe <- function(x) {
atc_property(x, "certe")
}
#' @rdname atc_property
#' @export
atc_umcg <- function(x) {
atc_property(x, "umcg")
}
#' @rdname atc_property
#' @export
atc_tradenames <- function(x) {
res <- atc_property(x, "trade_name")
res <- strsplit(res, "|", fixed = TRUE)
if (length(x) == 1) {
res <- unlist(res)
} else {
names(res) <- x
}
res
}

55
R/count.R

@ -44,55 +44,55 @@ @@ -44,55 +44,55 @@
#' ?septic_patients
#'
#' # Count resistant isolates
#' count_R(septic_patients$amox)
#' count_IR(septic_patients$amox)
#' count_R(septic_patients$AMX)
#' count_IR(septic_patients$AMX)
#'
#' # Or susceptible isolates
#' count_S(septic_patients$amox)
#' count_SI(septic_patients$amox)
#' count_S(septic_patients$AMX)
#' count_SI(septic_patients$AMX)
#'
#' # Count all available isolates
#' count_all(septic_patients$amox)
#' n_rsi(septic_patients$amox)
#' count_all(septic_patients$AMX)
#' n_rsi(septic_patients$AMX)
#'
#' # Since n_rsi counts available isolates, you can
#' # calculate back to count e.g. non-susceptible isolates.
#' # This results in the same:
#' count_IR(septic_patients$amox)
#' portion_IR(septic_patients$amox) * n_rsi(septic_patients$amox)
#' count_IR(septic_patients$AMX)
#' portion_IR(septic_patients$AMX) * n_rsi(septic_patients$AMX)
#'
#' library(dplyr)
#' septic_patients %>%
#' group_by(hospital_id) %>%
#' summarise(R = count_R(cipr),
#' I = count_I(cipr),
#' S = count_S(cipr),
#' n1 = count_all(cipr), # the actual total; sum of all three
#' n2 = n_rsi(cipr), # same - analogous to n_distinct
#' summarise(R = count_R(CIP),
#' I = count_I(CIP),
#' S = count_S(CIP),
#' n1 = count_all(CIP), # the actual total; sum of all three
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
#' total = n()) # NOT the number of tested isolates!
#'
#' # Count co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy.
#' # Please mind that `portion_S` calculates percentages right away instead.
#' count_S(septic_patients$amcl) # S = 1342 (71.4%)
#' count_all(septic_patients$amcl) # n = 1879
#' count_S(septic_patients$AMC) # S = 1342 (71.4%)
#' count_all(septic_patients$AMC) # n = 1879
#'
#' count_S(septic_patients$gent) # S = 1372 (74.0%)
#' count_all(septic_patients$gent) # n = 1855
#' count_S(septic_patients$GEN) # S = 1372 (74.0%)
#' count_all(septic_patients$GEN) # n = 1855
#'
#' with(septic_patients,
#' count_S(amcl, gent)) # S = 1660 (92.3%)
#' count_S(AMC, GEN)) # S = 1660 (92.3%)
#' with(septic_patients, # n = 1798
#' n_rsi(amcl, gent))
#' n_rsi(AMC, GEN))
#'
#' # Get portions S/I/R immediately of all rsi columns
#' septic_patients %>%
#' select(amox, cipr) %>%
#' select(AMX, CIP) %>%
#' count_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' septic_patients %>%
#' select(hospital_id, amox, cipr) %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' count_df(translate = FALSE)
#'
@ -172,7 +172,8 @@ n_rsi <- function(...) { @@ -172,7 +172,8 @@ n_rsi <- function(...) {
#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything
#' @export
count_df <- function(data,
translate_ab = getOption("get_antibiotic_names", "official"),
translate_ab = "name",
language = get_locale(),
combine_IR = FALSE) {
if (!"data.frame" %in% class(data)) {
@ -183,10 +184,9 @@ count_df <- function(data, @@ -183,10 +184,9 @@ count_df <- function(data,
stop("No columns with class 'rsi' found. See ?as.rsi.")
}
if (as.character(translate_ab) == "TRUE") {
translate_ab <- "official"
if (as.character(translate_ab) %in% c("TRUE", "official")) {
translate_ab <- "name"
}
options(get_antibiotic_names = translate_ab)
resS <- summarise_if(.tbl = data,
.predicate = is.rsi,
@ -227,10 +227,7 @@ count_df <- function(data, @@ -227,10 +227,7 @@ count_df <- function(data,
}
if (!translate_ab == FALSE) {
if (!tolower(translate_ab) %in% tolower(colnames(AMR::antibiotics))) {
stop("Parameter `translate_ab` does not occur in the `antibiotics` data set.", call. = FALSE)
}
res <- res %>% mutate(Antibiotic = abname(Antibiotic, from = "guess", to = translate_ab))
res <- res %>% mutate(Antibiotic = ab_property(Antibiotic, property = translate_ab, language = language))
}
res

148
R/data.R

@ -19,115 +19,36 @@ @@ -19,115 +19,36 @@
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Data set with ~500 antibiotics
#' Data set with ~450 antibiotics
#'
#' A data set containing all antibiotics with a J0 code and some other antimicrobial agents, with their DDDs. Except for trade names and abbreviations, all properties were downloaded from the WHO, see Source.
#' @format A \code{\link{data.frame}} with 488 observations and 17 variables:
#' A data set containing all antibiotics. Use \code{\link{as.ab}} or one of the \code{\link{ab_property}} functions to retrieve values from this data set. Three identifiers are included in this data set: an antibiotic ID (\code{ab}, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (\code{atc}) as defined by the WHO, and a Compound ID (\code{cid}) as found in PubChem. Other properties in this data set are derived from one or more of these codes.
#' @format A \code{\link{data.frame}} with 455 observations and 13 variables:
#' \describe{
#' \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical), like \code{J01CR02}}
#' \item{\code{ears_net}}{EARS-Net code (European Antimicrobial Resistance Surveillance Network), like \code{AMC}}
#' \item{\code{certe}}{Certe code, like \code{amcl}}
#' \item{\code{umcg}}{UMCG code, like \code{AMCL}}
#' \item{\code{abbr}}{Abbreviation as used by many countries, used internally by \code{\link{as.atc}}}
#' \item{\code{official}}{Official name by the WHO, like \code{"Amoxicillin and beta-lactamase inhibitor"}}
#' \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}}
#' \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}}
#' \item{\code{trade_name}}{Trade name as used by many countries (a total of 294), used internally by \code{\link{as.atc}}}
#' \item{\code{ab}}{Antibiotic ID as used in this package (like \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available}
#' \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}}
#' \item{\code{cid}}{Compound ID as found in PubChem}
#' \item{\code{name}}{Official name as used by WHONET/EARS-Net or the WHO}
#' \item{\code{group}}{A short and concise group name, based on WHONET and WHOCC definitions}
#' \item{\code{atc_group1}}{Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like \code{"Macrolides, lincosamides and streptogramins"}}
#' \item{\code{atc_group2}}{Official chemical subgroup (4th level ATC code) as defined by the WHOCC, like \code{"Macrolides"}}
#' \item{\code{abbr}}{List of abbreviations as used in many countries, also for antibiotic susceptibility testing (AST)}
#' \item{\code{synonyms}}{Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID}
#' \item{\code{oral_ddd}}{Defined Daily Dose (DDD), oral treatment}
#' \item{\code{oral_units}}{Units of \code{ddd_units}}
#' \item{\code{iv_ddd}}{Defined Daily Dose (DDD), parenteral treatment}
#' \item{\code{iv_units}}{Units of \code{iv_ddd}}
#' \item{\code{atc_group1}}{ATC group, like \code{"Macrolides, lincosamides and streptogramins"}}
#' \item{\code{atc_group2}}{Subgroup of \code{atc_group1}, like \code{"Macrolides"}}
#' \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
#' \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
#' }
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
#' @details Properties that are based on an ATC code are only available when an ATC is available. These properties are: \code{atc_group1}, \code{atc_group2}, \code{oral_ddd}, \code{oral_units}, \code{iv_ddd} and \code{iv_units}
#'
#' Table antibiotic coding EARSS (from WHONET 5.3): \url{http://www.madsonline.dk/Tutorials/landskoder_antibiotika_WM.pdf}
#' Synonyms (i.e. trade names) are derived from the Compound ID (\code{cid}) and consequently only available where a CID is available.
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology (WHOCC): \url{https://www.whocc.no/atc_ddd_index/}
#'
#' EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes Tables. Version 3.1, 2016: \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
#' WHONET 2019 software: \url{http://www.whonet.org/software.html}
#'
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
#' @inheritSection WHOCC WHOCC
#' @inheritSection AMR Read more on our website!
#' @seealso \code{\link{microorganisms}}
# use this later to further fill AMR::antibiotics
# drug <- "Ciprofloxacin"
# url <- xml2::read_html(paste0("https://www.ncbi.nlm.nih.gov/pccompound?term=", drug)) %>%
# html_nodes(".rslt") %>%
# .[[1]] %>%
# html_nodes(".title a") %>%
# html_attr("href") %>%
# gsub("/compound/", "/rest/pug_view/data/compound/", ., fixed = TRUE) %>%
# paste0("/XML/?response_type=display")
# synonyms <- url %>%
# read_xml() %>%
# xml_contents() %>% .[[6]] %>%
# xml_contents() %>% .[[8]] %>%
# xml_contents() %>% .[[3]] %>%
# xml_contents() %>% .[[3]] %>%
# xml_contents() %>%
# paste() %>%
# .[. %like% "StringValueList"] %>%
# gsub("[</]+StringValueList[>]", "", .)
# last two columns created with:
# antibiotics %>%
# mutate(useful_gramnegative =
# if_else(
# atc_group1 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' |
# atc_group2 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' |
# official %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)',
# FALSE,
# NA
# ),
# useful_grampositive =
# if_else(
# atc_group1 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' |
# atc_group2 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' |
# official %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)',
# FALSE,
# NA
# )
# )
#
# ADD NEW TRADE NAMES FROM OTHER DATAFRAME
# antibiotics_add_to_property <- function(ab_df, atc, property, value) {
# if (length(atc) > 1L) {
# stop("only one atc at a time")
# }
# if (!property %in% c("abbr", "trade_name")) {
# stop("only possible for abbr and trade_name")
# }
#
# value <- gsub(ab_df[which(ab_df$atc == atc),] %>% pull("official"), "", value, fixed = TRUE)
# value <- gsub("||", "|", value, fixed = TRUE)
# value <- gsub("[äáàâ]", "a", value)
# value <- gsub("[ëéèê]", "e", value)
# value <- gsub("[ïíìî]", "i", value)
# value <- gsub("[öóòô]", "o", value)
# value <- gsub("[üúùû]", "u", value)
# if (!atc %in% ab_df$atc) {
# message("SKIPPING - UNKNOWN ATC: ", atc)
# }
# if (is.na(value)) {
# message("SKIPPING - VALUE MISSES: ", atc)
# }
# if (atc %in% ab_df$atc & !is.na(value)) {
# current <- ab_df[which(ab_df$atc == atc),] %>% pull(property)
# if (!is.na(current)) {
# value <- paste(current, value, sep = "|")
# }
# value <- strsplit(value, "|", fixed = TRUE) %>% unlist() %>% unique() %>% paste(collapse = "|")
# value <- gsub("||", "|", value, fixed = TRUE)
# # print(value)
# ab_df[which(ab_df$atc == atc), property] <- value
# message("Added ", value, " to ", ab_official(atc), " (", atc, ", ", ab_certe(atc), ")")
# }
# ab_df
# }
#
"antibiotics"
#' Data set with ~65,000 microorganisms
@ -262,6 +183,24 @@ catalogue_of_life <- list( @@ -262,6 +183,24 @@ catalogue_of_life <- list(
#' @inheritSection AMR Read more on our website!
"WHONET"
#' Data set for RSI interpretation
#'
#' Data set to interpret MIC and disk diffusion to RSI values. Included guidelines are CLSI (2011-2019) and EUCAST (2011-2019). Use \code{\link{as.rsi}} to transform MICs or disks measurements to RSI values.
#' @format A \code{\link{data.frame}} with 11,559 observations and 9 variables:
#' \describe{
#' \item{\code{guideline}}{Name of the guideline}
#' \item{\code{mo}}{Microbial ID, see \code{\link{as.mo}}}
#' \item{\code{ab}}{Antibiotic ID, see \code{\link{as.ab}}}
#' \item{\code{ref_tbl}}{Info about where the guideline rule can be found}
#' \item{\code{S_mic}}{Lowest MIC value that leads to "S"}
#' \item{\code{R_mic}}{Highest MIC value that leads to "R"}
#' \item{\code{dose_disk}}{Dose of the used disk diffusion method}
#' \item{\code{S_disk}}{Lowest number of millimeters that leads to "S"}
#' \item{\code{R_disk}}{Highest number of millimeters that leads to "R"}
#' }
#' @inheritSection AMR Read more on our website!
"rsi_translation"
# transforms data set to data.frame with only ASCII values, to comply with CRAN policies
dataset_UTF8_to_ASCII <- function(df) {
trans <- function(vect) {
@ -270,14 +209,21 @@ dataset_UTF8_to_ASCII <- function(df) { @@ -270,14 +209,21 @@ dataset_UTF8_to_ASCII <- function(df) {
df <- as.data.frame(df, stringsAsFactors = FALSE)
for (i in 1:NCOL(df)) {
col <- df[, i]
if (is.factor(col)) {
levels(col) <- trans(levels(col))
} else if (is.character(col)) {
col <- trans(col)
if (is.list(col)) {
for (j in 1:length(col)) {
col[[j]] <- trans(col[[j]])
}
df[, i] <- list(col)
} else {
col
if (is.factor(col)) {
levels(col) <- trans(levels(col))
} else if (is.character(col)) {
col <- trans(col)
} else {
col
}
df[, i] <- col
}
df[, i] <- col
}
df
}

64
R/deprecated.R

@ -49,71 +49,49 @@ ratio <- function(x, ratio) { @@ -49,71 +49,49 @@ ratio <- function(x, ratio) {
#' @rdname AMR-deprecated
#' @export
ab_property <- function(...) {
.Deprecated(new = "atc_property", package = "AMR")
atc_property(...)
abname <- function(...) {
.Deprecated("ab_name", package = "AMR")
ab_name(...)
}
#' @rdname AMR-deprecated
#' @export
ab_atc <- function(...) {
.Deprecated(new = "as.atc", package = "AMR")
as.atc(...)
atc_property <- function(...) {
.Deprecated("ab_property", package = "AMR")
ab_property(...)
}
#' @rdname AMR-deprecated
#' @export
ab_official <- function(...) {
.Deprecated(new = "atc_official", package = "AMR")
atc_official(...)
}
#' @rdname AMR-deprecated
#' @export
ab_name <- function(...) {
.Deprecated(new = "atc_name", package = "AMR")
atc_name(...)
atc_official <- function(...) {
.Deprecated("ab_name", package = "AMR