diff --git a/NEWS.md b/NEWS.md index 6d347bb1..fca8315b 100755 --- a/NEWS.md +++ b/NEWS.md @@ -11,10 +11,14 @@ We've got a new website: [https://msberends.gitlab.io/AMR](https://msberends.git #### New * **BREAKING**: removed deprecated functions, parameters and references to 'bactid'. Use `as.mo()` to identify an MO code. * Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The `microorganisms` data set now contains: - * All ~55,000 species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses - * All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales. The kingdom of Fungi is a very large taxon with almost 300,000 different species, of which most are not microbial. Including everything tremendously slows down our algortihms, and not all fungi fit the scope of this package. By only including the aforementioned taxonomic orders, the most relevant species are covered (like genera *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*). - * All ~15,000 previously accepted names of species that have been taxonomically renamed + * All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses + * All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales. + + The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant (sub)species are covered (like all species of *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*). + * All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed * The responsible author(s) and year of scientific publication + + This data is updated annually - check the included version with `catalogue_of_life_version()`. * Due to this change, some `mo` codes changed (e.g. *Streptococcus* changed from `B_STRPTC` to `B_STRPT`). A translation table is used internally to support older microorganism IDs, so users will not notice this difference. * Support for data from [WHONET](https://whonet.org/) and [EARS-Net](https://ecdc.europa.eu/en/about-us/partnerships-and-networks/disease-and-laboratory-networks/ears-net) (European Antimicrobial Resistance Surveillance Network): * Exported files from WHONET can be read and used in this package. For functions like `first_isolate()` and `eucast_rules()`, all parameters will be filled in automatically. diff --git a/R/mo.R b/R/mo.R index cd495022..ecf598ae 100755 --- a/R/mo.R +++ b/R/mo.R @@ -372,7 +372,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, x[i] <- microorganismsDT[mo == 'B_ENTRC', ..property][[1]][1L] next } - if (toupper(x_trimmed[i]) %in% c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC')) { + if (toupper(x_trimmed[i]) %in% c("EHEC", "EPEC", "EIEC", "STEC", "ATEC")) { x[i] <- microorganismsDT[mo == 'B_ESCHR_COL', ..property][[1]][1L] next } @@ -614,8 +614,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, 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" + # 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 { @@ -632,7 +632,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # check for uncertain results ---- if (allow_uncertain == TRUE) { - uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only, e.x) { + uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only) { # (1) look for genus only, part of name ---- if (nchar(b.x_trimmed) > 4 & !b.x_trimmed %like% " ") { @@ -650,8 +650,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # (2) look again for old taxonomic names, now for G. species ---- found <- microorganisms.oldDT[fullname %like% c.x_withspaces_start_end - | fullname %like% d.x_withspaces_start_only - | fullname %like% e.x,] + | fullname %like% d.x_withspaces_start_only] if (NROW(found) > 0 & nchar(b.x_trimmed) >= 6) { if (property == "ref") { # when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so: @@ -715,7 +714,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } } - # (6) not yet implemented taxonomic changes in ITIS ---- + # (6) not yet implemented taxonomic changes in Catalogue of Life ---- found <- suppressMessages(suppressWarnings(exec_as.mo(TEMPORARY_TAXONOMY(b.x_trimmed), clear_options = FALSE, allow_uncertain = FALSE))) if (!is.na(found)) { found_result <- found @@ -732,7 +731,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, return(NA_character_) } - x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i], x[i]) + x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i]) if (!is.na(x[i])) { next } diff --git a/R/zzz.R b/R/zzz.R index 349055cb..17bdba90 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -19,60 +19,246 @@ # Visit our website for more info: https://msberends.gitab.io/AMR. # # ==================================================================== # -#' @importFrom dplyr mutate case_when #' @importFrom data.table as.data.table setkey .onLoad <- function(libname, pkgname) { # get new functions not available in older versions of R backports::import(pkgname) # register data - if (!all(c("microorganismsDT", - "microorganisms.prevDT", - "microorganisms.unprevDT", - "microorganisms.oldDT") %in% ls(envir = asNamespace("AMR")))) { - - # packageStartupMessage("Loading taxonomic database...", appendLF = FALSE) - - microorganismsDT <- AMR::microorganisms %>% - mutate(prevalence = case_when( - # most important Gram negatives # Streptococci and Staphylococci - class == "Gammaproteobacteria" - | order %in% c("Lactobacillales", "Bacillales") - ~ 1, - phylum %in% c("Proteobacteria", - "Firmicutes", - "Actinobacteria", - "Bacteroidetes") - | genus %in% c("Candida", - "Aspergillus", - "Trichophyton", - "Giardia", - "Dientamoeba", - "Entamoeba") - ~ 2, - TRUE ~ 3 - )) %>% - as.data.table() - setkey(microorganismsDT, kingdom, prevalence, fullname) + if (!all(c("microorganismsDT", "microorganisms.oldDT") %in% ls(envir = asNamespace("AMR")))) { microorganisms.oldDT <- as.data.table(AMR::microorganisms.old) setkey(microorganisms.oldDT, col_id, fullname) assign(x = "microorganismsDT", - value = microorganismsDT, + value = make_DT(), envir = asNamespace("AMR")) assign(x = "microorganisms.oldDT", value = microorganisms.oldDT, envir = asNamespace("AMR")) - # conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life) - mo_codes_v0.5.0 <- c(B_ACHRMB = "B_ACHRM", B_ANNMA = "B_ACTNS", B_ACLLS = "B_ALCYC", B_AHNGM = "B_ARCHN", B_ARMTM = "B_ARMTMN", B_ARTHRS = "B_ARTHR", B_APHLS = "B_AZRHZP", B_BRCHA = "B_BRCHY", B_BCTRM = "B_BRVBCT", B_CLRBCT = "B_CLRBC", B_CTRDM = "B_CLSTR", B_CPRMM = "B_CYLND", B_DLCLN = "B_DPLCL", B_DMCLM = "B_DSLFT", B_DSLFVB = "B_DSLFV", B_FCTRM = "B_FSBCT", B_GNRLA = "B_GRDNR", B_HNRBM = "B_HLNRB", B_HPHGA = "B_HNPHGA", B_HCCCS = "B_HYDRC", B_MCRCLS = "B_MCRCL", B_MTHYLS = "B_MLSMA", B_MARCLS = "B_MRCLS", B_MGCLS = "B_MSTGC", B_MCLLA = "B_MTHYLC", B_MYCPLS = "B_MYCPL", B_NBCTR = "B_NTRBC", B_OCLLS = "B_OCNBC", B_PTHRX = "B_PLNKT", B_PCCCS = "B_PRCHL", B_PSPHN = "B_PRPHY", B_PDMNS = "B_PSDMN", B_SCCHRP = "B_SCCHR", B_SRBCTR = "B_SHRBCTR", B_STRPTC = "B_STRPT", B_SHMNS = "B_SYNTR", B_TRBCTR = "B_THRMN", P_ALBMN = "C_ABMNA", F_ACHLY = "C_ACHLY", P_ACINT = "C_ACINT", P_ARTCL = "C_ACLNA", P_ACRVL = "C_ACRVL", P_ADRCT = "C_ADRCT", P_AMPHS = "C_AHSRS", F_ALBUG = "C_ALBUG", P_ALCNT = "C_ALCNT", P_ALFRD = "C_ALFRD", P_ALLGR = "C_ALLGR", P_AMPHL = "C_ALPTS", F_ALTHR = "C_ALTHR", P_AMLLA = "C_AMLLA", P_ANMLN = "C_AMLNA", P_AMMBC = "C_AMMBC", P_AMMDS = "C_AMMDS", P_AMMLG = "C_AMMLG", P_AMMMR = "C_AMMMR", P_AMMMS = "C_AMMMS", P_AMMON = "C_AMMON", P_AMMSC = "C_AMMSC", P_AMMSP = "C_AMMSP", P_AMMST = "C_AMMST", P_AMMTM = "C_AMMTM", F_AMYCS = "C_AMYCS", P_ANARM = "C_ANARM", P_ANGLD = "C_ANGLD", P_ANGLG = "C_ANGLG", P_ANNLC = "C_ANNLC", F_ANSLP = "C_ANSLP", F_APDCH = "C_APDCH", F_APHND = "C_APHND", F_APLNC = "C_APLNC", F_AQLND = "C_AQLND", P_ARCHS = "C_ARCHAS", P_ASTRN = "C_ARNNN", P_ARNPR = "C_ARNPR", F_ARSPR = "C_ARSPR", P_ARTST = "C_ARTSTR", P_AMPHC = "C_ARYNA", P_ASCHM = "C_ASCHM", P_ASPDS = "C_ASPDS", P_ASTCL = "C_ASTCL", P_ASTRG = "C_ASTRGR", P_ASTRM = "C_ASTRMM", P_ASTRR = "C_ASTRR", P_ASTRT = "C_ASTRTR", F_ATKNS = "C_ATKNS", F_AYLLA = "C_AYLLA", P_BAGGN = "C_BAGGN", P_BCCLL = "C_BCCLL", P_BDLLD = "C_BDLLD", P_BGNRN = "C_BGNRN", P_BLCLN = "C_BLCLN", P_BLMND = "C_BLMND", P_BLMNL = "C_BLMNL", P_BLPHR = "C_BLPHR", P_BLVNT = "C_BLVNT", P_BOLVN = "C_BOLVN", P_BORLS = "C_BORLS", P_BRNNM = "C_BRNNM", P_BRSLN = "C_BRSLN", P_BRSRD = "C_BRSRD", F_BRVLG = "C_BRVLG", F_BNLLA = "C_BRVLGN", P_BSCCM = "C_BSCCM", F_BSDPH = "C_BSDPH", P_BTHYS = "C_BTHYS", P_BTLLN = "C_BTLLN", P_BULMN = "C_BULMN", P_CCLDM = "C_CCLDM", P_CDNLL = "C_CDNLL", P_CLPSS = "C_CDNLLP", P_CHLDN = "C_CHLDNL", P_CHLST = "C_CHLST", P_CHNLM = "C_CHNLM", P_CHRYS = "C_CHRYSL", P_CHTSP = "C_CHTSP", P_CBCDS = "C_CIBCDS", P_CLCRN = "C_CLCRN", P_CLMNA = "C_CLMNA", P_CLPDM = "C_CLPDM", P_CLPHR = "C_CLPHRY", P_CLVLN = "C_CLVLN", P_CMPNL = "C_CMPNL", P_CNCRS = "C_CNCRS", P_CNTCH = "C_CNTCH", F_CNTRM = "C_CNTRMY", P_COLPD = "C_COLPD", P_COLPS = "C_COLPS", P_CPRDS = "C_CPRDS", P_CRNSP = "C_CPRMA", P_CRBNL = "C_CRBNL", P_CRBRB = "C_CRBRB", P_CRBRG = "C_CRBRG", P_CRBRS = "C_CRBRS", P_CRCHS = "C_CRCHS", P_CRCLC = "C_CRCLC", P_CRNLC = "C_CRNLC", P_CRNTH = "C_CRNTH", P_CRPNT = "C_CRPNT", P_CRSTG = "C_CRSTG", P_CRTHN = "C_CRTHN", P_CRTRN = "C_CRTRN", P_CYMBL = "C_CRTTA", P_CRYPT = "C_CRYPT", P_CSHMN = "C_CSHMNL", P_CSSDL = "C_CSSDL", P_CLNDS = "C_CSSDLN", P_CHRNA = "C_CTHRN", P_CTPSS = "C_CTPSS", P_CUNLN = "C_CUNLN", P_CYLND = "C_CVLNA", P_CYCLC = "C_CYCLCB", P_CDNTA = "C_CYCLD", P_CYCLG = "C_CYCLG", P_CYCLM = "C_CYCLM", P_CYRTL = "C_CYRTL", P_CYSTM = "C_CYSTM", P_DCHLM = "C_DCHLM", P_DCRBS = "C_DCRBS", P_DCTYC = "C_DCTYC", P_DIDNM = "C_DIDNM", P_DLPTS = "C_DLPTS", P_DNTLN = "C_DNTLN", P_DNTST = "C_DNTST", P_DORTH = "C_DORTH", P_DCTYP = "C_DPHMS", F_DPLCY = "C_DPLCY", P_DNDRT = "C_DRTNA", P_DSCMM = "C_DSCMM", P_DSCRB = "C_DSCRB", P_DSCRN = "C_DSCRN", P_DSCSP = "C_DSCSP", P_DSNBR = "C_DSNBR", P_DYCBC = "C_DYCBC", F_DCTYC = "C_DYCHS", F_ECTRG = "C_ECTRG", B_EDWRD = "C_EDWRD", P_EGGRL = "C_EGGRL", P_EHLYS = "C_EHLYS", P_EHRNB = "C_EHRNB", P_ELPHD = "C_ELPHD", P_ENCHL = "C_ELYDM", P_EPHDM = "C_EPHDM", P_EPLTS = "C_EPLTS", P_EPLXL = "C_EPLXL", P_EPNDL = "C_EPNDL", P_EPNDS = "C_EPNDS", P_ENLLA = "C_EPSTM", P_EPSTY = "C_EPSTY", F_ERYCH = "C_ERYCH", F_ESMDM = "C_ESMDM", P_ESSYR = "C_ESSYR", P_FSCHR = "C_FHRNA", P_FLRLS = "C_FLRLS", P_FLNTN = "C_FNTNA", P_FRNDC = "C_FRNDC", P_FRNTN = "C_FRNTN", P_FRSNK = "C_FRSNK", P_FNLLA = "C_FSCHRN", P_FSSRN = "C_FSSRN", P_FVCSS = "C_FVCSS", P_GDRYN = "C_GDRYN", F_GELGN = "C_GELGN", P_GERDA = "C_GERDA", P_GLACM = "C_GLACM", P_GLBBL = "C_GLBBL", P_GLBGR = "C_GLBGR", P_GLBLN = "C_GLBLN", P_GRTLA = "C_GLBRT", P_GLBTX = "C_GLBTX", P_GLLNA = "C_GLLNA", P_GLMSP = "C_GLMSP", P_GLNDL = "C_GLNDL", F_GNMCH = "C_GNMCH", P_GOSLL = "C_GOSLL", P_GRNDS = "C_GRNDS", P_GRNTA = "C_GRNTA", P_GLBRT = "C_GTLLA", P_GTTLN = "C_GTTLN", P_GVLNP = "C_GVLNP", P_GYPSN = "C_GYPSN", P_GYRDN = "C_GYRDN", P_HALTR = "C_HALTR", P_HANZW = "C_HANZW", P_HAURN = "C_HAURN", P_HELNN = "C_HELNN", P_HLPHR = "C_HHRYA", P_HLNTA = "C_HLNTA", F_HLPHT = "C_HLPHT", P_HLSTC = "C_HLSTC", P_HMSPH = "C_HMSPH", P_HMTRM = "C_HMTRM", P_HPKNS = "C_HPKNS", P_HPLPH = "C_HPLPH", P_HPPCR = "C_HPPCR", P_HNLLA = "C_HPPCRP", P_HRMSN = "C_HRMSN", P_HRNLL = "C_HRNLL", F_HRPCH = "C_HRPCH", P_HSTGR = "C_HSTGR", P_HSTTL = "C_HSTTL", P_HTRST = "C_HTGNA", P_HTRLL = "C_HTRLL", P_HTRPH = "C_HTRPH", F_HYPHC = "C_HYPHC", P_HYPRM = "C_HYPRM", P_INTRN = "C_INTRN", P_IRIDI = "C_IRIDI", P_ISLND = "C_ISLND", P_JCLLL = "C_JCLLL", P_KHLLL = "C_KHLLL", P_KRNPS = "C_KRNPS", P_KRRRL = "C_KRRRL", P_LABOE = "C_LABOE", P_LAGEN = "C_LAGEN", P_LBSLL = "C_LBSLL", F_LTHLA = "C_LBYRN", P_LCRYM = "C_LCRYM", P_LEMBS = "C_LEMBS", F_LGNDM = "C_LGNDM", P_LGNMM = "C_LGNMM", P_LGNPH = "C_LGNPHR", F_LGNSM = "C_LGNSM", P_LGYNP = "C_LGYNP", P_LITTB = "C_LITTB", P_LITUL = "C_LITUL", P_LMBDN = "C_LMBDN", P_LMRCK = "C_LMRCK", F_LBYRN = "C_LMYXA", P_LNGLN = "C_LNGLN", P_LNTCL = "C_LNTCL", P_LOXDS = "C_LOXDS", F_LPTLG = "C_LPTLG", F_LNLLA = "C_LPTLGN", F_LPTMT = "C_LPTMT", P_LRYNG = "C_LRYNG", P_LTCRN = "C_LTCRN", P_LTHPL = "C_LTHPL", P_LTNTS = "C_LTNTS", F_LTRST = "C_LTRST", P_LXPHY = "C_LXPHY", P_MCRTH = "C_MCRTH", P_MELNS = "C_MELNS", P_MSDNM = "C_MESDNM", P_METPS = "C_METPS", P_MIMSN = "C_MIMSN", P_MINCN = "C_MINCN", P_MLLNL = "C_MLLNL", P_MLMMN = "C_MLMMN", F_MNDNL = "C_MNDNL", P_MNLYS = "C_MNLYS", P_MNPSS = "C_MNPSS", P_MRGNL = "C_MRGNL", P_MRGNP = "C_MRGNP", P_MRSPL = "C_MRSPL", P_MRTNT = "C_MRTNT", P_MSSLN = "C_MSSLN", P_MSSSS = "C_MSSSS", P_MTCNT = "C_MTCNT", P_MYCHS = "C_MYCHS", P_MYSCH = "C_MYSCH", F_MYZCY = "C_MYZCY", P_NASSL = "C_NASSL", P_NBCLN = "C_NBCLN", P_NBCLR = "C_NBCLR", P_NCNRB = "C_NCNRB", P_NDBCL = "C_NDBCL", P_NRLLA = "C_NDBCLR", P_NMMLC = "C_NMMLC", F_NMTPH = "C_NMTPH", P_NNNLL = "C_NNNLL", P_NODSR = "C_NODSR", P_NONIN = "C_NONIN", P_NOURI = "C_NOURI", P_OCLNA = "C_OCLNA", P_OGLNA = "C_OGLNA", P_OPHTH = "C_OLMDM", F_OLPDP = "C_OLPDP", P_ONYCH = "C_OMPSS", P_OOLIN = "C_OOLIN", P_OPRCL = "C_OPRCL", P_ORBLN = "C_ORBLN", F_ORCAD = "C_ORCAD", P_ORDRS = "C_ORDRS", P_OPHRY = "C_ORYDM", P_OSNGL = "C_OSNGL", P_OXYTR = "C_OXYTR", P_PARRN = "C_PARRN", P_PATRS = "C_PATRS", P_PAVNN = "C_PAVNN", P_PTYCH = "C_PCYLS", P_PDPHR = "C_PDPHR", P_PELSN = "C_PELSN", F_PHGMY = "C_PHGMY", F_PSDSP = "C_PHRTA", P_PHRYG = "C_PHRYG", P_PHYSL = "C_PHYSL", F_PHYTP = "C_PHYTP", P_PLACS = "C_PLACS", P_PLCPS = "C_PLCPS", P_PLCPSL = "C_PLCPSL", P_PLCTN = "C_PLCTN", P_PLGPH = "C_PLGPH", B_PLGTH = "C_PLGTH", P_PLMRN = "C_PLMRN", P_PLNCT = "C_PLNCT", P_PLNDSC = "C_PLNDSC", P_PLNGY = "C_PLNGY", P_PLNRBL = "C_PLNLLA", P_PLNLN = "C_PLNLN", P_PLNLR = "C_PLNLR", P_PLNRB = "C_PLNRB", P_PLNSP = "C_PLNSPR", P_PLRNM = "C_PLRNM", P_PLRST = "C_PLRST", P_PLRTR = "C_PLRTR", F_PLSMD = "C_PLSMD", P_PLTYC = "C_PLTYC", P_PSDBL = "C_PLVNA", P_PLYMR = "C_PLYMR", P_PLTYN = "C_PNMTM", P_PNRPL = "C_PNRPL", F_PNTSM = "C_PNTSM", P_PRCNT = "C_PRCNT", P_PRFSS = "C_PRFSS", P_PRMCM = "C_PRMCUM", F_PRNSP = "C_PRNSP", P_PRPND = "C_PRPND", P_PRPYX = "C_PRPYX", P_PRRDN = "C_PRRDN", P_PSDDF = "C_PSDDF", P_PSDMC = "C_PSDMC", P_PSDND = "C_PSDND", P_PSDNN = "C_PSDNN", P_PSDPL = "C_PSDPLY", P_PSMMS = "C_PSMMS", P_PTLLN = "C_PTLLN", P_PTLLND = "C_PTLLND", F_PTRSN = "C_PTRSN", P_PULLN = "C_PULLN", P_PUTLN = "C_PUTLN", P_PRTTR = "C_PYMNA", P_PYRGL = "C_PYRGL", P_PYRGO = "C_PYRGO", P_PYRLN = "C_PYRLN", F_PYTHM = "C_PYTHIM", F_PYTHL = "C_PYTHL", P_PYXCL = "C_PYXCL", P_QNQLC = "C_QNQLC", P_RAMLN = "C_RAMLN", P_RBRTN = "C_RBRTN", P_RCRVD = "C_RCRVD", P_RCTBL = "C_RCTBL", P_RCTCB = "C_RCTCB", P_RCTGL = "C_RCTGL", P_RCTVG = "C_RCTVG", P_RDGDR = "C_RDGDR", P_REMNC = "C_REMNC", P_REPHX = "C_REPHX", P_RHBDM = "C_RHBDMM", F_RHBDS = "C_RHBDSP", P_RHPDD = "C_RHPDD", F_RHPDM = "C_RHPDM", F_RHZDMY = "C_RHZDM", P_RHZMM = "C_RHZMM", P_RIVRN = "C_RIVRN", P_ROSLN = "C_ROSLN", P_ROTAL = "C_ROTAL", P_RPHDP = "C_RPHDP", P_RPRTN = "C_RPRTN", P_RSSLL = "C_RSSLL", P_RTLMM = "C_RTLMM", P_RTYLA = "C_RTYLA", P_RUGID = "C_RUGID", F_RZLLP = "C_RZLLP", P_SAGRN = "C_SAGRN", P_SCCMM = "C_SCCMM", P_SCCRH = "C_SCCRH", P_SCHLM = "C_SCHLM", F_SCLRS = "C_SCLRS", P_SCTLR = "C_SCTLR", P_SEBRK = "C_SEBRK", P_SGMLN = "C_SGMLN", P_SGMLP = "C_SGMLP", P_SGMMR = "C_SGMMR", P_SGMVR = "C_SGMVR", F_SMMRS = "C_SMMRS", P_SNNDS = "C_SNNDS", P_SORTS = "C_SORTS", P_SPHGN = "C_SPHGN", P_SPHNN = "C_SPHNN", P_SNLLA = "C_SPHNNL", P_SPHTR = "C_SPHTR", P_SPHTX = "C_SPHTX", P_SPHVG = "C_SPHVG", P_SPRDT = "C_SPRDT", P_SPRLC = "C_SPRLC", F_SPRLG = "C_SPRLG", P_SPRLL = "C_SPRLL", F_SPRMY = "C_SPRMY", P_SPRPL = "C_SPRPL", P_SPRSG = "C_SPRSG", P_SPRST = "C_SPRST", P_SPHNP = "C_SPRTA", P_SPRZN = "C_SPRZN", P_SPHRG = "C_SPSNA", P_STHDM = "C_SPTHD", P_SRCNR = "C_SRCNR", F_SRLPD = "C_SRLPD", F_SPNGS = "C_SSPRA", F_STEIN = "C_STEIN", P_SPTHD = "C_STHDDS", P_STHRP = "C_STHRP", P_STNFR = "C_STNFR", P_STNSM = "C_STNSM", P_STNTR = "C_STNTR", P_STRBL = "C_STRBL", P_STRMB = "C_STRMB", P_STTSN = "C_STTSN", P_STYLN = "C_SYCHA", F_SCHZC = "C_SYTRM", P_TBNLL = "C_TBNLL", P_TRCHL = "C_TCHLS", P_TCHNT = "C_TCHNT", P_THRCL = "C_THRCL", P_THRMM = "C_THRMM", P_TIARN = "C_TIARN", P_TKPHR = "C_TKPHR", P_TLNMA = "C_TLNMA", P_TLYPM = "C_TLYPM", P_TMNDS = "C_TMNDS", P_TMNTA = "C_TMNTA", P_TNTNN = "C_TNNDM", P_TTNNS = "C_TNTNN", P_TNPSS = "C_TNTNNP", P_TONTN = "C_TONTN", P_TOSAI = "C_TOSAI", P_TPHTR = "C_TPHTR", P_TRCHH = "C_TRCHH", P_TRPHS = "C_TRCHLR", P_TMMNA = "C_TRCHM", P_TRCHS = "C_TRCHSP", P_TRFRN = "C_TRFRN", P_TRLCL = "C_TRLCL", P_TRTXL = "C_TRTXL", P_TRTXS = "C_TRTXS", P_TTRHY = "C_TTRHY", F_TTRMY = "C_TTRMY", P_TXTLR = "C_TXTLR", F_THRST = "C_TYTRM", P_URLPT = "C_ULPTS", P_UNGLT = "C_UNGLT", P_URCNT = "C_URCNT", P_URONM = "C_URONM", P_UROSM = "C_UROSM", P_URTRC = "C_URTRC", P_URSTY = "C_UTYLA", P_UVGRN = "C_UVGRN", P_VLVLN = "C_VALVLN", P_VGNLN = "C_VGNLN", P_VGNLNP = "C_VGNLNP", P_VLNRA = "C_VLVLN", P_VGNCL = "C_VNCLA", P_VRGLN = "C_VRGLN", P_VRGLNP = "C_VRGLNP", P_VRTCL = "C_VRTCL", P_WBBNL = "C_WBBNL", P_WEBBN = "C_WEBBN", P_WSNRL = "C_WSNRL", P_ZTHMN = "C_ZHMNM", B_ZOOGL = "C_ZOOGL", F_DDSCS = "F_DPDSC", F_SCCHR = "F_SMYCS", P_AMTRN = "P_ACNTH", F_AMBDM = "P_AMBDM", F_ARCYR = "P_ARCYR", F_BADHM = "P_BADHM", F_BDHMP = "P_BDHMP", F_BRBYL = "P_BRBYL", F_BRFLD = "P_BRFLD", F_CLMYX = "P_CLMYX", F_CLSTD = "P_CLSTD", F_CMTRC = "P_CMTRC", F_CRBRR = "P_CRBRR", F_CRTMY = "P_CRTMY", F_CRTRM = "P_CRTRM", F_DCTYD = "P_DCTYD", F_DDYMM = "P_DDYMM", F_DIACH = "P_DIACH", F_DIANM = "P_DIANM", F_DIDRM = "P_DIDRM", F_ELMYX = "P_ELMYX", F_ESTLM = "P_ESTLM", F_FULIG = "P_FULIG", F_HMTRC = "P_HMTRC", F_LCRPS = "P_LCRPS", F_LICEA = "P_LICEA", F_LMPRD = "P_LMPRD", F_LPTDR = "P_LPTDR", F_LSTRL = "P_LSTRL", F_LYCGL = "P_LYCGL", F_MCBRD = "P_MCBRD", F_MNKTL = "P_MNKTL", F_MTTRC = "P_MTTRC", F_MUCLG = "P_MUCLG", F_PHYSR = "P_PHYSR", F_PRCHN = "P_PRCHN", F_PRMBD = "P_PRMBD", F_PRTPH = "P_PRTPH", F_PSRNA = "P_PSRNA", F_PYSRM = "P_PYSRM", F_RTCLR = "P_RTCLR", F_STMNT = "P_STMNT", F_SYMPH = "P_SYMPH", F_TRBRK = "P_TRBRK", F_TRICH = "P_TRICH", F_TUBFR = "P_TUBFR") - assign(x = "mo_codes_v0.5.0", - value = mo_codes_v0.5.0, + value = make_trans_tbl(), envir = asNamespace("AMR")) - - # packageStartupMessage("OK.", appendLF = TRUE) } } + +#' @importFrom dplyr mutate case_when +#' @importFrom data.table as.data.table setkey +make_DT <- function() { + microorganismsDT <- AMR::microorganisms %>% + mutate(prevalence = case_when( + class == "Gammaproteobacteria" + | order %in% c("Lactobacillales", "Bacillales") + ~ 1, + phylum %in% c("Proteobacteria", + "Firmicutes", + "Actinobacteria", + "Bacteroidetes") + | genus %in% c("Candida", + "Aspergillus", + "Trichophyton", + "Giardia", + "Dientamoeba", + "Entamoeba") + ~ 2, + TRUE ~ 3 + )) %>% + as.data.table() + setkey(microorganismsDT, + kingdom, + prevalence, + fullname) + microorganismsDT +} + +make_trans_tbl <- function() { +# conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life) + c(B_ACHRMB = "B_ACHRM", B_ANNMA = "B_ACTNS", B_ACLLS = "B_ALCYC", + B_AHNGM = "B_ARCHN", B_ARMTM = "B_ARMTMN", B_ARTHRS = "B_ARTHR", + B_APHLS = "B_AZRHZP", B_BRCHA = "B_BRCHY", B_BCTRM = "B_BRVBCT", + B_CLRBCT = "B_CLRBC", B_CTRDM = "B_CLSTR", B_CPRMM = "B_CYLND", + B_DLCLN = "B_DPLCL", B_DMCLM = "B_DSLFT", B_DSLFVB = "B_DSLFV", + B_FCTRM = "B_FSBCT", B_GNRLA = "B_GRDNR", B_HNRBM = "B_HLNRB", + B_HPHGA = "B_HNPHGA", B_HCCCS = "B_HYDRC", B_MCRCLS = "B_MCRCL", + B_MTHYLS = "B_MLSMA", B_MARCLS = "B_MRCLS", B_MGCLS = "B_MSTGC", + B_MCLLA = "B_MTHYLC", B_MYCPLS = "B_MYCPL", B_NBCTR = "B_NTRBC", + B_OCLLS = "B_OCNBC", B_PTHRX = "B_PLNKT", B_PCCCS = "B_PRCHL", + B_PSPHN = "B_PRPHY", B_PDMNS = "B_PSDMN", B_SCCHRP = "B_SCCHR", + B_SRBCTR = "B_SHRBCTR", B_STRPTC = "B_STRPT", B_SHMNS = "B_SYNTR", + B_TRBCTR = "B_THRMN", P_ALBMN = "C_ABMNA", F_ACHLY = "C_ACHLY", + P_ACINT = "C_ACINT", P_ARTCL = "C_ACLNA", P_ACRVL = "C_ACRVL", + P_ADRCT = "C_ADRCT", P_AMPHS = "C_AHSRS", F_ALBUG = "C_ALBUG", + P_ALCNT = "C_ALCNT", P_ALFRD = "C_ALFRD", P_ALLGR = "C_ALLGR", + P_AMPHL = "C_ALPTS", F_ALTHR = "C_ALTHR", P_AMLLA = "C_AMLLA", + P_ANMLN = "C_AMLNA", P_AMMBC = "C_AMMBC", P_AMMDS = "C_AMMDS", + P_AMMLG = "C_AMMLG", P_AMMMR = "C_AMMMR", P_AMMMS = "C_AMMMS", + P_AMMON = "C_AMMON", P_AMMSC = "C_AMMSC", P_AMMSP = "C_AMMSP", + P_AMMST = "C_AMMST", P_AMMTM = "C_AMMTM", F_AMYCS = "C_AMYCS", + P_ANARM = "C_ANARM", P_ANGLD = "C_ANGLD", P_ANGLG = "C_ANGLG", + P_ANNLC = "C_ANNLC", F_ANSLP = "C_ANSLP", F_APDCH = "C_APDCH", + F_APHND = "C_APHND", F_APLNC = "C_APLNC", F_AQLND = "C_AQLND", + P_ARCHS = "C_ARCHAS", P_ASTRN = "C_ARNNN", P_ARNPR = "C_ARNPR", + F_ARSPR = "C_ARSPR", P_ARTST = "C_ARTSTR", P_AMPHC = "C_ARYNA", + P_ASCHM = "C_ASCHM", P_ASPDS = "C_ASPDS", P_ASTCL = "C_ASTCL", + P_ASTRG = "C_ASTRGR", P_ASTRM = "C_ASTRMM", P_ASTRR = "C_ASTRR", + P_ASTRT = "C_ASTRTR", F_ATKNS = "C_ATKNS", F_AYLLA = "C_AYLLA", + P_BAGGN = "C_BAGGN", P_BCCLL = "C_BCCLL", P_BDLLD = "C_BDLLD", + P_BGNRN = "C_BGNRN", P_BLCLN = "C_BLCLN", P_BLMND = "C_BLMND", + P_BLMNL = "C_BLMNL", P_BLPHR = "C_BLPHR", P_BLVNT = "C_BLVNT", + P_BOLVN = "C_BOLVN", P_BORLS = "C_BORLS", P_BRNNM = "C_BRNNM", + P_BRSLN = "C_BRSLN", P_BRSRD = "C_BRSRD", F_BRVLG = "C_BRVLG", + F_BNLLA = "C_BRVLGN", P_BSCCM = "C_BSCCM", F_BSDPH = "C_BSDPH", + P_BTHYS = "C_BTHYS", P_BTLLN = "C_BTLLN", P_BULMN = "C_BULMN", + P_CCLDM = "C_CCLDM", P_CDNLL = "C_CDNLL", P_CLPSS = "C_CDNLLP", + P_CHLDN = "C_CHLDNL", P_CHLST = "C_CHLST", P_CHNLM = "C_CHNLM", + P_CHRYS = "C_CHRYSL", P_CHTSP = "C_CHTSP", P_CBCDS = "C_CIBCDS", + P_CLCRN = "C_CLCRN", P_CLMNA = "C_CLMNA", P_CLPDM = "C_CLPDM", + P_CLPHR = "C_CLPHRY", P_CLVLN = "C_CLVLN", P_CMPNL = "C_CMPNL", + P_CNCRS = "C_CNCRS", P_CNTCH = "C_CNTCH", F_CNTRM = "C_CNTRMY", + P_COLPD = "C_COLPD", P_COLPS = "C_COLPS", P_CPRDS = "C_CPRDS", + P_CRNSP = "C_CPRMA", P_CRBNL = "C_CRBNL", P_CRBRB = "C_CRBRB", + P_CRBRG = "C_CRBRG", P_CRBRS = "C_CRBRS", P_CRCHS = "C_CRCHS", + P_CRCLC = "C_CRCLC", P_CRNLC = "C_CRNLC", P_CRNTH = "C_CRNTH", + P_CRPNT = "C_CRPNT", P_CRSTG = "C_CRSTG", P_CRTHN = "C_CRTHN", + P_CRTRN = "C_CRTRN", P_CYMBL = "C_CRTTA", P_CRYPT = "C_CRYPT", + P_CSHMN = "C_CSHMNL", P_CSSDL = "C_CSSDL", P_CLNDS = "C_CSSDLN", + P_CHRNA = "C_CTHRN", P_CTPSS = "C_CTPSS", P_CUNLN = "C_CUNLN", + P_CYLND = "C_CVLNA", P_CYCLC = "C_CYCLCB", P_CDNTA = "C_CYCLD", + P_CYCLG = "C_CYCLG", P_CYCLM = "C_CYCLM", P_CYRTL = "C_CYRTL", + P_CYSTM = "C_CYSTM", P_DCHLM = "C_DCHLM", P_DCRBS = "C_DCRBS", + P_DCTYC = "C_DCTYC", P_DIDNM = "C_DIDNM", P_DLPTS = "C_DLPTS", + P_DNTLN = "C_DNTLN", P_DNTST = "C_DNTST", P_DORTH = "C_DORTH", + P_DCTYP = "C_DPHMS", F_DPLCY = "C_DPLCY", P_DNDRT = "C_DRTNA", + P_DSCMM = "C_DSCMM", P_DSCRB = "C_DSCRB", P_DSCRN = "C_DSCRN", + P_DSCSP = "C_DSCSP", P_DSNBR = "C_DSNBR", P_DYCBC = "C_DYCBC", + F_DCTYC = "C_DYCHS", F_ECTRG = "C_ECTRG", B_EDWRD = "C_EDWRD", + P_EGGRL = "C_EGGRL", P_EHLYS = "C_EHLYS", P_EHRNB = "C_EHRNB", + P_ELPHD = "C_ELPHD", P_ENCHL = "C_ELYDM", P_EPHDM = "C_EPHDM", + P_EPLTS = "C_EPLTS", P_EPLXL = "C_EPLXL", P_EPNDL = "C_EPNDL", + P_EPNDS = "C_EPNDS", P_ENLLA = "C_EPSTM", P_EPSTY = "C_EPSTY", + F_ERYCH = "C_ERYCH", F_ESMDM = "C_ESMDM", P_ESSYR = "C_ESSYR", + P_FSCHR = "C_FHRNA", P_FLRLS = "C_FLRLS", P_FLNTN = "C_FNTNA", + P_FRNDC = "C_FRNDC", P_FRNTN = "C_FRNTN", P_FRSNK = "C_FRSNK", + P_FNLLA = "C_FSCHRN", P_FSSRN = "C_FSSRN", P_FVCSS = "C_FVCSS", + P_GDRYN = "C_GDRYN", F_GELGN = "C_GELGN", P_GERDA = "C_GERDA", + P_GLACM = "C_GLACM", P_GLBBL = "C_GLBBL", P_GLBGR = "C_GLBGR", + P_GLBLN = "C_GLBLN", P_GRTLA = "C_GLBRT", P_GLBTX = "C_GLBTX", + P_GLLNA = "C_GLLNA", P_GLMSP = "C_GLMSP", P_GLNDL = "C_GLNDL", + F_GNMCH = "C_GNMCH", P_GOSLL = "C_GOSLL", P_GRNDS = "C_GRNDS", + P_GRNTA = "C_GRNTA", P_GLBRT = "C_GTLLA", P_GTTLN = "C_GTTLN", + P_GVLNP = "C_GVLNP", P_GYPSN = "C_GYPSN", P_GYRDN = "C_GYRDN", + P_HALTR = "C_HALTR", P_HANZW = "C_HANZW", P_HAURN = "C_HAURN", + P_HELNN = "C_HELNN", P_HLPHR = "C_HHRYA", P_HLNTA = "C_HLNTA", + F_HLPHT = "C_HLPHT", P_HLSTC = "C_HLSTC", P_HMSPH = "C_HMSPH", + P_HMTRM = "C_HMTRM", P_HPKNS = "C_HPKNS", P_HPLPH = "C_HPLPH", + P_HPPCR = "C_HPPCR", P_HNLLA = "C_HPPCRP", P_HRMSN = "C_HRMSN", + P_HRNLL = "C_HRNLL", F_HRPCH = "C_HRPCH", P_HSTGR = "C_HSTGR", + P_HSTTL = "C_HSTTL", P_HTRST = "C_HTGNA", P_HTRLL = "C_HTRLL", + P_HTRPH = "C_HTRPH", F_HYPHC = "C_HYPHC", P_HYPRM = "C_HYPRM", + P_INTRN = "C_INTRN", P_IRIDI = "C_IRIDI", P_ISLND = "C_ISLND", + P_JCLLL = "C_JCLLL", P_KHLLL = "C_KHLLL", P_KRNPS = "C_KRNPS", + P_KRRRL = "C_KRRRL", P_LABOE = "C_LABOE", P_LAGEN = "C_LAGEN", + P_LBSLL = "C_LBSLL", F_LTHLA = "C_LBYRN", P_LCRYM = "C_LCRYM", + P_LEMBS = "C_LEMBS", F_LGNDM = "C_LGNDM", P_LGNMM = "C_LGNMM", + P_LGNPH = "C_LGNPHR", F_LGNSM = "C_LGNSM", P_LGYNP = "C_LGYNP", + P_LITTB = "C_LITTB", P_LITUL = "C_LITUL", P_LMBDN = "C_LMBDN", + P_LMRCK = "C_LMRCK", F_LBYRN = "C_LMYXA", P_LNGLN = "C_LNGLN", + P_LNTCL = "C_LNTCL", P_LOXDS = "C_LOXDS", F_LPTLG = "C_LPTLG", + F_LNLLA = "C_LPTLGN", F_LPTMT = "C_LPTMT", P_LRYNG = "C_LRYNG", + P_LTCRN = "C_LTCRN", P_LTHPL = "C_LTHPL", P_LTNTS = "C_LTNTS", + F_LTRST = "C_LTRST", P_LXPHY = "C_LXPHY", P_MCRTH = "C_MCRTH", + P_MELNS = "C_MELNS", P_MSDNM = "C_MESDNM", P_METPS = "C_METPS", + P_MIMSN = "C_MIMSN", P_MINCN = "C_MINCN", P_MLLNL = "C_MLLNL", + P_MLMMN = "C_MLMMN", F_MNDNL = "C_MNDNL", P_MNLYS = "C_MNLYS", + P_MNPSS = "C_MNPSS", P_MRGNL = "C_MRGNL", P_MRGNP = "C_MRGNP", + P_MRSPL = "C_MRSPL", P_MRTNT = "C_MRTNT", P_MSSLN = "C_MSSLN", + P_MSSSS = "C_MSSSS", P_MTCNT = "C_MTCNT", P_MYCHS = "C_MYCHS", + P_MYSCH = "C_MYSCH", F_MYZCY = "C_MYZCY", P_NASSL = "C_NASSL", + P_NBCLN = "C_NBCLN", P_NBCLR = "C_NBCLR", P_NCNRB = "C_NCNRB", + P_NDBCL = "C_NDBCL", P_NRLLA = "C_NDBCLR", P_NMMLC = "C_NMMLC", + F_NMTPH = "C_NMTPH", P_NNNLL = "C_NNNLL", P_NODSR = "C_NODSR", + P_NONIN = "C_NONIN", P_NOURI = "C_NOURI", P_OCLNA = "C_OCLNA", + P_OGLNA = "C_OGLNA", P_OPHTH = "C_OLMDM", F_OLPDP = "C_OLPDP", + P_ONYCH = "C_OMPSS", P_OOLIN = "C_OOLIN", P_OPRCL = "C_OPRCL", + P_ORBLN = "C_ORBLN", F_ORCAD = "C_ORCAD", P_ORDRS = "C_ORDRS", + P_OPHRY = "C_ORYDM", P_OSNGL = "C_OSNGL", P_OXYTR = "C_OXYTR", + P_PARRN = "C_PARRN", P_PATRS = "C_PATRS", P_PAVNN = "C_PAVNN", + P_PTYCH = "C_PCYLS", P_PDPHR = "C_PDPHR", P_PELSN = "C_PELSN", + F_PHGMY = "C_PHGMY", F_PSDSP = "C_PHRTA", P_PHRYG = "C_PHRYG", + P_PHYSL = "C_PHYSL", F_PHYTP = "C_PHYTP", P_PLACS = "C_PLACS", + P_PLCPS = "C_PLCPS", P_PLCPSL = "C_PLCPSL", P_PLCTN = "C_PLCTN", + P_PLGPH = "C_PLGPH", B_PLGTH = "C_PLGTH", P_PLMRN = "C_PLMRN", + P_PLNCT = "C_PLNCT", P_PLNDSC = "C_PLNDSC", P_PLNGY = "C_PLNGY", + P_PLNRBL = "C_PLNLLA", P_PLNLN = "C_PLNLN", P_PLNLR = "C_PLNLR", + P_PLNRB = "C_PLNRB", P_PLNSP = "C_PLNSPR", P_PLRNM = "C_PLRNM", + P_PLRST = "C_PLRST", P_PLRTR = "C_PLRTR", F_PLSMD = "C_PLSMD", + P_PLTYC = "C_PLTYC", P_PSDBL = "C_PLVNA", P_PLYMR = "C_PLYMR", + P_PLTYN = "C_PNMTM", P_PNRPL = "C_PNRPL", F_PNTSM = "C_PNTSM", + P_PRCNT = "C_PRCNT", P_PRFSS = "C_PRFSS", P_PRMCM = "C_PRMCUM", + F_PRNSP = "C_PRNSP", P_PRPND = "C_PRPND", P_PRPYX = "C_PRPYX", + P_PRRDN = "C_PRRDN", P_PSDDF = "C_PSDDF", P_PSDMC = "C_PSDMC", + P_PSDND = "C_PSDND", P_PSDNN = "C_PSDNN", P_PSDPL = "C_PSDPLY", + P_PSMMS = "C_PSMMS", P_PTLLN = "C_PTLLN", P_PTLLND = "C_PTLLND", + F_PTRSN = "C_PTRSN", P_PULLN = "C_PULLN", P_PUTLN = "C_PUTLN", + P_PRTTR = "C_PYMNA", P_PYRGL = "C_PYRGL", P_PYRGO = "C_PYRGO", + P_PYRLN = "C_PYRLN", F_PYTHM = "C_PYTHIM", F_PYTHL = "C_PYTHL", + P_PYXCL = "C_PYXCL", P_QNQLC = "C_QNQLC", P_RAMLN = "C_RAMLN", + P_RBRTN = "C_RBRTN", P_RCRVD = "C_RCRVD", P_RCTBL = "C_RCTBL", + P_RCTCB = "C_RCTCB", P_RCTGL = "C_RCTGL", P_RCTVG = "C_RCTVG", + P_RDGDR = "C_RDGDR", P_REMNC = "C_REMNC", P_REPHX = "C_REPHX", + P_RHBDM = "C_RHBDMM", F_RHBDS = "C_RHBDSP", P_RHPDD = "C_RHPDD", + F_RHPDM = "C_RHPDM", F_RHZDMY = "C_RHZDM", P_RHZMM = "C_RHZMM", + P_RIVRN = "C_RIVRN", P_ROSLN = "C_ROSLN", P_ROTAL = "C_ROTAL", + P_RPHDP = "C_RPHDP", P_RPRTN = "C_RPRTN", P_RSSLL = "C_RSSLL", + P_RTLMM = "C_RTLMM", P_RTYLA = "C_RTYLA", P_RUGID = "C_RUGID", + F_RZLLP = "C_RZLLP", P_SAGRN = "C_SAGRN", P_SCCMM = "C_SCCMM", + P_SCCRH = "C_SCCRH", P_SCHLM = "C_SCHLM", F_SCLRS = "C_SCLRS", + P_SCTLR = "C_SCTLR", P_SEBRK = "C_SEBRK", P_SGMLN = "C_SGMLN", + P_SGMLP = "C_SGMLP", P_SGMMR = "C_SGMMR", P_SGMVR = "C_SGMVR", + F_SMMRS = "C_SMMRS", P_SNNDS = "C_SNNDS", P_SORTS = "C_SORTS", + P_SPHGN = "C_SPHGN", P_SPHNN = "C_SPHNN", P_SNLLA = "C_SPHNNL", + P_SPHTR = "C_SPHTR", P_SPHTX = "C_SPHTX", P_SPHVG = "C_SPHVG", + P_SPRDT = "C_SPRDT", P_SPRLC = "C_SPRLC", F_SPRLG = "C_SPRLG", + P_SPRLL = "C_SPRLL", F_SPRMY = "C_SPRMY", P_SPRPL = "C_SPRPL", + P_SPRSG = "C_SPRSG", P_SPRST = "C_SPRST", P_SPHNP = "C_SPRTA", + P_SPRZN = "C_SPRZN", P_SPHRG = "C_SPSNA", P_STHDM = "C_SPTHD", + P_SRCNR = "C_SRCNR", F_SRLPD = "C_SRLPD", F_SPNGS = "C_SSPRA", + F_STEIN = "C_STEIN", P_SPTHD = "C_STHDDS", P_STHRP = "C_STHRP", + P_STNFR = "C_STNFR", P_STNSM = "C_STNSM", P_STNTR = "C_STNTR", + P_STRBL = "C_STRBL", P_STRMB = "C_STRMB", P_STTSN = "C_STTSN", + P_STYLN = "C_SYCHA", F_SCHZC = "C_SYTRM", P_TBNLL = "C_TBNLL", + P_TRCHL = "C_TCHLS", P_TCHNT = "C_TCHNT", P_THRCL = "C_THRCL", + P_THRMM = "C_THRMM", P_TIARN = "C_TIARN", P_TKPHR = "C_TKPHR", + P_TLNMA = "C_TLNMA", P_TLYPM = "C_TLYPM", P_TMNDS = "C_TMNDS", + P_TMNTA = "C_TMNTA", P_TNTNN = "C_TNNDM", P_TTNNS = "C_TNTNN", + P_TNPSS = "C_TNTNNP", P_TONTN = "C_TONTN", P_TOSAI = "C_TOSAI", + P_TPHTR = "C_TPHTR", P_TRCHH = "C_TRCHH", P_TRPHS = "C_TRCHLR", + P_TMMNA = "C_TRCHM", P_TRCHS = "C_TRCHSP", P_TRFRN = "C_TRFRN", + P_TRLCL = "C_TRLCL", P_TRTXL = "C_TRTXL", P_TRTXS = "C_TRTXS", + P_TTRHY = "C_TTRHY", F_TTRMY = "C_TTRMY", P_TXTLR = "C_TXTLR", + F_THRST = "C_TYTRM", P_URLPT = "C_ULPTS", P_UNGLT = "C_UNGLT", + P_URCNT = "C_URCNT", P_URONM = "C_URONM", P_UROSM = "C_UROSM", + P_URTRC = "C_URTRC", P_URSTY = "C_UTYLA", P_UVGRN = "C_UVGRN", + P_VLVLN = "C_VALVLN", P_VGNLN = "C_VGNLN", P_VGNLNP = "C_VGNLNP", + P_VLNRA = "C_VLVLN", P_VGNCL = "C_VNCLA", P_VRGLN = "C_VRGLN", + P_VRGLNP = "C_VRGLNP", P_VRTCL = "C_VRTCL", P_WBBNL = "C_WBBNL", + P_WEBBN = "C_WEBBN", P_WSNRL = "C_WSNRL", P_ZTHMN = "C_ZHMNM", + B_ZOOGL = "C_ZOOGL", F_DDSCS = "F_DPDSC", F_SCCHR = "F_SMYCS", + P_AMTRN = "P_ACNTH", F_AMBDM = "P_AMBDM", F_ARCYR = "P_ARCYR", + F_BADHM = "P_BADHM", F_BDHMP = "P_BDHMP", F_BRBYL = "P_BRBYL", + F_BRFLD = "P_BRFLD", F_CLMYX = "P_CLMYX", F_CLSTD = "P_CLSTD", + F_CMTRC = "P_CMTRC", F_CRBRR = "P_CRBRR", F_CRTMY = "P_CRTMY", + F_CRTRM = "P_CRTRM", F_DCTYD = "P_DCTYD", F_DDYMM = "P_DDYMM", + F_DIACH = "P_DIACH", F_DIANM = "P_DIANM", F_DIDRM = "P_DIDRM", + F_ELMYX = "P_ELMYX", F_ESTLM = "P_ESTLM", F_FULIG = "P_FULIG", + F_HMTRC = "P_HMTRC", F_LCRPS = "P_LCRPS", F_LICEA = "P_LICEA", + F_LMPRD = "P_LMPRD", F_LPTDR = "P_LPTDR", F_LSTRL = "P_LSTRL", + F_LYCGL = "P_LYCGL", F_MCBRD = "P_MCBRD", F_MNKTL = "P_MNKTL", + F_MTTRC = "P_MTTRC", F_MUCLG = "P_MUCLG", F_PHYSR = "P_PHYSR", + F_PRCHN = "P_PRCHN", F_PRMBD = "P_PRMBD", F_PRTPH = "P_PRTPH", + F_PSRNA = "P_PSRNA", F_PYSRM = "P_PYSRM", F_RTCLR = "P_RTCLR", + F_STMNT = "P_STMNT", F_SYMPH = "P_SYMPH", F_TRBRK = "P_TRBRK", + F_TRICH = "P_TRICH", F_TUBFR = "P_TUBFR") +} diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 17046f02..89199875 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -327,19 +327,41 @@ -2012-08-08 -P2 -Hospital B -Streptococcus pneumoniae -S +2010-03-19 +Z1 +Hospital A +Escherichia coli +R S S S F -2011-03-05 -D8 +2012-12-24 +Z8 +Hospital A +Klebsiella pneumoniae +R +S +S +S +F + + +2013-12-12 +Z1 +Hospital A +Staphylococcus aureus +R +S +S +S +F + + +2014-08-13 +J4 Hospital A Escherichia coli S @@ -349,20 +371,20 @@ M -2012-04-03 -D4 -Hospital C -Staphylococcus aureus -R +2012-04-09 +F5 +Hospital A +Escherichia coli +S +S S -R S M -2012-10-25 -I1 -Hospital B +2010-08-11 +N1 +Hospital A Klebsiella pneumoniae S S @@ -370,28 +392,6 @@ S M - -2017-04-18 -X3 -Hospital B -Streptococcus pneumoniae -S -I -S -R -F - - -2013-03-18 -C4 -Hospital A -Streptococcus pneumoniae -S -I -S -S -M -

Now, let’s start the cleaning and the analysis!

@@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,458 52.3% 10,458 52.3% -#> 2 F 9,542 47.7% 20,000 100.0% +#> 1 M 10,436 52.2% 10,436 52.2% +#> 2 F 9,564 47.8% 20,000 100.0%

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

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

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

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

-

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

+#> => Found 5,692 first isolates (28.5% of total) +

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

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

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

@@ -516,19 +516,19 @@ 1 -2010-01-23 -A4 +2010-01-14 +O6 B_ESCHR_COL -S -S -S +R +I +R S TRUE 2 -2010-03-13 -A4 +2010-02-22 +O6 B_ESCHR_COL S S @@ -538,8 +538,8 @@ 3 -2010-04-19 -A4 +2010-04-01 +O6 B_ESCHR_COL S S @@ -549,21 +549,21 @@ 4 -2010-06-11 -A4 +2010-04-25 +O6 B_ESCHR_COL S S -R +S S FALSE 5 -2010-07-04 -A4 +2010-05-09 +O6 B_ESCHR_COL -R +S S S S @@ -571,52 +571,52 @@ 6 -2010-07-05 -A4 +2010-05-29 +O6 B_ESCHR_COL S -S -S +I +R S FALSE 7 -2011-03-21 -A4 +2010-06-27 +O6 B_ESCHR_COL S S -R S -TRUE +S +FALSE 8 -2011-04-02 -A4 +2010-06-27 +O6 B_ESCHR_COL -R S -R +S +S S FALSE 9 -2011-04-05 -A4 +2011-02-01 +O6 B_ESCHR_COL -S -S -S R -FALSE +S +S +S +TRUE 10 -2011-04-13 -A4 +2011-03-20 +O6 B_ESCHR_COL S S @@ -637,7 +637,7 @@ #> NOTE: Using column `patient_id` as input for `col_patient_id`. #> NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this. #> [Criterion] Inclusion based on key antibiotics, ignoring I. -#> => Found 15,801 first weighted isolates (79.0% of total) +#> => Found 15,851 first weighted isolates (79.3% of total) @@ -654,32 +654,32 @@ - - + + - - - + + + - - + + - + - - + + @@ -690,80 +690,80 @@ - - + + - + - + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - - - + + + + - - + + @@ -774,11 +774,11 @@
isolate
12010-01-23A42010-01-14O6 B_ESCHR_COLSSSRIR S TRUE TRUE
22010-03-13A42010-02-22O6 B_ESCHR_COL S S S S FALSEFALSETRUE
32010-04-19A42010-04-01O6 B_ESCHR_COL S S
42010-06-11A42010-04-25O6 B_ESCHR_COL S SRS S FALSETRUEFALSE
52010-07-04A42010-05-09O6 B_ESCHR_COLRS S S S FALSETRUEFALSE
62010-07-05A42010-05-29O6 B_ESCHR_COL SSSIR S FALSE TRUE
72011-03-21A42010-06-27O6 B_ESCHR_COL S SR STRUESFALSE TRUE
82011-04-02A42010-06-27O6 B_ESCHR_COLR SRSS S FALSETRUEFALSE
92011-04-05A42011-02-01O6 B_ESCHR_COLSSS RFALSESSSTRUE TRUE
102011-04-13A42011-03-20O6 B_ESCHR_COL S S
-

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

+

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

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

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

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

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -786,6 +786,7 @@
head(data_1st)
+ @@ -802,23 +803,25 @@ - - - - - - - + + + + + + + + - - + + - - + + + @@ -832,24 +835,26 @@ - - - - - + + + + + + + - - - - + + + - - - + + + + @@ -862,33 +867,35 @@ - - - - - - - + + + + + - - - + + + + + + - - + + + - - + + - - + + @@ -908,9 +915,9 @@
freq(paste(data_1st$genus, data_1st$species))

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

data_1st %>% freq(genus, species)
-

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

+

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

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

Shortest: 16
Longest: 24

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

- - - - + + + + - - - - + + + + - - - - + + + + - - - + + + @@ -964,7 +971,7 @@ Longest: 24

Resistance percentages

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

data_1st %>% portion_IR(amox)
-#> [1] 0.4747801
+#> [1] 0.4764368

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

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

- + - + - + - +
date patient_id hospital
2012-08-08P2Hospital BB_STRPT_PNESSS32013-12-12Z1Hospital AB_STPHY_AUR RSSS F Gram positiveStreptococcuspneumoniaeStaphylococcusaureus TRUE
2011-03-05D842014-08-13J4 Hospital A B_ESCHR_COL STRUE
2012-04-03D4Hospital CB_STPHY_AURR52012-04-09F5Hospital AB_ESCHR_COLSS SR S MGram positiveStaphylococcusaureusGram negativeEscherichiacoli TRUE
2012-10-25I1Hospital B62010-08-11N1Hospital A B_KLBSL_PNE R STRUE
2017-04-18X3Hospital BB_STRPT_PNESIS72010-02-25E9Hospital AB_KLBSL_PNE RFGram positiveStreptococcusRSSMGram negativeKlebsiella pneumoniae TRUE
2013-03-18C482013-04-09N1 Hospital AB_STRPT_PNESB_STPHY_AUR I S RS M Gram positiveStreptococcuspneumoniaeStaphylococcusaureus TRUE
1 Escherichia coli7,85049.7%7,85049.7%7,85349.5%7,85349.5%
2 Staphylococcus aureus3,91824.8%11,76874.5%3,94324.9%11,79674.4%
3 Streptococcus pneumoniae2,44615.5%14,21490.0%2,43215.3%14,22889.8%
4 Klebsiella pneumoniae1,58710.0%15,8011,62310.2%15,851 100.0%
Hospital A0.46969390.4722165
Hospital B0.47829300.4788707
Hospital C0.46834380.4670535
Hospital D0.48150510.4859994
@@ -1007,23 +1014,23 @@ Longest: 24

Hospital A -0.4696939 -4867 +0.4722165 +4841 Hospital B -0.4782930 -5413 +0.4788707 +5490 Hospital C -0.4683438 -2385 +0.4670535 +2413 Hospital D -0.4815051 -3136 +0.4859994 +3107 @@ -1043,27 +1050,27 @@ Longest: 24

Escherichia -0.7278981 -0.8996178 -0.9742675 +0.7324589 +0.9016936 +0.9759328 Klebsiella -0.7303088 -0.9004411 -0.9716446 +0.7221195 +0.9081947 +0.9821319 Staphylococcus -0.7304747 -0.9157734 -0.9757529 +0.7420746 +0.9163074 +0.9792037 Streptococcus -0.7485691 +0.7203947 0.0000000 -0.7485691 +0.7203947 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 e304aff8..c531478d 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 026008e8..fe381070 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 26b9ee11..9919bc8c 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 abb13738..5154ee14 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 63ca9bff..8095f07d 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -218,16 +218,25 @@ times = 10) print(S.aureus, unit = "ms", signif = 2) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> as.mo("sau") 42.00 43.00 47.00 43.00 44.0 81.00 10 -#> as.mo("stau") 86.00 87.00 93.00 88.00 89.0 130.00 10 -#> as.mo("staaur") 43.00 43.00 45.00 43.00 43.0 64.00 10 -#> as.mo("S. aureus") 23.00 23.00 27.00 23.00 24.0 60.00 10 -#> as.mo("S. aureus") 23.00 23.00 29.00 24.00 24.0 73.00 10 -#> as.mo("STAAUR") 43.00 43.00 43.00 43.00 44.0 46.00 10 -#> as.mo("Staphylococcus aureus") 14.00 15.00 19.00 15.00 16.0 53.00 10 -#> as.mo("B_STPHY_AUR") 0.34 0.42 0.47 0.49 0.5 0.58 10
-

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 10 milliseconds means it can determine 100 input values per second. It case of 50 milliseconds, this is only 20 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of as.mo("B_STPHY_AUR"), the input is already a valid MO code, so it only almost takes no time at all (494 millionths of a second).

+#> expr min lq mean median uq max +#> as.mo("sau") 100.00 100.00 110.00 100.00 100.00 160.00 +#> as.mo("stau") 140.00 140.00 170.00 160.00 190.00 200.00 +#> as.mo("staaur") 99.00 100.00 100.00 100.00 100.00 110.00 +#> as.mo("S. aureus") 64.00 64.00 65.00 65.00 66.00 67.00 +#> as.mo("S. aureus") 65.00 65.00 70.00 66.00 66.00 110.00 +#> as.mo("STAAUR") 97.00 98.00 100.00 100.00 100.00 100.00 +#> as.mo("Staphylococcus aureus") 35.00 35.00 36.00 36.00 37.00 38.00 +#> as.mo("B_STPHY_AUR") 0.34 0.47 0.52 0.48 0.56 0.89 +#> neval +#> 10 +#> 10 +#> 10 +#> 10 +#> 10 +#> 10 +#> 10 +#> 10 +

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 10 milliseconds means it can determine 100 input values per second. It case of 50 milliseconds, this is only 20 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of as.mo("B_STPHY_AUR"), the input is already a valid MO code, so it only almost takes no time at all (476 millionths of a second).

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 Mycoplasma leonicaptivi (B_MYCPL_LEO), a bug probably never found before in humans:

M.leonicaptivi <- microbenchmark(as.mo("myle"),
                                  as.mo("mycleo"),
@@ -239,14 +248,14 @@
                                  times = 10)
 print(M.leonicaptivi, unit = "ms", signif = 2)
 #> Unit: milliseconds
-#>                              expr    min     lq  mean median     uq    max
-#>                     as.mo("myle") 140.00 140.00 150.0 140.00 140.00 180.00
-#>                   as.mo("mycleo") 470.00 480.00 500.0 510.00 520.00 560.00
-#>          as.mo("M. leonicaptivi") 240.00 240.00 250.0 240.00 280.00 290.00
-#>         as.mo("M.  leonicaptivi") 240.00 240.00 250.0 240.00 280.00 280.00
-#>                   as.mo("MYCLEO") 470.00 510.00 510.0 520.00 520.00 540.00
-#>  as.mo("Mycoplasma leonicaptivi") 150.00 150.00 170.0 180.00 190.00 200.00
-#>              as.mo("B_MYCPL_LEO")   0.32   0.58   0.6   0.59   0.61   0.97
+#>                              expr    min     lq  mean median     uq max
+#>                     as.mo("myle") 210.00 220.00 240.0 230.00 260.00 310
+#>                   as.mo("mycleo") 610.00 630.00 680.0 680.00 720.00 770
+#>          as.mo("M. leonicaptivi") 370.00 370.00 390.0 390.00 410.00 410
+#>         as.mo("M.  leonicaptivi") 350.00 350.00 390.0 390.00 410.00 480
+#>                   as.mo("MYCLEO") 630.00 650.00 680.0 670.00 680.00 880
+#>  as.mo("Mycoplasma leonicaptivi") 250.00 250.00 260.0 250.00 260.00 290
+#>              as.mo("B_MYCPL_LEO")   0.35   0.43   5.6   0.69   0.75  50
 #>  neval
 #>     10
 #>     10
@@ -255,7 +264,7 @@
 #>     10
 #>     10
 #>     10
-

That takes 6.9 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:

+

That takes 4.7 times as much time on average! A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance:

par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
 
 # highest value on y axis
@@ -292,8 +301,8 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>            expr min  lq mean median  uq max neval
-#>  mo_fullname(x) 445 466  497    491 536 543    10
-

So transforming 500,000 values (!) of 95 unique values only takes 0.49 seconds (490 ms). You only lose time on your unique input values.

+#> mo_fullname(x) 487 499 527 535 538 573 10 +

So transforming 500,000 values (!) of 95 unique values only takes 0.54 seconds (535 ms). You only lose time on your unique input values.

@@ -305,11 +314,11 @@ times = 10) print(run_it, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> A 38.70 39.100 40.200 40.000 40.100 45.300 10 -#> B 24.50 24.600 24.800 24.700 24.700 25.500 10 -#> C 0.26 0.392 0.434 0.447 0.516 0.561 10

-

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

+#> expr min lq mean median uq max neval +#> A 65.500 66.100 66.200 66.300 66.500 66.700 10 +#> B 61.000 61.200 61.900 61.700 62.300 64.500 10 +#> C 0.329 0.335 0.461 0.527 0.551 0.556 10 +

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

run_it <- microbenchmark(A = mo_species("aureus"),
                          B = mo_genus("Staphylococcus"),
                          C = mo_fullname("Staphylococcus aureus"),
@@ -322,14 +331,14 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>  expr   min    lq  mean median    uq   max neval
-#>     A 0.297 0.329 0.400  0.416 0.453 0.459    10
-#>     B 0.277 0.304 0.349  0.363 0.382 0.407    10
-#>     C 0.281 0.430 0.436  0.440 0.471 0.493    10
-#>     D 0.249 0.277 0.310  0.316 0.337 0.347    10
-#>     E 0.214 0.252 0.300  0.306 0.338 0.403    10
-#>     F 0.237 0.270 0.300  0.311 0.326 0.335    10
-#>     G 0.245 0.282 0.297  0.298 0.314 0.348    10
-#>     H 0.241 0.282 0.308  0.312 0.328 0.373    10
+#> A 0.288 0.372 0.440 0.418 0.481 0.662 10 +#> B 0.281 0.294 0.364 0.369 0.411 0.461 10 +#> C 0.390 0.493 0.563 0.550 0.645 0.731 10 +#> D 0.244 0.269 0.733 0.337 0.347 4.420 10 +#> E 0.283 0.344 0.368 0.363 0.410 0.434 10 +#> F 0.250 0.319 0.343 0.339 0.354 0.492 10 +#> G 0.286 0.329 0.363 0.340 0.392 0.496 10 +#> H 0.292 0.305 0.365 0.359 0.421 0.459 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.

@@ -356,13 +365,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> en 10.85 10.89 11.10 11.03 11.23 11.83 10 -#> de 19.43 19.50 19.86 19.58 20.35 20.99 10 -#> nl 19.08 19.17 19.40 19.48 19.56 19.63 10 -#> es 19.35 19.44 26.07 19.48 20.06 52.36 10 -#> it 19.23 19.40 22.91 19.49 19.91 52.92 10 -#> fr 19.10 19.22 19.40 19.45 19.54 19.68 10 -#> pt 19.01 19.46 29.32 19.55 52.32 52.50 10
+#> en 24.41 25.27 26.34 25.41 26.92 30.60 10 +#> de 35.53 35.76 36.76 35.98 37.20 41.19 10 +#> nl 34.51 35.55 39.93 35.60 40.15 69.76 10 +#> es 34.36 35.98 44.29 37.46 39.98 73.16 10 +#> it 35.78 36.22 37.44 36.75 38.70 40.78 10 +#> fr 35.45 35.71 36.09 35.79 36.15 37.93 10 +#> pt 35.10 35.44 44.61 35.76 39.68 77.27 10

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

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index c65eb537..b4941911 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-2.png index 63634790..8922a449 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-2.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-2.png differ diff --git a/docs/news/index.html b/docs/news/index.html index 32062816..cc6240ae 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -251,10 +251,15 @@ BREAKING: removed deprecated functions, parameters and references to ‘bactid’. Use as.mo() to identify an MO code.
  • Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The microorganisms data set now contains: +This data is updated annually - check the included version with catalogue_of_life_version(). +
  • diff --git a/reproduction_of_microorganisms.R b/reproduction_of_microorganisms.R index 462393db..e95a1a3d 100644 --- a/reproduction_of_microorganisms.R +++ b/reproduction_of_microorganisms.R @@ -4,7 +4,9 @@ # unzip and extract taxon.tab, then: taxon <- data.table::fread("taxon.tab") -# result is over 3.7M rows +# result is over 3.7M rows: +library(dplyr) +library(AMR) taxon %>% freq(kingdom) # Item Count Percent Cum. Count Cum. Percent # --- ---------- ---------- -------- ----------- ------------- @@ -128,6 +130,7 @@ MOs <- MOs %>% mutate(mo = ifelse(duplicated(.$mo), paste0(mo, "1"), mo)) %>% select(mo, everything(), -abbr_genus, -abbr_species, -abbr_subspecies) + # everything distinct? sum(duplicated(MOs$mo)) diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index f401d154..4a1addab 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -56,3 +56,9 @@ test_that("data sets are valid", { }) + +test_that("creation of data sets is valid", { + DT <- make_DT() + expect_lt(nrow(DT[prevalence == 1]), nrow(DT[prevalence == 2])) + expect_lt(nrow(DT[prevalence == 2]), nrow(DT[prevalence == 3])) +}) diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index 39ccbd0f..a2ce9a68 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -35,6 +35,7 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL") expect_equal(as.character(as.mo("Escherichia species")), "B_ESCHR") expect_equal(as.character(as.mo("Escherichia")), "B_ESCHR") + expect_equal(as.character(as.mo("Esch spp.")), "B_ESCHR") expect_equal(as.character(as.mo(" B_ESCHR_COL ")), "B_ESCHR_COL") expect_equal(as.character(as.mo("e coli")), "B_ESCHR_COL") # not Campylobacter expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNE") @@ -45,6 +46,7 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNE") expect_equal(as.character(as.mo("Strepto")), "B_STRPT") expect_equal(as.character(as.mo("Streptococcus")), "B_STRPT") # not Peptostreptoccus + expect_equal(as.character(as.mo("B_STRPTC")), "B_STRPT") # old MO code (<=v0.5.0) expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRA", "B_STRPT_GRB")) @@ -80,6 +82,10 @@ test_that("as.mo works", { "MRSA", "VISA"))), rep("B_STPHY_AUR", 8)) + expect_identical( + as.character( + as.mo(c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC'))), + rep("B_ESCHR_COL", 5)) # unprevalent MO expect_identical( as.character( @@ -116,6 +122,7 @@ test_that("as.mo works", { expect_identical(as.character(as.mo("STCPYO", Lancefield = TRUE)), "B_STRPT_GRA") # group A expect_identical(as.character(as.mo("S. agalactiae", Lancefield = FALSE)), "B_STRPT_AGA") expect_identical(as.character(as.mo("S. agalactiae", Lancefield = TRUE)), "B_STRPT_GRB") # group B + expect_identical(as.character(suppressWarnings(as.mo("estreptococos grupo B"))), "B_STRPT_GRB") expect_identical(as.character(as.mo("S. equisimilis", Lancefield = FALSE)), "B_STRPT_DYS_EQU") expect_identical(as.character(as.mo("S. equisimilis", Lancefield = TRUE)), "B_STRPT_GRC") # group C # Enterococci must only be influenced if Lancefield = "all" @@ -229,4 +236,13 @@ test_that("as.mo works", { # Salmonella (City) are all actually Salmonella enterica spp (City) expect_equal(as.character(suppressMessages(as.mo("Salmonella Goettingen"))), "B_SLMNL_ENT") + expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL") + + # no virusses + expect_warning(as.mo("Virus")) + + # summary + expect_equal(length(summary(septic_patients$mo)), 6) + + expect_warning(as.mo("Cutibacterium")) }) diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 1dded3be..dc420dd8 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -75,6 +75,9 @@ test_that("mo_property works", { expect_identical(mo_property("E. coli", property = "species"), mo_species("E. coli")) + expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968") + expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999") + # check vector with random values #library(dplyr) #df_sample <- AMR::microorganisms %>% sample_n(100)