mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 00:10:57 +01:00
* Update taxonomy of microorganisms (2026-10) Rebuild of the microorganisms data set from COL 2026-04-18 XR, LPSN and BacDive of October 2026 and MycoBank of January 2026, with v3.0.1 as the previous data set: 111,103 records (v3.0.1: 78,679), 0 changed MO codes of existing names, 522 released codes retired (275 to be reviewed). Script fixes (data-raw/_reproduction_scripts/reproduction_of_microorganisms.R): - previous data set from the last release; COL read as COL Data Package (NameUsage.tsv) - keep COL records without authors (a filter on NA dropped them, e.g. Balamuthia mandrillaris) - genus homonyms: unclassified MycoBank entries are not authoritative; the released domain of a genus wins if a source supports it (e.g. Moorella, Serpula, Pirella stay Bacteria) - protect current names of relevant species instead of whole current genera (data set tripled) - current names and synonyms only within the same domain and for known names (Brugia -> Lycoperdon) - MycoBank names in Latin script only; old records outside their source's scope become manually added - Graphium butterflies of v3.0.1 are not carried over, re-added or restored - restore released taxa by name and rank; retire older cross-domain homonyms for review - fill empty families from COL and a commented override list (Ascaris, Balamuthia) - add Brugia malayi and B. timori; remove Salmonella species synonyms that are serovars - BacDive: a minority of facultative strain records no longer decides (C. difficile) - translate codes of other data sets with the development version; review unmatched codes - scope decisions: COL XR names only if relevant or released; Protozoa follow the Fungi rules Also: all checkpoints (data-raw/taxonomy*.rds), updated data sets, Bartlett et al. list, accessed dates in TAXONOMY_VERSION, NEWS, two staphylococci added to CoNS, tests updated for real taxonomic changes, known defects file removed (all solved), and the findings report with all review files in data-raw/taxonomy_review/2026-10/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy review report: note on the .dta export and the single commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fix as.mo() for Salmonella serovars written with the species; add S. xeri to CoNS - "Salmonella enterica (subsp. enterica) serovar Typhi" returned S. bongori, and "S. enterica Typhimurium" S. enterica diarizonae; "Paratyphi A/B/C" became serogroups - Staphylococcus xeri and S. parequorum confirmed as coagulase-negative Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy build: remove lichens (decision of 5 October 2026) Fungi in the lichen-forming classes and the order Verrucariales are removed unless their genus is clinically relevant, with the synonyms that point to them (4,155 records); released lichens are restored. microorganisms now has 107,126 records (Fungi 45,739); all tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy review decisions: microsporidia in Fungi, accepted names, missing protozoa - all microsporidia in the Fungi (1,394 names of v3.0.1 from P_ to F_, old codes translated by name) - Enterocytozoon bieneusi and Encephalitozoon cuniculi as accepted names (accepted_name_override) - Balantidium and Isospora added to MO_RELEVANT_GENERA; Cystoisospora belli as synonym of Isospora belli - synonym cycles decided: Capillidium and Scolecobasidium are the current genera - removed the stale data-raw/taxonomy_lpsn0.rds - microorganisms now has 107,253 records; all tests pass Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy review report: all items reviewed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Rule matching by accepted taxon; Erysipelatoclostridium as synonym of Thomasclavelia - interpretive_rules(): species named in a rule (literal names, genus_species/fullname) now also match all other names of the same accepted taxon, e.g. 'Clostridium ramosum' for Thomasclavelia ramosa; not for genera or regex rules - Erysipelatoclostridium and its species are synonyms of Thomasclavelia (accepted_name_override); E. merdavium is retired by decision of 6 October 2026, and the build removes taxa retired by a human decision - microorganisms patched with the same logic as the build script (no full rebuild): 107,252 records - intrinsic_resistant regenerated with the new taxonomy and rule matching: 308,646 rows - clinical_breakpoints: EUCAST workbook rows merged again, 24 EUCAST 2026 rows moved from C. ramosum to T. ramosa Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy: correct records for names listed twice, no synonyms without a current name, strict data tests - one record per name keeps the accepted record (e.g. Eggerthella lenta, Gordonia amarae, Anisakis simplex and Enterobius vermicularis were synonyms without a current name), links to dropped records are moved - LPSN lookup reads the taxonomic status and correct name; validly published synonyms are no longer 'accepted' - synonyms without a current name: linked via LPSN or removed, released codes retired (3,668); records with kept children become 'unknown'; the M. tuberculosis complex is protected (decisions of 7 October 2026) - subspecies codes reserved, current names of synonyms kept when pruning, missing parent records added or moved, higher taxonomy harmonised, shared identifiers resolved per domain and rank, pointers and parent links cleaned - data sets refer only to current names (except intrinsic_resistant); group members only from current names; internal CoNS/CoPS/streptococcal lists keep a synonym only with its current name - intrinsic_resistant, clinical_breakpoints (EUCAST workbooks) and microorganisms.groups regenerated - 28 new tests in test-data.R; devtools::test(): 1,581 expectations, 0 failures - open decisions listed in data-raw/taxonomy_review/2026-10/REPORT.md, section 6 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy: protect WHO priority genera, follow LPSN for the M. tuberculosis complex, place protist groups in one domain - all taxa of the genera in MO_WHO_PRIORITY_GENERA are protected, also names that are not validly published (replaces the hard-coded M. tuberculosis complex; keeps e.g. Klebsiella quasivariicola, M. canettii, M. orygis) - LPSN is followed for the M. tuberculosis complex: M. bovis, M. africanum, M. caprae, M. microti and M. pinnipedii are heterotypic synonyms of M. tuberculosis (Riojas et al. 2018); a test enforces this - labyrinthulids in the Chromista (Aplanochytrium), Dictydiaethalium in the Protozoa (genus_domain_move), and the rank suffix also between domains ('Acantharia {class}' next to the fungal genus Acantharia) - devtools::test(): 1,582 expectations, 0 failures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy build no longer depends on the previous build - intrinsic_resistant is no input of the microorganisms build anymore (it is computed from it); the genera named in the interpretive rules are read from the rules instead - the previous data set no longer makes genera relevant; Debaryomyces added to MO_RELEVANT_GENERA - new run_after_microorganisms_build.R recreates microorganisms.groups, the EUCAST breakpoints and intrinsic_resistant in the right order, and the build runs it at its end - reproduction_of_intrinsic_resistant.R uses devtools::load_all() instead of the installed package - effect: 24 never released, not relevant COL records less; devtools::test(): 1,582 expectations, 0 failures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Taxonomy review report: summary updated to the second round Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MO code retirements: mark the 265 reviewed retirements as reviewed The Graphium and v2.x Protozoa retirements were reviewed and accepted on 6 October 2026 (see the taxonomy review report, section 5); 'NEEDS REVIEW' is replaced by 'reviewed by Matthijs S. Berends on 2026-10-06'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
921 lines
37 KiB
R
921 lines
37 KiB
R
# ==================================================================== #
|
|
# TITLE: #
|
|
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
|
# #
|
|
# SOURCE CODE: #
|
|
# https://github.com/msberends/AMR #
|
|
# #
|
|
# PLEASE CITE THIS SOFTWARE AS: #
|
|
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
|
|
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
|
|
# Journal of Statistical Software, 104(3), 1-31. #
|
|
# https://doi.org/10.18637/jss.v104.i03 #
|
|
# #
|
|
# Developed at the University of Groningen and the University Medical #
|
|
# Center Groningen in the Netherlands, in collaboration with many #
|
|
# colleagues from around the world, see our website. #
|
|
# #
|
|
# This R package is free software; you can freely use and distribute #
|
|
# it for both personal and commercial purposes under the terms of the #
|
|
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
|
# the Free Software Foundation. #
|
|
# We created this package for both routine data analysis and academic #
|
|
# research and it was publicly released in the hope that it will be #
|
|
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
|
# #
|
|
# Visit our website for the full manual and a complete tutorial about #
|
|
# how to conduct AMR data analysis: https://amr-for-r.org #
|
|
# ==================================================================== #
|
|
|
|
# Run this file to update the package using:
|
|
# source("data-raw/_pre_commit_checks.R")
|
|
|
|
library(dplyr, warn.conflicts = FALSE)
|
|
try(detach("package:data.table", unload = TRUE), silent = TRUE) # to prevent like() to precede over AMR::like
|
|
devtools::load_all(quiet = TRUE)
|
|
|
|
suppressMessages(set_AMR_locale("English"))
|
|
|
|
pre_commit_lst <- list()
|
|
|
|
# Save internal data to R/sysdata.rda -------------------------------------
|
|
|
|
usethis::ui_info(paste0("Updating internal package data"))
|
|
|
|
# See 'data-raw/interpretive_rules.tsv' for the interpretive rules reference file
|
|
pre_commit_lst$INTERPRETIVE_RULES_DF <- utils::read.delim(
|
|
file = "data-raw/interpretive_rules.tsv",
|
|
skip = 9,
|
|
sep = "\t",
|
|
stringsAsFactors = FALSE,
|
|
header = TRUE,
|
|
strip.white = TRUE,
|
|
na = c(NA, "", NULL)
|
|
) %>%
|
|
# take the order of the reference.rule_group column in the original data file
|
|
mutate(
|
|
reference.rule_group = factor(reference.rule_group,
|
|
levels = unique(reference.rule_group),
|
|
ordered = TRUE
|
|
),
|
|
sorting_rule = ifelse(grepl("^Table", reference.rule, ignore.case = TRUE), 1, 2)
|
|
) %>%
|
|
arrange(
|
|
reference.rule_group,
|
|
reference.version,
|
|
sorting_rule,
|
|
reference.rule
|
|
) %>%
|
|
mutate(reference.rule_group = as.character(reference.rule_group)) %>%
|
|
select(-sorting_rule)
|
|
|
|
pre_commit_lst$TRANSLATIONS <- utils::read.delim(
|
|
file = "data-raw/translations.tsv",
|
|
sep = "\t",
|
|
stringsAsFactors = FALSE,
|
|
header = TRUE,
|
|
blank.lines.skip = TRUE,
|
|
fill = TRUE,
|
|
strip.white = TRUE,
|
|
encoding = "UTF-8",
|
|
fileEncoding = "UTF-8",
|
|
na.strings = c(NA, "", NULL),
|
|
allowEscapes = TRUE, # else "\\1" will be imported as "\\\\1"
|
|
quote = ""
|
|
)
|
|
pre_commit_lst$TRANSLATIONS <- pre_commit_lst$TRANSLATIONS[, which(colnames(pre_commit_lst$TRANSLATIONS) != "en"), drop = FALSE]
|
|
|
|
pre_commit_lst$LANGUAGES_SUPPORTED_NAMES <- c(
|
|
list(en = list(exonym = "English", endonym = "English")),
|
|
lapply(
|
|
pre_commit_lst$TRANSLATIONS[, which(nchar(colnames(pre_commit_lst$TRANSLATIONS)) == 2), drop = FALSE],
|
|
function(x) list(exonym = x[1], endonym = x[2])
|
|
)
|
|
)
|
|
|
|
pre_commit_lst$LANGUAGES_SUPPORTED <- names(pre_commit_lst$LANGUAGES_SUPPORTED_NAMES)
|
|
|
|
# vectors of CoNS and CoPS, improves speed in as.mo()
|
|
create_species_cons_cops <- function(type = c("CoNS", "CoPS")) {
|
|
# Determination of which staphylococcal species are CoNS/CoPS according to:
|
|
# - Becker et al. 2014, PMID 25278577
|
|
# - Becker et al. 2019, PMID 30872103
|
|
# - Becker et al. 2020, PMID 32056452
|
|
# this function returns class <mo>
|
|
MO_staph <- microorganisms
|
|
MO_staph <- MO_staph[which(MO_staph$genus == "Staphylococcus"), , drop = FALSE]
|
|
if (type == "CoNS") {
|
|
MO_staph[
|
|
which(MO_staph$species %in% c(
|
|
"coagulase-negative", "argensis", "arlettae",
|
|
"auricularis", "borealis", "caeli", "capitis", "caprae",
|
|
"carnosus", "casei", "caseorum", "caseolyticus", "chromogenes", "cohnii", "condimenti",
|
|
"croceilyticus",
|
|
"debuckii", "devriesei", "edaphicus", "epidermidis",
|
|
"equorum", "felis", "fleurettii", "gallinarum", "halotolerans",
|
|
"haemolyticus", "hominis", "hsinchuensis", "jettensis", "kloosii",
|
|
"lentus", "lugdunensis", "massiliensis", "microti",
|
|
"muscae", "nepalensis", "pasteuri", "petrasii",
|
|
"pettenkoferi", "piscifermentans", "pragensis", "pseudoxylosus",
|
|
"pulvereri", "rostri", "saccharolyticus", "saprophyticus",
|
|
"sciuri", "simulans", "stepanovicii", "succinus",
|
|
"ureilyticus",
|
|
"vitulinus", "vitulus", "warneri", "xylosus",
|
|
"caledonicus", "canis",
|
|
"durrellii", "lloydii",
|
|
"ratti", "taiwanensis", "veratri", "urealyticus",
|
|
"americanisciuri", "marylandisciuri", "shinii", "brunensis",
|
|
# Kuhnert et al. 2026 (doi:10.1099/ijsem.0.007230), Baek et al. 2025 (J Microbiol, S. parequorum) and
|
|
# Belhout et al. 2026 (doi:10.1099/ijsem.0.007253, S. xeri); S. parequorum and S. xeri confirmed by
|
|
# Matthijs S. Berends
|
|
"dromedarii", "parequorum", "xeri"
|
|
) |
|
|
# old, now renamed to S. schleiferi (but still as synonym in our data of course):
|
|
(MO_staph$species == "schleiferi" & MO_staph$subspecies %in% c("schleiferi", ""))),
|
|
"mo",
|
|
drop = TRUE
|
|
]
|
|
} else if (type == "CoPS") {
|
|
MO_staph[
|
|
which(MO_staph$species %in% c(
|
|
"coagulase-positive", "coagulans",
|
|
"agnetis", "argenteus",
|
|
"cornubiensis",
|
|
"delphini", "lutrae",
|
|
"hyicus", "intermedius",
|
|
"pseudintermedius", "pseudointermedius",
|
|
"schweitzeri", "simiae",
|
|
"roterodami",
|
|
"singaporensis",
|
|
"ursi"
|
|
) |
|
|
# old, now renamed to S. coagulans (but still as synonym in our data of course):
|
|
(MO_staph$species == "schleiferi" & MO_staph$subspecies == "coagulans")),
|
|
"mo",
|
|
drop = TRUE
|
|
]
|
|
}
|
|
}
|
|
pre_commit_lst$MO_CONS <- create_species_cons_cops("CoNS")
|
|
pre_commit_lst$MO_COPS <- create_species_cons_cops("CoPS")
|
|
pre_commit_lst$MO_STREP_ABCG <- microorganisms$mo[which(microorganisms$genus == "Streptococcus" &
|
|
tolower(microorganisms$species) %in% c(
|
|
"pyogenes", "agalactiae", "dysgalactiae", "equi", "canis",
|
|
"group a", "group b", "group c", "group g"
|
|
))]
|
|
pre_commit_lst$MO_LANCEFIELD <- microorganisms$mo[which(microorganisms$mo %like% "^(B_STRPT_PYGN(_|$)|B_STRPT_AGLC(_|$)|B_STRPT_(DYSG|EQUI)(_|$)|B_STRPT_ANGN(_|$)|B_STRPT_(DYSG|CANS)(_|$)|B_STRPT_SNGN(_|$)|B_STRPT_SLVR(_|$))")]
|
|
# a synonym only belongs to these lists if its current name does as well (decision by Matthijs S. Berends, 7 October
|
|
# 2026), e.g. not Staphylococcus caseolyticus (now Macrococcus caseolyticus) in CoNS, nor Staphylococcus roterodami
|
|
# (now Staphylococcus aureus) in CoPS
|
|
for (lst in c("MO_CONS", "MO_COPS", "MO_STREP_ABCG", "MO_LANCEFIELD")) {
|
|
current <- AMR:::synonym_mo_to_accepted_mo(as.character(pre_commit_lst[[lst]]))
|
|
pre_commit_lst[[lst]] <- pre_commit_lst[[lst]][is.na(current) | current %in% as.character(pre_commit_lst[[lst]])]
|
|
}
|
|
rm(lst, current)
|
|
pre_commit_lst$MO_WHO_PRIORITY_GENERA <- c(
|
|
# World Health Organization's (WHO) Priority Pathogen List (some are from the group Enterobacteriaceae)
|
|
"Acinetobacter",
|
|
"Aspergillus",
|
|
"Blastomyces",
|
|
"Campylobacter",
|
|
"Candida",
|
|
"Citrobacter",
|
|
"Clostridioides",
|
|
"Coccidioides",
|
|
"Cryptococcus",
|
|
"Edwardsiella",
|
|
"Enterobacter",
|
|
"Enterococcus",
|
|
"Escherichia",
|
|
"Fusarium",
|
|
"Haemophilus",
|
|
"Helicobacter",
|
|
"Histoplasma",
|
|
"Klebsiella",
|
|
"Morganella",
|
|
"Mycobacterium",
|
|
"Neisseria",
|
|
"Paracoccidioides",
|
|
"Pneumocystis",
|
|
"Proteus",
|
|
"Providencia",
|
|
"Pseudomonas",
|
|
"Salmonella",
|
|
"Serratia",
|
|
"Shigella",
|
|
"Staphylococcus",
|
|
"Streptococcus",
|
|
"Yersinia"
|
|
)
|
|
pre_commit_lst$MO_RELEVANT_GENERA <- c(
|
|
"Absidia",
|
|
"Acanthamoeba",
|
|
"Acremonium",
|
|
"Actinomucor",
|
|
"Aedes",
|
|
"Alternaria",
|
|
"Amoeba",
|
|
"Ancylostoma",
|
|
"Angiostrongylus",
|
|
"Anisakis",
|
|
"Anopheles",
|
|
"Apiotrichum",
|
|
"Apophysomyces",
|
|
"Arthroderma",
|
|
"Ascaris",
|
|
"Aspergillus",
|
|
"Aureobasidium",
|
|
"Babesia",
|
|
"Balamuthia",
|
|
"Balantidium", # COL name of Balantioides coli (Balantidium coli)
|
|
"Balantioides",
|
|
"Basidiobolus",
|
|
"Beauveria",
|
|
"Bipolaris",
|
|
"Blastobotrys",
|
|
"Blastocystis",
|
|
"Blastomyces",
|
|
"Brugia",
|
|
"Candida",
|
|
"Candidozyma",
|
|
"Capillaria",
|
|
"Chaetomium",
|
|
"Chilomastix",
|
|
"Chrysonilia",
|
|
"Chrysosporium",
|
|
"Cladophialophora",
|
|
"Cladosporium",
|
|
"Clavispora",
|
|
"Clonorchis",
|
|
"Coccidioides",
|
|
"Cokeromyces",
|
|
"Conidiobolus",
|
|
"Coniochaeta",
|
|
"Contracaecum",
|
|
"Cordylobia",
|
|
"Cryptococcus",
|
|
"Cryptosporidium",
|
|
"Cunninghamella",
|
|
"Curvularia",
|
|
"Cutaneotrichosporon",
|
|
"Cyberlindnera",
|
|
"Cyclospora",
|
|
"Cystoisospora",
|
|
"Debaryomyces",
|
|
"Debaryozyma",
|
|
"Demodex",
|
|
"Dermatobia",
|
|
"Dientamoeba",
|
|
"Diphyllobothrium",
|
|
"Dirofilaria",
|
|
"Diutina",
|
|
"Echinococcus",
|
|
"Echinostoma",
|
|
"Emergomyces",
|
|
"Emmonsia",
|
|
"Encephalitozoon",
|
|
"Entamoeba",
|
|
"Enterobius",
|
|
"Enterocytozoon",
|
|
"Epidermophyton",
|
|
"Exidia",
|
|
"Exophiala",
|
|
"Exserohilum",
|
|
"Fasciola",
|
|
"Fasciolopsis",
|
|
"Fonsecaea",
|
|
"Fusarium",
|
|
"Geotrichum",
|
|
"Giardia",
|
|
"Graphium",
|
|
"Haloarcula",
|
|
"Halobacterium",
|
|
"Halococcus",
|
|
"Hansenula",
|
|
"Hendersonula",
|
|
"Heterophyes",
|
|
"Histomonas",
|
|
"Histoplasma",
|
|
"Hortaea",
|
|
"Hymenolepis",
|
|
"Hypomyces",
|
|
"Hysterothylacium",
|
|
"Isospora", # COL name of Cystoisospora belli (Isospora belli)
|
|
"Kazachstania",
|
|
"Kloeckera",
|
|
"Kluyveromyces",
|
|
"Kodamaea",
|
|
"Lacazia",
|
|
"Leishmania",
|
|
"Lichtheimia",
|
|
"Loa",
|
|
"Lodderomyces",
|
|
"Lomentospora",
|
|
"Madurella",
|
|
"Magnusiomyces",
|
|
"Malassezia",
|
|
"Malbranchea",
|
|
"Mansonella",
|
|
"Metagonimus",
|
|
"Meyerozyma",
|
|
"Microascus",
|
|
"Microsporidium",
|
|
"Microsporum",
|
|
"Millerozyma",
|
|
"Mortierella",
|
|
"Mucor",
|
|
"Mycocentrospora",
|
|
"Naegleria",
|
|
"Nakaseomyces",
|
|
"Nannizzia",
|
|
"Necator",
|
|
"Nectria",
|
|
"Neocosmospora",
|
|
"Ochroconis",
|
|
"Oesophagostomum",
|
|
"Oidiodendron",
|
|
"Onchocerca",
|
|
"Opisthorchis",
|
|
"Paecilomyces",
|
|
"Paracoccidioides",
|
|
"Paragonimus",
|
|
"Pediculus",
|
|
"Penicillium",
|
|
"Phaeoacremonium",
|
|
"Phaeomoniella",
|
|
"Phialophora",
|
|
"Phlebotomus",
|
|
"Phoma",
|
|
"Pichia",
|
|
"Piedraia",
|
|
"Pithomyces",
|
|
"Pityrosporum",
|
|
"Plasmodium",
|
|
"Pneumocystis",
|
|
"Pseudallescheria",
|
|
"Pseudoscopulariopsis",
|
|
"Pseudoterranova",
|
|
"Pulex",
|
|
"Purpureocillium",
|
|
"Quambalaria",
|
|
"Rasamsonia",
|
|
"Rhinocladiella",
|
|
"Rhizomucor",
|
|
"Rhizopus",
|
|
"Rhodotorula",
|
|
"Saccharomyces",
|
|
"Saksenaea",
|
|
"Saprochaete",
|
|
"Sarcocystis",
|
|
"Sarcoptes",
|
|
"Scedosporium",
|
|
"Schistosoma",
|
|
"Schizophyllum",
|
|
"Schizosaccharomyces",
|
|
"Scolecobasidium",
|
|
"Scopulariopsis",
|
|
"Scytalidium",
|
|
"Spirometra",
|
|
"Sporobolomyces",
|
|
"Sporopachydermia",
|
|
"Sporothrix",
|
|
"Sporotrichum",
|
|
"Stachybotrys",
|
|
"Strongyloides",
|
|
"Syncephalastrum",
|
|
"Syngamus",
|
|
"Taenia",
|
|
"Talaromyces",
|
|
"Toxocara",
|
|
"Toxoplasma",
|
|
"Trichinella",
|
|
"Trichobilharzia",
|
|
"Trichoderma",
|
|
"Trichomonas",
|
|
"Trichophyton",
|
|
"Trichosporon",
|
|
"Trichostrongylus",
|
|
"Trichuris",
|
|
"Tritirachium",
|
|
"Trombicula",
|
|
"Trypanosoma",
|
|
"Tunga",
|
|
"Ulocladium",
|
|
"Ustilago",
|
|
"Verticillium",
|
|
"Wallemia",
|
|
"Wangiella",
|
|
"Wickerhamomyces",
|
|
"Wuchereria",
|
|
"Yarrowia",
|
|
"Zygosaccharomyces"
|
|
)
|
|
|
|
# antibiotic groups
|
|
# (these will also be used for interpretive_rules() and understanding data-raw/interpretive_rules.tsv)
|
|
pre_commit_lst$AB_AMINOGLYCOSIDES <- antimicrobials %>%
|
|
filter(group %like% "aminoglycoside|paromomycin|spectinomycin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_AMINOPENICILLINS <- as.ab(c("AMP", "AMX", "AMC"))
|
|
pre_commit_lst$AB_AMINOCOUMARINS <- antimicrobials %>%
|
|
filter(name %like% "novobiocin|clorobiocin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_ANTIFUNGALS <- antimicrobials %>%
|
|
filter(group %like% "antifungal") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_ANTIMYCOBACTERIALS <- antimicrobials %>%
|
|
filter(group %like% "antimycobacterial") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CARBAPENEMS <- antimicrobials %>%
|
|
filter(group %like% "carbapenem") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_1ST <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin.*1") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_2ND <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin.*2") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_3RD <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin.*3") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_4TH <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin.*4") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_5TH <- antimicrobials %>%
|
|
filter(group %like% "cephalosporin.*5") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_CEPHALOSPORINS_EXCEPT_CAZ <- pre_commit_lst$AB_CEPHALOSPORINS[pre_commit_lst$AB_CEPHALOSPORINS != "CAZ"]
|
|
pre_commit_lst$AB_GLYCOPEPTIDES <- antimicrobials %>%
|
|
filter(group %like% "glycopeptide") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_FUSIDANES <- antimicrobials %>%
|
|
filter(name %like% "fusi") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_IONOPHORES <- antimicrobials %>%
|
|
filter(name %like% "alamethicin|beauvericin|calcimycin|chloroquine|clioquinol|diiodohydroxyquinoline|dithiocarbamates|enniatin|epigallocatechin|gramicidin|hinokitiol|ionomycin|laidlomycin|lasalocid|maduramicin|monensin|narasin|nigericin|nonactin|nystatin|pyrazole|pyrithione|quercetin|salinomycin|semduramicin|valinomycin|zincophorin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_ISOXAZOLYLPENICILLINS <- antimicrobials %>%
|
|
filter(name %like% "oxacillin|cloxacillin|dicloxacillin|flucloxacillin|meth?icillin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_LIPOGLYCOPEPTIDES <- as.ab(c("DAL", "ORI", "TLV")) # dalba/orita/tela
|
|
pre_commit_lst$AB_GLYCOPEPTIDES_EXCEPT_LIPO <- pre_commit_lst$AB_GLYCOPEPTIDES[!pre_commit_lst$AB_GLYCOPEPTIDES %in% pre_commit_lst$AB_LIPOGLYCOPEPTIDES]
|
|
pre_commit_lst$AB_LINCOSAMIDES <- antimicrobials %>%
|
|
filter(atc_group2 %like% "lincosamide" | (group %like% "lincosamide" & is.na(atc_group2) & name %like% "^(pirlimycin|clinda)")) %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_MACROLIDES <- antimicrobials %>%
|
|
filter(atc_group2 %like% "macrolide" | (group %like% "macrolide" & is.na(atc_group2)) | name %like% "^(acetylmidecamycin|acetylspiramycin|gamith?romycin|kitasamycin|meleumycin|nafith?romycin|primycin|solith?romycin|tildipirosin|tilmicosin|tulath?romycin|tylosin|tylvalosin)") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_MONOBACTAMS <- antimicrobials %>%
|
|
filter(group %like% "monobactam" | name %like% "aztreonam|carumonam|tigemonam") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_NITROFURANS <- antimicrobials %>%
|
|
filter(name %like% "^furaz|nitrofura" | atc_group2 %like% "nitrofuran") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_OXAZOLIDINONES <- antimicrobials %>%
|
|
filter(group %like% "oxazolidinone") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_PENICILLINS <- antimicrobials %>%
|
|
filter(group %like% "penicillin" & !(name %unlike% "/" & name %like% ".*bactam$")) %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_PEPTIDES <- antimicrobials %>%
|
|
filter(ab %in% pre_commit_lst$AB_GLYCOPEPTIDES | name %like% "thiostrepton|actinomycin|bacitracin|daptomycin|vancomycin|teixobactin|tyrocidine|gramicidin|zwittermicin|epothilone|fabclavine|bleomycin|ciclosporin|cyclosporine|siderophores|pyoverdine|enterobactin|myxochelin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_PHENICOLS <- antimicrobials %>%
|
|
filter(group %like% "phenicol" | atc_group1 %like% "phenicol" | atc_group2 %like% "phenicol") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_PHOSPHONICS <- antimicrobials %>%
|
|
filter(group %like% "phosphonic" | name %like% "fosfo") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_PLEUROMUTILINS <- antimicrobials %>%
|
|
filter(name %like% "retapamulin|tiamulin|pleuromutilin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_POLYMYXINS <- antimicrobials %>%
|
|
filter(group %like% "polymyxin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_QUINOLONES <- antimicrobials %>%
|
|
filter(group %like% "quinolone" | atc_group1 %like% "quinolone" | atc_group2 %like% "quinolone" | name %like% "ozenoxacin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_FLUOROQUINOLONES <- antimicrobials %>%
|
|
# see DOI 10.23937/2378-3656/1410369, more specifically this table: https://www.clinmedjournals.org/articles/cmrcr/cmrcr-8-369-table1.html
|
|
filter(ab %in% pre_commit_lst$AB_QUINOLONES & name %unlike% " acid|nalidixic|cinoxacin|flumequine|oxolinic|ozenoxacin|piromidic|pipemidic|rosoxacin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_RIFAMYCINS <- antimicrobials %>%
|
|
filter(name %like% "Rifampi|Rifabutin|Rifapentine|rifamy") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_SPIROPYRIMIDINETRIONES <- antimicrobials %>%
|
|
filter(name %like% "zoliflodacin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_STREPTOGRAMINS <- antimicrobials %>%
|
|
filter(atc_group2 %like% "streptogramin" | name %like% "streptogramin|virginiamycin|ostreogrycin") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_TETRACYCLINES <- antimicrobials %>%
|
|
filter(atc_group1 %like% "tetracycline" | atc_group2 %like% "tetracycline" | name %like% "chlortetracycline|cetocycline|demeclocycline|doxycycline|eravacycline|lymecycline|meclocycline|meth?acycline|minocycline|omadacycline|oxytetracycline|rolitetracycline|sarecycline|tetracycline|tigecycline") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_TETRACYCLINES_EXCEPT_TGC <- pre_commit_lst$AB_TETRACYCLINES[pre_commit_lst$AB_TETRACYCLINES != "TGC"]
|
|
pre_commit_lst$AB_TRIMETHOPRIMS <- antimicrobials %>%
|
|
filter(atc_group1 %like% "trimethoprim" | atc_group2 %like% "trimethoprim" | name %like% "trimethoprim|ormetroprim|iclaprim") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_SULFONAMIDES <- antimicrobials %>%
|
|
filter(name %like% "(^|/)sulf[oai]") %>%
|
|
pull(ab)
|
|
pre_commit_lst$AB_UREIDOPENICILLINS <- as.ab(c("PIP", "TZP", "AZL", "MEZ"))
|
|
pre_commit_lst$AB_BETALACTAMS <- sort(c(
|
|
pre_commit_lst$AB_PENICILLINS,
|
|
pre_commit_lst$AB_CEPHALOSPORINS,
|
|
pre_commit_lst$AB_CARBAPENEMS,
|
|
pre_commit_lst$AB_MONOBACTAMS
|
|
))
|
|
pre_commit_lst$AB_BETALACTAMASE_INHIBITORS <- antimicrobials %>%
|
|
filter(atc_group2 %like% "Beta-lactamase inhibitors" | name %like% "bactam") %>%
|
|
pull(ab)
|
|
# for EUCAST:
|
|
pre_commit_lst$AB_BETALACTAMS_WITH_INHIBITOR <- antimicrobials %>%
|
|
filter(ab %in% pre_commit_lst$AB_BETALACTAMS & name %like% "/" & name %unlike% "EDTA") %>%
|
|
pull(ab)
|
|
# this will be used for documentation:
|
|
pre_commit_lst$DEFINED_AB_GROUPS <- sort(names(pre_commit_lst)[names(pre_commit_lst) %like% "^AB_" & names(pre_commit_lst) != "AB_LOOKUP"])
|
|
|
|
# Check that all AB_* groups with >= 4 members have a corresponding function
|
|
for (grp in pre_commit_lst$DEFINED_AB_GROUPS[pre_commit_lst$DEFINED_AB_GROUPS %unlike% "BETALACTAMASE_INHIBITORS|EXCEPT"]) {
|
|
if (length(pre_commit_lst[[grp]]) >= 4) {
|
|
fn_name <- tolower(gsub("^AB_", "", grp))
|
|
if (!fn_name %in% ls(envir = asNamespace("AMR"))) {
|
|
stop("Group '", grp, "' has ", length(pre_commit_lst[[grp]]),
|
|
" members (", toString(ab_name(pre_commit_lst[[grp]], tolower = T)), ") but no corresponding function '", fn_name, "()' exists in the AMR namespace.",
|
|
call. = FALSE
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
# Update the antimicrobials$group column
|
|
usethis::ui_info("Updating 'group' column in antimicrobials data set from AB_* vectors")
|
|
prettify_group_name <- function(name) {
|
|
raw <- gsub("^AB_", "", name)
|
|
pretty <- tools::toTitleCase(gsub("_", " ", tolower(raw)))
|
|
pretty[pretty %like% " (except|with) "] <- ""
|
|
pretty <- gsub(" (1st|2nd|3rd|4th|5th|6th)", " (\\1 gen.)", pretty)
|
|
pretty <- gsub("([Bb])eta[-]?", "\\1eta-", pretty)
|
|
pretty <- gsub(" Inhibitor", " inhibitor", pretty)
|
|
pretty <- pretty[pretty != ""]
|
|
return(pretty)
|
|
}
|
|
group_map <- vector("list", length = nrow(antimicrobials))
|
|
names(group_map) <- antimicrobials$ab
|
|
for (group_name in pre_commit_lst$DEFINED_AB_GROUPS) {
|
|
ab_vector <- pre_commit_lst[[group_name]]
|
|
pretty_name <- prettify_group_name(group_name)
|
|
for (ab in ab_vector) {
|
|
ab_chr <- as.character(ab)
|
|
group_map[[ab_chr]] <- sort(unique(c(group_map[[ab_chr]], pretty_name)))
|
|
}
|
|
}
|
|
for (i in seq_along(group_map)) {
|
|
if (is.null(group_map[[i]])) {
|
|
group_map[[i]] <- "Other"
|
|
if (antimicrobials$group[i] %unlike% "other") {
|
|
usethis::ui_warn(paste0("AB had a group but not anymore: ", antimicrobials$name[i], " (", antimicrobials$ab[i], "), was ", toString(antimicrobials$group[i])))
|
|
}
|
|
}
|
|
group_map[[i]] <- group_map[[i]][order(nchar(group_map[[i]]))]
|
|
}
|
|
|
|
# create priority list for ab_group()
|
|
pre_commit_lst$ABX_PRIORITY_LIST <- c(
|
|
"Aminopenicillins",
|
|
"Isoxazolylpenicillins",
|
|
"Ureidopenicillins",
|
|
"Oxazolidinones",
|
|
"Carbapenems",
|
|
"Cephalosporins (1st gen.)",
|
|
"Cephalosporins (2nd gen.)",
|
|
"Cephalosporins (3rd gen.)",
|
|
"Cephalosporins (4th gen.)",
|
|
"Cephalosporins (5th gen.)",
|
|
"Cephalosporins",
|
|
"Penicillins",
|
|
"Monobactams",
|
|
"Aminoglycosides",
|
|
"Lipoglycopeptides",
|
|
"Glycopeptides",
|
|
"Peptides",
|
|
"Lincosamides",
|
|
"Streptogramins",
|
|
"Macrolides",
|
|
"Nitrofurans",
|
|
"Phenicols",
|
|
"Phosphonics",
|
|
"Polymyxins",
|
|
"Fluoroquinolones",
|
|
"Quinolones",
|
|
"Rifamycins",
|
|
"Spiropyrimidinetriones",
|
|
"Trimethoprims",
|
|
"Sulfonamides",
|
|
"Tetracyclines",
|
|
"Ionophores",
|
|
"Antifungals",
|
|
"Antimycobacterials",
|
|
"Fusidanes",
|
|
"Beta-lactams",
|
|
"Beta-lactamase inhibitors",
|
|
"Pleuromutilins",
|
|
"Aminocoumarins",
|
|
"Other"
|
|
)
|
|
if (!all(unlist(antimicrobials$group) %in% pre_commit_lst$ABX_PRIORITY_LIST)) {
|
|
stop("Missing group(s) in priority list: ", paste(setdiff(unlist(antimicrobials$group), pre_commit_lst$ABX_PRIORITY_LIST), collapse = ", "))
|
|
}
|
|
for (i in seq_along(group_map)) {
|
|
group_map[[i]] <- intersect(pre_commit_lst$ABX_PRIORITY_LIST, group_map[[i]])
|
|
}
|
|
antimicrobials$group <- unname(group_map)
|
|
usethis::use_data(antimicrobials, overwrite = TRUE, version = 2, compress = "xz")
|
|
|
|
pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(antimicrobials)
|
|
pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(antivirals)
|
|
|
|
# MO codes of earlier releases that are not in the current data set anymore, with the current code of the same
|
|
# taxon (see data-raw/microorganisms_files/README.md). as.mo() uses this to translate them, instead of guessing.
|
|
source("tests/testthat/helper-microorganisms.R")
|
|
mo_registry <- read_mo_registry(".")
|
|
mo_renames <- read_mo_renames(".")
|
|
retired <- mo_registry[!mo_registry$mo %in% as.character(microorganisms$mo), c("mo", "fullname", "rank"), drop = FALSE]
|
|
renamed <- match(retired$mo, mo_renames$mo)
|
|
retired$fullname[!is.na(renamed)] <- mo_renames$new_name[renamed[!is.na(renamed)]]
|
|
# the same name, or else the same name without a rank suffix (such as "Kapabacteria {class}") and the same rank
|
|
current_mo <- as.character(microorganisms$mo)[match(retired$fullname, microorganisms$fullname)]
|
|
by_rank <- as.character(microorganisms$mo)[match(
|
|
paste(mo_name_without_suffix(retired$fullname), retired$rank),
|
|
paste(mo_name_without_suffix(microorganisms$fullname), microorganisms$rank)
|
|
)]
|
|
mo_retirements <- read_mo_retirements(".")
|
|
pre_commit_lst$MO_RETIRED_CODES <- data.frame(
|
|
old_mo = retired$mo,
|
|
mo = ifelse(is.na(current_mo), by_rank, current_mo),
|
|
fullname = retired$fullname,
|
|
# codes retired on purpose, because their taxon was another organism, never lead to a taxon
|
|
reason = mo_retirements$reason[match(retired$mo, mo_retirements$mo)],
|
|
stringsAsFactors = FALSE
|
|
)
|
|
pre_commit_lst$MO_RETIRED_CODES$mo[!is.na(pre_commit_lst$MO_RETIRED_CODES$reason)] <- NA_character_
|
|
rm(mo_registry, mo_renames, mo_retirements, retired, renamed, current_mo, by_rank)
|
|
|
|
# Export to package as internal data ----
|
|
# usethis::use_data() must receive unquoted object names, which is not flexible at all.
|
|
# we'll use good old base::save() instead
|
|
save(
|
|
list = names(pre_commit_lst),
|
|
file = "R/sysdata.rda",
|
|
envir = as.environment(pre_commit_lst),
|
|
compress = "xz",
|
|
version = 2,
|
|
ascii = FALSE
|
|
)
|
|
usethis::ui_done("Saved to {usethis::ui_value('R/sysdata.rda')}")
|
|
|
|
|
|
# Export data sets to the repository in different formats -----------------
|
|
|
|
for (pkg in c("haven", "openxlsx2", "arrow")) {
|
|
if (!pkg %in% rownames(utils::installed.packages())) {
|
|
message("NOTE: package '", pkg, "' not installed! Ignoring export where this package is required.")
|
|
}
|
|
}
|
|
if ("digest" %in% rownames(utils::installed.packages())) {
|
|
md5 <- function(object) digest::digest(object, "md5")
|
|
} else {
|
|
# will write all files anyway, since MD5 hash cannot be determined
|
|
md5 <- function(object) "unknown-md5-hash"
|
|
}
|
|
|
|
write_md5 <- function(object) {
|
|
conn <- file(paste0("data-raw/", deparse(substitute(object)), ".md5"))
|
|
writeLines(md5(object), conn)
|
|
close(conn)
|
|
}
|
|
changed_md5 <- function(object) {
|
|
path <- paste0("data-raw/", deparse(substitute(object)), ".md5")
|
|
if (!file.exists(path)) {
|
|
return(TRUE)
|
|
}
|
|
tryCatch(
|
|
{
|
|
conn <- file(path)
|
|
compared <- md5(object) != readLines(con = conn)
|
|
close(conn)
|
|
compared
|
|
},
|
|
error = function(e) TRUE
|
|
)
|
|
}
|
|
|
|
# give official names to ABs and MOs
|
|
clin_break <- clinical_breakpoints %>%
|
|
mutate(mo_name = microorganisms$fullname[match(mo, microorganisms$mo)], .after = mo) %>%
|
|
mutate(ab_name = antimicrobials$name[match(ab, antimicrobials$ab)], .after = ab)
|
|
if (changed_md5(clin_break)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(clin_break)
|
|
try(saveRDS(clin_break, "data-raw/datasets/clinical_breakpoints.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(write.table(clinical_breakpoints, "data-raw/datasets/clinical_breakpoints.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(haven::write_sav(clin_break, "data-raw/datasets/clinical_breakpoints.sav"), silent = TRUE)
|
|
# long notes as strL, otherwise Stata's fixed-width strings make the file exceed 100 MB; a missing string is "" in Stata
|
|
try(haven::write_dta(clin_break %>% mutate(note = if_else(is.na(note), "", note)), "data-raw/datasets/clinical_breakpoints.dta", strl_threshold = 255), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(clin_break, "data-raw/datasets/clinical_breakpoints.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(clin_break, "data-raw/datasets/clinical_breakpoints.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(clin_break, "data-raw/datasets/clinical_breakpoints.parquet"), silent = TRUE)
|
|
}
|
|
|
|
if (changed_md5(microorganisms)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(microorganisms)
|
|
try(saveRDS(microorganisms, "data-raw/datasets/microorganisms.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
max_50_snomed <- sapply(microorganisms$snomed, function(x) paste(x[seq_len(min(50, length(x), na.rm = TRUE))], collapse = " "))
|
|
mo <- microorganisms
|
|
mo$snomed <- max_50_snomed
|
|
mo <- dplyr::mutate_if(mo, ~ !is.numeric(.), as.character)
|
|
try(haven::write_sav(mo, "data-raw/datasets/microorganisms.sav"), silent = TRUE)
|
|
# (long strings as strL, as otherwise the file would exceed the file size limit of GitHub)
|
|
try(haven::write_dta(mo, "data-raw/datasets/microorganisms.dta", strl_threshold = 255), silent = TRUE)
|
|
mo_all_snomed <- microorganisms %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
try(write.table(mo_all_snomed, "data-raw/datasets/microorganisms.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(mo_all_snomed, "data-raw/datasets/microorganisms.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(microorganisms, "data-raw/datasets/microorganisms.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(microorganisms, "data-raw/datasets/microorganisms.parquet"), silent = TRUE)
|
|
}
|
|
|
|
if (changed_md5(microorganisms.codes)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms.codes')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(microorganisms.codes)
|
|
try(saveRDS(microorganisms.codes, "data-raw/datasets/microorganisms.codes.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(write.table(microorganisms.codes, "data-raw/datasets/microorganisms.codes.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(haven::write_sav(microorganisms.codes, "data-raw/datasets/microorganisms.codes.sav"), silent = TRUE)
|
|
try(haven::write_dta(microorganisms.codes, "data-raw/datasets/microorganisms.codes.dta"), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(microorganisms.codes, "data-raw/datasets/microorganisms.codes.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(microorganisms.codes, "data-raw/datasets/microorganisms.codes.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(microorganisms.codes, "data-raw/datasets/microorganisms.codes.parquet"), silent = TRUE)
|
|
}
|
|
|
|
if (changed_md5(microorganisms.groups)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms.groups')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(microorganisms.groups)
|
|
try(saveRDS(microorganisms.groups, "data-raw/datasets/microorganisms.groups.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(write.table(microorganisms.groups, "data-raw/datasets/microorganisms.groups.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(haven::write_sav(microorganisms.groups, "data-raw/datasets/microorganisms.groups.sav"), silent = TRUE)
|
|
try(haven::write_dta(microorganisms.groups, "data-raw/datasets/microorganisms.groups.dta"), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(microorganisms.groups, "data-raw/datasets/microorganisms.groups.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(microorganisms.groups, "data-raw/datasets/microorganisms.groups.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(microorganisms.groups, "data-raw/datasets/microorganisms.groups.parquet"), silent = TRUE)
|
|
}
|
|
|
|
ab <- dplyr::mutate_if(antimicrobials, ~ !is.numeric(.), as.character)
|
|
if (changed_md5(ab)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('antimicrobials')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(ab)
|
|
try(saveRDS(antimicrobials, "data-raw/datasets/antimicrobials.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(haven::write_sav(ab, "data-raw/datasets/antimicrobials.sav"), silent = TRUE)
|
|
try(haven::write_dta(ab, "data-raw/datasets/antimicrobials.dta"), silent = TRUE)
|
|
ab_lists <- antimicrobials %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
try(write.table(ab_lists, "data-raw/datasets/antimicrobials.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(ab_lists, "data-raw/datasets/antimicrobials.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(antimicrobials, "data-raw/datasets/antimicrobials.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(antimicrobials, "data-raw/datasets/antimicrobials.parquet"), silent = TRUE)
|
|
}
|
|
|
|
av <- dplyr::mutate_if(antivirals, ~ !is.numeric(.), as.character)
|
|
if (changed_md5(av)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('antivirals')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(av)
|
|
try(saveRDS(antivirals, "data-raw/datasets/antivirals.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(haven::write_sav(av, "data-raw/datasets/antivirals.sav"), silent = TRUE)
|
|
try(haven::write_dta(av, "data-raw/datasets/antivirals.dta"), silent = TRUE)
|
|
av_lists <- antivirals %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
try(write.table(av_lists, "data-raw/datasets/antivirals.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(av_lists, "data-raw/datasets/antivirals.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(antivirals, "data-raw/datasets/antivirals.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(antivirals, "data-raw/datasets/antivirals.parquet"), silent = TRUE)
|
|
}
|
|
|
|
# give official names to ABs and MOs
|
|
intrinsicR <- data.frame(
|
|
microorganism = mo_name(intrinsic_resistant$mo, language = NULL, keep_synonyms = TRUE, info = FALSE),
|
|
antibiotic = ab_name(intrinsic_resistant$ab, language = NULL),
|
|
stringsAsFactors = FALSE
|
|
)
|
|
if (changed_md5(intrinsicR)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('intrinsic_resistant')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(intrinsicR)
|
|
try(saveRDS(intrinsicR, "data-raw/datasets/intrinsic_resistant.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(write.table(intrinsicR, "data-raw/datasets/intrinsic_resistant.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(haven::write_sav(intrinsicR, "data-raw/datasets/intrinsic_resistant.sav"), silent = TRUE)
|
|
try(haven::write_dta(intrinsicR, "data-raw/datasets/intrinsic_resistant.dta"), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(intrinsicR, "data-raw/datasets/intrinsic_resistant.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(intrinsicR, "data-raw/datasets/intrinsic_resistant.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(intrinsicR, "data-raw/datasets/intrinsic_resistant.parquet"), silent = TRUE)
|
|
}
|
|
|
|
if (changed_md5(dosage)) {
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('dosage')} to {usethis::ui_value('data-raw/datasets/')}"))
|
|
write_md5(dosage)
|
|
try(saveRDS(dosage, "data-raw/datasets/dosage.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
try(write.table(dosage, "data-raw/datasets/dosage.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
try(haven::write_sav(dosage, "data-raw/datasets/dosage.sav"), silent = TRUE)
|
|
try(haven::write_dta(dosage, "data-raw/datasets/dosage.dta"), silent = TRUE)
|
|
try(openxlsx2::write_xlsx(dosage, "data-raw/datasets/dosage.xlsx"), silent = TRUE)
|
|
try(arrow::write_feather(dosage, "data-raw/datasets/dosage.feather"), silent = TRUE)
|
|
try(arrow::write_parquet(dosage, "data-raw/datasets/dosage.parquet"), silent = TRUE)
|
|
}
|
|
|
|
# Set `antibiotics` as a deprecated data set
|
|
antibiotics <- structure(antimicrobials, class = c("deprecated_amr_dataset", class(antimicrobials)))
|
|
usethis::use_data(antibiotics, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)
|
|
rm(antibiotics)
|
|
|
|
suppressMessages(reset_AMR_locale())
|
|
|
|
devtools::load_all(quiet = TRUE)
|
|
suppressMessages(set_AMR_locale("English"))
|
|
|
|
files_changed <- function(paths = "^(R|data)/") {
|
|
tryCatch(
|
|
{
|
|
changed_files <- system("git status", intern = TRUE)
|
|
changed_files <- unlist(strsplit(changed_files, " "))
|
|
any(changed_files %like% paths[paths != "R/sysdata.rda"])
|
|
},
|
|
error = function(e) TRUE
|
|
)
|
|
}
|
|
|
|
# Update URLs -------------------------------------------------------------
|
|
if (files_changed()) {
|
|
usethis::ui_info("Checking URLs for redirects")
|
|
# Step 1: Get sources from tools (excluding man/)
|
|
sources <- tools:::url_db_from_package_sources(".")
|
|
sources <- sources[!grepl("^man/", sources$Parent), ]
|
|
# Step 2: Get URLs from .R files in R/
|
|
r_files <- list.files("R", pattern = "\\.R$", full.names = TRUE)
|
|
# Function to extract URLs from a file
|
|
extract_urls_from_file <- function(file_path) {
|
|
lines <- readLines(file_path, warn = FALSE)
|
|
urls <- stringr::str_extract_all(lines, "https?://[^\\s)\"'>}]+")
|
|
urls <- unlist(urls)
|
|
if (length(urls) == 0) {
|
|
return(NULL)
|
|
}
|
|
# Remove trailing punctuation (e.g., .,), etc.)
|
|
urls <- stringr::str_replace(urls, "[\\.,;)]+$", "")
|
|
data.frame(
|
|
URL = urls,
|
|
Parent = gsub("^\\./", "", file_path),
|
|
stringsAsFactors = FALSE
|
|
)
|
|
}
|
|
r_file_urls <- do.call(rbind, lapply(r_files, extract_urls_from_file))
|
|
# Step 3: Combine the two sources
|
|
total <- rbind(sources, r_file_urls)
|
|
# Step 4: Check URLs and update
|
|
results <- urlchecker::url_check(db = total)
|
|
invisible(urlchecker::url_update(results = results))
|
|
}
|
|
|
|
# Style pkg ---------------------------------------------------------------
|
|
if (files_changed(paths = "^(R|tests)/")) {
|
|
usethis::ui_info("Styling package")
|
|
styler::style_pkg(
|
|
include_roxygen_examples = FALSE,
|
|
exclude_dirs = list.dirs(full.names = FALSE, recursive = FALSE)[!list.dirs(full.names = FALSE, recursive = FALSE) %in% c("R", "tests")]
|
|
)
|
|
}
|
|
|
|
# Document pkg ------------------------------------------------------------
|
|
if (files_changed()) {
|
|
usethis::ui_info("Documenting package")
|
|
suppressMessages(devtools::document(quiet = TRUE))
|
|
}
|
|
|
|
# Update index.md and README.md -------------------------------------------
|
|
if (files_changed("README.Rmd") ||
|
|
files_changed("index.Rmd") ||
|
|
files_changed("man/microorganisms.Rd") ||
|
|
files_changed("man/antimicrobials.Rd") ||
|
|
files_changed("man/clinical_breakpoints.Rd") ||
|
|
files_changed("man/antibiogram.Rd") ||
|
|
files_changed("R/antibiogram.R") ||
|
|
files_changed("data-raw/translations.tsv")) {
|
|
usethis::ui_info("Rendering {usethis::ui_field('index.md')} and {usethis::ui_field('README.md')}")
|
|
suppressWarnings(rmarkdown::render("index.Rmd", quiet = TRUE))
|
|
suppressWarnings(rmarkdown::render("README.Rmd", quiet = TRUE))
|
|
unlink("index.html") # remove previews from folder
|
|
unlink("README.html")
|
|
}
|
|
|
|
# Finished ----------------------------------------------------------------
|
|
rm(antimicrobials)
|
|
usethis::ui_done("All done")
|
|
suppressMessages(reset_AMR_locale())
|