diff --git a/DESCRIPTION b/DESCRIPTION index 38933095..2e6fe735 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.7.1.9013 -Date: 2021-07-04 +Version: 1.7.1.9014 +Date: 2021-07-06 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index 50e584a2..861eed8f 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -93,6 +93,7 @@ S3method(exp,mic) S3method(expm1,mic) S3method(floor,mic) S3method(format,bug_drug_combinations) +S3method(format,taxonomic_name) S3method(gamma,mic) S3method(hist,mic) S3method(kurtosis,data.frame) @@ -127,7 +128,12 @@ S3method(print,taxonomic_name) S3method(prod,mic) S3method(quantile,mic) S3method(range,mic) +S3method(rep,ab) +S3method(rep,disk) +S3method(rep,mic) S3method(rep,mo) +S3method(rep,rsi) +S3method(rep,taxonomic_name) S3method(round,mic) S3method(sign,mic) S3method(signif,mic) diff --git a/NEWS.md b/NEWS.md index 18bdce54..f6ecc759 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# `AMR` 1.7.1.9013 -## Last updated: 4 July 2021 +# `AMR` 1.7.1.9014 +## Last updated: 6 July 2021 ### Changed * Antibiotic class selectors (see `ab_class()`) diff --git a/R/ab.R b/R/ab.R index c99de647..05a94cde 100755 --- a/R/ab.R +++ b/R/ab.R @@ -580,6 +580,15 @@ unique.ab <- function(x, incomparables = FALSE, ...) { y } +#' @method rep ab +#' @export +#' @noRd +rep.ab <- function(x, ...) { + y <- NextMethod() + attributes(y) <- attributes(x) + y +} + generalise_antibiotic_name <- function(x) { x <- toupper(x) # remove suffices diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index 89592c5f..05c24384 100644 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -113,7 +113,7 @@ bug_drug_combinations <- function(x, data.frame(S = m["S", ], I = m["I", ], R = m["R", ], stringsAsFactors = FALSE) }) merged <- do.call(rbind, pivot) - out_group <- data.frame(mo = unique_mo[i], + out_group <- data.frame(mo = rep(unique_mo[i], NROW(merged)), ab = rownames(merged), S = merged$S, I = merged$I, diff --git a/R/disk.R b/R/disk.R index 0f901bd8..064b83d8 100644 --- a/R/disk.R +++ b/R/disk.R @@ -195,6 +195,15 @@ unique.disk <- function(x, incomparables = FALSE, ...) { y } +#' @method rep disk +#' @export +#' @noRd +rep.disk <- function(x, ...) { + y <- NextMethod() + attributes(y) <- attributes(x) + y +} + # will be exported using s3_register() in R/zzz.R get_skimmers.disk <- function(column) { skimr::sfl( diff --git a/R/mic.R b/R/mic.R index c339c9ea..a944e7c1 100755 --- a/R/mic.R +++ b/R/mic.R @@ -320,6 +320,15 @@ unique.mic <- function(x, incomparables = FALSE, ...) { y } +#' @method rep mic +#' @export +#' @noRd +rep.mic <- function(x, ...) { + y <- NextMethod() + attributes(y) <- attributes(x) + y +} + #' @method sort mic #' @export #' @noRd @@ -337,7 +346,7 @@ sort.mic <- function(x, decreasing = FALSE, ...) { #' @export #' @noRd hist.mic <- function(x, ...) { - warning_("Use `plot()` or `ggplot()` for optimal plotting of MIC values", call = FALSE) + warning_("Use `plot()` or ggplot2's `autoplot()` for optimal plotting of MIC values", call = FALSE) hist(log2(x)) } diff --git a/R/mo_property.R b/R/mo_property.R index 17226ae6..5cb37cbb 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -48,7 +48,7 @@ #' #' Intrinsic resistance - [mo_is_intrinsic_resistant()] - will be determined based on the [intrinsic_resistant] data set, which is based on `r format_eucast_version_nr(3.2)`. The [mo_is_intrinsic_resistant()] functions can be vectorised over arguments `x` (input for microorganisms) and over `ab` (input for antibiotics). #' -#' The functions [mo_family()], [mo_genus()], [mo_name()], [mo_fullname()] and [mo_shortname()] are returned with an additional class `taxonomic_name`, which allows italic printing in [tibbles][tibble::tibble()]. +#' The functions [mo_family()], [mo_genus()], [mo_name()], [mo_fullname()] and [mo_shortname()] are returned with an additional class `taxonomic_name`, which allows italic printing in [tibbles][tibble::tibble()] and markdown tables such as with [knitr::kable()]. #' #' All output [will be translated][translate] where possible. #' @@ -786,9 +786,9 @@ print.taxonomic_name <- function(x, ...) { as.data.frame.taxonomic_name <- function(x, ...) { nm <- deparse1(substitute(x)) if (!"nm" %in% names(list(...))) { - as.data.frame(unclass(x), ..., nm = nm) + as.data.frame.vector(x, ..., nm = nm) } else { - as.data.frame(unclass(x), ...) + as.data.frame.vector(x, ...) } } @@ -801,12 +801,27 @@ type_sum.taxonomic_name <- function(x, ...) { pillar_shaft.taxonomic_name <- function(x, ...) { out <- format(x) hits <- tolower(x) %in% MO_lookup$fullname_lower | tolower(gsub("[^a-zA-Z ]", "", x)) %in% c(MO_lookup$g_species) - # grey out the kingdom (part until first "_") out[hits] <- font_italic(x[hits], collapse = NULL) out[is.na(x)] <- font_na(out[is.na(x)], collapse = NULL) create_pillar_column(out, align = "left") } +#' @method format taxonomic_name +#' @export +#' @noRd +format.taxonomic_name <- function(x, ...) { + # format only in case of markdown knitting + x <- unclass(x) + if (any(as.character(sys.calls()) %like% "(^|:| )kable\\(") || + tryCatch(!is.null(knitr::opts_knit$get("out.format")), error = function(e) FALSE) || + tryCatch(isTRUE(getOption('knitr.in.progress')), error = function(e) FALSE)) { + # perhaps this could be extended or better specified in the future? + hits <- tolower(x) %in% MO_lookup$fullname_lower | tolower(gsub("[^a-zA-Z ]", "", x)) %in% c(MO_lookup$g_species) + x[hits] <- paste0("*", x[hits], "*") + } + x +} + #' @method [ taxonomic_name #' @export #' @noRd @@ -856,3 +871,12 @@ unique.taxonomic_name <- function(x, incomparables = FALSE, ...) { attributes(y) <- attributes(x) y } + +#' @method rep taxonomic_name +#' @export +#' @noRd +rep.taxonomic_name <- function(x, ...) { + y <- NextMethod() + attributes(y) <- attributes(x) + y +} diff --git a/R/rsi.R b/R/rsi.R index ba20c141..12982cdc 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -1054,6 +1054,15 @@ unique.rsi <- function(x, incomparables = FALSE, ...) { y } +#' @method rep rsi +#' @export +#' @noRd +rep.rsi <- function(x, ...) { + y <- NextMethod() + attributes(y) <- attributes(x) + y +} + check_reference_data <- function(reference_data) { if (!identical(reference_data, AMR::rsi_translation)) { class_rsi <- vapply(FUN.VALUE = character(1), rsi_translation, function(x) paste0("<", class(x), ">", collapse = " and ")) diff --git a/R/sysdata.rda b/R/sysdata.rda index 8ab09c8f..56276449 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 3ca36cf9..cfa3954f 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/data-raw/translations.tsv b/data-raw/translations.tsv index 96d76f61..29e65e96 100644 --- a/data-raw/translations.tsv +++ b/data-raw/translations.tsv @@ -18,17 +18,17 @@ unknown subspecies TRUE TRUE FALSE TRUE unbekannte Unterart onbekende ondersoort unknown rank TRUE TRUE FALSE TRUE unbekannter Rang onbekende rang rango desconocido grado sconosciuto rang inconnu classificação desconhecido CoNS FALSE TRUE FALSE TRUE KNS CNS SCN CoPS FALSE TRUE FALSE TRUE KPS CPS SCP -Gram-negative TRUE TRUE FALSE FALSE Gramnegativ Gram-negatief Gram negativo Gram negativo Gram négatif Gram negativo -Gram-positive TRUE TRUE FALSE FALSE Grampositiv Gram-positief Gram positivo Gram positivo Gram positif Gram positivo -^Bacteria$ TRUE TRUE FALSE FALSE Bakterien Bacteriën Bacterias Batteri Bactéries Bactérias -^Fungi$ TRUE TRUE FALSE FALSE Pilze Schimmels Hongos Funghi Champignons Fungos -^Yeasts$ TRUE TRUE FALSE FALSE Hefen Gisten Levaduras Lieviti Levures Leveduras -^Protozoa$ TRUE TRUE FALSE FALSE Protozoen Protozoën Protozoarios Protozoi Protozoaires Protozoários -biogroup TRUE TRUE FALSE FALSE Biogruppe biogroep biogrupo biogruppo biogroupe biogrupo -biotype TRUE TRUE FALSE FALSE Biotyp biotipo biotipo biótipo -vegetative TRUE TRUE FALSE FALSE vegetativ vegetatief vegetativo vegetativo végétatif vegetativo -([([ ]*?)group TRUE TRUE FALSE FALSE \\1Gruppe \\1groep \\1grupo \\1gruppo \\1groupe \\1grupo -([([ ]*?)Group TRUE TRUE FALSE FALSE \\1Gruppe \\1Groep \\1Grupo \\1Gruppo \\1Groupe \\1Grupo +Gram-negative TRUE TRUE FALSE TRUE Gramnegativ Gram-negatief Gram negativo Gram negativo Gram négatif Gram negativo +Gram-positive TRUE TRUE FALSE TRUE Grampositiv Gram-positief Gram positivo Gram positivo Gram positif Gram positivo +^Bacteria$ TRUE TRUE FALSE TRUE Bakterien Bacteriën Bacterias Batteri Bactéries Bactérias +^Fungi$ TRUE TRUE FALSE TRUE Pilze Schimmels Hongos Funghi Champignons Fungos +^Yeasts$ TRUE TRUE FALSE TRUE Hefen Gisten Levaduras Lieviti Levures Leveduras +^Protozoa$ TRUE TRUE FALSE TRUE Protozoen Protozoën Protozoarios Protozoi Protozoaires Protozoários +biogroup TRUE TRUE FALSE TRUE Biogruppe biogroep biogrupo biogruppo biogroupe biogrupo +biotype TRUE TRUE FALSE TRUE Biotyp biotipo biotipo biótipo +vegetative TRUE TRUE FALSE TRUE vegetativ vegetatief vegetativo vegetativo végétatif vegetativo +([([ ]*?)group TRUE TRUE FALSE TRUE \\1Gruppe \\1groep \\1grupo \\1gruppo \\1groupe \\1grupo +([([ ]*?)Group TRUE TRUE FALSE TRUE \\1Gruppe \\1Groep \\1Grupo \\1Gruppo \\1Groupe \\1Grupo no .*growth TRUE FALSE FALSE FALSE keine? .*wachstum geen .*groei no .*crecimientonon sem .*crescimento pas .*croissance sem .*crescimento no|not TRUE FALSE FALSE FALSE keine? geen|niet no|sin sem non sem Susceptible TRUE FALSE FALSE FALSE Empfindlich Gevoelig Susceptible diff --git a/docs/404.html b/docs/404.html index bd5ebcce..f2c66511 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 04ce1862..6a916de0 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 5fe8eef4..3e3dac10 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -39,7 +39,7 @@ @@ -193,7 +193,7 @@vignettes/AMR.Rmd
AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 04 July 2021.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 06 July 2021.
So only 53.5% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
So only 53.3% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
data_1st <- data %>%
filter(first == TRUE)
data_1st <- data %>%
filter_first_isolate()
So we end up with 10,702 isolates for analysis. Now our data looks like:
+So we end up with 10,656 isolates for analysis. Now our data looks like:
head(data_1st)
1 | -2016-09-28 | -A1 | -Hospital A | -B_ESCHR_COLI | -S | -S | -S | -R | -M | -Gram-negative | -Escherichia | -coli | -TRUE | -|||||
2 | -2012-09-28 | -J9 | +2011-09-24 | +D2 | Hospital A | B_STRPT_PNMN | -S | -S | +R | +R | S | R | M | Gram-positive | -Streptococcus | +Streptococcus | pneumoniae | TRUE |
5 | -2016-12-08 | -B10 | -Hospital A | -B_ESCHR_COLI | -S | -S | -S | -S | -M | -Gram-negative | -Escherichia | -coli | -TRUE | -|||||
7 | -2015-04-29 | -W8 | -Hospital A | -B_ESCHR_COLI | -R | -S | -S | -R | -F | -Gram-negative | -Escherichia | -coli | -TRUE | -|||||
8 | -2010-06-19 | -Q5 | +3 | +2014-06-20 | +Z9 | Hospital C | B_STPHY_AURS | S | @@ -628,26 +580,74 @@ Longest: 1S | F | Gram-positive | -Staphylococcus | +Staphylococcus | +aureus | +TRUE | +|||
6 | +2016-07-27 | +R6 | +Hospital B | +B_STPHY_AURS | +R | +S | +R | +S | +F | +Gram-positive | +Staphylococcus | aureus | TRUE | |||||
9 | -2010-08-20 | -A8 | -Hospital B | +7 | +2011-07-24 | +W2 | +Hospital A | B_ESCHR_COLI | -I | +R | +R | +S | +R | +F | +Gram-negative | +Escherichia | +coli | +TRUE | +
9 | +2012-01-12 | +K9 | +Hospital C | +B_ESCHR_COLI | +S | S | S | S | M | Gram-negative | -Escherichia | +Escherichia | coli | TRUE | ||||
11 | +2013-03-11 | +B6 | +Hospital D | +B_KLBSL_PNMN | +R | +S | +R | +S | +M | +Gram-negative | +Klebsiella | +pneumoniae | +TRUE | +
Time for the analysis!
@@ -669,8 +669,8 @@ Longest: 1data_1st %>% freq(genus, species)
Frequency table
Class: character
-Length: 10,702
-Available: 10,702 (100.0%, NA: 0 = 0.0%)
+Length: 10,656
+Available: 10,656 (100.0%, NA: 0 = 0.0%)
Unique: 4
Shortest: 16
Longest: 24
As per the EUCAST guideline of 2019, we calculate resistance as the proportion of R (proportion_R()
, equal to resistance()
) and susceptibility as the proportion of S and I (proportion_SI()
, equal to susceptibility()
). These functions can be used on their own:
data_1st %>% resistance(AMX)
-# [1] 0.5418613
Or can be used in conjunction with group_by()
and summarise()
, both from the dplyr
package:
data_1st %>%
@@ -991,19 +991,19 @@ Longest: 24
Hospital A
-0.5276730
+0.5512301
Hospital B
-0.5422819
+0.5383792
Hospital C
-0.5609308
+0.5587121
Hospital D
-0.5475970
+0.5329877
@@ -1022,23 +1022,23 @@ Longest: 24
Hospital A
-0.5276730
-3180
+0.5512301
+3211
Hospital B
-0.5422819
-3725
+0.5383792
+3739
Hospital C
-0.5609308
-1633
+0.5587121
+1584
Hospital D
-0.5475970
-2164
+0.5329877
+2122
@@ -1058,28 +1058,28 @@ Longest: 24
-Escherichia
-0.7661446
-0.8766359
-0.9759708
+Escherichia
+0.7581475
+0.8743568
+0.9762007
-Klebsiella
-0.8106756
-0.8907423
-0.9833194
+Klebsiella
+0.8323353
+0.8913601
+0.9760479
-Staphylococcus
-0.7942158
-0.8924731
-0.9818317
+Staphylococcus
+0.7945055
+0.8937729
+0.9831502
-Streptococcus
-0.5501166
+Streptococcus
+0.5351171
0.0000000
-0.5501166
+0.5351171
@@ -1104,23 +1104,23 @@ Longest: 24
Hospital A
-52.8%
-26.0%
+55.1%
+27.0%
Hospital B
-54.2%
-26.5%
+53.8%
+26.2%
Hospital C
-56.1%
-26.7%
+55.9%
+27.7%
Hospital D
-54.8%
-27.1%
+53.3%
+27.0%
@@ -1204,19 +1204,16 @@ Longest: 24
mic_values <- random_mic(size = 100)
mic_values
# Class <mic>
-# [1] 32 2 4 >=128 8 1 <=0.0625 >=128
-# [9] <=0.0625 <=0.0625 64 2 0.125 8 <=0.0625 0.125
-# [17] 64 >=128 >=128 16 32 2 8 32
-# [25] 0.5 0.5 16 8 >=128 2 16 >=128
-# [33] 0.5 2 64 64 16 <=0.0625 1 4
-# [41] 0.125 16 <=0.0625 0.125 0.25 0.125 8 4
-# [49] <=0.0625 32 1 <=0.0625 1 0.5 0.5 64
-# [57] 2 <=0.0625 8 <=0.0625 32 4 32 64
-# [65] 0.125 0.5 4 0.125 0.5 4 8 8
-# [73] 0.5 64 >=128 32 0.25 32 4 4
-# [81] 0.25 64 0.125 <=0.0625 2 1 2 <=0.0625
-# [89] 1 >=128 0.125 2 64 16 1 64
-# [97] 32 64 0.125 <=0.0625
# base R:
plot(mic_values)
# base R:
plot(disk_values, mo = "E. coli", ab = "cipro")
vignettes/datasets.Rmd
datasets.Rmd
NEWS.md
- AMR
1.7.1.9013AMR
1.7.1.9014The Gram stain - mo_gramstain()
- will be determined based on the taxonomic kingdom and phylum. According to Cavalier-Smith (2002, PMID 11837318), who defined subkingdoms Negibacteria and Posibacteria, only these phyla are Posibacteria: Actinobacteria, Chloroflexi, Firmicutes and Tenericutes. These bacteria are considered Gram-positive - all other bacteria are considered Gram-negative. Species outside the kingdom of Bacteria will return a value NA
. Functions mo_is_gram_negative()
and mo_is_gram_positive()
always return TRUE
or FALSE
(except when the input is NA
or the MO code is UNKNOWN
), thus always return FALSE
for species outside the taxonomic kingdom of Bacteria.
Determination of yeasts - mo_is_yeast()
- will be based on the taxonomic kingdom and class. Budding yeasts are fungi of the phylum Ascomycetes, class Saccharomycetes (also called Hemiascomycetes). True yeasts are aggregated into the underlying order Saccharomycetales. Thus, for all microorganisms that are fungi and member of the taxonomic class Saccharomycetes, the function will return TRUE
. It returns FALSE
otherwise (except when the input is NA
or the MO code is UNKNOWN
).
Intrinsic resistance - mo_is_intrinsic_resistant()
- will be determined based on the intrinsic_resistant data set, which is based on 'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.2 (2020). The mo_is_intrinsic_resistant()
functions can be vectorised over arguments x
(input for microorganisms) and over ab
(input for antibiotics).
The functions mo_family()
, mo_genus()
, mo_name()
, mo_fullname()
and mo_shortname()
are returned with an additional class taxonomic_name
, which allows italic printing in tibbles.
The functions mo_family()
, mo_genus()
, mo_name()
, mo_fullname()
and mo_shortname()
are returned with an additional class taxonomic_name
, which allows italic printing in tibbles and markdown tables such as with knitr::kable()
.
All output will be translated where possible.
The function mo_url()
will return the direct URL to the online database entry, which also shows the scientific reference of the concerned species.
SNOMED codes - mo_snomed()
- are from the US Edition of SNOMED CT from 1 September 2020. See Source and the microorganisms data set for more info.