diff --git a/DESCRIPTION b/DESCRIPTION
index 86e3b5d9..6c9cfd67 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: AMR
-Version: 1.6.0.9014
-Date: 2021-04-30
+Version: 1.6.0.9015
+Date: 2021-05-03
Title: Antimicrobial Resistance Data Analysis
Authors@R: c(
person(role = c("aut", "cre"),
diff --git a/NAMESPACE b/NAMESPACE
index abf29a54..2c00a467 100755
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -237,6 +237,8 @@ export(is.mo)
export(is.rsi)
export(is.rsi.eligible)
export(is_new_episode)
+export(italicise_taxonomy)
+export(italicize_taxonomy)
export(key_antibiotics)
export(key_antibiotics_equal)
export(key_antimicrobials)
diff --git a/NEWS.md b/NEWS.md
index fc558bef..2fb43dee 100755
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,8 +1,9 @@
-# `AMR` 1.6.0.9014
-## Last updated: 30 April 2021
+# `AMR` 1.6.0.9015
+## Last updated: 3 May 2021
### New
* Function `custom_eucast_rules()` that brings support for custom AMR rules in `eucast_rules()`
+* Function `italicise_taxonomy()` to make taxonomic names within a string italic, with support for markdown and ANSI
* Support for all four methods to determine first isolates as summarised by Hindler *et al* (doi: [10.1086/511864](https://doi.org/10.1086/511864)): isolate-based, patient-based, episode-based and phenotype-based. The last method is now the default.
* The `first_isolate()` function gained the argument `method` that has to be "phenotype-based", "episode-based", "patient-based", or "isolate-based". The old behaviour is equal to "episode-based". The new default is "phenotype-based" if antimicrobial test results are available, and "episode-based" otherwise. This new default will yield slightly more isolates for selection (which is a good thing).
* Since fungal isolates can also be selected, the functions `key_antibiotics()` and `key_antibiotics_equal()` are now deprecated in favour of the `key_antimicrobials()` and `antimicrobial_equal()` functions. Also, the new `all_antimicrobials()` function works like the old `key_antibiotics()` function, but includes any column with antimicrobial test results. Using `key_antimicrobials()` still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new `antifungal` argument to set antifungal agents (antimycotics).
diff --git a/R/ab.R b/R/ab.R
index 82c81235..fe4fc61b 100755
--- a/R/ab.R
+++ b/R/ab.R
@@ -477,7 +477,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
if (length(x_unknown) > 0 & fast_mode == FALSE) {
warning_("These values could not be coerced to a valid antimicrobial ID: ",
vector_and(x_unknown), ".",
- ".",
call = FALSE)
}
diff --git a/R/custom_eucast_rules.R b/R/custom_eucast_rules.R
index 4ba6c372..600d9b9e 100644
--- a/R/custom_eucast_rules.R
+++ b/R/custom_eucast_rules.R
@@ -93,6 +93,7 @@
#'
#' `r paste0(" * ", sapply(DEFINED_AB_GROUPS, function(x) paste0("``", tolower(x), "``\\cr(", paste0(sort(ab_name(eval(parse(text = x), envir = asNamespace("AMR")), language = NULL, tolower = TRUE)), collapse = ", "), ")"), USE.NAMES = FALSE), "\n", collapse = "")`
#' @returns A [list] containing the custom rules
+#' @inheritSection AMR Read more on Our Website!
#' @export
#' @examples
#' x <- custom_eucast_rules(AMC == "R" & genus == "Klebsiella" ~ aminopenicillins == "R",
diff --git a/R/eucast_rules.R b/R/eucast_rules.R
index 1b909701..52270a80 100755
--- a/R/eucast_rules.R
+++ b/R/eucast_rules.R
@@ -65,7 +65,6 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' @details
#' **Note:** This function does not translate MIC values to RSI values. Use [as.rsi()] for that. \cr
#' **Note:** When ampicillin (AMP, J01CA01) is not available but amoxicillin (AMX, J01CA04) is, the latter will be used for all rules where there is a dependency on ampicillin. These drugs are interchangeable when it comes to expression of antimicrobial resistance. \cr
-
#'
#' The file containing all EUCAST rules is located here: . **Note:** Old taxonomic names are replaced with the current taxonomy where applicable. For example, *Ochrobactrum anthropi* was renamed to *Brucella anthropi* in 2020; the original EUCAST rules v3.1 and v3.2 did not yet contain this new taxonomic name. The file used as input for this `AMR` package contains the taxonomy updated until [`r CATALOGUE_OF_LIFE$yearmonth_LPSN`][catalogue_of_life()].
#'
@@ -322,17 +321,6 @@ eucast_rules <- function(x,
}
cols_ab[match(x_new, names(cols_ab))]
}
- markup_italics_where_needed <- function(x) {
- # returns names found in family, genus or species as italics
- if (!has_colour()) {
- return(x)
- }
- x <- unlist(strsplit(x, " "))
- ind <- gsub("[)(:]", "", x) %in% c(MO_lookup[which(MO_lookup$rank %in% c("family", "genus")), ]$fullname,
- MO_lookup[which(MO_lookup$rank == "species"), ]$species)
- x[ind] <- font_italic(x[ind], collapse = NULL)
- paste(x, collapse = " ")
- }
get_antibiotic_names <- function(x) {
x <- x %pm>%
strsplit(",") %pm>%
@@ -343,6 +331,7 @@ eucast_rules <- function(x,
paste(collapse = ", ")
x <- gsub("_", " ", x, fixed = TRUE)
x <- gsub("except CAZ", paste("except", ab_name("CAZ", language = NULL, tolower = TRUE)), x, fixed = TRUE)
+ x <- gsub("except TGC", paste("except", ab_name("TGC", language = NULL, tolower = TRUE)), x, fixed = TRUE)
x <- gsub("cephalosporins (1st|2nd|3rd|4th|5th)", "cephalosporins (\\1 gen.)", x)
x
}
@@ -655,9 +644,10 @@ eucast_rules <- function(x,
# Print rule -------------------------------------------------------------
if (rule_current != rule_previous) {
# is new rule within group, print its name
- cat(markup_italics_where_needed(word_wrap(rule_current,
- width = getOption("width") - 30,
- extra_indent = 6)))
+ cat(italicise_taxonomy(word_wrap(rule_current,
+ width = getOption("width") - 30,
+ extra_indent = 6),
+ type = "ansi"))
warned <- FALSE
}
}
@@ -795,9 +785,10 @@ eucast_rules <- function(x,
get_antibiotic_names(cols))
if (info == TRUE) {
# print rule
- cat(markup_italics_where_needed(word_wrap(format_custom_query_rule(rule$query, colours = FALSE),
- width = getOption("width") - 30,
- extra_indent = 6)))
+ cat(italicise_taxonomy(word_wrap(format_custom_query_rule(rule$query, colours = FALSE),
+ width = getOption("width") - 30,
+ extra_indent = 6),
+ type = "ansi"))
warned <- FALSE
}
run_changes <- edit_rsi(x = x,
diff --git a/R/italicise_taxonomy.R b/R/italicise_taxonomy.R
new file mode 100644
index 00000000..c549b3de
--- /dev/null
+++ b/R/italicise_taxonomy.R
@@ -0,0 +1,119 @@
+# ==================================================================== #
+# TITLE #
+# Antimicrobial Resistance (AMR) Data Analysis for R #
+# #
+# SOURCE #
+# https://github.com/msberends/AMR #
+# #
+# LICENCE #
+# (c) 2018-2021 Berends MS, Luz CF et al. #
+# Developed at the University of Groningen, the Netherlands, in #
+# collaboration with non-profit organisations Certe Medical #
+# Diagnostics & Advice, and University Medical Center Groningen. #
+# #
+# 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. #
+# We created this package for both routine data analysis and academic #
+# research and it was publicly released in the hope that it will be #
+# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
+# #
+# Visit our website for the full manual and a complete tutorial about #
+# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
+# ==================================================================== #
+
+#' Italicise Taxonomic Families, Genera, Species, Subspecies
+#'
+#' According to the binomial nomenclature, the lowest four taxonomic levels (family, genus, species, subspecies) should be printed in italic. This function finds taxonomic names within strings and makes them italic.
+#' @inheritSection lifecycle Maturing Lifecycle
+#' @param string a character (vector)
+#' @param type type of conversion of the taxonomic names, either "markdown" or "ansi", see *Details*
+#' @details
+#' This function finds the taxonomic names and makes them italic based on the [microorganisms] data set.
+#'
+#' The taxonomic names can be italicised using markdown (the default) by adding `*` before and after the taxonomic names, or using ANSI colours by adding `\033[3m` before and `\033[23m` after the taxonomic names. If multiple ANSI colours are not available, no conversion will occur.
+#'
+#' This function also supports abbreviation of the genus if it is followed by a species, such as "E. coli" and "K. pneumoniae ozaenae".
+#' @inheritSection AMR Read more on Our Website!
+#' @export
+#' @examples
+#' italicise_taxonomy("An overview of Staphylococcus aureus isolates")
+#' italicise_taxonomy("An overview of S. aureus isolates")
+#'
+#' cat(italicise_taxonomy("An overview of S. aureus isolates", type = "ansi"))
+italicise_taxonomy <- function(string, type = c("markdown", "ansi")) {
+ if (missing(type)) {
+ type <- "markdown"
+ }
+ meet_criteria(string, allow_class = "character")
+ meet_criteria(type, allow_class = "character", has_length = 1, is_in = c("markdown", "ansi"))
+
+ if (type == "markdown") {
+ before <- "*"
+ after <- "*"
+ } else if (type == "ansi") {
+ if (!has_colour()) {
+ return(string)
+ }
+ before <- "\033[3m"
+ after <- "\033[23m"
+ }
+
+ vapply(FUN.VALUE = character(1),
+ string,
+ function(s) {
+ s_split <- unlist(strsplit(s, " "))
+
+ search_strings <- gsub("[^a-zA-Z-]", "", s_split)
+
+ ind_species <- search_strings != "" &
+ search_strings %in% MO_lookup[which(MO_lookup$rank %in% c("family",
+ "genus",
+ "species",
+ "subspecies",
+ "infraspecies",
+ "subsp.")),
+ "species",
+ drop = TRUE]
+
+ ind_fullname <- search_strings != "" &
+ search_strings %in% c(MO_lookup[which(MO_lookup$rank %in% c("family",
+ "genus",
+ "species",
+ "subspecies",
+ "infraspecies",
+ "subsp.")),
+ "fullname",
+ drop = TRUE],
+ MO_lookup[which(MO_lookup$rank %in% c("family",
+ "genus",
+ "species",
+ "subspecies",
+ "infraspecies",
+ "subsp.")),
+ "subspecies",
+ drop = TRUE])
+
+ # also support E. coli, add "E." to indices
+ has_previous_genera_abbr <- s_split[which(ind_species) - 1] %like_case% "^[A-Z][.]?$"
+ ind_species <- c(which(ind_species), which(ind_species)[has_previous_genera_abbr] - 1)
+
+ ind <- c(ind_species, which(ind_fullname))
+
+ s_split[ind] <- paste0(before, s_split[ind], after)
+ s_paste <- paste(s_split, collapse = " ")
+
+ # clean up a bit
+ s_paste <- gsub(paste0(after, " ", before), " ", s_paste, fixed = TRUE)
+
+ s_paste
+ },
+ USE.NAMES = FALSE)
+}
+
+#' @rdname italicise_taxonomy
+#' @export
+italicize_taxonomy <- function(string, type = c("markdown", "ansi")) {
+ italicise(string = string, type = type)
+}
diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz
index 9edabfab..706ce19f 100644
Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ
diff --git a/docs/404.html b/docs/404.html
index 57f35341..5e772d39 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.6.0.9014
+ 1.6.0.9015
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index f2a4ca14..2b45ddf4 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.6.0.9014
+ 1.6.0.9015
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html
index 0fa35575..0417b77d 100644
--- a/docs/articles/benchmarks.html
+++ b/docs/articles/benchmarks.html
@@ -39,7 +39,7 @@
AMR (for R)
- 1.6.0.9011
+ 1.6.0.9015
@@ -47,14 +47,14 @@