diff --git a/DESCRIPTION b/DESCRIPTION index c4969717..a610c6b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9074 -Date: 2019-09-16 +Version: 0.7.1.9075 +Date: 2019-09-18 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), @@ -15,6 +15,8 @@ Authors@R: c( family = "Albers", given = c("Casper", "J."), email = "c.j.albers@rug.nl", comment = c(ORCID = "0000-0002-9213-6743")), person(role = c("aut", "ths"), family = "Glasner", given = "Corinna", email = "c.glasner@umcg.nl", comment = c(ORCID = "0000-0003-1241-1328")), + person(role = "ctb", + family = "Fonville", given = c("Judith", "M."), email = "j.fonville@pamm.nl"), person(role = "ctb", family = "Hassing", given = c("Erwin", "E.", "A."), email = "e.hassing@certe.nl"), person(role = "ctb", diff --git a/NEWS.md b/NEWS.md index 0cdc86c8..2d9c6db7 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9074 -Last updated: 16-Sep-2019 +# AMR 0.7.1.9075 +Last updated: 18-Sep-2019 ### Breaking * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: @@ -72,7 +72,7 @@ ``` ### Changed -* Many algorithm improvements for `as.mo()` (of which some led to additions to the `microorganisms` data set): +* Many algorithm improvements for `as.mo()` (of which some led to additions to the `microorganisms` data set). Many thanks to all contributors that helped improving the algorithms. * Self-learning algorithm - the function now gains experience from previously determined microorganism IDs and learns from it (yielding 80-95% speed improvement for any guess after the first try) * Big improvement for misspelled input * These new trivial names known to the field are now understood: meningococcus, gonococcus, pneumococcus @@ -80,6 +80,7 @@ * Added support for Viridans Group Streptococci (VGS) and Milleri Group Streptococci (MGS) * Added support for 5,000 new fungi * Added support for unknown yeasts and fungi + * Changed most microorganism IDs to improve readability. **IMPORTANT:** Because of these changes, the microorganism IDs have been changed to a slightly different format. Old microorganism IDs are still supported, but support will be dropped in a future version. Use `as.mo()` on your old codes to transform them to the new format. * Renamed data set `septic_patients` to `example_isolates` * Function `eucast_rules()`: * Fixed a bug for *Yersinia pseudotuberculosis* @@ -105,7 +106,7 @@ * Fix for `key_antibiotics()` on foreign systems #### Other -* Added Prof Dr Casper Albers as doctoral advisor and Dr Bart Meijer, Dr Dennis Souverein and Annick Lenglet as contributors +* Added Prof. Dr. Casper Albers as doctoral advisor and added Dr. Judith Fonville, Eric Hazenberg, Dr. Bart Meijer, Dr. Dennis Souverein and Annick Lenglet as contributors # AMR 0.7.1 diff --git a/R/data.R b/R/data.R index 9fe927f6..95f3444f 100755 --- a/R/data.R +++ b/R/data.R @@ -55,7 +55,7 @@ #' #' A data set containing the microbial taxonomy of six kingdoms from the Catalogue of Life. MO codes can be looked up using \code{\link{as.mo}}. #' @inheritSection catalogue_of_life Catalogue of Life -#' @format A \code{\link{data.frame}} with 69,855 observations and 16 variables: +#' @format A \code{\link{data.frame}} with 69,460 observations and 16 variables: #' \describe{ #' \item{\code{mo}}{ID of microorganism as used by this package} #' \item{\code{col_id}}{Catalogue of Life ID} @@ -73,7 +73,7 @@ #' \item{2 entries of \emph{Staphylococcus} (coagulase-negative [CoNS] and coagulase-positive [CoPS])} #' \item{3 entries of \emph{Trichomonas} (\emph{Trichomonas vaginalis}, and its family and genus)} #' \item{5 other 'undefined' entries (unknown, unknown Gram negatives, unknown Gram positives, unknown yeast and unknown fungus)} -#' \item{8,970 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) that are not in the Catalogue of Life} +#' \item{22,654 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) overwriting records from the Catalogue of Life, since the DSMZ contain the latest taxonomic information based on recent publications} #' } #' @section About the records from DSMZ (see source): #' Names of prokaryotes are defined as being validly published by the International Code of Nomenclature of Bacteria. Validly published are all names which are included in the Approved Lists of Bacterial Names and the names subsequently published in the International Journal of Systematic Bacteriology (IJSB) and, from January 2000, in the International Journal of Systematic and Evolutionary Microbiology (IJSEM) as original articles or in the validation lists. @@ -98,7 +98,7 @@ catalogue_of_life <- list( #' #' A data set containing old (previously valid or accepted) taxonomic names according to the Catalogue of Life. This data set is used internally by \code{\link{as.mo}}. #' @inheritSection catalogue_of_life Catalogue of Life -#' @format A \code{\link{data.frame}} with 22,932 observations and 4 variables: +#' @format A \code{\link{data.frame}} with 24,246 observations and 4 variables: #' \describe{ #' \item{\code{col_id}}{Catalogue of Life ID that was originally given} #' \item{\code{col_id_new}}{New Catalogue of Life ID that responds to an entry in the \code{\link{microorganisms}} data set} @@ -110,12 +110,12 @@ catalogue_of_life <- list( #' @seealso \code{\link{as.mo}} \code{\link{mo_property}} \code{\link{microorganisms}} "microorganisms.old" -#' Translation table for microorganism codes +#' Translation table for common microorganism codes #' #' A data set containing commonly used codes for microorganisms, from laboratory systems and WHONET. Define your own with \code{\link{set_mo_source}}. -#' @format A \code{\link{data.frame}} with 4,965 observations and 2 variables: +#' @format A \code{\link{data.frame}} with 4,927 observations and 2 variables: #' \describe{ -#' \item{\code{certe}}{Commonly used code of a microorganism} +#' \item{\code{code}}{Commonly used code of a microorganism} #' \item{\code{mo}}{ID of the microorganism in the \code{\link{microorganisms}} data set} #' } #' @inheritSection catalogue_of_life Catalogue of Life @@ -123,9 +123,9 @@ catalogue_of_life <- list( #' @seealso \code{\link{as.mo}} \code{\link{microorganisms}} "microorganisms.codes" -#' Data set with 2,000 blood culture isolates from septic patients +#' Data set with 2,000 blood culture isolates #' -#' An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}. +#' An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found 4 different hospitals in the Netherlands, between 2001 and 2017. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}. #' @format A \code{\link{data.frame}} with 2,000 observations and 49 variables: #' \describe{ #' \item{\code{date}}{date of receipt at the laboratory} @@ -137,7 +137,7 @@ catalogue_of_life <- list( #' \item{\code{gender}}{gender of the patient} #' \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} #' \item{\code{mo}}{ID of microorganism created with \code{\link{as.mo}}, see also \code{\link{microorganisms}}} -#' \item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}} +#' \item{\code{PEN:RIF}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}} #' } #' @inheritSection AMR Read more on our website! "example_isolates" diff --git a/R/globals.R b/R/globals.R index 16affa4b..3ccba949 100755 --- a/R/globals.R +++ b/R/globals.R @@ -67,6 +67,7 @@ globalVariables(c(".", "observations", "observed", "old", + "old_name", "other_pat_or_mo", "package_version", "patient_id", diff --git a/R/mo.R b/R/mo.R index b93735d6..63398f11 100755 --- a/R/mo.R +++ b/R/mo.R @@ -29,7 +29,7 @@ #' @param Lancefield a logical to indicate whether beta-haemolytic \emph{Streptococci} should be categorised into Lancefield groups instead of their own species, according to Rebecca C. Lancefield [3]. These \emph{Streptococci} will be categorised in their first group, e.g. \emph{Streptococcus dysgalactiae} will be group C, although officially it was also categorised into groups G and L. #' #' This excludes \emph{Enterococci} at default (who are in group D), use \code{Lancefield = "all"} to also categorise all \emph{Enterococci} as group D. -#' @param allow_uncertain a number between 0 (or "none") and 3 (or "all"), or TRUE (= 2) or FALSE (= 0) to indicate whether the input should be checked for less possible results, see Details +#' @param allow_uncertain a number between 0 (or "none") and 3 (or "all"), or TRUE (= 2) or FALSE (= 0) to indicate whether the input should be checked for less probable results, see Details #' @param reference_df a \code{data.frame} to use for extra reference when translating \code{x} to a valid \code{mo}. See \code{\link{set_mo_source}} and \code{\link{get_mo_source}} to automate the usage of your own codes (e.g. used in your analysis or organisation). #' @param ... other parameters passed on to functions #' @rdname as.mo @@ -39,16 +39,16 @@ #' \strong{General info} \cr #' A microorganism ID from this package (class: \code{mo}) typically looks like these examples:\cr #' \preformatted{ -#' Code Full name -#' --------------- -------------------------------------- -#' B_KLBSL Klebsiella -#' B_KLBSL_PNE Klebsiella pneumoniae -#' B_KLBSL_PNE_RHI Klebsiella pneumoniae rhinoscleromatis -#' | | | | -#' | | | | -#' | | | ----> subspecies, a 3-4 letter acronym -#' | | ----> species, a 3-4 letter acronym -#' | ----> genus, a 5-7 letter acronym, mostly without vowels +#' Code Full name +#' --------------- -------------------------------------- +#' B_KLBSL Klebsiella +#' B_KLBSL_PNMN Klebsiella pneumoniae +#' B_KLBSL_PNMN_RHNS Klebsiella pneumoniae rhinoscleromatis +#' | | | | +#' | | | | +#' | | | ---> subspecies, a 4-5 letter acronym +#' | | ----> species, a 4-5 letter acronym +#' | ----> genus, a 5-7 letter acronym #' ----> taxonomic kingdom: A (Archaea), AN (Animalia), B (Bacteria), #' C (Chromista), F (Fungi), P (Protozoa) #' } @@ -95,7 +95,7 @@ #' #' Examples: #' \itemize{ -#' \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRB}) needs review.} +#' \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRPB}) needs review.} #' \item{\code{"S. aureus - please mind: MRSA"}. The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result \emph{Staphylococcus aureus} (\code{B_STPHY_AUR}) needs review.} #' \item{\code{"Fluoroquinolone-resistant Neisseria gonorrhoeae"}. The first word will be stripped, after which the function will try to find a match. A warning will be thrown that the result \emph{Neisseria gonorrhoeae} (\code{B_NESSR_GON}) needs review.} #' } @@ -135,7 +135,7 @@ #' @importFrom dplyr %>% pull left_join #' @examples #' \donttest{ -#' # These examples all return "B_STPHY_AUR", the ID of S. aureus: +#' # These examples all return "B_STPHY_AURS", the ID of S. aureus: #' as.mo("sau") # WHONET code #' as.mo("stau") #' as.mo("STAU") @@ -160,11 +160,11 @@ #' as.mo("GAS") # Group A Streptococci #' as.mo("GBS") # Group B Streptococci #' -#' as.mo("S. epidermidis") # will remain species: B_STPHY_EPI -#' as.mo("S. epidermidis", Becker = TRUE) # will not remain species: B_STPHY_CNS +#' as.mo("S. epidermidis") # will remain species: B_STPHY_EPDR +#' as.mo("S. epidermidis", Becker = TRUE) # will not remain species: B_STPHY_CONS #' -#' as.mo("S. pyogenes") # will remain species: B_STRPT_PYO -#' as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRA +#' as.mo("S. pyogenes") # will remain species: B_STRPT_PYGN +#' as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRPA #' #' # All mo_* functions use as.mo() internally too (see ?mo_property): #' mo_genus("E. coli") # returns "Escherichia" @@ -342,6 +342,7 @@ exec_as.mo <- function(x, stringsAsFactors = FALSE) failures <- character(0) uncertainty_level <- translate_allow_uncertain(allow_uncertain) + old_mo_warning <- FALSE x_input <- x # already strip leading and trailing spaces @@ -359,6 +360,7 @@ exec_as.mo <- function(x, if (any(x %like_case% "^[BFP]_[A-Z]{3,7}") & !all(x %in% microorganisms$mo)) { leftpart <- gsub("^([BFP]_[A-Z]{3,7}).*", "\\1", x) if (any(leftpart %in% names(mo_codes_v0.5.0))) { + old_mo_warning <- TRUE rightpart <- gsub("^[BFP]_[A-Z]{3,7}(.*)", "\\1", x) leftpart <- mo_codes_v0.5.0[leftpart] x[!is.na(leftpart)] <- paste0(leftpart[!is.na(leftpart)], rightpart[!is.na(leftpart)]) @@ -366,6 +368,7 @@ exec_as.mo <- function(x, # now check if some are still old still_old <- x[x %in% names(mo_codes_v0.5.0)] if (length(still_old) > 0) { + old_mo_warning <- TRUE x[x %in% names(mo_codes_v0.5.0)] <- data.frame(old = still_old, stringsAsFactors = FALSE) %>% left_join(data.frame(old = names(mo_codes_v0.5.0), new = mo_codes_v0.5.0, @@ -466,6 +469,14 @@ exec_as.mo <- function(x, x <- reference_data_to_use[data.table(mo = y[["mo"]]), on = "mo", ..property][[1]] + } else if (all(x %in% microorganisms.translation$mo_old)) { + # is an old mo code, used in previous versions of this package + old_mo_warning <- TRUE + y <- as.data.table(microorganisms.translation)[data.table(mo_old = x), on = "mo_old", "mo_new"][[1]] + y <- reference_data_to_use[data.table(mo = y), on = "mo", ..property][[1]] + # don't save to history, as all items are already in microorganisms.translation + x <- y + } else if (!all(x %in% AMR::microorganisms[, property])) { strip_whitespace <- function(x, dyslexia_mode) { @@ -487,6 +498,8 @@ exec_as.mo <- function(x, # from here on case-insensitive x <- tolower(x) + x_backup[grepl("^(fungus|fungi)$", x)] <- "F_FUNGUS" # will otherwise become the kingdom + # remove spp and species x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x, ignore.case = TRUE) x <- gsub("(spp.?|ssp.?|subsp.?|subspecies|biovar|serovar|species)", "", x, ignore.case = TRUE) @@ -499,12 +512,14 @@ exec_as.mo <- function(x, # no groups and complexes as ending x <- gsub("(complex|group)$", "", x) x <- gsub("((an)?aero+b)[a-z]*", "", x) + x <- gsub("^atyp[a-z]*", "", x) x <- gsub("(vergroen)[a-z]*", "viridans", x) + x <- gsub("[a-z]*diff?erent[a-z]*", "", x) x <- gsub("(hefe|gist|gisten|levadura|lievito|fermento|levure)[a-z]*", "yeast", x) x <- gsub("(schimmels?|mofo|molde|stampo|moisissure|fungi)[a-z]*", "fungus", x) x <- gsub("fungus[ph|f]rya", "fungiphrya", x) # remove non-text in case of "E. coli" except dots and spaces - x <- gsub("[^.a-zA-Z0-9/ \\-]+", "", x) + x <- trimws(gsub("[^.a-zA-Z0-9/ \\-]+", " ", x)) # replace minus by a space x <- gsub("-+", " ", x) # replace hemolytic by haemolytic @@ -543,7 +558,7 @@ exec_as.mo <- function(x, x[nchar(x_backup_without_spp) > 10] <- gsub("[+]", paste0("+[", constants, "]?"), x[nchar(x_backup_without_spp) > 10]) } x <- strip_whitespace(x, dyslexia_mode) - + x_trimmed <- x x_trimmed_species <- paste(x_trimmed, "species") x_trimmed_without_group <- gsub(" gro.u.p$", "", x_trimmed) @@ -591,6 +606,11 @@ exec_as.mo <- function(x, } } + if (x_backup[i] %like_case% "\\(unknown [a-z]+\\)") { + x[i] <- "UNKNOWN" + next + } + found <- reference_data_to_use[mo == toupper(x_backup[i]), ..property][[1]] # is a valid MO code if (length(found) > 0) { @@ -598,6 +618,17 @@ exec_as.mo <- function(x, next } + if (x_backup[i] %in% microorganisms.translation$mo_old) { + # is an old mo code, used in previous versions of this package + old_mo_warning <- TRUE + found <- reference_data_to_use[mo == microorganisms.translation[which(microorganisms.translation$mo_old == x_backup[i]), "mo_new"], ..property][[1]] + if (length(found) > 0) { + x[i] <- found[1L] + # don't save to history, as all items are already in microorganisms.translation + next + } + } + found <- reference_data_to_use[fullname_lower %in% tolower(c(x_backup[i], x_backup_without_spp[i])), ..property][[1]] # most probable: is exact match in fullname if (length(found) > 0) { @@ -665,19 +696,22 @@ exec_as.mo <- function(x, if (x_backup_without_spp[i] %like_case% "virus") { # there is no fullname like virus, so don't try to coerce it - x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] - if (initial_search == TRUE) { - failures <- c(failures, x_backup[i]) - set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) - } + x[i] <- NA_character_ next } + # x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] + # if (initial_search == TRUE) { + # failures <- c(failures, x_backup[i]) + # set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) + # } + # next + # } # translate known trivial abbreviations to genus + species ---- if (!is.na(x_trimmed[i])) { if (toupper(x_backup_without_spp[i]) %in% c('MRSA', 'MSSA', 'VISA', 'VRSA') | x_backup_without_spp[i] %like_case% " (mrsa|mssa|visa|vrsa) ") { - x[i] <- microorganismsDT[mo == 'B_STPHY_AUR', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STPHY_AURS', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -685,7 +719,7 @@ exec_as.mo <- function(x, } if (toupper(x_backup_without_spp[i]) %in% c('MRSE', 'MSSE') | x_backup_without_spp[i] %like_case% " (mrse|msse) ") { - x[i] <- microorganismsDT[mo == 'B_STPHY_EPI', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STPHY_EPDR', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -715,7 +749,7 @@ exec_as.mo <- function(x, if (toupper(x_backup_without_spp[i]) %in% c("AIEC", "ATEC", "DAEC", "EAEC", "EHEC", "EIEC", "EPEC", "ETEC", "NMEC", "STEC", "UPEC") # also support O-antigens of E. coli: O26, O103, O104, O111, O121, O145, O157 | x_backup_without_spp[i] %like_case% "o?(26|103|104|111|121|145|157)") { - x[i] <- microorganismsDT[mo == 'B_ESCHR_COL', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_ESCHR_COLI', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -724,7 +758,7 @@ exec_as.mo <- function(x, if (toupper(x_backup_without_spp[i]) == 'MRPA' | x_backup_without_spp[i] %like_case% " mrpa ") { # multi resistant P. aeruginosa - x[i] <- microorganismsDT[mo == 'B_PSDMN_AER', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_PSDMN_ARGN', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -733,7 +767,7 @@ exec_as.mo <- function(x, if (toupper(x_backup_without_spp[i]) == 'CRS' | toupper(x_backup_without_spp[i]) == 'CRSM') { # co-trim resistant S. maltophilia - x[i] <- microorganismsDT[mo == 'B_STNTR_MAL', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STNTR_MLTP', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -742,15 +776,15 @@ exec_as.mo <- function(x, if (toupper(x_backup_without_spp[i]) %in% c('PISP', 'PRSP', 'VISP', 'VRSP') | x_backup_without_spp[i] %like_case% " (pisp|prsp|visp|vrsp) ") { # peni I, peni R, vanco I, vanco R: S. pneumoniae - x[i] <- microorganismsDT[mo == 'B_STRPT_PNE', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STRPT_PNMN', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } next } if (x_backup_without_spp[i] %like_case% '^g[abcdfghk]s$') { - # Streptococci, like GBS = Group B Streptococci (B_STRPT_GRB) - x[i] <- microorganismsDT[mo == toupper(gsub("g([abcdfghk])s", "B_STRPT_GR\\1", x_backup_without_spp[i])), ..property][[1]][1L] + # Streptococci, like GBS = Group B Streptococci (B_STRPT_GRPB) + x[i] <- microorganismsDT[mo == toupper(gsub("g([abcdfghk])s", "B_STRPT_GRP\\1", x_backup_without_spp[i])), ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -758,7 +792,7 @@ exec_as.mo <- function(x, } if (x_backup_without_spp[i] %like_case% '(streptococ|streptokok).* [abcdfghk]$') { # Streptococci in different languages, like "estreptococos grupo B" - x[i] <- microorganismsDT[mo == toupper(gsub(".*(streptococ|streptokok|estreptococ).* ([abcdfghk])$", "B_STRPT_GR\\2", x_backup_without_spp[i])), ..property][[1]][1L] + x[i] <- microorganismsDT[mo == toupper(gsub(".*(streptococ|streptokok|estreptococ).* ([abcdfghk])$", "B_STRPT_GRP\\2", x_backup_without_spp[i])), ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -766,7 +800,7 @@ exec_as.mo <- function(x, } if (x_backup_without_spp[i] %like_case% 'group [abcdfghk] (streptococ|streptokok|estreptococ)') { # Streptococci in different languages, like "Group A Streptococci" - x[i] <- microorganismsDT[mo == toupper(gsub(".*group ([abcdfghk]) (streptococ|streptokok|estreptococ).*", "B_STRPT_GR\\1", x_backup_without_spp[i])), ..property][[1]][1L] + x[i] <- microorganismsDT[mo == toupper(gsub(".*group ([abcdfghk]) (streptococ|streptokok|estreptococ).*", "B_STRPT_GRP\\1", x_backup_without_spp[i])), ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -774,7 +808,7 @@ exec_as.mo <- function(x, } if (x_backup_without_spp[i] %like_case% 'haemoly.*strept') { # Haemolytic streptococci in different languages - x[i] <- microorganismsDT[mo == 'B_STRPT_HAE', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STRPT_HAEM', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -785,7 +819,7 @@ exec_as.mo <- function(x, | x_trimmed[i] %like_case% '[ck]oagulas[ea] negatie?[vf]' | x_backup_without_spp[i] %like_case% '[ck]o?ns[^a-z]?$') { # coerce S. coagulase negative - x[i] <- microorganismsDT[mo == 'B_STPHY_CNS', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STPHY_CONS', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -795,7 +829,7 @@ exec_as.mo <- function(x, | x_trimmed[i] %like_case% '[ck]oagulas[ea] positie?[vf]' | x_backup_without_spp[i] %like_case% '[ck]o?ps[^a-z]?$') { # coerce S. coagulase positive - x[i] <- microorganismsDT[mo == 'B_STPHY_CPS', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STPHY_COPS', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -806,7 +840,7 @@ exec_as.mo <- function(x, | x_backup_without_spp[i] %like_case% 'strepto.* milleri' | x_backup_without_spp[i] %like_case% 'mgs[^a-z]?$') { # Milleri Group Streptococcus (MGS) - x[i] <- microorganismsDT[mo == 'B_STRPT_MIL', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STRPT_MILL', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -816,7 +850,7 @@ exec_as.mo <- function(x, | x_backup_without_spp[i] %like_case% 'strepto.* viridans' | x_backup_without_spp[i] %like_case% 'vgs[^a-z]?$') { # Viridans Group Streptococcus (VGS) - x[i] <- microorganismsDT[mo == 'B_STRPT_VIR', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_STRPT_VIRI', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -842,6 +876,15 @@ exec_as.mo <- function(x, } next } + if (x_backup_without_spp[i] %like_case% 'mycoba[ck]teri.[nm]?$') { + # coerce Gram positives + x[i] <- microorganismsDT[mo == 'B_MYCBC', ..property][[1]][1L] + if (initial_search == TRUE) { + set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) + } + next + } + if (x_backup_without_spp[i] %like_case% "salmonella [a-z]+ ?.*") { if (x_backup_without_spp[i] %like_case% "salmonella group") { # Salmonella Group A to Z, just return S. species for now @@ -852,38 +895,38 @@ exec_as.mo <- function(x, next } else if (grepl("[sS]almonella [A-Z][a-z]+ ?.*", x_backup[i], ignore.case = FALSE)) { # Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica - x[i] <- microorganismsDT[mo == 'B_SLMNL_ENT', ..property][[1]][1L] + x[i] <- microorganismsDT[mo == 'B_SLMNL_ENTR', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } uncertainties <- rbind(uncertainties, format_uncertainty_as_df(uncertainty_level = 1, input = x_backup_without_spp[i], - result_mo = "B_SLMNL_ENT")) + result_mo = "B_SLMNL_ENTR")) next } } # trivial names known to the field: if ("meningococcus" %like_case% x_trimmed[i]) { - # coerce S. coagulase positive - x[i] <- microorganismsDT[mo == 'B_NESSR_MEN', ..property][[1]][1L] + # coerce Neisseria meningitidis + x[i] <- microorganismsDT[mo == 'B_NESSR_MNNG', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } next } if ("gonococcus" %like_case% x_trimmed[i]) { - # coerce S. coagulase positive - x[i] <- microorganismsDT[mo == 'B_NESSR_GON', ..property][[1]][1L] + # coerce Neisseria gonorrhoeae + x[i] <- microorganismsDT[mo == 'B_NESSR_GNRR', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } next } if ("pneumococcus" %like_case% x_trimmed[i]) { - # coerce S. coagulase positive - x[i] <- microorganismsDT[mo == 'B_STRPT_PNE', ..property][[1]][1L] + # coerce Streptococcus penumoniae + x[i] <- microorganismsDT[mo == 'B_STRPT_PNMN', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) } @@ -1611,35 +1654,35 @@ exec_as.mo <- function(x, immediate. = TRUE) } - x[x %in% CoNS] <- microorganismsDT[mo == 'B_STPHY_CNS', ..property][[1]][1L] - x[x %in% CoPS] <- microorganismsDT[mo == 'B_STPHY_CPS', ..property][[1]][1L] + x[x %in% CoNS] <- microorganismsDT[mo == 'B_STPHY_CONS', ..property][[1]][1L] + x[x %in% CoPS] <- microorganismsDT[mo == 'B_STPHY_COPS', ..property][[1]][1L] if (Becker == "all") { - x[x %in% microorganismsDT[mo %like_case% '^B_STPHY_AUR', ..property][[1]]] <- microorganismsDT[mo == 'B_STPHY_CPS', ..property][[1]][1L] + x[x %in% microorganismsDT[mo %like_case% '^B_STPHY_AURS', ..property][[1]]] <- microorganismsDT[mo == 'B_STPHY_COPS', ..property][[1]][1L] } } # Lancefield ---- if (Lancefield == TRUE | Lancefield == "all") { # group A - S. pyogenes - x[x == microorganismsDT[mo == 'B_STRPT_PYO', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRA', ..property][[1]][1L] + x[x == microorganismsDT[mo == 'B_STRPT_PYGN', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRPA', ..property][[1]][1L] # group B - S. agalactiae - x[x == microorganismsDT[mo == 'B_STRPT_AGA', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRB', ..property][[1]][1L] + x[x == microorganismsDT[mo == 'B_STRPT_AGLC', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRPB', ..property][[1]][1L] # group C S_groupC <- microorganismsDT %>% filter(genus == "Streptococcus", species %in% c("equisimilis", "equi", "zooepidemicus", "dysgalactiae")) %>% pull(property) - x[x %in% S_groupC] <- microorganismsDT[mo == 'B_STRPT_GRC', ..property][[1]][1L] + x[x %in% S_groupC] <- microorganismsDT[mo == 'B_STRPT_GRPC', ..property][[1]][1L] if (Lancefield == "all") { # all Enterococci - x[x %like% "^(Enterococcus|B_ENTRC)"] <- microorganismsDT[mo == 'B_STRPT_GRD', ..property][[1]][1L] + x[x %like% "^(Enterococcus|B_ENTRC)"] <- microorganismsDT[mo == 'B_STRPT_GRPD', ..property][[1]][1L] } # group F - S. anginosus - x[x == microorganismsDT[mo == 'B_STRPT_ANG', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRF', ..property][[1]][1L] + x[x == microorganismsDT[mo == 'B_STRPT_ANGN', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRPF', ..property][[1]][1L] # group H - S. sanguinis - x[x == microorganismsDT[mo == 'B_STRPT_SAN', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRH', ..property][[1]][1L] + x[x == microorganismsDT[mo == 'B_STRPT_SNGN', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRPH', ..property][[1]][1L] # group K - S. salivarius - x[x == microorganismsDT[mo == 'B_STRPT_SAL', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRK', ..property][[1]][1L] + x[x == microorganismsDT[mo == 'B_STRPT_SLVR', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRPK', ..property][[1]][1L] } # Wrap up ---------------------------------------------------------------- @@ -1672,6 +1715,10 @@ exec_as.mo <- function(x, print(mo_renamed()) } + if (old_mo_warning == TRUE) { + warning("The input contained old microorganism IDs from previous versions of this package. Please use as.mo() on these old codes.\nSUPPORT FOR THIS WILL BE DROPPED IN A FUTURE VERSION.", call. = FALSE) + } + x } @@ -1682,6 +1729,7 @@ empty_result <- function(x) { #' @importFrom crayon italic was_renamed <- function(name_old, name_new, ref_old = "", ref_new = "", mo = "") { newly_set <- data.frame(old_name = name_old, + old_ref = ref_old, new_name = name_new, new_ref = ref_new, mo = mo, @@ -1757,7 +1805,7 @@ pillar_shaft.mo <- function(x, ...) { #' @noRd summary.mo <- function(object, ...) { # unique and top 1-3 - x <- object + x <- as.mo(object) top_3 <- unname(top_freq(freq(x), 3)) c("Class" = "mo", "" = length(x[is.na(x)]), @@ -1803,7 +1851,7 @@ as.data.frame.mo <- function(x, ...) { "[<-.mo" <- function(i, j, ..., value) { y <- NextMethod() attributes(y) <- attributes(i) - class_integrity_check(y, "microbial code", AMR::microorganisms$mo) + class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @exportMethod [[<-.mo #' @export @@ -1811,7 +1859,7 @@ as.data.frame.mo <- function(x, ...) { "[[<-.mo" <- function(i, j, ..., value) { y <- NextMethod() attributes(y) <- attributes(i) - class_integrity_check(y, "microbial code", AMR::microorganisms$mo) + class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @exportMethod c.mo #' @export @@ -1819,7 +1867,7 @@ as.data.frame.mo <- function(x, ...) { c.mo <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(x) - class_integrity_check(y, "microbial code", AMR::microorganisms$mo) + class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @rdname as.mo @@ -1898,9 +1946,12 @@ print.mo_renamed <- function(x, ...) { } for (i in 1:nrow(x)) { message(blue(paste0("NOTE: ", - italic(x$old_name[i]), " was renamed ", italic(x$new_name[i]), - " (", gsub("et al.", italic("et al."), x$new_ref[i]), ")", - " (", x$mo[i], ")"))) + italic(x$old_name[i]), ifelse(x$old_ref[i] %in% c("", NA), "", + paste0(" (", gsub("et al.", italic("et al."), x$old_ref[i]), ")")), + " was renamed ", + italic(x$new_name[i]), ifelse(x$new_ref[i] %in% c("", NA), "", + paste0(" (", gsub("et al.", italic("et al."), x$new_ref[i]), ")")), + " [", x$mo[i], "]"))) } } diff --git a/R/mo_history.R b/R/mo_history.R index 17d9b88e..445d9fea 100644 --- a/R/mo_history.R +++ b/R/mo_history.R @@ -83,7 +83,7 @@ get_mo_history <- function(x, uncertainty_level, force = FALSE, disable = FALSE) if (base::is.null(history)) { result <- NA } else { - result <- data.frame(x = toupper(x), stringsAsFactors = FALSE) %>% + result <- data.frame(x = as.character(toupper(x)), stringsAsFactors = FALSE) %>% left_join(history, by = "x") %>% pull(mo) } diff --git a/R/rsi.R b/R/rsi.R index 8c5c50d1..0a7f78ad 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -197,7 +197,7 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) { mo_order <- as.mo(mo_order(mo)) mo_becker <- as.mo(mo, Becker = TRUE) mo_lancefield <- as.mo(mo, Lancefield = TRUE) - + guideline_param <- toupper(guideline) if (guideline_param %in% c("CLSI", "EUCAST")) { guideline_param <- AMR::rsi_translation %>% diff --git a/R/sysdata.rda b/R/sysdata.rda index 9588a803..36481c99 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/zzz.R b/R/zzz.R index 0599f71d..626ae0eb 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -54,29 +54,29 @@ .onAttach <- function(...) { - if (interactive() & !isFALSE(getOption("AMR_survey"))) { - options(AMR_survey = FALSE) - console_width <- options()$width - 1 - url <- "https://www.surveymonkey.com/r/AMR_for_R" - txt <- paste0("Thanks for using the AMR package! ", - "As researchers, we are interested in how and why you use this package and if there are things you're missing from it. ", - "Please fill in our 2-minute survey at: ", url, ". ", - "This message can be turned off with: options(AMR_survey = FALSE)") - - # make it honour new lines bases on console width: - txt <- unlist(strsplit(txt, " ")) - txt_new <- "" - total_chars <- 0 - for (i in 1:length(txt)) { - total_chars <- total_chars + nchar(txt[i]) + 1 - if (total_chars > console_width) { - txt_new <- paste0(txt_new, "\n") - total_chars <- 0 - } - txt_new <- paste0(txt_new, txt[i], " ") - } - # packageStartupMessage(txt_new) - } + # if (interactive() & !isFALSE(getOption("AMR_survey"))) { + # options(AMR_survey = FALSE) + # console_width <- options()$width - 1 + # url <- "https://www.surveymonkey.com/r/AMR_for_R" + # txt <- paste0("Thanks for using the AMR package! ", + # "As researchers, we are interested in how and why you use this package and if there are things you're missing from it. ", + # "Please fill in our 2-minute survey at: ", url, ". ", + # "This message can be turned off with: options(AMR_survey = FALSE)") + # + # # make it honour new lines bases on console width: + # txt <- unlist(strsplit(txt, " ")) + # txt_new <- "" + # total_chars <- 0 + # for (i in 1:length(txt)) { + # total_chars <- total_chars + nchar(txt[i]) + 1 + # if (total_chars > console_width) { + # txt_new <- paste0(txt_new, "\n") + # total_chars <- 0 + # } + # txt_new <- paste0(txt_new, txt[i], " ") + # } + # # packageStartupMessage(txt_new) + # } } #' @importFrom data.table as.data.table setkey diff --git a/cran-comments.md b/cran-comments.md index 13f1e7fa..ed725dd0 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,4 @@ # Version 0.8.0 * A NOTE for having a data directory over 3 MB. This is needed to offer users reference data for the complete taxonomy of microorganisms - one of the most important features of this pacakge. Has been this way since version 0.3.0. -* This package writes lines to `[user library]/AMR/inst/mo_history/mo_history.csv` when using the `as.mo()` function. Users are notified about this. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. Staged install still works. The source code was taken from the `extrafont` package on CRAN (version 0.17), that writes to the package folder in the user library exactly the same way. See the source code of `set_mo_history()` and `clear_mo_history()`. +* This package writes lines to `[user library]/AMR/mo_history/mo_history.csv` when using the `as.mo()` function, in the exact same way (and borrowed from) the `extrafont` package on CRAN (version 0.17) writes to the package folder. Users are notified about this and staged install still works. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. See the source code of `set_mo_history()` and `clear_mo_history()`. diff --git a/data-raw/DRGLST1.xlsx b/data-raw/DRGLST1.xlsx new file mode 100644 index 00000000..5ebc801b Binary files /dev/null and b/data-raw/DRGLST1.xlsx differ diff --git a/data-raw/internals.R b/data-raw/internals.R index f5fc6e72..9d26e23c 100644 --- a/data-raw/internals.R +++ b/data-raw/internals.R @@ -33,8 +33,12 @@ translations_file <- utils::read.delim(file = "data-raw/translations.tsv", allowEscapes = TRUE, # else "\\1" will be imported as "\\\\1" quote = "") +# Old microorganism codes ------------------------------------------------- + +microorganisms.translation <- readRDS("data-raw/microorganisms.translation.rds") + # Export to package as internal data ---- -usethis::use_data(eucast_rules_file, translations_file, +usethis::use_data(eucast_rules_file, translations_file, microorganisms.translation, internal = TRUE, overwrite = TRUE, version = 2) @@ -42,6 +46,7 @@ usethis::use_data(eucast_rules_file, translations_file, # Remove from global environment ---- rm(eucast_rules_file) rm(translations_file) +rm(microorganisms.translation) # Clean mo history ---- mo_history_file <- file.path(file.path(system.file(package = "AMR"), "mo_history"), "mo_history.csv") diff --git a/data-raw/microorganisms.translation.rds b/data-raw/microorganisms.translation.rds new file mode 100644 index 00000000..f4972c25 Binary files /dev/null and b/data-raw/microorganisms.translation.rds differ diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index eee3cdcf..c21f389f 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -102,22 +102,38 @@ MOs <- data_total %>% & !order %in% c("Eurotiales", "Microascales", "Mucorales", "Saccharomycetales", "Schizosaccharomycetales", "Tremellales", "Onygenales", "Pneumocystales")) ) # or the genus has to be one of the genera we found in our hospitals last decades (Northern Netherlands, 2002-2018) - | genus %in% c("Absidia", "Acremonium", "Actinotignum", "Alternaria", "Anaerosalibacter", "Ancylostoma", "Anisakis", "Apophysomyces", - "Arachnia", "Ascaris", "Aureobacterium", "Aureobasidium", "Balantidum", "Bilophilia", "Branhamella", "Brochontrix", - "Brugia", "Calymmatobacterium", "Catabacter", "Cdc", "Chilomastix", "Chryseomonas", "Cladophialophora", "Cladosporium", - "Clonorchis", "Cordylobia", "Curvularia", "Demodex", "Dermatobia", "Diphyllobothrium", "Dracunculus", "Echinococcus", - "Enterobius", "Euascomycetes", "Exophiala", "Fasciola", "Fusarium", "Hendersonula", "Hymenolepis", "Hypomyces", "Kloeckera", - "Koserella", "Larva", "Leishmania", "Lelliottia", "Loa", "Lumbricus", "Malassezia", "Metagonimus", "Molonomonas", - "Mucor", "Nattrassia", "Necator", "Nectria", "Novospingobium", "Onchocerca", "Opistorchis", "Paragonimus", "Paramyxovirus", - "Pediculus", "Phoma", "Phthirus", "Pityrosporum", "Pseudallescheria", "Pulex", "Rhizomucor", "Rhizopus", "Rhodotorula", - "Salinococcus", "Sanguibacteroides", "Schistosoma", "Scopulariopsis", "Scytalidium", "Sporobolomyces", "Stomatococcus", - "Strongyloides", "Syncephalastraceae", "Taenia", "Torulopsis", "Trichinella", "Trichobilharzia", "Trichoderma", "Trichomonas", - "Trichosporon", "Trichuris", "Trypanosoma", "Wuchereria") + | genus %in% c("Absidia", "Acremonium", "Actinotignum", "Aedes", "Alternaria", "Anaerosalibacter", "Ancylostoma", "Angiostrongylus", + "Anisakis", "Anopheles", "Apophysomyces", "Arachnia", "Ascaris", "Aureobacterium", "Aureobasidium", "Balantidum", "Basidiobolus", + "Beauveria", "Bilophilia", "Branhamella", "Brochontrix", "Brugia", "Calymmatobacterium", "Capillaria", "Catabacter", "Cdc", "Chaetomium", + "Chilomastix", "Chryseomonas", "Chrysonilia", "Cladophialophora", "Cladosporium", "Clonorchis", "Conidiobolus", "Contracaecum", + "Cordylobia", "Curvularia", "Demodex", "Dermatobia", "Dicrocoelium", "Dioctophyma", "Diphyllobothrium", "Dipylidium", "Dirofilaria", + "Dracunculus", "Echinococcus", "Echinostoma", "Enterobius", "Enteromonas", "Euascomycetes", "Exophiala", "Exserohilum", "Fasciola", + "Fasciolopsis", "Fonsecaea", "Fusarium", "Gnathostoma", "Hendersonula", "Heterophyes", "Hymenolepis", "Hypomyces", "Hysterothylacium", + "Kloeckera", "Koserella", "Larva", "Lecythophora", "Leishmania", "Lelliottia", "Leptomyxida", "Leptosphaeria", "Loa", "Lucilia", + "Lumbricus", "Malassezia", "Malbranchea", "Mansonella", "Mesocestoides", "Metagonimus", "Metarrhizium", "Molonomonas", "Mortierella", + "Mucor", "Multiceps", "Mycocentrospora", "Nanophetus", "Nattrassia", "Necator", "Nectria", "Novospingobium", "Ochroconis", + "Oesophagostomum", "Oidiodendron", "Onchocerca", "Opisthorchis", "Opistorchis", "Paragonimus", "Paramyxovirus", "Pediculus", + "Phlebotomus", "Phocanema", "Phoma", "Phthirus", "Piedraia", "Pithomyces", "Pityrosporum", "Pseudallescheria", "Pseudoterranova", + "Pulex", "Retortamonas", "Rhizomucor", "Rhizopus", "Rhodotorula", "Salinococcus", "Sanguibacteroides", "Sarcophagidae", "Sarcoptes", + "Schistosoma", "Scolecobasidium", "Scopulariopsis", "Scytalidium", "Spirometra", "Sporobolomyces", "Stachybotrys", "Stenotrophomononas", + "Stomatococcus", "Strongyloides", "Syncephalastraceae", "Syngamus", "Taenia", "Ternidens", "Torulopsis", "Toxocara", "Trichinella", + "Trichobilharzia", "Trichoderma", "Trichomonas", "Trichosporon", "Trichostrongylus", "Trichuris", "Tritirachium", "Trombicula", + "Trypanosoma", "Tunga", "Wuchereria") # or the taxonomic entry is old - the species was renamed | !is.na(col_id_new) ) %>% # really no Plantae (e.g. Dracunculus exist both as worm and as plant) - filter(kingdom != "Plantae") + filter(kingdom != "Plantae") %>% + filter(!rank %in% c("kingdom", "phylum", "class", "order", "family", "genus")) + +# include all ranks other than species for the included species +MOs <- MOs %>% bind_rows(data_total %>% + filter((kingdom %in% MOs$kingdom & rank == "kingdom") + | (phylum %in% MOs$phylum & rank == "phylum") + | (class %in% MOs$class & rank == "class") + | (order %in% MOs$order & rank == "order") + | (family %in% MOs$family & rank == "family") + | (genus %in% MOs$genus & rank == "genus"))) # filter old taxonomic names so only the ones with an existing reference will be kept MOs <- MOs %>% @@ -193,6 +209,11 @@ MOs.old <- MOs %>% distinct(fullname, .keep_all = TRUE) %>% arrange(col_id) +MO.bak <- MOs +MOold.bak <- MOs.old +MOs <- MO.bak +MOs.old <- MOold.bak + MOs <- MOs %>% filter(is.na(col_id_new) | source == "DSMZ") %>% transmute(col_id, @@ -215,20 +236,93 @@ MOs <- MOs %>% species_id = gsub(".*/([a-f0-9]+)", "\\1", species_id), source) %>% #distinct(fullname, .keep_all = TRUE) %>% - filter(!grepl("unassigned", fullname, ignore.case = TRUE)) + filter(!grepl("unassigned", fullname, ignore.case = TRUE)) %>% + # prefer DSMZ over CoL, since that's more recent + arrange(desc(source)) %>% + distinct(kingdom, fullname, .keep_all = TRUE) -# Filter out the DSMZ records that were renamed and are now in MOs.old -MOs <- MOs %>% - filter(!(source == "DSMZ" & fullname %in% MOs.old$fullname), - !(source == "DSMZ" & fullname %in% (MOs %>% filter(source == "CoL") %>% pull(fullname)))) %>% - distinct(fullname, .keep_all = TRUE) +# # Filter out the DSMZ records that were renamed and are now in MOs.old +# MOs <- MOs %>% +# filter(!(source == "DSMZ" & fullname %in% MOs.old$fullname)) %>% +# distinct(kingdom, fullname, .keep_all = TRUE) %>% +# filter(fullname != "") + +# remove all genera that have no species - they are irrelevant for microbiology and almost all from the kingdom of Animalia +to_remove <- MOs %>% + filter(!kingdom %in% c("Bacteria", "Protozoa")) %>% + group_by(kingdom, genus) %>% + count() %>% + filter(n == 1) %>% + ungroup() %>% + mutate(kingdom_genus = paste(kingdom, genus)) %>% + pull(kingdom_genus) +MOs <- MOs %>% filter(!(paste(kingdom, genus) %in% to_remove)) +rm(to_remove) + +# add CoL ID from MOs.bak, for the cases where DSMZ took preference +MOs <- MOs %>% + mutate(kingdom_fullname = paste(kingdom, fullname)) %>% + select(-col_id) %>% + left_join(MO.bak %>% + filter(is.na(col_id_new), !is.na(col_id)) %>% + transmute(col_id, kingdom_fullname = trimws(paste(kingdom, genus, species, subspecies))), + by = "kingdom_fullname") %>% + select(col_id, everything(), -kingdom_fullname) + + +MOs.old <- MOs.old %>% + # remove the ones that are in the MOs data set + filter(col_id_new %in% MOs$col_id) %>% + # and remove the ones that have the exact same fullname in the MOs data set, like Moraxella catarrhalis + left_join(MOs, by = "fullname") %>% + filter(col_id_new != col_id.y | is.na(col_id.y)) %>% + select(col_id = col_id.x, col_id_new, fullname, ref = ref.x) + +# remove the records that are in MOs.old +MOs <- MOs %>% filter(!fullname %in% MOs.old$fullname) # what characters are in the fullnames? table(sort(unlist(strsplit(x = paste(MOs$fullname, collapse = ""), split = "")))) +table(MOs$kingdom, MOs$rank) +table(AMR::microorganisms$kingdom, AMR::microorganisms$rank) + +# set prevalence per species +MOs <- MOs %>% + mutate(prevalence = case_when( + class == "Gammaproteobacteria" + | genus %in% c("Enterococcus", "Staphylococcus", "Streptococcus") + ~ 1, + phylum %in% c("Proteobacteria", + "Firmicutes", + "Actinobacteria", + "Sarcomastigophora") + | genus %in% c("Aspergillus", + "Bacteroides", + "Candida", + "Capnocytophaga", + "Chryseobacterium", + "Cryptococcus", + "Elisabethkingia", + "Flavobacterium", + "Fusobacterium", + "Giardia", + "Leptotrichia", + "Mycoplasma", + "Prevotella", + "Rhodotorula", + "Treponema", + "Trichophyton", + "Ureaplasma") + | rank %in% c("kingdom", "phylum", "class", "order", "family") + ~ 2, + TRUE ~ 3 + )) + # Add abbreviations so we can easily know which ones are which ones. # These will become valid and unique microbial IDs for the AMR package. MOs <- MOs %>% + arrange(prevalence, fullname) %>% group_by(kingdom) %>% mutate(abbr_other = case_when( rank == "family" ~ paste0("[FAM]_", @@ -270,14 +364,14 @@ MOs <- MOs %>% # species abbreviations may be the same between genera # because the genus abbreviation is part of the abbreviation mutate(abbr_species = abbreviate(species, - minlength = 3, - use.classes = FALSE, + minlength = 4, + use.classes = TRUE, method = "both.sides")) %>% ungroup() %>% group_by(genus, species) %>% mutate(abbr_subspecies = abbreviate(subspecies, - minlength = 3, - use.classes = FALSE, + minlength = 4, + use.classes = TRUE, method = "both.sides")) %>% ungroup() %>% # remove trailing underscores @@ -302,9 +396,6 @@ MOs <- MOs %>% # put `mo` in front, followed by the rest select(mo, everything(), -abbr_other, -abbr_genus, -abbr_species, -abbr_subspecies) -# remove empty fullnames -MOs <- MOs %>% filter(fullname != "") - # add non-taxonomic entries MOs <- MOs %>% bind_rows( @@ -324,6 +415,7 @@ MOs <- MOs %>% ref = NA_character_, species_id = "", source = "manually added", + prevalence = 1, stringsAsFactors = FALSE), data.frame(mo = "B_GRAMN", col_id = NA_integer_, @@ -340,6 +432,7 @@ MOs <- MOs %>% ref = NA_character_, species_id = "", source = "manually added", + prevalence = 1, stringsAsFactors = FALSE), data.frame(mo = "B_GRAMP", col_id = NA_integer_, @@ -356,6 +449,7 @@ MOs <- MOs %>% ref = NA_character_, species_id = "", source = "manually added", + prevalence = 1, stringsAsFactors = FALSE), data.frame(mo = "F_YEAST", col_id = NA_integer_, @@ -372,6 +466,7 @@ MOs <- MOs %>% ref = NA_character_, species_id = "", source = "manually added", + prevalence = 2, stringsAsFactors = FALSE), data.frame(mo = "F_FUNGUS", col_id = NA_integer_, @@ -388,11 +483,12 @@ MOs <- MOs %>% ref = NA_character_, species_id = "", source = "manually added", + prevalence = 2, stringsAsFactors = FALSE), # CoNS MOs %>% filter(genus == "Staphylococcus", species == "epidermidis") %>% .[1,] %>% - mutate(mo = gsub("EPI", "CNS", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_CONS", mo), col_id = NA_integer_, species = "coagulase-negative", fullname = "Coagulase-negative Staphylococcus (CoNS)", @@ -402,7 +498,7 @@ MOs <- MOs %>% # CoPS MOs %>% filter(genus == "Staphylococcus", species == "epidermidis") %>% .[1,] %>% - mutate(mo = gsub("EPI", "CPS", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_COPS", mo), col_id = NA_integer_, species = "coagulase-positive", fullname = "Coagulase-positive Staphylococcus (CoPS)", @@ -413,18 +509,20 @@ MOs <- MOs %>% MOs %>% filter(genus == "Streptococcus", species == "pyogenes") %>% .[1,] %>% # we can keep all other details, since S. pyogenes is the only member of group A - mutate(mo = gsub("PYO", "GRA", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPA", mo), species = "group A" , - fullname = "Streptococcus group A"), + fullname = "Streptococcus group A", + source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% # we can keep all other details, since S. agalactiae is the only member of group B - mutate(mo = gsub("AGA", "GRB", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPB", mo), species = "group B" , - fullname = "Streptococcus group B"), + fullname = "Streptococcus group B", + source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "dysgalactiae") %>% .[1,] %>% - mutate(mo = gsub("DYS", "GRC", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPC", mo), col_id = NA_integer_, species = "group C" , fullname = "Streptococcus group C", @@ -433,7 +531,7 @@ MOs <- MOs %>% source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "GRD", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPD", mo), col_id = NA_integer_, species = "group D" , fullname = "Streptococcus group D", @@ -442,7 +540,7 @@ MOs <- MOs %>% source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "GRF", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPF", mo), col_id = NA_integer_, species = "group F" , fullname = "Streptococcus group F", @@ -451,7 +549,7 @@ MOs <- MOs %>% source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "GRG", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPG", mo), col_id = NA_integer_, species = "group G" , fullname = "Streptococcus group G", @@ -460,7 +558,7 @@ MOs <- MOs %>% source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "GRH", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPH", mo), col_id = NA_integer_, species = "group H" , fullname = "Streptococcus group H", @@ -469,7 +567,7 @@ MOs <- MOs %>% source = "manually added"), MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "GRK", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_GRPK", mo), col_id = NA_integer_, species = "group K" , fullname = "Streptococcus group K", @@ -479,7 +577,7 @@ MOs <- MOs %>% # Beta haemolytic Streptococci MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "HAE", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_HAEM", mo), col_id = NA_integer_, species = "beta-haemolytic" , fullname = "Beta-haemolytic Streptococcus", @@ -489,7 +587,7 @@ MOs <- MOs %>% # Viridans Streptococci MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "VIR", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_VIRI", mo), col_id = NA_integer_, species = "viridans" , fullname = "Viridans Group Streptococcus (VGS)", @@ -499,7 +597,7 @@ MOs <- MOs %>% # Milleri Streptococci MOs %>% filter(genus == "Streptococcus", species == "agalactiae") %>% .[1,] %>% - mutate(mo = gsub("AGA", "MIL", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_MILL", mo), col_id = NA_integer_, species = "milleri" , fullname = "Milleri Group Streptococcus (MGS)", @@ -509,7 +607,7 @@ MOs <- MOs %>% # Trichomonas vaginalis is missing, same order as Dientamoeba MOs %>% filter(fullname == "Dientamoeba") %>% - mutate(mo = gsub("DNTMB", "THMNS", mo), + mutate(mo = gsub("(.*?)_.*", "\\1_THMNS", mo), col_id = NA, fullname = "Trichomonas", family = "Trichomonadidae", @@ -519,8 +617,7 @@ MOs <- MOs %>% species_id = ""), MOs %>% filter(fullname == "Dientamoeba fragilis") %>% - mutate(mo = gsub("DNTMB", "THMNS", mo), - mo = gsub("FRA", "VAG", mo), + mutate(mo = gsub("(.*?)_.*", "\\1_THMNS_VAG", mo), col_id = NA, fullname = "Trichomonas vaginalis", family = "Trichomonadidae", @@ -531,7 +628,7 @@ MOs <- MOs %>% species_id = ""), MOs %>% # add family as such too filter(fullname == "Monocercomonadidae") %>% - mutate(mo = gsub("MNCRCMND", "TRCHMNDD", mo), + mutate(mo = gsub("(.*)_(.*)_.*", "\\1_\\2_TRCHMNDD", mo), col_id = NA, fullname = "Trichomonadidae", family = "Trichomonadidae", @@ -541,9 +638,12 @@ MOs <- MOs %>% source = "manually added", ref = "", species_id = ""), - ) +MOs <- MOs %>% + group_by(kingdom) %>% + distinct(fullname, .keep_all = TRUE) %>% + ungroup() # everything distinct? sum(duplicated(MOs$mo)) @@ -551,60 +651,44 @@ sum(duplicated(MOs$fullname)) colnames(MOs) # here we welcome the new ones: -MOs %>% filter(!fullname %in% AMR::microorganisms$fullname) %>% View() +MOs %>% arrange(genus, species, subspecies) %>% filter(!fullname %in% AMR::microorganisms$fullname) %>% View() # and the ones we lost: AMR::microorganisms %>% filter(!fullname %in% MOs$fullname) %>% View() # and these IDs have changed: -MOs %>% - filter(fullname %in% AMR::microorganisms$fullname) %>% - left_join(AMR::microorganisms %>% select(mo, fullname), by = "fullname", suffix = c("_new", "_old")) %>% +old_new <- MOs %>% + mutate(kingdom_fullname = paste(kingdom, fullname)) %>% + filter(kingdom_fullname %in% (AMR::microorganisms %>% mutate(kingdom_fullname = paste(kingdom, fullname)) %>% pull(kingdom_fullname))) %>% + left_join(AMR::microorganisms %>% mutate(kingdom_fullname = paste(kingdom, fullname)) %>% select(mo, kingdom_fullname), by = "kingdom_fullname", suffix = c("_new", "_old")) %>% filter(mo_new != mo_old) %>% - select(mo_old, mo_new, everything()) %>% + select(mo_old, mo_new, everything()) +old_new %>% View() # and these codes are now missing (which will throw a unit test error): -AMR::microorganisms.codes %>% filter(!mo %in% AMR::microorganisms$mo) - -# set prevalence per species -MOs <- MOs %>% - mutate(prevalence = case_when( - class == "Gammaproteobacteria" - | genus %in% c("Enterococcus", "Staphylococcus", "Streptococcus") - | mo %in% c("UNKNOWN", "B_GRAMN", "B_GRAMP") - ~ 1, - phylum %in% c("Proteobacteria", - "Firmicutes", - "Actinobacteria", - "Sarcomastigophora") - | genus %in% c("Aspergillus", - "Bacteroides", - "Candida", - "Capnocytophaga", - "Chryseobacterium", - "Cryptococcus", - "Elisabethkingia", - "Flavobacterium", - "Fusobacterium", - "Giardia", - "Leptotrichia", - "Mycoplasma", - "Prevotella", - "Rhodotorula", - "Treponema", - "Trichophyton", - "Ureaplasma") - | rank %in% c("kingdom", "phylum", "class", "order", "family") - ~ 2, - TRUE ~ 3 - )) +AMR::microorganisms.codes %>% filter(!mo %in% MOs$mo) +# this is how to fix it +microorganisms.codes <- AMR::microorganisms.codes %>% + left_join(MOs %>% + mutate(kingdom_fullname = paste(kingdom, fullname)) %>% + left_join(AMR::microorganisms %>% + mutate(kingdom_fullname = paste(kingdom, fullname)) %>% + select(mo, kingdom_fullname), by = "kingdom_fullname", suffix = c("_new", "_old")) %>% + select(mo_old, mo_new), + by = c("mo" = "mo_old")) %>% + select(code, mo = mo_new) %>% + filter(!is.na(mo)) +microorganisms.codes %>% filter(!mo %in% MOs$mo) # arrange MOs <- MOs %>% arrange(genus, species, subspecies) MOs.old <- MOs.old %>% arrange(fullname) +microorganisms.codes <- microorganisms.codes %>% arrange(code) # transform MOs <- as.data.frame(MOs, stringsAsFactors = FALSE) MOs.old <- as.data.frame(MOs.old, stringsAsFactors = FALSE) +microorganisms.codes <- as.data.frame(microorganisms.codes, stringsAsFactors = FALSE) class(MOs$mo) <- "mo" +class(microorganisms.codes$mo) <- "mo" MOs$col_id <- as.integer(MOs$col_id) MOs.old$col_id <- as.integer(MOs.old$col_id) MOs.old$col_id_new <- as.integer(MOs.old$col_id_new) @@ -616,10 +700,17 @@ saveRDS(MOs.old, "microorganisms.old.rds") ### for same server microorganisms <- MOs microorganisms.old <- MOs.old +microorganisms.translation <- old_new %>% select(mo_old, mo_new) +class(microorganisms.translation$mo_old) <- "mo" +class(microorganisms.translation$mo_new) <- "mo" # on the server, do: usethis::use_data(microorganisms, overwrite = TRUE, version = 2) usethis::use_data(microorganisms.old, overwrite = TRUE, version = 2) +usethis::use_data(microorganisms.codes, overwrite = TRUE, version = 2) +saveRDS(AMR::microorganisms.translation, file = "microorganisms.translation.rds", version = 2) # this one will be covered in data-raw/internals.R rm(microorganisms) rm(microorganisms.old) +rm(microorganisms.codes) +rm(microorganisms.translation) # and update the year and dimensions in R/data.R diff --git a/data-raw/reproduction_of_rsi_translation.R b/data-raw/reproduction_of_rsi_translation.R index 3382d29f..d522fdfc 100644 --- a/data-raw/reproduction_of_rsi_translation.R +++ b/data-raw/reproduction_of_rsi_translation.R @@ -4,7 +4,7 @@ library(readxl) # Installed WHONET 2019 software on Windows (http://www.whonet.org/software.html), # opened C:\WHONET\Codes\WHONETCodes.mdb in MS Access # and exported table 'DRGLST1' to MS Excel -DRGLST1 <- read_excel("DRGLST1.xlsx") +DRGLST1 <- read_excel("data-raw/DRGLST1.xlsx") rsi_translation <- DRGLST1 %>% # only keep CLSI and EUCAST guidelines: filter(GUIDELINES %like% "^(CLSI|EUCST)") %>% @@ -22,6 +22,8 @@ rsi_translation <- DRGLST1 %>% filter(!is.na(mo) & !is.na(ab)) %>% arrange(desc(guideline), mo, ab) +print(mo_failures()) + # create 2 tables: MIC and disk tbl_mic <- rsi_translation %>% filter(method == "MIC") %>% diff --git a/data/example_isolates.rda b/data/example_isolates.rda index 2a00a286..7f011549 100644 Binary files a/data/example_isolates.rda and b/data/example_isolates.rda differ diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index 80c6586b..1c593472 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/data/microorganisms.old.rda b/data/microorganisms.old.rda index 805070c3..b63591f2 100644 Binary files a/data/microorganisms.old.rda and b/data/microorganisms.old.rda differ diff --git a/data/microorganisms.rda b/data/microorganisms.rda index afb04778..7a5210e2 100755 Binary files a/data/microorganisms.rda and b/data/microorganisms.rda differ diff --git a/data/rsi_translation.rda b/data/rsi_translation.rda index 24f4af2c..eb93caf7 100644 Binary files a/data/rsi_translation.rda and b/data/rsi_translation.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 9e8e8f17..3aa3bf2c 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075 diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index acffb8a8..f5ac3722 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075 @@ -185,7 +185,7 @@

Benchmarks

Matthijs S. Berends

-

16 September 2019

+

18 September 2019

@@ -199,7 +199,7 @@

Using the microbenchmark package, we can review the calculation performance of this function. Its function microbenchmark() runs different input expressions independently of each other and measures their time-to-result.

library(microbenchmark)
 library(AMR)
-

In the next test, we try to ‘coerce’ different input values for Staphylococcus aureus. The actual result is the same every time: it returns its MO code B_STPHY_AUR (B stands for Bacteria, the taxonomic kingdom).

+

In the next test, we try to ‘coerce’ different input values for Staphylococcus aureus. The actual result is the same every time: it returns its MO code B_STPHY_AURS (B stands for Bacteria, the taxonomic kingdom).

But the calculation time differs a lot:

S.aureus <- microbenchmark(
   as.mo("sau"), # WHONET code
@@ -220,38 +220,38 @@
 print(S.aureus, unit = "ms", signif = 2)
 # Unit: milliseconds
 #                                   expr   min    lq  mean median    uq
-#                           as.mo("sau")   8.6   8.7  11.0    8.8   9.3
-#                          as.mo("stau")  30.0  30.0  41.0   31.0  32.0
-#                          as.mo("STAU")  30.0  30.0  42.0   31.0  32.0
-#                        as.mo("staaur")   8.5   8.9  12.0    9.1   9.6
-#                        as.mo("STAAUR")   8.5   9.0   9.1    9.2   9.3
-#                     as.mo("S. aureus")  23.0  23.0  30.0   23.0  40.0
-#                      as.mo("S aureus")  22.0  23.0  28.0   23.0  37.0
-#         as.mo("Staphylococcus aureus")  28.0  29.0  30.0   30.0  31.0
-#  as.mo("Staphylococcus aureus (MRSA)") 520.0 530.0 540.0  540.0 550.0
-#       as.mo("Sthafilokkockus aaureuz") 270.0 280.0 300.0  290.0 300.0
-#                          as.mo("MRSA")   8.5   8.7   8.9    8.8   9.0
-#                          as.mo("VISA")  18.0  19.0  24.0   19.0  35.0
-#                          as.mo("VRSA")  18.0  18.0  31.0   19.0  34.0
-#                        as.mo(22242419)  17.0  18.0  22.0   18.0  19.0
+#                           as.mo("sau")   8.5   8.9  12.0    9.1   9.7
+#                          as.mo("stau")  31.0  32.0  48.0   34.0  55.0
+#                          as.mo("STAU")  31.0  31.0  35.0   32.0  33.0
+#                        as.mo("staaur")   8.6   8.8  12.0    9.0   9.3
+#                        as.mo("STAAUR")   8.6   8.9   9.0    9.0   9.1
+#                     as.mo("S. aureus")  23.0  23.0  26.0   24.0  24.0
+#                      as.mo("S aureus")  23.0  23.0  31.0   24.0  44.0
+#         as.mo("Staphylococcus aureus")  27.0  28.0  29.0   29.0  29.0
+#  as.mo("Staphylococcus aureus (MRSA)") 550.0 560.0 590.0  580.0 590.0
+#       as.mo("Sthafilokkockus aaureuz") 270.0 290.0 340.0  300.0 330.0
+#                          as.mo("MRSA")   8.7   8.8   9.1    9.1   9.4
+#                          as.mo("VISA")  18.0  19.0  20.0   19.0  20.0
+#                          as.mo("VRSA")  19.0  19.0  23.0   19.0  22.0
+#                        as.mo(22242419)  18.0  18.0  37.0   30.0  42.0
 #    max neval
-#   28.0    10
+#   31.0    10
 #  120.0    10
-#  120.0    10
+#   59.0    10
 #   34.0    10
-#    9.4    10
-#   41.0    10
-#   43.0    10
-#   31.0    10
-#  570.0    10
-#  400.0    10
-#    9.3    10
-#   36.0    10
-#  110.0    10
-#   43.0    10
+# 9.2 10 +# 49.0 10 +# 53.0 10 +# 30.0 10 +# 670.0 10 +# 620.0 10 +# 9.5 10 +# 28.0 10 +# 45.0 10 +# 110.0 10

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.

-

To achieve this speed, the as.mo function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISL), a bug probably never found before in humans:

+

To achieve this speed, the as.mo function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISLN), a bug probably never found before in humans:

T.islandicus <- microbenchmark(as.mo("theisl"),
                                as.mo("THEISL"),
                                as.mo("T. islandicus"),
@@ -320,53 +320,53 @@
 print(T.islandicus, unit = "ms", signif = 2)
 # Unit: milliseconds
 #                         expr  min   lq mean median   uq  max neval
-#              as.mo("theisl") 1300 1300 1300   1300 1400 1400    10
-#              as.mo("THEISL") 1300 1300 1300   1300 1300 1400    10
-#       as.mo("T. islandicus")  360  360  370    380  380  390    10
-#      as.mo("T.  islandicus")  360  370  400    380  450  480    10
-#  as.mo("Thermus islandicus")   29   30   32     30   30   50    10
-

That takes 8.6 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.

+# as.mo("theisl") 1300 1400 1400 1400 1500 1600 10 +# as.mo("THEISL") 1400 1400 1400 1400 1500 1600 10 +# as.mo("T. islandicus") 370 400 410 410 420 450 10 +# as.mo("T. islandicus") 360 370 400 380 410 490 10 +# as.mo("Thermus islandicus") 28 30 35 32 35 59 10 +

That takes 8.5 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.

In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is uncommon):

# Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
 
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# Warning: 
+# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
 
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
 
 # Warning: 
 # Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
 # Warning: 
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning: 
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.

In reality, the as.mo() functions learns from its own output to speed up determinations for next times. In above figure, this effect was disabled to show the difference with the boxplot below - when you would use as.mo() yourself:

# NOTE: results are saved to /Users/msberends/Library/R/3.6/library/AMR/mo_history/mo_history.csv.
+# NOTE: Prevotella ruminicola brevis (Shah et al., 1990) was renamed Prevotella brevis (Avgustin et al., 2016) [B_PRVTL_BRVS]
 # Warning: 
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-# NOTE: Prevotella ruminicola brevis was renamed Prevotella brevis (Avgustin et al., 1997) (B_PRVTL_BRE)
+# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.

The highest outliers are the first times. All next determinations were done in only thousands of seconds.

Uncommon microorganisms take a lot more time than common microorganisms. To relieve this pitfall and further improve performance, two important calculations take almost no time at all: repetitive results and already precalculated results.

@@ -400,23 +400,23 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# mo_name(x) 607 619 636 632 660 671 10 -

So transforming 500,000 values (!!) of 50 unique values only takes 0.63 seconds (632 ms). You only lose time on your unique input values.

+# mo_name(x) 610 644 669 665 684 748 10 +

So transforming 500,000 values (!!) of 50 unique values only takes 0.66 seconds (664 ms). You only lose time on your unique input values.

Precalculated results

What about precalculated results? If the input is an already precalculated result of a helper function like mo_name(), it almost doesn’t take any time at all (see ‘C’ below):

-

So going from mo_name("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0008 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:

+# A 0.467 0.471 0.509 0.492 0.512 0.680 10 +# B 0.628 0.634 0.664 0.646 0.685 0.748 10 +# C 0.712 0.723 0.771 0.755 0.797 0.906 10 +# D 0.444 0.455 0.475 0.464 0.501 0.518 10 +# E 0.452 0.453 0.468 0.457 0.487 0.510 10 +# F 0.439 0.450 0.462 0.459 0.470 0.501 10 +# G 0.450 0.460 0.476 0.480 0.492 0.496 10 +# H 0.443 0.455 0.461 0.456 0.466 0.495 10

Of course, when running mo_phylum("Firmicutes") the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes" too, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.

@@ -464,13 +464,13 @@ print(run_it, unit = "ms", signif = 4) # Unit: milliseconds # expr min lq mean median uq max neval -# en 17.29 17.79 18.11 18.13 18.57 18.86 10 -# de 18.44 19.01 20.23 19.76 19.86 27.61 10 -# nl 23.83 24.71 26.99 25.97 26.53 39.93 10 -# es 18.71 18.88 19.43 19.24 19.47 21.88 10 -# it 18.48 18.84 19.40 19.50 19.84 20.57 10 -# fr 18.51 19.39 25.08 20.26 37.11 38.24 10 -# pt 18.60 18.92 19.33 19.45 19.64 19.96 10
+# en 18.19 18.35 18.84 18.65 18.99 20.91 10 +# de 19.31 19.71 20.39 20.29 20.92 21.83 10 +# nl 24.43 24.92 25.51 25.37 25.65 27.97 10 +# es 19.22 19.53 20.06 19.82 20.47 21.81 10 +# it 19.36 20.03 24.77 20.26 20.96 45.31 10 +# fr 19.11 19.30 19.71 19.72 20.11 20.37 10 +# pt 19.40 19.90 27.80 21.38 41.88 45.37 10

Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png index 6fc093ec..1df1557a 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-6-1.png index dee8e9b8..ff8208ee 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-7-1.png index 9e14b133..ad62008e 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index d169534c..daaf7f8e 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075 diff --git a/docs/authors.html b/docs/authors.html index 18990bcc..4f9f44c2 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075 @@ -249,6 +249,10 @@

Corinna Glasner. Author, thesis advisor. ORCID

+
  • +

    Judith M. Fonville. Contributor. +

    +
  • Erwin E. A. Hassing. Contributor.

    diff --git a/docs/extra.js b/docs/extra.js index 1c4fecad..960e0285 100644 --- a/docs/extra.js +++ b/docs/extra.js @@ -81,13 +81,14 @@ $( document ).ready(function() { x = x.replace(/Author, maintainer/g, "Main developer"); x = x.replace(/Author, contributor/g, "Main contributor"); x = x.replace(/Author, thesis advisor/g, "Doctoral advisor"); - x = x.replace("Alex", "Prof. Dr Alex"); - x = x.replace("Bhanu", "Prof. Dr Bhanu"); - x = x.replace("Casper", "Prof. Dr Casper"); - x = x.replace("Corinna", "Dr Corinna"); + x = x.replace("Alex", "Prof. Dr. Alex"); + x = x.replace("Bhanu", "Prof. Dr. Bhanu"); + x = x.replace("Casper", "Prof. Dr. Casper"); + x = x.replace("Corinna", "Dr. Corinna"); // others - x = x.replace("Bart", "Dr Bart"); - x = x.replace("Dennis", "Dr Dennis"); + x = x.replace("Bart", "Dr. Bart"); + x = x.replace("Dennis", "Dr. Dennis"); + x = x.replace("Judith", "Dr. Judith"); } return(x); } diff --git a/docs/index.html b/docs/index.html index 09dbe453..3d6da21d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075 @@ -307,7 +307,7 @@
  • It cleanses existing data by providing new classes for microoganisms, antibiotics and antimicrobial results (both S/I/R and MIC). By installing this package, you teach R everything about microbiology that is needed for analysis. These functions all use intelligent rules to guess results that you would expect:

    You can also use e.g. as.mo(..., allow_uncertain = 1) to only allow up to level 1 uncertainty.

    Examples:

      -
    • "Streptococcus group B (known as S. agalactiae)". The text between brackets will be removed and a warning will be thrown that the result Streptococcus group B (B_STRPT_GRB) needs review.

    • +
    • "Streptococcus group B (known as S. agalactiae)". The text between brackets will be removed and a warning will be thrown that the result Streptococcus group B (B_STRPT_GRPB) needs review.

    • "S. aureus - please mind: MRSA". The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result Staphylococcus aureus (B_STPHY_AUR) needs review.

    • "Fluoroquinolone-resistant Neisseria gonorrhoeae". The first word will be stripped, after which the function will try to find a match. A warning will be thrown that the result Neisseria gonorrhoeae (B_NESSR_GON) needs review.

    @@ -369,7 +369,7 @@ The mo_property functions (like Examples
    # NOT RUN {
    -# These examples all return "B_STPHY_AUR", the ID of S. aureus:
    +# These examples all return "B_STPHY_AURS", the ID of S. aureus:
     as.mo("sau") # WHONET code
     as.mo("stau")
     as.mo("STAU")
    @@ -394,11 +394,11 @@ The mo_property functions (like as.mo("GAS") # Group A Streptococci
     as.mo("GBS") # Group B Streptococci
     
    -as.mo("S. epidermidis")                 # will remain species: B_STPHY_EPI
    -as.mo("S. epidermidis", Becker = TRUE)  # will not remain species: B_STPHY_CNS
    +as.mo("S. epidermidis")                 # will remain species: B_STPHY_EPDR
    +as.mo("S. epidermidis", Becker = TRUE)  # will not remain species: B_STPHY_CONS
     
    -as.mo("S. pyogenes")                    # will remain species: B_STRPT_PYO
    -as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRA
    +as.mo("S. pyogenes")                    # will remain species: B_STRPT_PYGN
    +as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRPA
     
     # All mo_* functions use as.mo() internally too (see ?mo_property):
     mo_genus("E. coli")           # returns "Escherichia"
    diff --git a/docs/reference/example_isolates.html b/docs/reference/example_isolates.html
    index d6d8238c..81405040 100644
    --- a/docs/reference/example_isolates.html
    +++ b/docs/reference/example_isolates.html
    @@ -6,7 +6,7 @@
     
     
     
    -Data set with 2,000 blood culture isolates from septic patients — example_isolates • AMR (for R)
    +Data set with 2,000 blood culture isolates — example_isolates • AMR (for R)
     
     
     
    @@ -45,9 +45,9 @@
     
       
       
    -
    +
     
    -
    +
     
     
     
    @@ -80,7 +80,7 @@
           
           
             AMR (for R)
    -        0.7.1.9067
    +        0.7.1.9075
           
         
     
    @@ -223,14 +223,14 @@
     
    -

    An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis. For examples, please read the tutorial on our website.

    +

    An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found 4 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis. For examples, please read the tutorial on our website.

    @@ -248,7 +248,7 @@
    gender

    gender of the patient

    patient_id

    ID of the patient, first 10 characters of an SHA hash containing irretrievable information

    mo

    ID of microorganism created with as.mo, see also microorganisms

    -
    peni:rifa

    40 different antibiotics with class rsi (see as.rsi); these column names occur in antibiotics data set and can be translated with ab_name

    +
    PEN:RIF

    40 different antibiotics with class rsi (see as.rsi); these column names occur in antibiotics data set and can be translated with ab_name

    Read more on our website!

    diff --git a/docs/reference/index.html b/docs/reference/index.html index 0b1f9618..4351f074 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9074 + 0.7.1.9075
    @@ -492,7 +492,7 @@

    example_isolates

    -

    Data set with 2,000 blood culture isolates from septic patients

    +

    Data set with 2,000 blood culture isolates

    @@ -504,7 +504,7 @@

    microorganisms.codes

    -

    Translation table for microorganism codes

    +

    Translation table for common microorganism codes

    diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html index ddea5210..2b3e0e44 100644 --- a/docs/reference/microorganisms.codes.html +++ b/docs/reference/microorganisms.codes.html @@ -6,7 +6,7 @@ -Translation table for microorganism codes — microorganisms.codes • AMR (for R) +Translation table for common microorganism codes — microorganisms.codes • AMR (for R) @@ -45,7 +45,7 @@ - + @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9055 + 0.7.1.9075
    @@ -223,7 +223,7 @@
    @@ -238,8 +238,8 @@

    Format

    -

    A data.frame with 4,965 observations and 2 variables:

    -
    certe

    Commonly used code of a microorganism

    +

    A data.frame with 4,927 observations and 2 variables:

    +
    code

    Commonly used code of a microorganism

    mo

    ID of the microorganism in the microorganisms data set

    diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html index c02cbe77..cca326e5 100644 --- a/docs/reference/microorganisms.html +++ b/docs/reference/microorganisms.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9055 + 0.7.1.9075
    @@ -238,7 +238,7 @@

    Format

    -

    A data.frame with 69,855 observations and 16 variables:

    +

    A data.frame with 69,460 observations and 16 variables:

    mo

    ID of microorganism as used by this package

    col_id

    Catalogue of Life ID

    fullname

    Full name, like "Escherichia coli"

    @@ -262,7 +262,7 @@
  • 2 entries of Staphylococcus (coagulase-negative [CoNS] and coagulase-positive [CoPS])

  • 3 entries of Trichomonas (Trichomonas vaginalis, and its family and genus)

  • 5 other 'undefined' entries (unknown, unknown Gram negatives, unknown Gram positives, unknown yeast and unknown fungus)

  • -
  • 8,970 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) that are not in the Catalogue of Life

  • +
  • 22,654 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) overwriting records from the Catalogue of Life, since the DSMZ contain the latest taxonomic information based on recent publications

  • About the records from DSMZ (see source)

    diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index 411a3173..14b4ebce 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9055 + 0.7.1.9075
    @@ -238,7 +238,7 @@

    Format

    -

    A data.frame with 22,932 observations and 4 variables:

    +

    A data.frame with 24,246 observations and 4 variables:

    col_id

    Catalogue of Life ID that was originally given

    col_id_new

    New Catalogue of Life ID that responds to an entry in the microorganisms data set

    fullname

    Old full taxonomic name of the microorganism

    diff --git a/index.md b/index.md index b408f390..0f0f5448 100644 --- a/index.md +++ b/index.md @@ -123,7 +123,7 @@ The `AMR` package basically does four important things: 1. It **cleanses existing data** by providing new *classes* for microoganisms, antibiotics and antimicrobial results (both S/I/R and MIC). By installing this package, you teach R everything about microbiology that is needed for analysis. These functions all use intelligent rules to guess results that you would expect: - * Use `as.mo()` to get a microbial ID. The IDs are human readable for the trained eye - the ID of *Klebsiella pneumoniae* is "B_KLBSL_PNE" (B stands for Bacteria) and the ID of *S. aureus* is "B_STPHY_AUR". The function takes almost any text as input that looks like the name or code of a microorganism like "E. coli", "esco" or "esccol" and tries to find expected results using intelligent rules combined with the included Catalogue of Life data set. It only takes milliseconds to find results, please see our [benchmarks](./articles/benchmarks.html). Moreover, it can group *Staphylococci* into coagulase negative and positive (CoNS and CoPS, see [source](./reference/as.mo.html#source)) and can categorise *Streptococci* into Lancefield groups (like beta-haemolytic *Streptococcus* Group B, [source](./reference/as.mo.html#source)). + * Use `as.mo()` to get a microbial ID. The IDs are human readable for the trained eye - the ID of *Klebsiella pneumoniae* is "B_KLBSL_PNMN" (B stands for Bacteria) and the ID of *S. aureus* is "B_STPHY_AURS". The function takes almost any text as input that looks like the name or code of a microorganism like "E. coli", "esco" or "esccol" and tries to find expected results using intelligent rules combined with the included Catalogue of Life data set. It only takes milliseconds to find results, please see our [benchmarks](./articles/benchmarks.html). Moreover, it can group *Staphylococci* into coagulase negative and positive (CoNS and CoPS, see [source](./reference/as.mo.html#source)) and can categorise *Streptococci* into Lancefield groups (like beta-haemolytic *Streptococcus* Group B, [source](./reference/as.mo.html#source)). * Use `as.ab()` to get an antibiotic ID. Like microbial IDs, these IDs are also human readable based on those used by EARS-Net. For example, the ID of amoxicillin is `AMX` and the ID of gentamicin is `GEN`. The `as.ab()` function also uses intelligent rules to find results like accepting misspelling, trade names and abbrevations used in many laboratory systems. For instance, the values "Furabid", "Furadantin", "nitro" all return the ID of Nitrofurantoine. To accomplish this, the package contains a database with most LIS codes, official names, trade names, ATC codes, defined daily doses (DDD) and drug categories of antibiotics. * Use `as.rsi()` to get antibiotic interpretations based on raw MIC values (in mg/L) or disk diffusion values (in mm), or transform existing values to valid antimicrobial results. It produces just S, I or R based on your input and warns about invalid values. Even values like "<=0.002; S" (combined MIC/RSI) will result in "S". * Use `as.mic()` to cleanse your MIC values. It produces a so-called factor (called *ordinal* in SPSS) with valid MIC values as levels. A value like "<=0.002; S" (combined MIC/RSI) will result in "<=0.002". diff --git a/man/as.mo.Rd b/man/as.mo.Rd index 62f40090..64317d8f 100644 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -34,7 +34,7 @@ clear_mo_history(...) This excludes \emph{Enterococci} at default (who are in group D), use \code{Lancefield = "all"} to also categorise all \emph{Enterococci} as group D.} -\item{allow_uncertain}{a number between 0 (or "none") and 3 (or "all"), or TRUE (= 2) or FALSE (= 0) to indicate whether the input should be checked for less possible results, see Details} +\item{allow_uncertain}{a number between 0 (or "none") and 3 (or "all"), or TRUE (= 2) or FALSE (= 0) to indicate whether the input should be checked for less probable results, see Details} \item{reference_df}{a \code{data.frame} to use for extra reference when translating \code{x} to a valid \code{mo}. See \code{\link{set_mo_source}} and \code{\link{get_mo_source}} to automate the usage of your own codes (e.g. used in your analysis or organisation).} @@ -50,16 +50,16 @@ Use this function to determine a valid microorganism ID (\code{mo}). Determinati \strong{General info} \cr A microorganism ID from this package (class: \code{mo}) typically looks like these examples:\cr \preformatted{ - Code Full name - --------------- -------------------------------------- - B_KLBSL Klebsiella - B_KLBSL_PNE Klebsiella pneumoniae - B_KLBSL_PNE_RHI Klebsiella pneumoniae rhinoscleromatis - | | | | - | | | | - | | | ----> subspecies, a 3-4 letter acronym - | | ----> species, a 3-4 letter acronym - | ----> genus, a 5-7 letter acronym, mostly without vowels + Code Full name + --------------- -------------------------------------- + B_KLBSL Klebsiella + B_KLBSL_PNMN Klebsiella pneumoniae + B_KLBSL_PNMN_RHNS Klebsiella pneumoniae rhinoscleromatis + | | | | + | | | | + | | | ---> subspecies, a 4-5 letter acronym + | | ----> species, a 4-5 letter acronym + | ----> genus, a 5-7 letter acronym ----> taxonomic kingdom: A (Archaea), AN (Animalia), B (Bacteria), C (Chromista), F (Fungi), P (Protozoa) } @@ -105,7 +105,7 @@ You can also use e.g. \code{as.mo(..., allow_uncertain = 1)} to only allow up to Examples: \itemize{ - \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRB}) needs review.} + \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRPB}) needs review.} \item{\code{"S. aureus - please mind: MRSA"}. The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result \emph{Staphylococcus aureus} (\code{B_STPHY_AUR}) needs review.} \item{\code{"Fluoroquinolone-resistant Neisseria gonorrhoeae"}. The first word will be stripped, after which the function will try to find a match. A warning will be thrown that the result \emph{Neisseria gonorrhoeae} (\code{B_NESSR_GON}) needs review.} } @@ -154,7 +154,7 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https:// \examples{ \donttest{ -# These examples all return "B_STPHY_AUR", the ID of S. aureus: +# These examples all return "B_STPHY_AURS", the ID of S. aureus: as.mo("sau") # WHONET code as.mo("stau") as.mo("STAU") @@ -179,11 +179,11 @@ as.mo("Streptococcus group A") as.mo("GAS") # Group A Streptococci as.mo("GBS") # Group B Streptococci -as.mo("S. epidermidis") # will remain species: B_STPHY_EPI -as.mo("S. epidermidis", Becker = TRUE) # will not remain species: B_STPHY_CNS +as.mo("S. epidermidis") # will remain species: B_STPHY_EPDR +as.mo("S. epidermidis", Becker = TRUE) # will not remain species: B_STPHY_CONS -as.mo("S. pyogenes") # will remain species: B_STRPT_PYO -as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRA +as.mo("S. pyogenes") # will remain species: B_STRPT_PYGN +as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRPA # All mo_* functions use as.mo() internally too (see ?mo_property): mo_genus("E. coli") # returns "Escherichia" diff --git a/man/example_isolates.Rd b/man/example_isolates.Rd index 0ca805ae..456de6cf 100644 --- a/man/example_isolates.Rd +++ b/man/example_isolates.Rd @@ -3,7 +3,7 @@ \docType{data} \name{example_isolates} \alias{example_isolates} -\title{Data set with 2,000 blood culture isolates from septic patients} +\title{Data set with 2,000 blood culture isolates} \format{A \code{\link{data.frame}} with 2,000 observations and 49 variables: \describe{ \item{\code{date}}{date of receipt at the laboratory} @@ -15,13 +15,13 @@ \item{\code{gender}}{gender of the patient} \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} \item{\code{mo}}{ID of microorganism created with \code{\link{as.mo}}, see also \code{\link{microorganisms}}} - \item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}} + \item{\code{PEN:RIF}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}} }} \usage{ example_isolates } \description{ -An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}. +An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found 4 different hospitals in the Netherlands, between 2001 and 2017. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}. } \section{Read more on our website!}{ diff --git a/man/microorganisms.Rd b/man/microorganisms.Rd index 63d094cd..4ec1ae5a 100755 --- a/man/microorganisms.Rd +++ b/man/microorganisms.Rd @@ -4,7 +4,7 @@ \name{microorganisms} \alias{microorganisms} \title{Data set with ~70,000 microorganisms} -\format{A \code{\link{data.frame}} with 69,855 observations and 16 variables: +\format{A \code{\link{data.frame}} with 69,460 observations and 16 variables: \describe{ \item{\code{mo}}{ID of microorganism as used by this package} \item{\code{col_id}}{Catalogue of Life ID} @@ -34,7 +34,7 @@ Manually added were: \item{2 entries of \emph{Staphylococcus} (coagulase-negative [CoNS] and coagulase-positive [CoPS])} \item{3 entries of \emph{Trichomonas} (\emph{Trichomonas vaginalis}, and its family and genus)} \item{5 other 'undefined' entries (unknown, unknown Gram negatives, unknown Gram positives, unknown yeast and unknown fungus)} - \item{8,970 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) that are not in the Catalogue of Life} + \item{22,654 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) overwriting records from the Catalogue of Life, since the DSMZ contain the latest taxonomic information based on recent publications} } } \section{About the records from DSMZ (see source)}{ diff --git a/man/microorganisms.codes.Rd b/man/microorganisms.codes.Rd index bef7ef17..46d101a8 100644 --- a/man/microorganisms.codes.Rd +++ b/man/microorganisms.codes.Rd @@ -3,10 +3,10 @@ \docType{data} \name{microorganisms.codes} \alias{microorganisms.codes} -\title{Translation table for microorganism codes} -\format{A \code{\link{data.frame}} with 4,965 observations and 2 variables: +\title{Translation table for common microorganism codes} +\format{A \code{\link{data.frame}} with 4,927 observations and 2 variables: \describe{ - \item{\code{certe}}{Commonly used code of a microorganism} + \item{\code{code}}{Commonly used code of a microorganism} \item{\code{mo}}{ID of the microorganism in the \code{\link{microorganisms}} data set} }} \usage{ diff --git a/man/microorganisms.old.Rd b/man/microorganisms.old.Rd index 755fbebd..c15d42f6 100644 --- a/man/microorganisms.old.Rd +++ b/man/microorganisms.old.Rd @@ -4,7 +4,7 @@ \name{microorganisms.old} \alias{microorganisms.old} \title{Data set with previously accepted taxonomic names} -\format{A \code{\link{data.frame}} with 22,932 observations and 4 variables: +\format{A \code{\link{data.frame}} with 24,246 observations and 4 variables: \describe{ \item{\code{col_id}}{Catalogue of Life ID that was originally given} \item{\code{col_id_new}}{New Catalogue of Life ID that responds to an entry in the \code{\link{microorganisms}} data set} diff --git a/pkgdown/extra.js b/pkgdown/extra.js index 1c4fecad..960e0285 100644 --- a/pkgdown/extra.js +++ b/pkgdown/extra.js @@ -81,13 +81,14 @@ $( document ).ready(function() { x = x.replace(/Author, maintainer/g, "Main developer"); x = x.replace(/Author, contributor/g, "Main contributor"); x = x.replace(/Author, thesis advisor/g, "Doctoral advisor"); - x = x.replace("Alex", "Prof. Dr Alex"); - x = x.replace("Bhanu", "Prof. Dr Bhanu"); - x = x.replace("Casper", "Prof. Dr Casper"); - x = x.replace("Corinna", "Dr Corinna"); + x = x.replace("Alex", "Prof. Dr. Alex"); + x = x.replace("Bhanu", "Prof. Dr. Bhanu"); + x = x.replace("Casper", "Prof. Dr. Casper"); + x = x.replace("Corinna", "Dr. Corinna"); // others - x = x.replace("Bart", "Dr Bart"); - x = x.replace("Dennis", "Dr Dennis"); + x = x.replace("Bart", "Dr. Bart"); + x = x.replace("Dennis", "Dr. Dennis"); + x = x.replace("Judith", "Dr. Judith"); } return(x); } diff --git a/tests/testthat/test-first_isolate.R b/tests/testthat/test-first_isolate.R index e30cb6f9..e3640ef7 100755 --- a/tests/testthat/test-first_isolate.R +++ b/tests/testthat/test-first_isolate.R @@ -190,19 +190,19 @@ test_that("first isolates work", { # unknown MOs expect_equal(example_isolates %>% - mutate(mo = ifelse(mo == "B_ESCHR_COL", "UNKNOWN", mo)) %>% + mutate(mo = ifelse(mo == "B_ESCHR_COLI", "UNKNOWN", mo)) %>% mutate(first = first_isolate(., include_unknown = FALSE)) %>% .$first %>% sum(), 1062) expect_equal(example_isolates %>% - mutate(mo = ifelse(mo == "B_ESCHR_COL", "UNKNOWN", mo)) %>% + mutate(mo = ifelse(mo == "B_ESCHR_COLI", "UNKNOWN", mo)) %>% mutate(first = first_isolate(., include_unknown = TRUE)) %>% .$first %>% sum(), 1529) expect_equal(example_isolates %>% - mutate(mo = ifelse(mo == "B_ESCHR_COL", NA, mo)) %>% + mutate(mo = ifelse(mo == "B_ESCHR_COLI", NA, mo)) %>% mutate(first = first_isolate(.)) %>% .$first %>% sum(), diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index 9f1e94e1..c115db54 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -26,8 +26,8 @@ test_that("frequency table works", { # mo expect_true(is.freq(freq(example_isolates$mo))) # for this to work, the output of mo_gramstain() is to be expected as follows: - expect_equal(mo_gramstain("B_ESCHR_COL", language = NULL), "Gram-negative") - expect_equal(mo_gramstain("B_STPHY_AUR", language = NULL), "Gram-positive") + expect_equal(mo_gramstain("B_ESCHR_COLI", language = NULL), "Gram-negative") + expect_equal(mo_gramstain("B_STPHY_AURS", language = NULL), "Gram-positive") # rsi expect_true(is.freq(freq(example_isolates$AMX))) diff --git a/tests/testthat/test-join_microorganisms.R b/tests/testthat/test-join_microorganisms.R index 3f2e77fa..a637346d 100755 --- a/tests/testthat/test-join_microorganisms.R +++ b/tests/testthat/test-join_microorganisms.R @@ -45,17 +45,17 @@ test_that("joins work", { expect_true(nrow(unjoined) < nrow(full)) - expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COL")), 1) - expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COL", by = c("mo" = "mo"))), 1) + expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COLI")), 1) + expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COLI", by = c("mo" = "mo"))), 1) expect_warning(inner_join_microorganisms("Escherichia", by = c("mo" = "genus"))) - expect_equal(nrow(left_join_microorganisms("B_ESCHR_COL")), 1) + expect_equal(nrow(left_join_microorganisms("B_ESCHR_COLI")), 1) expect_warning(left_join_microorganisms("Escherichia", by = c("mo" = "genus"))) - expect_equal(nrow(semi_join_microorganisms("B_ESCHR_COL")), 1) - expect_equal(nrow(anti_join_microorganisms("B_ESCHR_COL")), 0) + expect_equal(nrow(semi_join_microorganisms("B_ESCHR_COLI")), 1) + expect_equal(nrow(anti_join_microorganisms("B_ESCHR_COLI")), 0) - expect_warning(right_join_microorganisms("B_ESCHR_COL")) - expect_warning(full_join_microorganisms("B_ESCHR_COL")) + expect_warning(right_join_microorganisms("B_ESCHR_COLI")) + expect_warning(full_join_microorganisms("B_ESCHR_COLI")) }) diff --git a/tests/testthat/test-mdro.R b/tests/testthat/test-mdro.R index e17cf7c8..7bce8e03 100755 --- a/tests/testthat/test-mdro.R +++ b/tests/testthat/test-mdro.R @@ -40,7 +40,7 @@ test_that("mdro works", { # example_isolates should have these finding using Dutch guidelines expect_equal(outcome %>% freq() %>% pull(count), - c(1969, 25, 6)) # 1969 neg, 25 unconfirmed, 6 pos + c(1972, 22, 6)) # 1969 neg, 25 unconfirmed, 6 pos expect_equal(brmo(example_isolates, info = FALSE), mdro(example_isolates, guideline = "BRMO", info = FALSE)) diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index 9fbaa3a6..3becb18c 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -31,49 +31,50 @@ test_that("as.mo works", { expect_identical( as.character(as.mo(c("E. coli", "H. influenzae"))), - c("B_ESCHR_COL", "B_HMPHL_INF")) + c("B_ESCHR_COLI", "B_HMPHL_INFL")) - expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL") - expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL") - expect_equal(as.character(as.mo(22242416)), "B_ESCHR_COL") + expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") + expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") + expect_equal(as.character(as.mo(22242416)), "B_ESCHR_COLI") expect_equal(as.character(as.mo("Escherichia species")), "B_ESCHR") expect_equal(as.character(as.mo("Escherichia")), "B_ESCHR") expect_equal(as.character(as.mo("Esch spp.")), "B_ESCHR") - expect_equal(as.character(as.mo(" B_ESCHR_COL ")), "B_ESCHR_COL") - expect_equal(as.character(as.mo("e coli")), "B_ESCHR_COL") # not Campylobacter - expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNE") + expect_equal(as.character(as.mo(" B_ESCHR_COLI ")), "B_ESCHR_COLI") + expect_equal(as.character(as.mo("e coli")), "B_ESCHR_COLI") # not Campylobacter + expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNMN") expect_equal(as.character(as.mo("Klebsiella")), "B_KLBSL") - expect_equal(as.character(as.mo("K. pneu rhino")), "B_KLBSL_PNE_RHI") # K. pneumoniae subspp. rhinoscleromatis + expect_equal(as.character(as.mo("K. pneu rhino")), "B_KLBSL_PNMN_RHNS") # K. pneumoniae subspp. rhinoscleromatis expect_equal(as.character(as.mo("Bartonella")), "B_BRTNL") - expect_equal(as.character(as.mo("C. difficile")), "B_CLSTR_DIF") - expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNE") + expect_equal(as.character(as.mo("C. difficile")), "B_CTRDM_DFFC") + expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNMP") expect_equal(as.character(as.mo("Strepto")), "B_STRPT") expect_equal(as.character(as.mo("Streptococcus")), "B_STRPT") # not Peptostreptoccus - expect_equal(as.character(as.mo("Estreptococos grupo B")), "B_STRPT_GRB") - expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRB") - expect_equal(as.character(as.mo("B_STRPTC")), "B_STRPT") # old MO code (<=v0.5.0) + expect_equal(as.character(as.mo("Estreptococos grupo B")), "B_STRPT_GRPB") + expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRPB") + expect_equal(as.character(suppressWarnings(as.mo("B_STRPTC"))), "B_STRPT") # old MO code (<=v0.5.0) + expect_equal(as.character(suppressWarnings(as.mo("B_STRPT_PNE"))), "B_STRPT_PNMN") # old MO code (<=v0.8.0) - expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRA", "B_STRPT_GRB")) + expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRPA", "B_STRPT_GRPB")) - expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYO") # not Actinomyces pyogenes + expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYGN") # not Actinomyces pyogenes # GLIMS - expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRA") + expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRGL") - expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPI") + expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPDR") expect_equal(as.character(as.mo("VRE")), "B_ENTRC") - expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_AER") - expect_equal(as.character(as.mo("PISP")), "B_STRPT_PNE") - expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNE") - expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNE") - expect_equal(as.character(as.mo("VRSP")), "B_STRPT_PNE") + expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_ARGN") + expect_equal(as.character(as.mo("PISP")), "B_STRPT_PNMN") + expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNMN") + expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNMN") + expect_equal(as.character(as.mo("VRSP")), "B_STRPT_PNMN") - expect_equal(as.character(as.mo("CNS")), "B_STPHY_CNS") - expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CNS") - expect_equal(as.character(as.mo("CPS")), "B_STPHY_CPS") - expect_equal(as.character(as.mo("CoPS")), "B_STPHY_CPS") - expect_equal(as.character(as.mo("VGS")), "B_STRPT_VIR") - expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MIL") + expect_equal(as.character(as.mo("CNS")), "B_STPHY_CONS") + expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CONS") + expect_equal(as.character(as.mo("CPS")), "B_STPHY_COPS") + expect_equal(as.character(as.mo("CoPS")), "B_STPHY_COPS") + expect_equal(as.character(as.mo("VGS")), "B_STRPT_VIRI") + expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MILL") expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAMN", "B_GRAMP")) @@ -90,11 +91,11 @@ test_that("as.mo works", { "Staphylococcus aureus", "MRSA", "VISA")))), - rep("B_STPHY_AUR", 9)) + rep("B_STPHY_AURS", 9)) expect_identical( as.character( as.mo(c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC', 'UPEC'))), - rep("B_ESCHR_COL", 6)) + rep("B_ESCHR_COLI", 6)) # unprevalent MO expect_identical( as.character( @@ -102,7 +103,7 @@ test_that("as.mo works", { "B. nodosa", "B nodosa", "Burkholderia nodosa"))), - rep("B_BRKHL_NOD", 4)) + rep("B_BRKHL_NODS", 4)) # empty values expect_identical(as.character(as.mo(c("", NA, NaN))), rep(NA_character_, 3)) @@ -110,40 +111,40 @@ test_that("as.mo works", { expect_warning(as.mo("ab")) expect_equal(suppressWarnings(as.character(as.mo(c("Qq species", "", "CRS", "K. pneu rhino", "esco")))), - c("UNKNOWN", NA_character_, "B_STNTR_MAL", "B_KLBSL_PNE_RHI", "B_ESCHR_COL")) + c("UNKNOWN", NA_character_, "B_STNTR_MLTP", "B_KLBSL_PNMN_RHNS", "B_ESCHR_COLI")) # check for Becker classification - expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPI") - expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CNS") - expect_identical(as.character(as.mo("STAEPI", Becker = TRUE)), "B_STPHY_CNS") - expect_identical(as.character(as.mo("S. intermedius", Becker = FALSE)), "B_STPHY_INT") - expect_identical(as.character(as.mo("Sta intermedius",Becker = FALSE)), "B_STPHY_INT") - expect_identical(as.character(as.mo("Sta intermedius",Becker = TRUE)), "B_STPHY_CPS") - expect_identical(as.character(as.mo("STAINT", Becker = TRUE)), "B_STPHY_CPS") + expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR") + expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS") + expect_identical(as.character(as.mo("STAEPI", Becker = TRUE)), "B_STPHY_CONS") + expect_identical(as.character(as.mo("S. intermedius", Becker = FALSE)), "B_STPHY_INTR") + expect_identical(as.character(as.mo("Sta intermedius",Becker = FALSE)), "B_STPHY_INTR") + expect_identical(as.character(as.mo("Sta intermedius",Becker = TRUE)), "B_STPHY_COPS") + expect_identical(as.character(as.mo("STAINT", Becker = TRUE)), "B_STPHY_COPS") # aureus must only be influenced if Becker = "all" - expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AUR") - expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AUR") - expect_identical(as.character(as.mo("STAAUR", Becker = "all")), "B_STPHY_CPS") + expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AURS") + expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AURS") + expect_identical(as.character(as.mo("STAAUR", Becker = "all")), "B_STPHY_COPS") # check for Lancefield classification - expect_identical(as.character(as.mo("S. pyogenes", Lancefield = FALSE)), "B_STRPT_PYO") - expect_identical(as.character(as.mo("S. pyogenes", Lancefield = TRUE)), "B_STRPT_GRA") - expect_identical(as.character(as.mo("STCPYO", Lancefield = TRUE)), "B_STRPT_GRA") # group A - expect_identical(as.character(as.mo("S. agalactiae", Lancefield = FALSE)), "B_STRPT_AGA") - expect_identical(as.character(as.mo("S. agalactiae", Lancefield = TRUE)), "B_STRPT_GRB") # group B - expect_identical(as.character(suppressWarnings(as.mo("estreptococos grupo B"))), "B_STRPT_GRB") - expect_identical(as.character(as.mo("S. equisimilis", Lancefield = FALSE)), "B_STRPT_DYS_EQU") - expect_identical(as.character(as.mo("S. equisimilis", Lancefield = TRUE)), "B_STRPT_GRC") # group C + expect_identical(as.character(as.mo("S. pyogenes", Lancefield = FALSE)), "B_STRPT_PYGN") + expect_identical(as.character(as.mo("S. pyogenes", Lancefield = TRUE)), "B_STRPT_GRPA") + expect_identical(as.character(as.mo("STCPYO", Lancefield = TRUE)), "B_STRPT_GRPA") # group A + expect_identical(as.character(as.mo("S. agalactiae", Lancefield = FALSE)), "B_STRPT_AGLC") + expect_identical(as.character(as.mo("S. agalactiae", Lancefield = TRUE)), "B_STRPT_GRPB") # group B + expect_identical(as.character(suppressWarnings(as.mo("estreptococos grupo B"))), "B_STRPT_GRPB") + expect_identical(as.character(as.mo("S. equisimilis", Lancefield = FALSE)), "B_STRPT_DYSG_EQSM") + expect_identical(as.character(as.mo("S. equisimilis", Lancefield = TRUE)), "B_STRPT_GRPC") # group C # Enterococci must only be influenced if Lancefield = "all" - expect_identical(as.character(as.mo("E. faecium", Lancefield = FALSE)), "B_ENTRC_IUM") - expect_identical(as.character(as.mo("E. faecium", Lancefield = TRUE)), "B_ENTRC_IUM") - expect_identical(as.character(as.mo("E. faecium", Lancefield = "all")), "B_STRPT_GRD") # group D - expect_identical(as.character(as.mo("S. anginosus", Lancefield = FALSE)), "B_STRPT_ANG") - expect_identical(as.character(as.mo("S. anginosus", Lancefield = TRUE)), "B_STRPT_GRF") # group F - expect_identical(as.character(as.mo("S. sanguinis", Lancefield = FALSE)), "B_STRPT_SAN") - expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRPT_GRH") # group H - expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SAL") - expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRK") # group K + expect_identical(as.character(as.mo("E. faecium", Lancefield = FALSE)), "B_ENTRC_FACM") + expect_identical(as.character(as.mo("E. faecium", Lancefield = TRUE)), "B_ENTRC_FACM") + expect_identical(as.character(as.mo("E. faecium", Lancefield = "all")), "B_STRPT_GRPD") # group D + expect_identical(as.character(as.mo("S. anginosus", Lancefield = FALSE)), "B_STRPT_ANGN") + expect_identical(as.character(as.mo("S. anginosus", Lancefield = TRUE)), "B_STRPT_GRPF") # group F + expect_identical(as.character(as.mo("S. sanguinis", Lancefield = FALSE)), "B_STRPT_SNGN") + expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRPT_GRPH") # group H + expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR") + expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K library(dplyr) @@ -173,14 +174,14 @@ test_that("as.mo works", { expect_error(example_isolates %>% select(1:3) %>% as.mo()) # print - expect_output(print(as.mo(c("B_ESCHR_COL", NA)))) + expect_output(print(as.mo(c("B_ESCHR_COLI", NA)))) # test pull expect_equal(nrow(example_isolates %>% mutate(mo = as.mo(mo))), 2000) # test data.frame - expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COL"))), + expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COLI"))), 1) # check empty values @@ -188,40 +189,40 @@ test_that("as.mo works", { NA_character_) # check less prevalent MOs - expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APO_DEL") - expect_equal(as.character(as.mo("Gomphosphaeria apo del")), "B_GMPHS_APO_DEL") - expect_equal(as.character(as.mo("G apo deli")), "B_GMPHS_APO_DEL") - expect_equal(as.character(as.mo("Gomphosphaeria aponina")), "B_GMPHS_APO") + expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APNN_DLCT") + expect_equal(as.character(as.mo("Gomphosphaeria apo del")), "B_GMPHS_APNN_DLCT") + expect_equal(as.character(as.mo("G apo deli")), "B_GMPHS_APNN_DLCT") + expect_equal(as.character(as.mo("Gomphosphaeria aponina")), "B_GMPHS_APNN") expect_equal(as.character(as.mo("Gomphosphaeria species")), "B_GMPHS") expect_equal(as.character(as.mo("Gomphosphaeria")), "B_GMPHS") - expect_equal(as.character(as.mo(" B_GMPHS_APO ")), "B_GMPHS_APO") - expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APO") + expect_equal(as.character(as.mo(" B_GMPHS_APNN ")), "B_GMPHS_APNN") + expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APNN") # check old names - expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLA") + expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLTT") print(mo_renamed()) # check uncertain names - expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AUR") + expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = FALSE))), "UNKNOWN") expect_warning(as.mo("esco extra_text", allow_uncertain = TRUE)) - expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AUR") + expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY") - expect_equal(suppressWarnings(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AUR") + expect_equal(suppressWarnings(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AURS") # predefined reference_df expect_equal(as.character(as.mo("TestingOwnID", - reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COL"))), - "B_ESCHR_COL") + reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COLI"))), + "B_ESCHR_COLI") expect_equal(as.character(as.mo(c("TestingOwnID", "E. coli"), - reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COL"))), - c("B_ESCHR_COL", "B_ESCHR_COL")) + reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COLI"))), + c("B_ESCHR_COLI", "B_ESCHR_COLI")) expect_warning(as.mo("TestingOwnID", reference_df = NULL)) expect_error(as.mo("E. coli", reference_df = data.frame(mycol = "TestingOwnID"))) # combination of existing mo and other code - expect_identical(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL"))), - c("B_ESCHR_COL", "B_ESCHR_COL")) + expect_identical(suppressWarnings(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL")))), + c("B_ESCHR_COLI", "B_ESCHR_COLI")) # expect_equal(mo_fullname(c("E. spp.", # "E. spp", @@ -230,24 +231,24 @@ test_that("as.mo works", { # from different sources expect_equal(as.character(as.mo( - c("PRTMIR", "bclcer", "B_ESCHR_COL"))), - c("B_PROTS_MIR", "B_BCLLS_CER", "B_ESCHR_COL")) + c("PRTMIR", "bclcer", "B_ESCHR_COLI"))), + c("B_PROTS_MRBL", "B_BCLLS_CERS", "B_ESCHR_COLI")) # hard to find expect_equal(as.character(suppressWarnings(as.mo( c("Microbacterium paraoxidans", "Streptococcus suis (bovis gr)", "Raoultella (here some text) terrigena")))), - c("B_MCRBC_PAR", "B_STRPT_SUI", "B_RLTLL_TER")) - print(mo_uncertainties()) + c("B_MCRBC_PRXY", "B_STRPT_SUIS", "B_RLTLL_TRRG")) + expect_output(print(mo_uncertainties())) # Salmonella (City) are all actually Salmonella enterica spp (City) expect_equal(as.character(suppressWarnings(as.mo("Salmonella Goettingen"))), - "B_SLMNL_ENT") + "B_SLMNL_ENTR") expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL") # no virusses - expect_warning(as.mo("Virus")) + expect_equal(as.character(as.mo("Virus")), NA_character_) # summary expect_equal(length(summary(example_isolates$mo)), 6) @@ -257,7 +258,7 @@ test_that("as.mo works", { rep(NA_character_, 3)) expect_equal(as.character(as.mo("con")), "UNKNOWN") expect_equal(as.character(as.mo("xxx")), NA_character_) - expect_equal(as.character(as.mo(c("xxx", "con", "eco"))), c(NA_character_, "UNKNOWN", "B_ESCHR_COL")) + expect_equal(as.character(as.mo(c("xxx", "con", "eco"))), c(NA_character_, "UNKNOWN", "B_ESCHR_COLI")) expect_equal(as.character(as.mo(c("other", "none", "unknown"))), rep("UNKNOWN", 3)) @@ -271,21 +272,21 @@ test_that("as.mo works", { expect_error(translate_allow_uncertain(5)) # very old MO codes (<= v0.5.0) - expect_equal(as.character(as.mo("F_CCCCS_NEO")), "F_CRYPT_NEO") - expect_equal(as.character(as.mo("F_CANDD_GLB")), "F_CANDD_GLA") + expect_equal(suppressWarnings(as.character(as.mo("F_CCCCS_NEO"))), "F_CRYPT_NFRM") + expect_equal(suppressWarnings(as.character(as.mo("F_CANDD_GLB"))), "F_CANDD_GLBR") # debug mode expect_output(print(suppressMessages(suppressWarnings(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3))))) # ..coccus expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))), - c("B_NESSR_MEN", "B_NESSR_GON", "B_STRPT_PNE")) + c("B_NESSR_MNNG", "B_NESSR_GNRR", "B_STRPT_PNMN")) # yeasts and fungi expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))), c("F_YEAST", "F_FUNGUS")) # print tibble - expect_output(print(tibble(mo = as.mo("B_STRPT_PNE")))) + expect_output(print(tibble(mo = as.mo("B_ESCHR_COLI")))) # assigning and subsetting x <- example_isolates$mo diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 969948d4..777f922a 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -57,7 +57,7 @@ test_that("mo_property works", { expect_equal(mo_shortname("Streptococcus agalactiae"), "S. agalactiae") expect_equal(mo_shortname("Streptococcus agalactiae", Lancefield = TRUE), "GBS") - expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org") + #expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org") # test integrity MOs <- AMR::microorganisms diff --git a/tests/testthat/test-read.4d.R b/tests/testthat/test-read.4d.R index a52def16..4d5e5d4a 100644 --- a/tests/testthat/test-read.4d.R +++ b/tests/testthat/test-read.4d.R @@ -45,7 +45,7 @@ test_that("read 4D works", { expect_equal(ncol(x), 11) expect_equal(class(x$date_received), "Date") expect_equal(class(x$mo), "mo") - expect_equal(as.character(x$mo), "B_ESCHR_COL") + expect_equal(as.character(x$mo), "B_ESCHR_COLI") expect_equal(is.rsi(x$peni), TRUE) }) diff --git a/tests/testthat/test-resistance_predict.R b/tests/testthat/test-resistance_predict.R index 20fb4a47..527634ca 100644 --- a/tests/testthat/test-resistance_predict.R +++ b/tests/testthat/test-resistance_predict.R @@ -23,7 +23,7 @@ context("resistance_predict.R") test_that("prediction of rsi works", { AMX_R <- example_isolates %>% - filter(mo == "B_ESCHR_COL") %>% + filter(mo == "B_ESCHR_COLI") %>% rsi_predict(col_ab = "AMX", col_date = "date", model = "binomial", @@ -40,47 +40,47 @@ test_that("prediction of rsi works", { library(dplyr) - expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "AMX", col_date = "date", info = TRUE)) - expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "loglin", col_ab = "AMX", col_date = "date", info = TRUE)) - expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_output(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "lin", col_ab = "AMX", col_date = "date", info = TRUE)) - expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "INVALID MODEL", col_ab = "AMX", col_date = "date", info = TRUE)) - expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "NOT EXISTING COLUMN", col_date = "date", info = TRUE)) - expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "AMX", col_date = "NOT EXISTING COLUMN", info = TRUE)) - expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), col_ab = "AMX", col_date = "NOT EXISTING COLUMN", info = TRUE)) - expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(rsi_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), col_ab = "AMX", col_date = "date", info = TRUE)) # almost all E. coli are MEM S in the Netherlands :) - expect_error(resistance_predict(x = filter(example_isolates, mo == "B_ESCHR_COL"), + expect_error(resistance_predict(x = filter(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "MEM", col_date = "date", diff --git a/tests/testthat/test-rsi.R b/tests/testthat/test-rsi.R index 28a6b51e..1703a5d9 100644 --- a/tests/testthat/test-rsi.R +++ b/tests/testthat/test-rsi.R @@ -58,13 +58,13 @@ test_that("rsi works", { test_that("mic2rsi works", { expect_equal(as.character( as.rsi(x = as.mic(0.125), - mo = "B_STRPT_PNE", + mo = "B_STRPT_PNMN", ab = "AMX", guideline = "EUCAST")), "S") expect_equal(as.character( as.rsi(x = as.mic(4), - mo = "B_STRPT_PNE", + mo = "B_STRPT_PNMN", ab = "AMX", guideline = "EUCAST")), "R") @@ -80,19 +80,19 @@ test_that("mic2rsi works", { test_that("disk2rsi works", { expect_equal(as.character( as.rsi(x = as.disk(22), - mo = "B_STRPT_PNE", + mo = "B_STRPT_PNMN", ab = "ERY", guideline = "CLSI")), "S") expect_equal(as.character( as.rsi(x = as.disk(18), - mo = "B_STRPT_PNE", + mo = "B_STRPT_PNMN", ab = "ERY", guideline = "CLSI")), "I") expect_equal(as.character( as.rsi(x = as.disk(10), - mo = "B_STRPT_PNE", + mo = "B_STRPT_PNMN", ab = "ERY", guideline = "CLSI")), "R") diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd index a5928899..68013505 100755 --- a/vignettes/benchmarks.Rmd +++ b/vignettes/benchmarks.Rmd @@ -64,7 +64,7 @@ library(microbenchmark) library(AMR) ``` -In the next test, we try to 'coerce' different input values for *Staphylococcus aureus*. The actual result is the same every time: it returns its MO code `B_STPHY_AUR` (*B* stands for *Bacteria*, the taxonomic kingdom). +In the next test, we try to 'coerce' different input values for *Staphylococcus aureus*. The actual result is the same every time: it returns its MO code `B_STPHY_AURS` (*B* stands for *Bacteria*, the taxonomic kingdom). But the calculation time differs a lot: @@ -93,7 +93,7 @@ ggplot.bm(S.aureus) In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred. -To achieve this speed, the `as.mo` function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of *Thermus islandicus* (`B_THERMS_ISL`), a bug probably never found before in humans: +To achieve this speed, the `as.mo` function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of *Thermus islandicus* (`B_THERMS_ISLN`), a bug probably never found before in humans: ```{r} T.islandicus <- microbenchmark(as.mo("theisl"), @@ -198,7 +198,7 @@ So transforming 500,000 values (!!) of `r n_distinct(x)` unique values only take What about precalculated results? If the input is an already precalculated result of a helper function like `mo_name()`, it almost doesn't take any time at all (see 'C' below): ```{r} -run_it <- microbenchmark(A = mo_name("B_STPHY_AUR"), +run_it <- microbenchmark(A = mo_name("B_STPHY_AURS"), B = mo_name("S. aureus"), C = mo_name("Staphylococcus aureus"), times = 10)