diff --git a/DESCRIPTION b/DESCRIPTION index a610c6b1..78eac206 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9075 -Date: 2019-09-18 +Version: 0.7.1.9076 +Date: 2019-09-20 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 2d9c6db7..84a260f8 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9075 -Last updated: 18-Sep-2019 +# AMR 0.7.1.9076 +Last updated: 20-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`: @@ -19,7 +19,7 @@ x <- as.mo("E. coli") x[1] <- "testvalue" #> Warning message: - #> invalid microbial code, NA generated + #> invalid microorganism code, NA generated ``` This is important, because a value like `"testvalue"` could never be understood by e.g. `mo_name()`, although the class would suggest a valid microbial code. * Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)), since creating frequency tables actually does not fit the scope of this package. The `freq()` function still works, since it is re-exported from the `clean` package (which will be installed automatically upon updating this `AMR` package). @@ -29,12 +29,13 @@ ```r x <- bug_drug_combinations(example_isolates) x - #> ab mo S I R total - #> 1 AMC B_ESCHR_COL 332 74 61 467 - #> 2 AMC B_KLBSL_PNE 49 3 6 58 - #> 3 AMC B_PROTS_MIR 28 7 1 36 - #> 4 AMC B_PSDMN_AER 0 0 30 30 - #> 5 AMC B_STPHY_AUR 234 0 1 235 + # NOTE: Using column `mo` as input for `col_mo`. + #> ab mo S I R total + #> 1 AMC B_ESCHR_COLI 332 74 61 467 + #> 2 AMC B_KLBSL_PNMN 49 3 6 58 + #> 3 AMC B_PROTS_MRBL 28 7 1 36 + #> 4 AMC B_PSDMN_AERG 0 0 30 30 + #> 5 AMC B_STPHY_AURS 234 0 1 235 ``` You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R `format()` function: ```r diff --git a/R/data.R b/R/data.R index 95f3444f..58c9d1bd 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,460 observations and 16 variables: +#' @format A \code{\link{data.frame}} with 69,454 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{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} +#' \item{9,460 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) 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. @@ -90,7 +90,7 @@ catalogue_of_life <- list( year = 2018, version = "Catalogue of Life: {year} Annual Checklist", url_CoL = "http://www.catalogueoflife.org/annual-checklist/{year}/", - url_DSMZ = "https://www.dsmz.de/microorganisms/pnu/bacterial_nomenclature_info_mm.php", + url_DSMZ = "https://www.dsmz.de/services/online-tools/prokaryotic-nomenclature-up-to-date/prokaryotic-nomenclature-up-to-date/genus-search", yearmonth_DSMZ = "August 2019" ) diff --git a/R/mo.R b/R/mo.R index 63398f11..4e03f138 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1065,30 +1065,33 @@ exec_as.mo <- function(x, } # MISCELLANEOUS ---- - + # look for old taxonomic names ---- - found <- microorganisms.oldDT[fullname_lower == tolower(a.x_backup) - | fullname_lower %like_case% d.x_withspaces_start_end,] - if (NROW(found) > 0) { - col_id_new <- found[1, col_id_new] - # when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so: - # mo_ref("Chlamydia psittaci") = "Page, 1968" (with warning) - # mo_ref("Chlamydophila psittaci") = "Everett et al., 1999" - if (property == "ref") { - x[i] <- found[1, ref] - } else { - x[i] <- microorganismsDT[col_id == found[1, col_id_new], ..property][[1]] + # wait until prevalence == 2 to run the old taxonomic results on both prevalence == 1 and prevalence == 2 + if (nrow(data_to_check) == nrow(microorganismsDT[prevalence == 2])) { + found <- microorganisms.oldDT[fullname_lower == tolower(a.x_backup) + | fullname_lower %like_case% d.x_withspaces_start_end,] + if (NROW(found) > 0) { + col_id_new <- found[1, col_id_new] + # when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so: + # mo_ref("Chlamydia psittaci") = "Page, 1968" (with warning) + # mo_ref("Chlamydophila psittaci") = "Everett et al., 1999" + if (property == "ref") { + x[i] <- found[1, ref] + } else { + x[i] <- microorganismsDT[col_id == found[1, col_id_new], ..property][[1]] + } + options(mo_renamed_last_run = found[1, fullname]) + was_renamed(name_old = found[1, fullname], + name_new = microorganismsDT[col_id == found[1, col_id_new], fullname], + ref_old = found[1, ref], + ref_new = microorganismsDT[col_id == found[1, col_id_new], ref], + mo = microorganismsDT[col_id == found[1, col_id_new], mo]) + if (initial_search == TRUE) { + set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) + } + return(x[i]) } - options(mo_renamed_last_run = found[1, fullname]) - was_renamed(name_old = found[1, fullname], - name_new = microorganismsDT[col_id == found[1, col_id_new], fullname], - ref_old = found[1, ref], - ref_new = microorganismsDT[col_id == found[1, col_id_new], ref], - mo = microorganismsDT[col_id == found[1, col_id_new], mo]) - if (initial_search == TRUE) { - set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) - } - return(x[i]) } # check for uncertain results ---- @@ -1851,7 +1854,7 @@ as.data.frame.mo <- function(x, ...) { "[<-.mo" <- function(i, j, ..., value) { y <- NextMethod() attributes(y) <- attributes(i) - class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) + class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @exportMethod [[<-.mo #' @export @@ -1859,7 +1862,7 @@ as.data.frame.mo <- function(x, ...) { "[[<-.mo" <- function(i, j, ..., value) { y <- NextMethod() attributes(y) <- attributes(i) - class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) + class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @exportMethod c.mo #' @export @@ -1867,7 +1870,7 @@ as.data.frame.mo <- function(x, ...) { c.mo <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(x) - class_integrity_check(y, "microbial code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) + class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo), as.character(microorganisms.translation$mo_old))) } #' @rdname as.mo diff --git a/R/mo_property.R b/R/mo_property.R index d8650eaa..aa45ea2e 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -355,6 +355,7 @@ mo_info <- function(x, language = get_locale(), ...) { #' @export mo_url <- function(x, open = FALSE, ...) { mo <- AMR::as.mo(x = x, ... = ...) + mo_names <- AMR::mo_name(mo) metadata <- get_mo_failures_uncertainties_renamed() df <- data.frame(mo, stringsAsFactors = FALSE) %>% @@ -362,12 +363,12 @@ mo_url <- function(x, open = FALSE, ...) { mutate(url = case_when(source == "CoL" ~ paste0(gsub("{year}", catalogue_of_life$year, catalogue_of_life$url_CoL, fixed = TRUE), "details/species/id/", species_id), source == "DSMZ" ~ - paste0(catalogue_of_life$url_DSMZ, "?bnu_no=", species_id, "#", species_id), + paste0(catalogue_of_life$url_DSMZ, "/", unlist(lapply(strsplit(mo_names, ""), function(x) x[1]))), TRUE ~ NA_character_)) u <- df$url - names(u) <- AMR::mo_name(mo) + names(u) <- mo_names if (open == TRUE) { if (length(u) > 1) { warning("only the first URL will be opened, as `browseURL()` only suports one string.") diff --git a/R/sysdata.rda b/R/sysdata.rda index 36481c99..62f80d47 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/microorganisms.translation.rds b/data-raw/microorganisms.translation.rds index f4972c25..65377f50 100644 Binary files a/data-raw/microorganisms.translation.rds 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 c21f389f..f1864d97 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -91,6 +91,32 @@ rm(data_col) rm(data_dsmz) rm(ref_taxonomy) +mo_found_in_NL <- c("Absidia", "Acremonium", "Actinotignum", "Aedes", "Alternaria", "Anaerosalibacter", "Ancylostoma", + "Angiostrongylus", "Anisakis", "Anopheles", "Apophysomyces", "Arachnia", "Ascaris", "Aspergillus", + "Aureobacterium", "Aureobasidium", "Bacteroides", "Balantidum", "Basidiobolus", "Beauveria", + "Bilophilia", "Branhamella", "Brochontrix", "Brugia", "Calymmatobacterium", "Candida", "Capillaria", + "Capnocytophaga", "Catabacter", "Cdc", "Chaetomium", "Chilomastix", "Chryseobacterium", + "Chryseomonas", "Chrysonilia", "Cladophialophora", "Cladosporium", "Clonorchis", "Conidiobolus", + "Contracaecum", "Cordylobia", "Cryptococcus", "Curvularia", "Demodex", "Dermatobia", "Dicrocoelium", + "Dioctophyma", "Diphyllobothrium", "Dipylidium", "Dirofilaria", "Dracunculus", "Echinococcus", + "Echinostoma", "Elisabethkingia", "Enterobius", "Enteromonas", "Euascomycetes", "Exophiala", + "Exserohilum", "Fasciola", "Fasciolopsis", "Flavobacterium", "Fonsecaea", "Fusarium", "Fusobacterium", + "Giardia", "Gnathostoma", "Hendersonula", "Heterophyes", "Hymenolepis", "Hypomyces", + "Hysterothylacium", "Kloeckera", "Koserella", "Larva", "Lecythophora", "Leishmania", "Lelliottia", + "Leptomyxida", "Leptosphaeria", "Leptotrichia", "Loa", "Lucilia", "Lumbricus", "Malassezia", + "Malbranchea", "Mansonella", "Mesocestoides", "Metagonimus", "Metarrhizium", "Molonomonas", + "Mortierella", "Mucor", "Multiceps", "Mycocentrospora", "Mycoplasma", "Nanophetus", "Nattrassia", + "Necator", "Nectria", "Novospingobium", "Ochroconis", "Oesophagostomum", "Oidiodendron", "Onchocerca", + "Opisthorchis", "Opistorchis", "Paragonimus", "Paramyxovirus", "Pediculus", "Phlebotomus", + "Phocanema", "Phoma", "Phthirus", "Piedraia", "Pithomyces", "Pityrosporum", "Prevotella", + "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", "Treponema", "Trichinella", "Trichobilharzia", "Trichoderma", + "Trichomonas", "Trichophyton", "Trichosporon", "Trichostrongylus", "Trichuris", "Tritirachium", + "Trombicula", "Trypanosoma", "Tunga", "Ureaplasma", "Wuchereria") + MOs <- data_total %>% filter( ( @@ -102,23 +128,7 @@ 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", "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") + | genus %in% mo_found_in_NL # or the taxonomic entry is old - the species was renamed | !is.na(col_id_new) ) %>% @@ -209,11 +219,6 @@ 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, @@ -241,12 +246,6 @@ MOs <- MOs %>% 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)) %>% -# 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")) %>% @@ -259,15 +258,19 @@ to_remove <- MOs %>% 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 +# add CoL's col_id, source and ref 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) + transmute(col_id, species_id, source, ref, kingdom_fullname = trimws(paste(kingdom, genus, species, subspecies))), + by = "kingdom_fullname", + suffix = c("_dsmz", "_col")) %>% + mutate(col_id = col_id_col, + species_id = ifelse(!is.na(species_id_col), gsub(".*/(.*)$", "\\1", species_id_col), species_id_dsmz), + source = ifelse(!is.na(species_id_col), source_col, source_dsmz), + ref = ifelse(!is.na(species_id_col) & ref_col != "", ref_col, ref_dsmz)) %>% + select(-matches("(_col|_dsmz|kingdom_fullname)")) MOs.old <- MOs.old %>% @@ -279,7 +282,9 @@ MOs.old <- MOs.old %>% select(col_id = col_id.x, col_id_new, fullname, ref = ref.x) # remove the records that are in MOs.old +sum(MOs.old$fullname %in% MOs$fullname) MOs <- MOs %>% filter(!fullname %in% MOs.old$fullname) +sum(MOs.old$fullname %in% MOs$fullname) # what characters are in the fullnames? table(sort(unlist(strsplit(x = paste(MOs$fullname, collapse = ""), split = "")))) @@ -293,28 +298,13 @@ MOs <- MOs %>% 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") + kingdom %in% c("Archaea", "Bacteria", "Chromista", "Fungi") + & (phylum %in% c("Proteobacteria", + "Firmicutes", + "Actinobacteria", + "Sarcomastigophora") + | genus %in% mo_found_in_NL + | rank %in% c("kingdom", "phylum", "class", "order", "family")) ~ 2, TRUE ~ 3 )) @@ -322,7 +312,7 @@ MOs <- MOs %>% # 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) %>% + arrange(prevalence, genus, species, subspecies) %>% group_by(kingdom) %>% mutate(abbr_other = case_when( rank == "family" ~ paste0("[FAM]_", @@ -354,22 +344,21 @@ MOs <- MOs %>% )) %>% # abbreviations may be same for genera between kingdoms, # because each abbreviation starts with the the first character(s) of the kingdom - mutate(abbr_genus = abbreviate(genus, + mutate(abbr_genus = abbreviate(gsub("^ae", "\u00E6\u00E6", genus, ignore.case = TRUE), # keep a starting Latin ae minlength = 5, use.classes = TRUE, - method = "both.sides", - strict = FALSE)) %>% + method = "both.sides")) %>% ungroup() %>% group_by(genus) %>% # species abbreviations may be the same between genera # because the genus abbreviation is part of the abbreviation - mutate(abbr_species = abbreviate(species, + mutate(abbr_species = abbreviate(gsub("^ae", "\u00E6\u00E6", species), minlength = 4, use.classes = TRUE, method = "both.sides")) %>% ungroup() %>% group_by(genus, species) %>% - mutate(abbr_subspecies = abbreviate(subspecies, + mutate(abbr_subspecies = abbreviate(gsub("^ae", "\u00E6\u00E6", subspecies), minlength = 4, use.classes = TRUE, method = "both.sides")) %>% @@ -385,7 +374,8 @@ MOs <- MOs %>% abbr_subspecies, sep = "_"), abbr_other), - sep = "_")))) %>% + sep = "_"))), + mo = gsub("(\u00C6|\u00E6)+", "AE", mo)) %>% mutate(mo = ifelse(duplicated(.$mo), # these one or two must be unique too paste0(mo, "1"), @@ -643,7 +633,8 @@ MOs <- MOs %>% MOs <- MOs %>% group_by(kingdom) %>% distinct(fullname, .keep_all = TRUE) %>% - ungroup() + ungroup() %>% + filter(fullname != "") # everything distinct? sum(duplicated(MOs$mo)) @@ -693,10 +684,11 @@ 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) -# save +# SAVE ### for other server saveRDS(MOs, "microorganisms.rds") saveRDS(MOs.old, "microorganisms.old.rds") +saveRDS(microorganisms.codes, "microorganisms.codes.rds") ### for same server microorganisms <- MOs microorganisms.old <- MOs.old @@ -708,9 +700,14 @@ class(microorganisms.translation$mo_new) <- "mo" 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 +saveRDS(microorganisms.translation, file = "data-raw/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 +devtools::load_all(".") + +# TO DO AFTER THIS +# * Update the year and dim()s in R/data.R +# * Rerun data-raw/reproduction_of_rsi_translation.R +# * Run unit tests diff --git a/data-raw/reproduction_of_microorganisms_new.R b/data-raw/reproduction_of_microorganisms_new.R index 6897dfd7..4e51be3e 100644 --- a/data-raw/reproduction_of_microorganisms_new.R +++ b/data-raw/reproduction_of_microorganisms_new.R @@ -654,4 +654,8 @@ usethis::use_data(microorganisms, overwrite = TRUE, version = 2) usethis::use_data(microorganisms.old, overwrite = TRUE, version = 2) rm(microorganisms) rm(microorganisms.old) -# and update the year in R/data.R + +# TO DO AFTER THIS +# * Update the year and dim()s in R/data.R +# * Rerun data-raw/reproduction_of_rsi_translation.R +# * Run unit tests diff --git a/data-raw/reproduction_of_rsi_translation.R b/data-raw/reproduction_of_rsi_translation.R index d522fdfc..d16ec5bf 100644 --- a/data-raw/reproduction_of_rsi_translation.R +++ b/data-raw/reproduction_of_rsi_translation.R @@ -52,3 +52,4 @@ rsi_translation <- tbl_mic %>% # save to package usethis::use_data(rsi_translation, overwrite = TRUE) rm(rsi_translation) +devtools::load_all(".") diff --git a/data/example_isolates.rda b/data/example_isolates.rda index 7f011549..82568530 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 1c593472..ff2420b4 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 b63591f2..73c3609c 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 old mode 100755 new mode 100644 index 7a5210e2..382f2fa8 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 eb93caf7..e59fad0b 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 3aa3bf2c..206af166 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 74153215..01ea8fe7 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.1.9067 + 0.7.1.9076 @@ -185,7 +185,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

28 August 2019

+

20 September 2019

@@ -194,7 +194,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 R Markdown. However, the methodology remains unchanged. This page was generated on 28 August 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 R Markdown. However, the methodology remains unchanged. This page was generated on 20 September 2019.

Introduction

@@ -210,21 +210,21 @@ -2019-08-28 +2019-09-20 abcd Escherichia coli S S -2019-08-28 +2019-09-20 abcd Escherichia coli S R -2019-08-28 +2019-09-20 efgh Escherichia coli R @@ -300,8 +300,7 @@ CIP = sample(ab_interpretations, size = sample_size, replace = TRUE, prob = c(0.80, 0.00, 0.20)), GEN = sample(ab_interpretations, size = sample_size, replace = TRUE, - prob = c(0.92, 0.00, 0.08)) - )
+ prob = c(0.92, 0.00, 0.08)))

Using the left_join() function from the dplyr package, we can ‘map’ the gender to the patient ID using the patients_table object we created earlier:

data <- data %>% left_join(patients_table)

The resulting data set contains 20,000 blood culture isolates. With the head() function we can preview the first 6 values of this data set:

@@ -320,67 +319,67 @@ -2017-06-03 -E4 -Hospital D -Escherichia coli -S -S -R -S -M - - -2015-02-25 -J4 -Hospital A -Streptococcus pneumoniae -R -S -S -S -M - - -2014-08-28 -F7 +2011-05-18 +O8 Hospital B Staphylococcus aureus S -R S S -M - - -2011-12-16 -U7 -Hospital A -Staphylococcus aureus -S -S -R S F - -2015-02-09 -C8 -Hospital A -Escherichia coli + +2011-03-28 +Q8 +Hospital B +Streptococcus pneumoniae R I S S -M +F - -2014-11-26 -Y5 -Hospital C -Escherichia coli + +2015-12-27 +W2 +Hospital A +Klebsiella pneumoniae S R +R +S +F + + +2014-05-30 +X6 +Hospital B +Escherichia coli +S +I +S +S +F + + +2015-07-30 +Q3 +Hospital D +Escherichia coli +S +S +S +S +F + + +2016-11-03 +O8 +Hospital D +Staphylococcus aureus +S +S S S F @@ -406,8 +405,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,360 51.8% 10,360 51.8% -# 2 F 9,640 48.2% 20,000 100.0% +# 1 M 10,330 51.6% 10,330 51.6% +# 2 F 9,670 48.4% 20,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M and F. From a researchers 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 %>%
@@ -437,14 +436,14 @@
 # Pasteurella multocida (no changes)
 # Staphylococcus (no changes)
 # Streptococcus groups A, B, C, G (no changes)
-# Streptococcus pneumoniae (1,477 values changed)
+# Streptococcus pneumoniae (1,405 values changed)
 # Viridans group streptococci (no changes)
 # 
 # EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,306 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,290 values changed)
 # Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
 # Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,760 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,639 values changed)
 # Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
 # Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
 # Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
@@ -452,24 +451,24 @@
 # Table 13: Interpretive rules for quinolones (no changes)
 # 
 # Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,250 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (100 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,299 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (101 values changed)
 # Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
 # Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
 # Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
 # Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
 # 
 # --------------------------------------------------------------------------
-# EUCAST rules affected 6,548 out of 20,000 rows, making a total of 7,893 edits
+# EUCAST rules affected 6,427 out of 20,000 rows, making a total of 7,734 edits
 # => added 0 test results
 # 
-# => changed 7,893 test results
-#    - 102 test results changed from S to I
-#    - 4,732 test results changed from S to R
-#    - 1,108 test results changed from I to S
-#    - 328 test results changed from I to R
-#    - 1,603 test results changed from R to S
-#    - 20 test results changed from R to I
+# => changed 7,734 test results
+#    - 99 test results changed from S to I
+#    - 4,591 test results changed from S to R
+#    - 1,111 test results changed from I to S
+#    - 289 test results changed from I to R
+#    - 1,622 test results changed from R to S
+#    - 22 test results changed from R to I
 # --------------------------------------------------------------------------
 # 
 # Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
@@ -497,8 +496,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,693 first isolates (28.5% of total) -

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

+# => Found 5,635 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:

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

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

@@ -508,7 +507,7 @@

First weighted isolates

-

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient Q3, sorted on date:

+

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient O6, sorted on date:

@@ -524,32 +523,32 @@ - - - + + + + - - - - - - + + + + + - - - - + + + + @@ -557,10 +556,10 @@ - - - - + + + + @@ -568,21 +567,21 @@ - - - + + + - - + + - - - - + + + + @@ -590,9 +589,9 @@ - - - + + + @@ -601,20 +600,20 @@ - - - + + + + + - - - + - - - + + + @@ -623,9 +622,9 @@ - - - + + + @@ -645,7 +644,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,134 first weighted isolates (75.7% of total) +# => Found 15,041 first weighted isolates (75.2% of total)
isolate
12010-01-10Q3B_ESCHR_COL2010-01-29O6B_ESCHR_COLIR R SR S TRUE
22010-03-10Q3B_ESCHR_COLSS2010-04-29O6B_ESCHR_COLI R SSS FALSE
32010-04-30Q3B_ESCHR_COLR2010-08-31O6B_ESCHR_COLIS S S S
42010-07-02Q3B_ESCHR_COLR2010-09-18O6B_ESCHR_COLIS S S S
52010-10-10Q3B_ESCHR_COL2011-03-23O6B_ESCHR_COLI S SR SFALSESTRUE
62010-11-26Q3B_ESCHR_COLR2011-03-24O6B_ESCHR_COLIS S S S
72011-01-09Q3B_ESCHR_COL2011-07-19O6B_ESCHR_COLI S S S
82011-02-01Q3B_ESCHR_COL2011-08-04O6B_ESCHR_COLIRR R SRSTRUEFALSE
92011-03-20Q3B_ESCHR_COL2011-08-15O6B_ESCHR_COLI S S S
102011-08-04Q3B_ESCHR_COL2011-08-22O6B_ESCHR_COLI S S S
@@ -662,34 +661,34 @@ - - - + + + + - - - - - - + + + + + - - - - + + + + @@ -698,10 +697,10 @@ - - - - + + + + @@ -710,57 +709,57 @@ - - - + + + - - + + - - - - + + + + - + - - - + + + - + - - - + + + + + - - - + - - - + + + @@ -770,9 +769,9 @@ - - - + + + @@ -782,11 +781,11 @@
isolate
12010-01-10Q3B_ESCHR_COL2010-01-29O6B_ESCHR_COLIR R SR S TRUE TRUE
22010-03-10Q3B_ESCHR_COLSS2010-04-29O6B_ESCHR_COLI R SSS FALSE TRUE
32010-04-30Q3B_ESCHR_COLR2010-08-31O6B_ESCHR_COLIS S S S
42010-07-02Q3B_ESCHR_COLR2010-09-18O6B_ESCHR_COLIS S S S
52010-10-10Q3B_ESCHR_COL2011-03-23O6B_ESCHR_COLI S SR SFALSESTRUE TRUE
62010-11-26Q3B_ESCHR_COLR2011-03-24O6B_ESCHR_COLIS S S S FALSETRUEFALSE
72011-01-09Q3B_ESCHR_COL2011-07-19O6B_ESCHR_COLI S S S S FALSETRUEFALSE
82011-02-01Q3B_ESCHR_COL2011-08-04O6B_ESCHR_COLIRR R SRSTRUEFALSE TRUE
92011-03-20Q3B_ESCHR_COL2011-08-15O6B_ESCHR_COLI S S S
102011-08-04Q3B_ESCHR_COL2011-08-22O6B_ESCHR_COLI S S S
-

Instead of 2, now 8 isolates are flagged. In total, of all isolates are marked ‘first weighted’ - 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, 75.2% of all isolates are marked ‘first weighted’ - 47% 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,134 isolates for analysis.

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -812,58 +811,58 @@ 1 -2017-06-03 -E4 -Hospital D -B_ESCHR_COL +2011-05-18 +O8 +Hospital B +B_STPHY_AURS S S -R S -M -Gram-negative -Escherichia -coli +S +F +Gram-positive +Staphylococcus +aureus TRUE 2 -2015-02-25 -J4 -Hospital A -B_STRPT_PNE +2011-03-28 +Q8 +Hospital B +B_STRPT_PNMN R R S R -M +F Gram-positive Streptococcus pneumoniae TRUE -4 -2011-12-16 -U7 +3 +2015-12-27 +W2 Hospital A -B_STPHY_AUR -S -S +B_KLBSL_PNMN +R +R R S F -Gram-positive -Staphylococcus -aureus +Gram-negative +Klebsiella +pneumoniae TRUE -6 -2014-11-26 -Y5 -Hospital C -B_ESCHR_COL +5 +2015-07-30 +Q3 +Hospital D +B_ESCHR_COLI S S S @@ -875,30 +874,14 @@ TRUE -7 -2010-08-09 -C5 -Hospital B -B_ESCHR_COL +6 +2016-11-03 +O8 +Hospital D +B_STPHY_AURS S S S -R -M -Gram-negative -Escherichia -coli -TRUE - - -8 -2011-07-24 -W6 -Hospital B -B_STPHY_AUR -R -S -R S F Gram-positive @@ -906,6 +889,22 @@ aureus TRUE + +7 +2013-04-03 +F8 +Hospital A +B_ESCHR_COLI +S +S +S +S +M +Gram-negative +Escherichia +coli +TRUE +

Time for the analysis!

@@ -925,7 +924,7 @@
data_1st %>% freq(genus, species)

Frequency table

Class: character
-Length: 15,134 (of which NA: 0 = 0.00%)
+Length: 15,041 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -942,33 +941,33 @@ Longest: 24

1 Escherichia coli -7,330 -48.4% -7,330 -48.4% +7,491 +49.8% +7,491 +49.8% 2 Staphylococcus aureus -3,816 -25.2% -11,146 -73.6% +3,732 +24.8% +11,223 +74.6% 3 Streptococcus pneumoniae -2,386 -15.8% -13,532 +2,223 +14.8% +13,446 89.4% 4 Klebsiella pneumoniae -1,602 +1,595 10.6% -15,134 +15,041 100.0% @@ -979,7 +978,7 @@ Longest: 24

Resistance percentages

The functions portion_S(), portion_SI(), portion_I(), portion_IR() and portion_R() can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()) and susceptibility as the portion of S and I (portion_SI()). These functions can be used on their own:

data_1st %>% portion_R(AMX)
-# [1] 0.4649795
+# [1] 0.4677216

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

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

Hospital A -0.4684865 +0.4646398 Hospital B -0.4595616 +0.4578497 Hospital C -0.4685616 +0.4776586 Hospital D -0.4664897 +0.4822200 @@ -1022,23 +1021,23 @@ Longest: 24

Hospital A -0.4684865 -4506 +0.4646398 +4539 Hospital B -0.4595616 -5292 +0.4578497 +5255 Hospital C -0.4685616 -2322 +0.4776586 +2238 Hospital D -0.4664897 -3014 +0.4822200 +3009 @@ -1058,27 +1057,27 @@ Longest: 24

Escherichia -0.9289222 -0.8896317 -0.9924966 +0.9236417 +0.8994794 +0.9942598 Klebsiella -0.8021223 -0.9082397 -0.9812734 +0.8206897 +0.9028213 +0.9868339 Staphylococcus -0.9263627 -0.9129979 -0.9900419 +0.9228296 +0.9265809 +0.9951768 Streptococcus -0.6240570 +0.6171840 0.0000000 -0.6240570 +0.6171840 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 efb2ed1a..09da251a 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 d19dbaf0..65fd4d62 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 d158321c..09af4838 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 dd02ed77..075b01d1 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/benchmarks.html b/docs/articles/benchmarks.html index f5ac3722..0f74654a 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076
@@ -185,7 +185,7 @@

Benchmarks

Matthijs S. Berends

-

18 September 2019

+

20 September 2019

@@ -219,36 +219,36 @@ times = 10) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq -# 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 -# 31.0 10 -# 120.0 10 -# 59.0 10 -# 34.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
+# expr min lq mean median uq max +# as.mo("sau") 8.4 8.8 23.0 8.8 30.0 100 +# as.mo("stau") 31.0 31.0 42.0 35.0 54.0 60 +# as.mo("STAU") 31.0 32.0 39.0 33.0 53.0 56 +# as.mo("staaur") 8.5 8.9 11.0 9.0 9.2 33 +# as.mo("STAAUR") 8.6 8.8 9.4 9.3 9.4 11 +# as.mo("S. aureus") 23.0 24.0 28.0 26.0 28.0 51 +# as.mo("S aureus") 23.0 24.0 29.0 25.0 25.0 51 +# as.mo("Staphylococcus aureus") 28.0 29.0 30.0 29.0 30.0 32 +# as.mo("Staphylococcus aureus (MRSA)") 600.0 620.0 640.0 620.0 640.0 800 +# as.mo("Sthafilokkockus aaureuz") 320.0 340.0 370.0 350.0 400.0 450 +# as.mo("MRSA") 8.7 8.7 11.0 9.2 9.9 31 +# as.mo("VISA") 19.0 19.0 20.0 19.0 20.0 23 +# as.mo("VRSA") 19.0 19.0 25.0 20.0 28.0 44 +# as.mo(22242419) 18.0 19.0 47.0 31.0 48.0 190 +# neval +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 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_ISLN), a bug probably never found before in humans:

@@ -258,93 +258,25 @@ as.mo("T. islandicus"), as.mo("Thermus islandicus"), times = 10) -# 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. - -# 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. - -# 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. - -# 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. - -# 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. - -# 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. - -# 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. - -# 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. - -# 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. - -# 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. -print(T.islandicus, unit = "ms", signif = 2) -# Unit: milliseconds -# expr min lq mean median uq max neval -# 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.

+print(T.islandicus, unit = "ms", signif = 2) +# Unit: milliseconds +# expr min lq mean median uq max neval +# as.mo("theisl") 1300 1500 1500 1500 1500 1600 10 +# as.mo("THEISL") 1400 1500 1500 1500 1500 1600 10 +# as.mo("T. islandicus") 410 410 430 410 450 500 10 +# as.mo("T. islandicus") 410 420 430 420 440 440 10 +# as.mo("Thermus islandicus") 30 30 31 31 32 35 10 +

That takes 8.2 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 (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 (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.
 
@@ -356,15 +288,18 @@
 
 # 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]
-# 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.
+
 # Warning: 
 # 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.

@@ -400,8 +335,8 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# 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.

+# mo_name(x) 604 632 655 644 660 764 10 +

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

@@ -414,9 +349,9 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# A 6.150 6.260 6.400 6.390 6.520 6.710 10 -# B 22.200 22.500 26.400 22.700 24.800 53.100 10 -# C 0.645 0.774 0.801 0.803 0.812 0.911 10

+# A 6.190 6.270 6.560 6.290 7.160 7.280 10 +# B 22.600 23.100 26.700 23.400 24.300 51.600 10 +# C 0.704 0.765 0.827 0.829 0.906 0.913 10

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:

run_it <- microbenchmark(A = mo_species("aureus"),
                          B = mo_genus("Staphylococcus"),
@@ -430,14 +365,14 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #  expr   min    lq  mean median    uq   max neval
-#     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
+# A 0.456 0.476 0.484 0.483 0.488 0.516 10 +# B 0.613 0.620 0.639 0.628 0.642 0.723 10 +# C 0.675 0.700 0.763 0.796 0.807 0.816 10 +# D 0.443 0.454 0.466 0.467 0.477 0.497 10 +# E 0.453 0.459 0.465 0.464 0.472 0.483 10 +# F 0.433 0.447 0.464 0.463 0.484 0.498 10 +# G 0.453 0.460 0.469 0.464 0.478 0.502 10 +# H 0.433 0.451 0.477 0.459 0.470 0.662 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 +399,13 @@ print(run_it, unit = "ms", signif = 4) # Unit: milliseconds # expr min lq mean median uq max neval -# 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
+# en 18.18 18.24 18.54 18.44 18.58 19.41 10 +# de 19.52 19.79 20.03 19.90 20.15 20.95 10 +# nl 24.54 24.94 26.29 25.70 26.35 31.90 10 +# es 19.52 19.69 22.29 19.86 20.27 44.03 10 +# it 19.52 19.57 22.05 19.74 20.46 41.43 10 +# fr 19.61 19.67 22.28 20.04 20.30 42.90 10 +# pt 19.51 19.79 25.16 20.01 20.73 49.48 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 1df1557a..8a53786c 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 ff8208ee..48e6e780 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 ad62008e..db7fffa8 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 daaf7f8e..1adba2ec 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 diff --git a/docs/authors.html b/docs/authors.html index 4f9f44c2..128b1c9e 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 diff --git a/docs/index.html b/docs/index.html index 3d6da21d..9a01a1d4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 diff --git a/docs/news/index.html b/docs/news/index.html index bf37a22f..78687526 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 @@ -225,11 +225,11 @@ -
+

-AMR 0.7.1.9075 Unreleased +AMR 0.7.1.9076 Unreleased

-

Last updated: 18-Sep-2019

+

Last updated: 20-Sep-2019

Breaking

@@ -250,7 +250,7 @@ For WHONET users, this means that all records/isolates with organism code x <- as.mo("E. coli") x[1] <- "testvalue" #> Warning message: -#> invalid microbial code, NA generated
+#> invalid microorganism code, NA generated
This is important, because a value like "testvalue" could never be understood by e.g. mo_name(), although the class would suggest a valid microbial code.
  • Function freq() has moved to a new package, clean (CRAN link), since creating frequency tables actually does not fit the scope of this package. The freq() function still works, since it is re-exported from the clean package (which will be installed automatically upon updating this AMR package).

  • @@ -263,12 +263,13 @@ This is important, because a value like "testvalue" could never be

    Function bug_drug_combinations() to quickly get a data.frame with the antimicrobial resistance of any bug-drug combination in a data set:

    x <- bug_drug_combinations(example_isolates)
     x
    -#>      ab          mo   S  I   R total
    -#> 1   AMC B_ESCHR_COL 332 74  61   467
    -#> 2   AMC B_KLBSL_PNE  49  3   6    58
    -#> 3   AMC B_PROTS_MIR  28  7   1    36
    -#> 4   AMC B_PSDMN_AER   0  0  30    30
    -#> 5   AMC B_STPHY_AUR 234  0   1   235
    +# NOTE: Using column `mo` as input for `col_mo`. +#> ab mo S I R total +#> 1 AMC B_ESCHR_COLI 332 74 61 467 +#> 2 AMC B_KLBSL_PNMN 49 3 6 58 +#> 3 AMC B_PROTS_MRBL 28 7 1 36 +#> 4 AMC B_PSDMN_AERG 0 0 30 30 +#> 5 AMC B_STPHY_AURS 234 0 1 235

    You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R format() function:

    format(x, combine_IR = FALSE)
    @@ -1266,7 +1267,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

    About the records from DSMZ (see source)

    diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index 14b4ebce..77208e82 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9075 + 0.7.1.9076 diff --git a/inst/mo_history/mo_history.csv b/inst/mo_history/mo_history.csv index a4d9a82e..db967b2c 100644 --- a/inst/mo_history/mo_history.csv +++ b/inst/mo_history/mo_history.csv @@ -1 +1 @@ -"x","mo","uncertainty_level","package_version" +"","x","mo","uncertainty_level","package_v" diff --git a/man/microorganisms.Rd b/man/microorganisms.Rd index 4ec1ae5a..399a5635 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,460 observations and 16 variables: +\format{A \code{\link{data.frame}} with 69,454 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{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} + \item{9,460 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) since the DSMZ contain the latest taxonomic information based on recent publications} } } \section{About the records from DSMZ (see source)}{ diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index bbaa333d..271b8477 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -30,6 +30,9 @@ test_that("data sets are valid", { # check cross table reference expect_true(all(microorganisms.codes$mo %in% microorganisms$mo)) + expect_true(all(example_isolates$mo %in% microorganisms$mo)) + expect_true(all(microorganisms.translation$mo_new %in% microorganisms$mo)) + expect_true(all(rsi_translation$mo %in% microorganisms$mo)) expect_false(any(is.na(microorganisms.codes$code))) expect_false(any(is.na(microorganisms.codes$mo))) @@ -40,6 +43,7 @@ test_that("data sets are valid", { datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item"] for (i in 1:length(datasets)) { dataset <- get(datasets[i], envir = asNamespace("AMR")) + #print(paste("testing data set", datasets[i])) expect_identical(dataset_UTF8_to_ASCII(dataset), dataset) } }) diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd index c847b4da..daadb4d1 100755 --- a/vignettes/AMR.Rmd +++ b/vignettes/AMR.Rmd @@ -121,8 +121,7 @@ data <- data.frame(date = sample(dates, size = sample_size, replace = TRUE), CIP = sample(ab_interpretations, size = sample_size, replace = TRUE, prob = c(0.80, 0.00, 0.20)), GEN = sample(ab_interpretations, size = sample_size, replace = TRUE, - prob = c(0.92, 0.00, 0.08)) - ) + prob = c(0.92, 0.00, 0.08))) ``` Using the `left_join()` function from the `dplyr` package, we can 'map' the gender to the patient ID using the `patients_table` object we created earlier: diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd index 68013505..fb3d4b1b 100755 --- a/vignettes/benchmarks.Rmd +++ b/vignettes/benchmarks.Rmd @@ -95,7 +95,7 @@ In the table above, all measurements are shown in milliseconds (thousands of sec 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} +```{r, warning=FALSE} T.islandicus <- microbenchmark(as.mo("theisl"), as.mo("THEISL"), as.mo("T. islandicus"),