diff --git a/DESCRIPTION b/DESCRIPTION index 3b9c49e8..5c62f9b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.5.0.9019 -Date: 2019-02-27 +Version: 0.5.0.9020 +Date: 2019-02-28 Title: Antimicrobial Resistance Analysis Authors@R: c( person( @@ -52,7 +52,7 @@ Imports: hms, knitr (>= 1.0.0), microbenchmark, - rlang (>= 0.2.0), + rlang (>= 0.3.1), tidyr (>= 0.7.0) Suggests: covr (>= 3.0.1), diff --git a/NAMESPACE b/NAMESPACE index 15abcb3d..44c0422e 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,8 @@ S3method(print,atc) S3method(print,frequency_tbl) S3method(print,mic) S3method(print,mo) +S3method(print,mo_renamed) +S3method(print,mo_uncertainties) S3method(print,rsi) S3method(pull,atc) S3method(pull,mo) @@ -179,6 +181,8 @@ exportMethods(print.atc) exportMethods(print.frequency_tbl) exportMethods(print.mic) exportMethods(print.mo) +exportMethods(print.mo_renamed) +exportMethods(print.mo_uncertainties) exportMethods(print.rsi) exportMethods(pull.atc) exportMethods(pull.mo) @@ -203,6 +207,7 @@ importFrom(crayon,magenta) importFrom(crayon,red) importFrom(crayon,silver) importFrom(crayon,strip_style) +importFrom(crayon,yellow) importFrom(data.table,as.data.table) importFrom(data.table,data.table) importFrom(data.table,setkey) diff --git a/NEWS.md b/NEWS.md index 971c292a..83092115 100755 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ We've got a new website: [https://msberends.gitlab.io/AMR](https://msberends.git * Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The `microorganisms` data set now contains: * All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses * All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales (covering at least like all species of *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*) + * All ~2,000 (sub)species from ~100 other relevant genera, from the kingdoms of Animalia and Plantae (like *Strongyloides* and *Taenia*) * All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed * The responsible author(s) and year of scientific publication diff --git a/R/catalogue_of_life.R b/R/catalogue_of_life.R index 4bca4357..0b9c98fd 100755 --- a/R/catalogue_of_life.R +++ b/R/catalogue_of_life.R @@ -23,13 +23,16 @@ #' #' This package contains the complete taxonomic tree of almost all microorganisms from the authoritative and comprehensive Catalogue of Life. #' @section Catalogue of Life: -#' \if{html}{\figure{logo_col.png}{options: height=60px style=margin-bottom:5px} \cr} -#' This package contains the complete taxonomic tree of almost all microorganisms from the authoritative and comprehensive Catalogue of Life (\url{http://www.catalogueoflife.org}). This data is updated annually - check the included version with \code{\link{catalogue_of_life_version}()}. +#' \if{html}{\figure{logo_col.png}{options: height=40px style=margin-bottom:5px} \cr} +#' This package contains the complete taxonomic tree of almost all microorganisms (~60,000 species) from the authoritative and comprehensive Catalogue of Life (\url{http://www.catalogueoflife.org}). The Catalogue of Life is the most comprehensive and authoritative global index of species currently available. #' +#' \link[=catalogue_of_life]{Click here} for more information about the included taxa. The Catalogue of Life releases updates annually; check which version was included in this package with \code{\link{catalogue_of_life_version}()}. +#' @section Included taxa: #' Included are: #' \itemize{ #' \item{All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses} -#' \item{All ~3,500 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales, Schizosaccharomycetales and Tremellales. This covers the most relevant microbial fungi (like all species of \emph{Aspergillus}, \emph{Candida}, \emph{Cryptococcus}, \emph{Histplasma}, \emph{Pneumocystis}, \emph{Saccharomyces} and \emph{Trichophyton}).} +#' \item{All ~3,500 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales, Schizosaccharomycetales and Tremellales. The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant fungi are covered (like all species of \emph{Aspergillus}, \emph{Candida}, \emph{Cryptococcus}, \emph{Histplasma}, \emph{Pneumocystis}, \emph{Saccharomyces} and \emph{Trichophyton}).} +#' \item{All ~2,000 (sub)species from ~100 other relevant genera, from the kingdoms of Animalia and Plantae (like \emph{Strongyloides} and \emph{Taenia})} #' \item{All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed} #' \item{The complete taxonomic tree of all included (sub)species: from kingdom to subspecies} #' \item{The responsible author(s) and year of scientific publication} diff --git a/R/mo.R b/R/mo.R index a381f408..a1b38299 100755 --- a/R/mo.R +++ b/R/mo.R @@ -47,12 +47,13 @@ #' | | | ----> subspecies, a 3-4 letter acronym #' | | ----> species, a 3-4 letter acronym #' | ----> genus, a 5-7 letter acronym, mostly without vowels -#' ----> taxonomic kingdom: A (Archaea), B (Bacteria), C (Chromista), -#' F (Fungi), P (Protozoa) or V (Viruses) +#' ----> taxonomic kingdom: A (Archaea), AN (Animalia), B (Bacteria), C (Chromista), +#' F (Fungi), P (Protozoa), PL (Plantae) or V (Viruses) #' } #' #' Use the \code{\link{mo_property}} functions to get properties based on the returned code, see Examples. #' +#' \strong{Artificial Intelligence} \cr #' This function uses Artificial Intelligence (AI) to help getting fast and logical results. It tries to find matches in this order: #' \itemize{ #' \item{Taxonomic kingdom: it first searches in Bacteria, then Fungi, then Protozoa} @@ -67,9 +68,9 @@ #' \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae} for the same reason} #' \item{Something like \code{"stau"} or \code{"S aur"} will return the ID of \emph{Staphylococcus aureus} and not \emph{Staphylococcus auricularis}} #' } -#' This means that looking up human pathogenic microorganisms takes less time than looking up human \strong{non}-pathogenic microorganisms. +#' This means that looking up human pathogenic microorganisms takes less time than looking up human non-pathogenic microorganisms. #' -#' \strong{UNCERTAIN RESULTS} \cr +#' \strong{Uncertain results} \cr #' When using \code{allow_uncertain = TRUE} (which is the default setting), it will use additional rules if all previous AI rules failed to get valid results. These are: #' \itemize{ #' \item{It tries to look for previously accepted (but now invalid) taxonomic names} @@ -88,11 +89,11 @@ #' #' Use \code{mo_failures()} to get a vector with all values that could not be coerced to a valid value. #' -#' Use \code{mo_uncertainties()} to get info about all values that were coerced to a valid value, but with uncertainty. +#' Use \code{mo_uncertainties()} to get a data.frame with all values that were coerced to a valid value, but with uncertainty. #' #' Use \code{mo_renamed()} to get a vector with all values that could be coerced based on an old, previously accepted taxonomic name. #' -#' @section Microbial prevalence of pathogens in humans: +#' \strong{Microbial prevalence of pathogens in humans} \cr #' The artificial intelligence takes into account microbial prevalence of pathogens in humans. It uses three groups and every (sub)species is in the group it matches first. These groups are: #' \itemize{ #' \item{1 (most prevalent): class is Gammaproteobacteria \strong{or} genus is one of: \emph{Enterococcus}, \emph{Staphylococcus}, \emph{Streptococcus}.} @@ -102,7 +103,7 @@ #' #' Group 1 contains all common Gram negatives, like all Enterobacteriaceae and e.g. \emph{Pseudomonas} and \emph{Legionella}. #' -#' Group 2 probably contains all microbial pathogens ever found in humans. +#' Group 2 probably contains all other microbial pathogens ever found in humans. #' @inheritSection catalogue_of_life Catalogue of Life # (source as a section, so it can be inherited by other man pages) #' @section Source: @@ -618,10 +619,6 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, if (length(found) > 0) { return(found[1L]) } - found <- data_to_check[fullname %like% f.x_withspaces_end_only, ..property][[1]] - if (length(found) > 0 & nchar(b.x_trimmed) >= 6) { - return(found[1L]) - } # try splitting of characters in the middle and then find ID ---- # only when text length is 6 or lower @@ -709,7 +706,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # check for uncertain results ---- if (allow_uncertain == TRUE) { - uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only) { + uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only, f.x_withspaces_end_only) { # (1) look for genus only, part of name ---- if (nchar(b.x_trimmed) > 4 & !b.x_trimmed %like% " ") { @@ -719,7 +716,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, if (length(found) > 0) { x[i] <- found[1L] uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 2, + input = a.x_backup, fullname = microorganismsDT[mo == found[1L], fullname][[1]], mo = found[1L])) return(x) @@ -745,27 +743,42 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, ref_new = microorganismsDT[col_id == found[1, col_id_new], ref], mo = microorganismsDT[col_id == found[1, col_id_new], mo]) uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 1, + input = a.x_backup, fullname = found[1, fullname], mo = paste("CoL", found[1, col_id]))) return(x) } - # (3) strip values between brackets ---- - a.x_backup_stripped <- gsub("( [(].*[)])", "", a.x_backup) - a.x_backup_stripped <- trimws(gsub(" ", " ", a.x_backup_stripped, fixed = TRUE)) - found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup_stripped, clear_options = FALSE, allow_uncertain = FALSE))) - if (!is.na(found) & nchar(b.x_trimmed) >= 6) { + # (3) not yet implemented taxonomic changes in Catalogue of Life ---- + found <- suppressMessages(suppressWarnings(exec_as.mo(TEMPORARY_TAXONOMY(b.x_trimmed), clear_options = FALSE, allow_uncertain = FALSE))) + if (!is.na(found)) { found_result <- found found <- microorganismsDT[mo == found, ..property][[1]] uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 1, + input = a.x_backup, fullname = microorganismsDT[mo == found_result[1L], fullname][[1]], mo = found_result[1L])) return(found[1L]) } - # (4) try to strip off one element from end and check the remains ---- + # (4) strip values between brackets ---- + a.x_backup_stripped <- gsub("( *[(].*[)] *)", " ", a.x_backup) + a.x_backup_stripped <- trimws(gsub(" +", " ", a.x_backup_stripped)) + found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup_stripped, clear_options = FALSE, allow_uncertain = FALSE))) + if (!is.na(found) & nchar(b.x_trimmed) >= 6) { + found_result <- found + found <- microorganismsDT[mo == found, ..property][[1]] + uncertainties <<- rbind(uncertainties, + data.frame(uncertainty = 2, + input = a.x_backup, + fullname = microorganismsDT[mo == found_result[1L], fullname][[1]], + mo = found_result[1L])) + return(found[1L]) + } + + # (5) try to strip off one element from end and check the remains ---- x_strip <- a.x_backup %>% strsplit(" ") %>% unlist() if (length(x_strip) > 1 & nchar(b.x_trimmed) >= 6) { for (i in 1:(length(x_strip) - 1)) { @@ -775,7 +788,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, found_result <- found found <- microorganismsDT[mo == found, ..property][[1]] uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 2, + input = a.x_backup, fullname = microorganismsDT[mo == found_result[1L], fullname][[1]], mo = found_result[1L])) return(found[1L]) @@ -783,7 +797,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } } - # (5) try to strip off one element from start and check the remains ---- + # (6) try to strip off one element from start and check the remains ---- x_strip <- a.x_backup %>% strsplit(" ") %>% unlist() if (length(x_strip) > 1 & nchar(b.x_trimmed) >= 6) { for (i in 2:(length(x_strip))) { @@ -793,7 +807,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, found_result <- found found <- microorganismsDT[mo == found, ..property][[1]] uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 3, + input = a.x_backup, fullname = microorganismsDT[mo == found_result[1L], fullname][[1]], mo = found_result[1L])) return(found[1L]) @@ -801,13 +816,14 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } } - # (6) not yet implemented taxonomic changes in Catalogue of Life ---- - found <- suppressMessages(suppressWarnings(exec_as.mo(TEMPORARY_TAXONOMY(b.x_trimmed), clear_options = FALSE, allow_uncertain = FALSE))) - if (!is.na(found)) { - found_result <- found - found <- microorganismsDT[mo == found, ..property][[1]] + # (7) part of a name (very unlikely match) ---- + found <- microorganismsDT[fullname %like% f.x_withspaces_end_only] + if (nrow(found) > 0) { + found_result <- found[["mo"]] + found <- microorganismsDT[mo == found_result[1L], ..property][[1]] uncertainties <<- rbind(uncertainties, - data.frame(input = a.x_backup, + data.frame(uncertainty = 3, + input = a.x_backup, fullname = microorganismsDT[mo == found_result[1L], fullname][[1]], mo = found_result[1L])) return(found[1L]) @@ -817,7 +833,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, return(NA_character_) } - x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i]) + x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i], x_withspaces_end_only[i]) if (!is.na(x[i])) { next } @@ -1041,20 +1057,53 @@ mo_failures <- function() { #' @importFrom crayon italic #' @export mo_uncertainties <- function() { - df <- as.data.frame(getOption("mo_uncertainties")) + structure(.Data = as.data.frame(getOption("mo_uncertainties"), stringsAsFactors = FALSE), + class = c("mo_uncertainties", "data.frame")) +} + +#' @exportMethod print.mo_uncertainties +#' @importFrom crayon green yellow red bgGreen bgYellow bgRed +#' @export +#' @noRd +print.mo_uncertainties <- function(x, ...) { + cat(paste0(bold(nrow(x), "unique result(s) guessed with uncertainty:"), + "\n(1 = ", green("renamed"), + ", 2 = ", yellow("uncertain"), + ", 3 = ", red("very uncertain"), ")\n")) + msg <- "" - for (i in 1:nrow(df)) { + for (i in 1:nrow(x)) { + if (x[i, "uncertainty"] == 1) { + colour1 <- green + colour2 <- bgGreen + } else if (x[i, "uncertainty"] == 2) { + colour1 <- yellow + colour2 <- bgYellow + } else { + colour1 <- red + colour2 <- bgRed + } msg <- paste(msg, - paste0('"', df[i, "input"], '" -> ', italic(df[i, "fullname"]), " (", df[i, "mo"], ")"), + paste0("[", colour2(paste0(" ", x[i, "uncertainty"], " ")), '] - "', x[i, "input"], '" -> ', + colour1(paste0(italic(x[i, "fullname"]), " (", x[i, "mo"], ")"))), sep = "\n") } - cat(paste0(bold("Results guessed with uncertainty:"), msg)) + cat(msg) } #' @rdname as.mo #' @export mo_renamed <- function() { - strip_style(gsub("was renamed", "->", getOption("mo_renamed"), fixed = TRUE)) + structure(.Data = strip_style(gsub("was renamed", "->", getOption("mo_renamed"), fixed = TRUE)), + class = c("mo_renamed", "character")) +} + +#' @exportMethod print.mo_renamed +#' @importFrom crayon blue +#' @export +#' @noRd +print.mo_renamed <- function(x, ...) { + cat(blue(paste(getOption("mo_renamed"), collapse = "\n"))) } nr2char <- function(x) { diff --git a/R/mo_property.R b/R/mo_property.R index bfb8c85d..c6a2df7d 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -260,13 +260,17 @@ mo_type <- function(x, language = get_locale(), ...) { #' @export mo_gramstain <- function(x, language = get_locale(), ...) { x.bak <- x - x <- mo_phylum(x, ...) - x[x %in% c("Actinobacteria", - "Chloroflexi", - "Firmicutes", - "Tenericutes")] <- "Gram positive" + x.mo <- as.mo(x, ...) + x.phylum <- mo_phylum(x.mo) + x[x.phylum %in% c("Actinobacteria", + "Chloroflexi", + "Firmicutes", + "Tenericutes")] <- "Gram positive" x[x != "Gram positive"] <- "Gram negative" - x[mo_kingdom(x.bak) != "Bacteria"] <- NA_character_ + x[mo_kingdom(x.mo) != "Bacteria"] <- NA_character_ + x[x.mo == "B_GRAMP"] <- "Gram positive" + x[x.mo == "B_GRAMN"] <- "Gram negative" + mo_translate(x, language = language) } diff --git a/R/mo_source.R b/R/mo_source.R index f4cc7fe1..43a4fd29 100644 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -21,7 +21,9 @@ #' Use predefined reference data set #' -#' These functions can be used to predefine your own reference to be used in \code{\link{as.mo}} and consequently all \code{mo_*} functions like \code{\link{mo_genus}} and \code{\link{mo_gramstain}}. +#' @description These functions can be used to predefine your own reference to be used in \code{\link{as.mo}} and consequently all \code{mo_*} functions like \code{\link{mo_genus}} and \code{\link{mo_gramstain}}. +#' +#' This is \strong{the fastest way} to have your organisation (or analysis) specific codes picked up and translated by this package. #' @param path location of your reference file, see Details #' @rdname mo_source #' @name mo_source @@ -33,45 +35,71 @@ #' \code{get_mo_source} will return the data set by reading \code{"~/.mo_source.rds"} with \code{\link{readRDS}}. If the original file has changed (the file defined with \code{path}), it will call \code{set_mo_source} to update the data file automatically. #' #' Reading an Excel file (\code{.xlsx}) with only one row has a size of 8-9 kB. The compressed file used by this package will have a size of 0.1 kB and can be read by \code{get_mo_source} in only a couple of microseconds (a millionth of a second). +#' @section How it works: +#' Imagine this data on a sheet of an Excel file (mo codes were looked up in the `microorganisms` data set). The first column contains the organisation specific codes, the second column contains an MO code from this package: +#' \preformatted{ +#' | A | B | +#' --|--------------------|-------------| +#' 1 | Organisation XYZ | mo | +#' 2 | lab_mo_ecoli | B_ESCHR_COL | +#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNE | +#' 4 | | | +#' } +#' +#' We save it as \code{'home/me/ourcodes.xlsx'}. Now we have to set it as a source: +#' \preformatted{ +#' set_mo_source("home/me/ourcodes.xlsx") +#' # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. +#' } +#' +#' It has now created a file "~/.mo_source.rds" with the contents of our Excel file. It it an R specific format with great compression. +#' +#' And now we can use it in our functions: +#' \preformatted{ +#' as.mo("lab_mo_ecoli") +#' # B_ESCHR_COL +#' +#' mo_genus("lab_mo_kpneumoniae") +#' # "Klebsiella" +#' } +#' +#' If we edit the Excel file to, let's say, this: +#' \preformatted{ +#' | A | B | +#' --|--------------------|-------------| +#' 1 | Organisation XYZ | mo | +#' 2 | lab_mo_ecoli | B_ESCHR_COL | +#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNE | +#' 4 | lab_Staph_aureus | B_STPHY_AUR | +#' 5 | | | +#' } +#' +#' ...any new usage of an MO function in this package will update your data: +#' \preformatted{ +#' as.mo("lab_mo_ecoli") +#' # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. +#' # B_ESCHR_COL +#' +#' mo_genus("lab_Staph_aureus") +#' # "Staphylococcus" +#' } +#' +#' To remove the reference completely, just use any of these: +#' \preformatted{ +#' set_mo_source("") +#' set_mo_source(NULL) +#' # Removed mo_source file '~/.mo_source.rds'. +#' } #' @importFrom dplyr select everything #' @export #' @inheritSection AMR Read more on our website! -#' @examples -#' \dontrun{ -#' -#' # imagine this Excel file (mo codes looked up in `microorganisms` data set): -#' # A B -#' # 1 our code mo -#' # 2 lab_mo_ecoli B_ESCHR_COL -#' # 3 lab_mo_kpneumoniae B_KLBSL_PNE -#' -#' # 1. We save it as 'home/me/ourcodes.xlsx' -#' -#' # 2. We use it for input: -#' set_mo_source("home/me/ourcodes.xlsx") -#' #> Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. -#' -#' # 3. And use it in our functions: -#' as.mo("lab_mo_ecoli") -#' #> B_ESCHR_COL -#' -#' mo_genus("lab_mo_kpneumoniae") -#' #> "Klebsiella" -#' -#' # 4. It will look for changes itself: -#' # (add new row to the Excel file and save it) -#' -#' mo_genus("lab_mo_kpneumoniae") -#' #> Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. -#' #> "Klebsiella" -#' } set_mo_source <- function(path) { if (!is.character(path) | length(path) > 1) { stop("`path` must be a character of length 1.") } - if (path == "") { + if (path %in% c(NULL, "")) { options(mo_source = NULL) options(mo_source_timestamp = NULL) if (file.exists("~/.mo_source.rds")) { diff --git a/data/microorganisms.old.rda b/data/microorganisms.old.rda index b35d6827..7ea93cfe 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 ad0de3ba..0e3d9f6d 100755 Binary files a/data/microorganisms.rda and b/data/microorganisms.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 05482055..17b48a67 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 508954b6..31d7506c 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

27 February 2019

+

28 February 2019

@@ -201,7 +201,7 @@ -

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 27 February 2019.

+

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 28 February 2019.

Introduction

@@ -217,21 +217,21 @@ -2019-02-27 +2019-02-28 abcd Escherichia coli S S -2019-02-27 +2019-02-28 abcd Escherichia coli S R -2019-02-27 +2019-02-28 efgh Escherichia coli R @@ -327,70 +327,70 @@ -2012-02-27 -B4 -Hospital C -Streptococcus pneumoniae -S +2015-09-11 +C6 +Hospital D +Staphylococcus aureus R S S +S M -2014-02-11 -T4 -Hospital B -Escherichia coli -R -S -R -S -F - - -2015-04-14 -N3 -Hospital B -Klebsiella pneumoniae -R -R -S -S -M - - -2017-03-09 -D1 +2015-05-10 +N2 Hospital A Escherichia coli +I +I S S -R -S M -2013-10-22 -W9 -Hospital B -Klebsiella pneumoniae +2012-03-06 +C2 +Hospital C +Escherichia coli +R +S +S +S +M + + +2011-11-09 +X3 +Hospital B +Staphylococcus aureus +S +S +S +S +F + + +2017-02-01 +O6 +Hospital A +Staphylococcus aureus +R S -I S R F -2012-08-12 -C10 -Hospital B -Streptococcus pneumoniae +2017-02-26 +X1 +Hospital D +Klebsiella pneumoniae S S S S -M +F @@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,333 51.7% 10,333 51.7% -#> 2 F 9,667 48.3% 20,000 100.0% +#> 1 M 10,244 51.2% 10,244 51.2% +#> 2 F 9,756 48.8% 20,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M and F. From a researcher perspective: there are slightly more men. Nothing we didn’t already know.

The data is already quite clean, but we still need to transform some variables. The bacteria column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate() function of the dplyr package makes this really easy:

data <- data %>%
@@ -443,10 +443,10 @@
 #> Kingella kingae (no changes)
 #> 
 #> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1264 changes)
+#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1275 changes)
 #> Table 2:  Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
 #> Table 3:  Intrinsic resistance in other Gram-negative bacteria (no changes)
-#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2835 changes)
+#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2727 changes)
 #> Table 8:  Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
 #> Table 9:  Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
 #> Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)
@@ -462,9 +462,9 @@
 #> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
 #> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
 #> 
-#> => EUCAST rules affected 7,417 out of 20,000 rows
+#> => EUCAST rules affected 7,427 out of 20,000 rows
 #>    -> added 0 test results
-#>    -> changed 4,099 test results (0 to S; 0 to I; 4,099 to R)
+#> -> changed 4,002 test results (0 to S; 0 to I; 4,002 to R)

@@ -489,8 +489,8 @@ #> NOTE: Using column `bacteria` as input for `col_mo`. #> NOTE: Using column `date` as input for `col_date`. #> NOTE: Using column `patient_id` as input for `col_patient_id`. -#> => Found 5,647 first isolates (28.2% of total)

-

So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+#> => Found 5,650 first isolates (28.3% of total) +

So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

data_1st <- data %>% 
   filter(first == TRUE)

For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

@@ -516,43 +516,43 @@ 1 -2010-01-07 -E5 +2010-04-26 +H9 B_ESCHR_COL R -R +S S S TRUE 2 -2010-01-14 -E5 +2010-05-27 +H9 B_ESCHR_COL S S R -R +S FALSE 3 -2010-02-07 -E5 +2010-07-20 +H9 B_ESCHR_COL -S -S +R +I S S FALSE 4 -2010-03-28 -E5 +2010-11-25 +H9 B_ESCHR_COL -I +S S S S @@ -560,54 +560,54 @@ 5 -2010-05-25 -E5 +2011-01-19 +H9 B_ESCHR_COL S S -R +S S FALSE 6 -2010-07-23 -E5 +2011-01-24 +H9 B_ESCHR_COL -R S -R -R +S +S +S FALSE 7 -2010-08-18 -E5 +2011-03-09 +H9 B_ESCHR_COL -I +R S R -R +S FALSE 8 -2010-11-19 -E5 +2011-06-07 +H9 B_ESCHR_COL -I S S S -FALSE +S +TRUE 9 -2010-12-05 -E5 +2011-07-30 +H9 B_ESCHR_COL -R +S S S S @@ -615,14 +615,14 @@ 10 -2011-02-04 -E5 +2011-08-01 +H9 B_ESCHR_COL S S -R S -TRUE +S +FALSE @@ -637,7 +637,7 @@ #> NOTE: Using column `patient_id` as input for `col_patient_id`. #> NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this. #> [Criterion] Inclusion based on key antibiotics, ignoring I. -#> => Found 15,867 first weighted isolates (79.3% of total) +#> => Found 15,814 first weighted isolates (79.1% of total) @@ -654,11 +654,11 @@ - - + + - + @@ -666,23 +666,23 @@ - - + + - + - - + + - - + + @@ -690,70 +690,70 @@ - - + + - + - + - - + + - + - + - - + + - - - + + + + - - - + + - + - - + + - - + + - - + + - - + + - + @@ -762,23 +762,23 @@ - - + + - - - + + +
isolate
12010-01-07E52010-04-26H9 B_ESCHR_COL RRS S S TRUE
22010-01-14E52010-05-27H9 B_ESCHR_COL S S RRS FALSE TRUE
32010-02-07E52010-07-20H9 B_ESCHR_COLSSRI S S FALSE
42010-03-28E52010-11-25H9 B_ESCHR_COLIS S S S FALSEFALSETRUE
52010-05-25E52011-01-19H9 B_ESCHR_COL S SRS S FALSETRUEFALSE
62010-07-23E52011-01-24H9 B_ESCHR_COLR SRRSSSFALSE FALSETRUE
72010-08-18E52011-03-09H9 B_ESCHR_COLIR S RRFALSES FALSETRUE
82010-11-19E52011-06-07H9 B_ESCHR_COLI S S SFALSESTRUE TRUE
92010-12-05E52011-07-30H9 B_ESCHR_COLRS S S S
102011-02-04E52011-08-01H9 B_ESCHR_COL S SR STRUETRUESFALSEFALSE
-

Instead of 2, now 7 isolates are flagged. In total, 79.3% of all isolates are marked ‘first weighted’ - 51.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

+

Instead of 2, now 6 isolates are flagged. In total, 79.1% of all isolates are marked ‘first weighted’ - 50.8% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

As with filter_first_isolate(), there’s a shortcut for this new algorithm too:

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 15,867 isolates for analysis.

+

So we end up with 15,814 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -803,63 +803,63 @@ -2 -2014-02-11 -T4 -Hospital B -B_ESCHR_COL +1 +2015-09-11 +C6 +Hospital D +B_STPHY_AUR R S -R S -F -Gram negative -Escherichia -coli +S +M +Gram positive +Staphylococcus +aureus TRUE 3 -2015-04-14 -N3 -Hospital B -B_KLBSL_PNE -R -R -S -S -M -Gram negative -Klebsiella -pneumoniae -TRUE - - -4 -2017-03-09 -D1 -Hospital A +2012-03-06 +C2 +Hospital C B_ESCHR_COL -S -S R S +S +S M Gram negative Escherichia coli TRUE - -5 -2013-10-22 -W9 + +4 +2011-11-09 +X3 Hospital B +B_STPHY_AUR +S +S +S +S +F +Gram positive +Staphylococcus +aureus +TRUE + + +6 +2017-02-26 +X1 +Hospital D B_KLBSL_PNE R -I S -R +S +S F Gram negative Klebsiella @@ -867,10 +867,26 @@ TRUE -6 -2012-08-12 -C10 -Hospital B +7 +2010-02-15 +P3 +Hospital C +B_STRPT_PNE +S +S +S +R +F +Gram positive +Streptococcus +pneumoniae +TRUE + + +8 +2012-10-20 +H4 +Hospital D B_STRPT_PNE S S @@ -882,22 +898,6 @@ pneumoniae TRUE - -7 -2012-05-06 -V7 -Hospital B -B_ESCHR_COL -S -S -S -R -F -Gram negative -Escherichia -coli -TRUE -

Time for the analysis!

@@ -915,9 +915,9 @@
freq(paste(data_1st$genus, data_1st$species))

Or can be used like the dplyr way, which is easier readable:

data_1st %>% freq(genus, species)
-

Frequency table of genus and species from a data.frame (15,867 x 13)

+

Frequency table of genus and species from a data.frame (15,814 x 13)

Columns: 2
-Length: 15,867 (of which NA: 0 = 0.00%)
+Length: 15,814 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -934,33 +934,33 @@ Longest: 24

1 Escherichia coli -7,816 -49.3% -7,816 -49.3% +7,918 +50.1% +7,918 +50.1% 2 Staphylococcus aureus -4,004 -25.2% -11,820 +3,865 +24.4% +11,783 74.5% 3 Streptococcus pneumoniae -2,496 -15.7% -14,316 -90.2% +2,458 +15.5% +14,241 +90.1% 4 Klebsiella pneumoniae -1,551 -9.8% -15,867 +1,573 +9.9% +15,814 100.0% @@ -969,9 +969,9 @@ Longest: 24

Resistance percentages

-

The functions portion_R, portion_RI, portion_I, portion_IS and portion_S can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:

+

The functions portion_R(), portion_RI(), portion_I(), portion_IS() and portion_S() can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:

data_1st %>% portion_IR(amox)
-#> [1] 0.4757673
+#> [1] 0.4762868

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
@@ -984,19 +984,19 @@ Longest: 24

Hospital A -0.4797111 +0.4752371 Hospital B -0.4868636 +0.4825898 Hospital C -0.4661747 +0.4705631 Hospital D -0.4581512 +0.4711928 @@ -1014,72 +1014,72 @@ Longest: 24

Hospital A -0.4797111 -4707 +0.4752371 +4745 Hospital B -0.4868636 -5519 +0.4825898 +5514 Hospital C -0.4661747 -2439 +0.4705631 +2344 Hospital D -0.4581512 -3202 +0.4711928 +3211 -

These functions can also be used to get the portion of multiple antibiotics, to calculate co-resistance very easily:

+

These functions can also be used to get the portion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:

data_1st %>% 
   group_by(genus) %>% 
-  summarise(amoxicillin = portion_S(amcl),
+  summarise(amoxiclav = portion_S(amcl),
             gentamicin = portion_S(gent),
-            "amox + gent" = portion_S(amcl, gent))
+ amoxiclav_genta = portion_S(amcl, gent))
- + - + - - - + + + - - - + + + - - - + + + - + - +
genusamoxicillinamoxiclav gentamicinamox + gentamoxiclav_genta
Escherichia0.73451890.89764590.97210850.73465520.89934330.9744885
Klebsiella0.74339140.89490650.97678920.74062300.90209790.9726637
Staphylococcus0.72852150.91533470.97877120.73221220.92108670.9785252
Streptococcus0.73157050.7135883 0.00000000.73157050.7135883

To make a transition to the next part, let’s see how this difference could be plotted:

data_1st %>% 
   group_by(genus) %>% 
-  summarise("1. Amoxicillin" = portion_S(amcl),
+  summarise("1. Amoxi/clav" = portion_S(amcl),
             "2. Gentamicin" = portion_S(gent),
-            "3. Amox + gent" = portion_S(amcl, gent)) %>% 
+            "3. Amoxi/clav + gent" = portion_S(amcl, gent)) %>% 
   tidyr::gather("Antibiotic", "S", -genus) %>%
   ggplot(aes(x = genus,
              y = S,
@@ -1100,9 +1100,9 @@ Longest: 24

x = "My X axis", y = "My Y axis") -ggplot(a_data_set, - aes(year, value) + - geom_bar()
+# or as short as: +ggplot(a_data_set) + + geom_bar(aes(year))

The AMR package contains functions to extend this ggplot2 package, for example geom_rsi(). It automatically transforms data with count_df() or portion_df() and show results in stacked bars. Its simplest and shortest example:

ggplot(data_1st) +
   geom_rsi(translate_ab = FALSE)
diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index 4474509d..f5356f1b 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 2fb7f210..87d6b07b 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 87f5e96e..28e02068 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 2c284fd1..6e6cfd89 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/EUCAST.html b/docs/articles/EUCAST.html index 7c0f984f..7479f23d 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

How to apply EUCAST rules

Matthijs S. Berends

-

27 February 2019

+

28 February 2019

diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index 85bbe8dc..1f505187 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

How to use the G-test

Matthijs S. Berends

-

27 February 2019

+

28 February 2019

diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html index 48307f1d..751ad91b 100644 --- a/docs/articles/SPSS.html +++ b/docs/articles/SPSS.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -218,16 +218,16 @@
  • R is extremely flexible.

    -

    Because you write the syntax yourself, you can do anything you want. The flexibility in transforming, gathering, grouping, summarising and drawing plots is endless - with SPSS, SAS or Stata you are bound to their algorithms and styles. It may be a bit flexible, but you can never create that very specific publication-ready plot without using other (paid) software.

    +

    Because you write the syntax yourself, you can do anything you want. The flexibility in transforming, gathering, grouping, summarising and drawing plots is endless - with SPSS, SAS or Stata you are bound to their algorithms and styles. They may be a bit flexible, but you can probably never create that very specific publication-ready plot without using other (paid) software.

  • R can be easily automated.

    Over the last years, R Markdown has really made an interesting development. With R Markdown, you can very easily reproduce your reports, whether it’s to Word, Powerpoint, a website, a PDF document or just the raw data to Excel. I use this a lot to generate monthly reports automatically. Just write the code once and enjoy the automatically updated reports at any interval you like.

    -

    For an even more professional environment, you could create Shiny apps: live manipulation of data using a custom made website. The webdesign knowledge needed (Javascript, CSS, HTML) is almost zero.

    +

    For an even more professional environment, you could create Shiny apps: live manipulation of data using a custom made website. The webdesign knowledge needed (JavaScript, CSS, HTML) is almost zero.

  • R has a huge community.

    -

    Many R users just ask questions on website like stackoverflow.com, the largest online community for programmers. At the time of writing, around 275,000 R questions have been asked on this platform (which covers questions and answer for any programming language). In my own experience, most questions are answered within a couple of minutes.

    +

    Many R users just ask questions on websites like StackOverflow.com, the largest online community for programmers. At the time of writing, more than 275,000 R-related questions have already been asked on this platform (which covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.

  • R understands any data type, including SPSS/SAS/Stata.

    diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index c7332bcb..b249cb45 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    How to work with WHONET data

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    diff --git a/docs/articles/atc_property.html b/docs/articles/atc_property.html index b99b6c90..b984a7a0 100644 --- a/docs/articles/atc_property.html +++ b/docs/articles/atc_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    How to get properties of an antibiotic

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 32f1ac01..a035fb11 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    Benchmarks

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    @@ -217,14 +217,14 @@ times = 10) print(S.aureus, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> as.mo("sau") 16.70 16.80 21.50 16.8 17.50 56.6 10 -#> as.mo("stau") 33.70 34.00 46.60 40.2 50.50 83.7 10 -#> as.mo("staaur") 16.70 16.80 28.60 17.3 41.90 59.7 10 -#> as.mo("STAAUR") 16.60 16.70 21.90 17.1 20.00 56.6 10 -#> as.mo("S. aureus") 24.50 24.90 25.40 25.2 26.10 26.7 10 -#> as.mo("S. aureus") 24.60 25.00 31.30 25.1 25.30 85.1 10 -#> as.mo("Staphylococcus aureus") 7.37 7.42 8.17 7.5 8.27 11.8 10 +#> expr min lq mean median uq max neval +#> as.mo("sau") 16.70 16.80 17.10 16.90 17.20 18.4 10 +#> as.mo("stau") 31.70 31.80 48.90 31.90 73.00 117.0 10 +#> as.mo("staaur") 16.70 16.80 23.10 16.90 17.90 76.0 10 +#> as.mo("STAAUR") 16.80 17.00 33.20 18.20 56.00 58.6 10 +#> as.mo("S. aureus") 24.60 24.70 29.00 24.70 25.30 65.8 10 +#> as.mo("S. aureus") 24.60 24.70 29.20 24.80 25.10 67.4 10 +#> as.mo("Staphylococcus aureus") 7.02 7.11 7.73 7.26 7.33 11.9 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:

    T.islandicus <- microbenchmark(as.mo("theisl"),
    @@ -235,13 +235,13 @@
                                      times = 10)
     print(T.islandicus, unit = "ms", signif = 3)
     #> Unit: milliseconds
    -#>                         expr   min    lq  mean median    uq max neval
    -#>              as.mo("theisl") 289.0 291.0 314.0  312.0 336.0 343    10
    -#>              as.mo("THEISL") 290.0 293.0 319.0  331.0 337.0 344    10
    -#>       as.mo("T. islandicus")  73.5  73.8  90.6   75.1 114.0 118    10
    -#>      as.mo("T.  islandicus")  73.7  73.9  78.5   74.6  74.7 115    10
    -#>  as.mo("Thermus islandicus")  66.5  67.3  80.3   69.5 107.0 108    10
    -

    That takes 6.7 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.

    +#> expr min lq mean median uq max neval +#> as.mo("theisl") 262.0 292.0 296.0 304.0 310 312 10 +#> as.mo("THEISL") 261.0 263.0 286.0 288.0 307 311 10 +#> as.mo("T. islandicus") 142.0 143.0 164.0 165.0 184 187 10 +#> as.mo("T. islandicus") 142.0 143.0 170.0 163.0 192 229 10 +#> as.mo("Thermus islandicus") 67.7 68.1 94.3 89.4 117 132 10 +

    That takes 7.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 very uncommon):

    par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
     
    @@ -260,7 +260,7 @@
     

    Repetitive results

    -

    Repetitive results mean that unique values are present more than once. Unique values will only be calculated once by as.mo(). We will use mo_fullname() for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses as.mo() internally.

    +

    Repetitive results are unique values that are present more than once. Unique values will only be calculated once by as.mo(). We will use mo_fullname() for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses as.mo() internally.

    -

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

    +#> expr min lq mean median uq max neval +#> mo_fullname(x) 732 739 818 819 837 1040 10
    +

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

    @@ -301,10 +301,10 @@ print(run_it, unit = "ms", signif = 3) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> A 10.900 11.300 11.900 11.500 11.700 15.200 10 -#> B 22.000 22.600 26.900 22.600 22.800 62.400 10 -#> C 0.311 0.502 0.531 0.533 0.577 0.765 10

    -

    So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0005 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 11.100 11.300 11.500 11.500 11.600 11.700 10 +#> B 22.200 22.500 22.800 22.900 23.000 23.500 10 +#> C 0.325 0.566 0.571 0.579 0.599 0.704 10 +

    So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0006 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:

    run_it <- microbenchmark(A = mo_species("aureus"),
                              B = mo_genus("Staphylococcus"),
                              C = mo_fullname("Staphylococcus aureus"),
    @@ -317,14 +317,14 @@
     print(run_it, unit = "ms", signif = 3)
     #> Unit: milliseconds
     #>  expr   min    lq  mean median    uq   max neval
    -#>     A 0.274 0.333 0.417  0.412 0.481 0.611    10
    -#>     B 0.337 0.353 0.403  0.411 0.438 0.461    10
    -#>     C 0.336 0.362 0.530  0.528 0.682 0.755    10
    -#>     D 0.263 0.316 0.340  0.331 0.360 0.474    10
    -#>     E 0.252 0.326 0.326  0.329 0.345 0.389    10
    -#>     F 0.250 0.300 0.319  0.327 0.351 0.351    10
    -#>     G 0.240 0.246 0.288  0.277 0.325 0.351    10
    -#>     H 0.242 0.257 0.304  0.294 0.332 0.395    10
    +#> A 0.308 0.392 0.419 0.406 0.478 0.524 10 +#> B 0.377 0.406 0.424 0.418 0.442 0.486 10 +#> C 0.359 0.516 0.580 0.574 0.664 0.730 10 +#> D 0.266 0.326 0.337 0.342 0.350 0.383 10 +#> E 0.254 0.281 0.332 0.336 0.359 0.446 10 +#> F 0.237 0.315 0.329 0.340 0.360 0.374 10 +#> G 0.261 0.295 0.318 0.323 0.341 0.390 10 +#> H 0.271 0.290 0.321 0.317 0.343 0.403 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.

    @@ -351,13 +351,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> en 14.68 15.11 15.28 15.27 15.34 16.21 10 -#> de 23.53 23.65 24.04 23.82 24.63 24.88 10 -#> nl 23.36 23.53 27.76 23.81 23.87 63.45 10 -#> es 23.59 23.83 23.94 23.96 24.07 24.22 10 -#> it 23.30 23.76 27.92 23.83 24.18 64.01 10 -#> fr 23.47 23.78 31.80 23.84 24.90 63.25 10 -#> pt 23.28 23.69 27.97 23.85 24.42 64.14 10
    +#> en 15.06 15.54 22.29 15.71 31.46 40.83 10 +#> de 23.57 23.91 28.72 24.04 26.24 47.77 10 +#> nl 23.46 23.87 33.14 24.71 45.69 68.77 10 +#> es 23.76 23.98 37.40 24.72 46.85 90.39 10 +#> it 23.98 24.07 30.76 24.49 25.18 67.52 10 +#> fr 24.03 24.04 27.06 24.14 26.51 47.08 10 +#> pt 23.66 24.00 30.90 24.17 25.84 65.76 10

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

    diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index b76d5495..b9b48285 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/freq.html b/docs/articles/freq.html index 9bf1d365..c331ff99 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    How to create frequency tables

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    diff --git a/docs/articles/index.html b/docs/articles/index.html index 8641eb00..8a3a33cb 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index 7e5c8d10..bd11e6dd 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    How to get properties of a microorganism

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index 1e9440e2..84fd3e73 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -192,7 +192,7 @@

    How to predict antimicrobial resistance

    Matthijs S. Berends

    -

    27 February 2019

    +

    28 February 2019

    diff --git a/docs/authors.html b/docs/authors.html index c39fc2b4..b68c9c3d 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 diff --git a/docs/index.html b/docs/index.html index 55733410..145331be 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -280,6 +280,7 @@

    All ~3,500 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales, Schizosaccharomycetales and Tremellales.

    The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant fungi are covered (like all species of Aspergillus, Candida, Cryptococcus, Histoplasma, Pneumocystis, Saccharomyces and Trichophyton).

  • +
  • All ~2,000 (sub)species from ~100 other relevant genera, from the kingdoms of Animalia and Plantae (like Strongyloides and Taenia)

  • All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed

  • The responsible author(s) and year of scientific publication

  • diff --git a/docs/news/index.html b/docs/news/index.html index 6b4def66..13dac0f4 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.5.0.9019 + 0.5.0.9020 @@ -253,6 +253,7 @@