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 @@
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 @@ @@ -185,7 +185,7 @@AMR.Rmd
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.
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:
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:
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.
So only is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
For future use, the above two syntaxes can be shortened with the filter_first_isolate()
function:
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:
isolate | @@ -524,32 +523,32 @@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-10 | -Q3 | -B_ESCHR_COL | +2010-01-29 | +O6 | +B_ESCHR_COLI | +R | R | S | -R | S | TRUE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | -2010-03-10 | -Q3 | -B_ESCHR_COL | -S | -S | +2010-04-29 | +O6 | +B_ESCHR_COLI | R | S | +S | +S | FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | -2010-04-30 | -Q3 | -B_ESCHR_COL | -R | +2010-08-31 | +O6 | +B_ESCHR_COLI | +S | S | S | S | @@ -557,10 +556,10 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | -2010-07-02 | -Q3 | -B_ESCHR_COL | -R | +2010-09-18 | +O6 | +B_ESCHR_COLI | +S | S | S | S | @@ -568,21 +567,21 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | -2010-10-10 | -Q3 | -B_ESCHR_COL | +2011-03-23 | +O6 | +B_ESCHR_COLI | S | S | -R | S | -FALSE | +S | +TRUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | -2010-11-26 | -Q3 | -B_ESCHR_COL | -R | +2011-03-24 | +O6 | +B_ESCHR_COLI | +S | S | S | S | @@ -590,9 +589,9 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | -2011-01-09 | -Q3 | -B_ESCHR_COL | +2011-07-19 | +O6 | +B_ESCHR_COLI | S | S | S | @@ -601,20 +600,20 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | -2011-02-01 | -Q3 | -B_ESCHR_COL | +2011-08-04 | +O6 | +B_ESCHR_COLI | +R | +R | R | S | -R | -S | -TRUE | +FALSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | -2011-03-20 | -Q3 | -B_ESCHR_COL | +2011-08-15 | +O6 | +B_ESCHR_COLI | S | S | S | @@ -623,9 +622,9 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | -2011-08-04 | -Q3 | -B_ESCHR_COL | +2011-08-22 | +O6 | +B_ESCHR_COLI | S | S | S | @@ -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 | @@ -662,34 +661,34 @@|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-10 | -Q3 | -B_ESCHR_COL | +2010-01-29 | +O6 | +B_ESCHR_COLI | +R | R | S | -R | S | TRUE | TRUE | ||
2 | -2010-03-10 | -Q3 | -B_ESCHR_COL | -S | -S | +2010-04-29 | +O6 | +B_ESCHR_COLI | R | S | +S | +S | FALSE | TRUE | |
3 | -2010-04-30 | -Q3 | -B_ESCHR_COL | -R | +2010-08-31 | +O6 | +B_ESCHR_COLI | +S | S | S | S | @@ -698,10 +697,10 @@||||
4 | -2010-07-02 | -Q3 | -B_ESCHR_COL | -R | +2010-09-18 | +O6 | +B_ESCHR_COLI | +S | S | S | S | @@ -710,57 +709,57 @@||||
5 | -2010-10-10 | -Q3 | -B_ESCHR_COL | +2011-03-23 | +O6 | +B_ESCHR_COLI | S | S | -R | S | -FALSE | +S | +TRUE | TRUE | |
6 | -2010-11-26 | -Q3 | -B_ESCHR_COL | -R | +2011-03-24 | +O6 | +B_ESCHR_COLI | +S | S | S | S | FALSE | -TRUE | +FALSE | |
7 | -2011-01-09 | -Q3 | -B_ESCHR_COL | +2011-07-19 | +O6 | +B_ESCHR_COLI | S | S | S | S | FALSE | -TRUE | +FALSE | ||
8 | -2011-02-01 | -Q3 | -B_ESCHR_COL | +2011-08-04 | +O6 | +B_ESCHR_COLI | +R | +R | R | S | -R | -S | -TRUE | +FALSE | TRUE |
9 | -2011-03-20 | -Q3 | -B_ESCHR_COL | +2011-08-15 | +O6 | +B_ESCHR_COLI | S | S | S | @@ -770,9 +769,9 @@||||||
10 | -2011-08-04 | -Q3 | -B_ESCHR_COL | +2011-08-22 | +O6 | +B_ESCHR_COLI | S | S | S | @@ -782,11 +781,11 @@
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:
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:
@@ -812,58 +811,58 @@Time for the analysis!
@@ -925,7 +924,7 @@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
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:
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 @@
benchmarks.Rmd
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:
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.
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
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.
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 @@ 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 @@ 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 @@ 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 @@ @@ -225,11 +225,11 @@ -Last updated: 18-Sep-2019
+Last updated: 20-Sep-2019
x <- as.mo("E. coli")
x[1] <- "testvalue"
#> Warning message:
-#> invalid microbial code, NA generated
"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).
"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
You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R format()
function:
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 @@
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"),