From 43c638d1220d5beca4c6cff612b865e1984e151b Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Mon, 10 Oct 2022 10:12:08 +0200 Subject: [PATCH] add `mo_current()` --- DESCRIPTION | 4 ++-- NAMESPACE | 1 + NEWS.md | 3 ++- R/mo.R | 9 +++++++-- R/mo_property.R | 16 ++++++++++++++-- inst/tinytest/test-mo_property.R | 5 +++++ man/mo_property.Rd | 7 ++++++- 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 701cda35..d5494513 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.8.2.9007 -Date: 2022-10-06 +Version: 1.8.2.9008 +Date: 2022-10-10 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NAMESPACE b/NAMESPACE index 03a2dbe0..fa976b43 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -267,6 +267,7 @@ export(mean_amr_distance) export(mo_authors) export(mo_class) export(mo_cleaning_regex) +export(mo_current) export(mo_domain) export(mo_failures) export(mo_family) diff --git a/NEWS.md b/NEWS.md index a4955a2a..81c3c809 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9007 +# AMR 1.8.2.9008 This version will eventually become v2.0! We're happy to reach a new major milestone soon! @@ -19,6 +19,7 @@ This version will eventually become v2.0! We're happy to reach a new major miles * Sequential coercion is now extremely fast as results are stored to the package environment, although coercion of unknown values must be run once per session. Previous results can be reset/removed with the new `mo_reset_session()` function. * Function `mean_amr_distance()` to calculate the mean AMR distance. The mean AMR distance is a normalised numeric value to compare AMR test results and can help to identify similar isolates, without comparing antibiograms by hand. * Function `rsi_interpretation_history()` to view the history of previous runs of `as.rsi()`. This returns a 'logbook' with the selected guideline, reference table and specific interpretation of each row in a data set on which `as.rsi()` was run. +* Function `mo_current()` to get the currently valid taxonomic name of a microorganism * Support for `data.frame`-enhancing R packages, more specifically: `data.table::data.table`, `janitor::tabyl`, `tibble::tibble`, and `tsibble::tsibble`. AMR package functions that have a data set as output (such as `rsi_df()` and `bug_drug_combinations()`), will now return the same data type as the input. * All data sets in this package are now exported as `tibble`, instead of base R `data.frame`s. Older R versions are still supported. * Support for the following languages: Chinese, Greek, Japanese, Polish, Turkish and Ukrainian. We are very grateful for the valuable input by our colleagues from other countries. The `AMR` package is now available in 16 languages. diff --git a/R/mo.R b/R/mo.R index 3ea26185..fdce9c75 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1094,14 +1094,19 @@ load_mo_uncertainties <- function(metadata) { AMR_env$mo_uncertainties <- metadata$uncertainties } -synonym_mo_to_accepted_mo <- function(x) { +synonym_mo_to_accepted_mo <- function(x, fill_in_accepted = FALSE) { x_gbif <- AMR::microorganisms$gbif_renamed_to[match(x, AMR::microorganisms$mo)] x_lpsn <- AMR::microorganisms$lpsn_renamed_to[match(x, AMR::microorganisms$mo)] x_gbif[!x_gbif %in% AMR::microorganisms$gbif] <- NA x_lpsn[!x_lpsn %in% AMR::microorganisms$lpsn] <- NA - ifelse(is.na(x_lpsn), + out <- ifelse(is.na(x_lpsn), AMR::microorganisms$mo[match(x_gbif, AMR::microorganisms$gbif)], AMR::microorganisms$mo[match(x_lpsn, AMR::microorganisms$lpsn)] ) + if (isTRUE(fill_in_accepted)) { + x_accepted <- which(AMR::microorganisms$status[match(x, AMR::microorganisms$mo)] == "accepted") + out[x_accepted] <- x[x_accepted] + } + out } diff --git a/R/mo_property.R b/R/mo_property.R index abbf519b..63891798 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -56,13 +56,15 @@ #' 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 version of `r documentation_date(TAXONOMY_VERSION$SNOMED$accessed_date)`. See *Source* and the [microorganisms] data set for more info. +#' +#' Old taxonomic names (so-called 'synonyms') can be retrieved with [mo_synonyms()], the current taxonomic name can be retrieved with [mo_current()]. Both functions return full names. #' @inheritSection mo_matching_score Matching Score for Microorganisms #' @inheritSection as.mo Source #' @rdname mo_property #' @name mo_property #' @return #' - An [integer] in case of [mo_year()] -#' - A [list] in case of [mo_taxonomy()] and [mo_info()] +#' - A [list] in case of [mo_taxonomy()], [mo_synonyms()] and [mo_info()] #' - A named [character] in case of [mo_url()] #' - A [numeric] in case of [mo_snomed()] #' - A [character] in all other cases @@ -672,7 +674,7 @@ mo_synonyms <- function(x, language = get_AMR_locale(), keep_synonyms = getOptio }) if (length(syns) > 1) { - names(syns) <- mo_name(x) + names(syns) <- mo_name(x, language = language) result <- syns } else { result <- unlist(syns) @@ -682,6 +684,16 @@ mo_synonyms <- function(x, language = get_AMR_locale(), keep_synonyms = getOptio result } +#' @rdname mo_property +#' @export +mo_current <- function(x, language = get_AMR_locale(), ...) { + meet_criteria(x, allow_NA = TRUE) + language <- validate_language(language) + x.mo <- suppressWarnings(as.mo(x, keep_synonyms = TRUE, ...)) + out <- synonym_mo_to_accepted_mo(x.mo, fill_in_accepted = TRUE) + mo_name(out, language = language) +} + #' @rdname mo_property #' @export mo_info <- function(x, language = get_AMR_locale(), keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...) { diff --git a/inst/tinytest/test-mo_property.R b/inst/tinytest/test-mo_property.R index 85c80634..4419895d 100644 --- a/inst/tinytest/test-mo_property.R +++ b/inst/tinytest/test-mo_property.R @@ -113,6 +113,11 @@ expect_identical( mo_gbif("Escherichia coli") ) +expect_true("Escherichia blattae" %in% mo_synonyms("Shimwellia blattae")) +expect_true(is.list(mo_synonyms(rep("Shimwellia blattae", 2)))) +expect_identical(mo_current(c("Escherichia blattae", "Escherichia coli")), + c("Shimwellia blattae", "Escherichia coli")) + expect_identical(mo_ref("Chlamydia psittaci"), "Garcia-Lopez et al., 2019") expect_identical(mo_ref("Chlamydophila psittaci", keep_synonyms = TRUE), "Everett et al., 1999") diff --git a/man/mo_property.Rd b/man/mo_property.Rd index 2721cb20..5d30674a 100644 --- a/man/mo_property.Rd +++ b/man/mo_property.Rd @@ -30,6 +30,7 @@ \alias{mo_rank} \alias{mo_taxonomy} \alias{mo_synonyms} +\alias{mo_current} \alias{mo_info} \alias{mo_url} \title{Get Properties of a Microorganism} @@ -231,6 +232,8 @@ mo_synonyms( ... ) +mo_current(x, language = get_AMR_locale(), ...) + mo_info( x, language = get_AMR_locale(), @@ -272,7 +275,7 @@ mo_property( \value{ \itemize{ \item An \link{integer} in case of \code{\link[=mo_year]{mo_year()}} -\item A \link{list} in case of \code{\link[=mo_taxonomy]{mo_taxonomy()}} and \code{\link[=mo_info]{mo_info()}} +\item A \link{list} in case of \code{\link[=mo_taxonomy]{mo_taxonomy()}}, \code{\link[=mo_synonyms]{mo_synonyms()}} and \code{\link[=mo_info]{mo_info()}} \item A named \link{character} in case of \code{\link[=mo_url]{mo_url()}} \item A \link{numeric} in case of \code{\link[=mo_snomed]{mo_snomed()}} \item A \link{character} in all other cases @@ -304,6 +307,8 @@ All output \link[=translate]{will be translated} where possible. The function \code{\link[=mo_url]{mo_url()}} will return the direct URL to the online database entry, which also shows the scientific reference of the concerned species. SNOMED codes - \code{\link[=mo_snomed]{mo_snomed()}} - are from the version of 1 July, 2021. See \emph{Source} and the \link{microorganisms} data set for more info. + +Old taxonomic names (so-called 'synonyms') can be retrieved with \code{\link[=mo_synonyms]{mo_synonyms()}}, the current taxonomic name can be retrieved with \code{\link[=mo_current]{mo_current()}}. Both functions return full names. } \section{Matching Score for Microorganisms}{