2020-01-05 17:22:09 +01:00
|
|
|
# ==================================================================== #
|
2023-06-26 13:52:02 +02:00
|
|
|
# TITLE: #
|
2022-10-05 09:12:22 +02:00
|
|
|
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
2020-01-05 17:22:09 +01:00
|
|
|
# #
|
2023-06-26 13:52:02 +02:00
|
|
|
# SOURCE CODE: #
|
2020-07-09 20:07:39 +02:00
|
|
|
# https://github.com/msberends/AMR #
|
2020-01-05 17:22:09 +01:00
|
|
|
# #
|
2023-06-26 13:52:02 +02:00
|
|
|
# PLEASE CITE THIS SOFTWARE AS: #
|
2024-07-16 14:51:57 +02:00
|
|
|
# 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. #
|
2023-05-27 10:39:22 +02:00
|
|
|
# https://doi.org/10.18637/jss.v104.i03 #
|
2022-10-05 09:12:22 +02:00
|
|
|
# #
|
2022-12-27 15:16:15 +01:00
|
|
|
# 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. #
|
2020-01-05 17:22:09 +01:00
|
|
|
# #
|
|
|
|
# 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. #
|
2020-10-08 11:16:03 +02:00
|
|
|
# #
|
|
|
|
# Visit our website for the full manual and a complete tutorial about #
|
2021-02-02 23:57:35 +01:00
|
|
|
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
2020-01-05 17:22:09 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
|
2021-01-22 10:20:41 +01:00
|
|
|
# Run this file to update the package using:
|
2024-04-23 10:55:48 +02:00
|
|
|
# source("data-raw/_pre_commit_checks.R")
|
2019-10-23 14:48:25 +02:00
|
|
|
|
2020-09-24 00:30:11 +02:00
|
|
|
library(dplyr, warn.conflicts = FALSE)
|
2023-05-08 13:04:18 +02:00
|
|
|
try(detach("package:data.table", unload = TRUE), silent = TRUE) # to prevent like() to precede over AMR::like
|
2021-01-22 10:20:41 +01:00
|
|
|
devtools::load_all(quiet = TRUE)
|
|
|
|
|
2022-08-28 22:38:08 +02:00
|
|
|
suppressMessages(set_AMR_locale("English"))
|
2022-08-19 12:33:14 +02:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst <- list()
|
2021-01-22 10:20:41 +01:00
|
|
|
|
2021-04-07 08:37:42 +02:00
|
|
|
# Save internal data to R/sysdata.rda -------------------------------------
|
2021-01-22 10:20:41 +01:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
usethis::ui_info(paste0("Updating internal package data"))
|
|
|
|
|
2021-01-22 10:20:41 +01:00
|
|
|
# See 'data-raw/eucast_rules.tsv' for the EUCAST reference file
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$EUCAST_RULES_DF <- utils::read.delim(
|
2022-08-28 10:31:50 +02:00
|
|
|
file = "data-raw/eucast_rules.tsv",
|
2022-11-14 15:20:39 +01:00
|
|
|
skip = 9,
|
2022-08-28 10:31:50 +02:00
|
|
|
sep = "\t",
|
|
|
|
stringsAsFactors = FALSE,
|
|
|
|
header = TRUE,
|
|
|
|
strip.white = TRUE,
|
|
|
|
na = c(NA, "", NULL)
|
|
|
|
) %>%
|
2020-09-24 00:30:11 +02:00
|
|
|
# take the order of the reference.rule_group column in the original data file
|
2022-08-28 10:31:50 +02:00
|
|
|
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
|
|
|
|
) %>%
|
2022-08-26 22:25:15 +02:00
|
|
|
mutate(reference.rule_group = as.character(reference.rule_group)) %>%
|
2020-09-24 00:30:11 +02:00
|
|
|
select(-sorting_rule)
|
2019-10-23 14:48:25 +02:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$TRANSLATIONS <- utils::read.delim(
|
2022-08-28 10:31:50 +02:00
|
|
|
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 = ""
|
|
|
|
)
|
2022-08-26 22:25:15 +02:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$LANGUAGES_SUPPORTED_NAMES <- c(
|
2022-08-28 10:31:50 +02:00
|
|
|
list(en = list(exonym = "English", endonym = "English")),
|
|
|
|
lapply(
|
2024-07-16 14:51:57 +02:00
|
|
|
TRANSLATIONS[, which(nchar(colnames(pre_commit_lst$TRANSLATIONS)) == 2), drop = FALSE],
|
2022-08-28 10:31:50 +02:00
|
|
|
function(x) list(exonym = x[1], endonym = x[2])
|
|
|
|
)
|
|
|
|
)
|
2022-08-26 22:25:15 +02:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$LANGUAGES_SUPPORTED <- names(pre_commit_lst$LANGUAGES_SUPPORTED_NAMES)
|
2022-08-26 22:25:15 +02:00
|
|
|
|
2021-01-22 10:20:41 +01:00
|
|
|
# vectors of CoNS and CoPS, improves speed in as.mo()
|
2021-05-30 22:14:38 +02:00
|
|
|
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 <- AMR::microorganisms
|
|
|
|
MO_staph <- MO_staph[which(MO_staph$genus == "Staphylococcus"), , drop = FALSE]
|
|
|
|
if (type == "CoNS") {
|
2023-01-23 15:01:21 +01:00
|
|
|
MO_staph[
|
|
|
|
which(MO_staph$species %in% c(
|
|
|
|
"coagulase-negative", "argensis", "arlettae",
|
|
|
|
"auricularis", "borealis", "caeli", "capitis", "caprae",
|
|
|
|
"carnosus", "casei", "caseolyticus", "chromogenes", "cohnii", "condimenti",
|
|
|
|
"croceilyticus",
|
|
|
|
"debuckii", "devriesei", "edaphicus", "epidermidis",
|
|
|
|
"equorum", "felis", "fleurettii", "gallinarum",
|
|
|
|
"haemolyticus", "hominis", "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",
|
2024-07-16 15:55:58 +02:00
|
|
|
"ratti", "taiwanensis", "veratri", "urealyticus",
|
|
|
|
"americanisciuri", "marylandisciuri", "shinii", "brunensis"
|
2023-01-23 15:01:21 +01:00
|
|
|
) |
|
|
|
|
# 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
|
2022-08-28 10:31:50 +02:00
|
|
|
]
|
2021-05-30 22:14:38 +02:00
|
|
|
} else if (type == "CoPS") {
|
2023-01-23 15:01:21 +01:00
|
|
|
MO_staph[
|
|
|
|
which(MO_staph$species %in% c(
|
|
|
|
"coagulase-positive", "coagulans",
|
|
|
|
"agnetis", "argenteus",
|
|
|
|
"cornubiensis",
|
|
|
|
"delphini", "lutrae",
|
|
|
|
"hyicus", "intermedius",
|
|
|
|
"pseudintermedius", "pseudointermedius",
|
|
|
|
"schweitzeri", "simiae",
|
|
|
|
"roterodami",
|
|
|
|
"singaporensis"
|
|
|
|
) |
|
|
|
|
# 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
|
2022-08-28 10:31:50 +02:00
|
|
|
]
|
2021-05-30 22:14:38 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-16 14:51:57 +02:00
|
|
|
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 <- AMR::microorganisms$mo[which(AMR::microorganisms$genus == "Streptococcus" &
|
2023-02-22 14:38:57 +01:00
|
|
|
tolower(AMR::microorganisms$species) %in% c(
|
2022-12-16 16:10:43 +01:00
|
|
|
"pyogenes", "agalactiae", "dysgalactiae", "equi", "canis",
|
2023-02-22 14:38:57 +01:00
|
|
|
"group a", "group b", "group c", "group g"
|
2022-10-05 09:12:22 +02:00
|
|
|
))]
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$MO_LANCEFIELD <- AMR::microorganisms$mo[which(AMR::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(_|$))")]
|
|
|
|
pre_commit_lst$MO_PREVALENT_GENERA <- c(
|
|
|
|
"Absidia",
|
|
|
|
"Acanthamoeba",
|
|
|
|
"Acremonium",
|
|
|
|
"Aedes",
|
|
|
|
"Alternaria",
|
|
|
|
"Amoeba",
|
|
|
|
"Ancylostoma",
|
|
|
|
"Angiostrongylus",
|
|
|
|
"Anisakis",
|
|
|
|
"Anopheles",
|
|
|
|
"Apophysomyces",
|
|
|
|
"Arthroderma",
|
|
|
|
"Aspergillus",
|
|
|
|
"Aureobasidium",
|
|
|
|
"Basidiobolus",
|
|
|
|
"Beauveria",
|
|
|
|
"Blastocystis",
|
|
|
|
"Blastomyces",
|
|
|
|
"Candida",
|
|
|
|
"Capillaria",
|
|
|
|
"Chaetomium",
|
|
|
|
"Chrysonilia",
|
|
|
|
"Chrysosporium",
|
|
|
|
"Cladophialophora",
|
|
|
|
"Cladosporium",
|
|
|
|
"Conidiobolus",
|
|
|
|
"Contracaecum",
|
|
|
|
"Cordylobia",
|
|
|
|
"Cryptococcus",
|
|
|
|
"Curvularia",
|
|
|
|
"Demodex",
|
|
|
|
"Dermatobia",
|
|
|
|
"Dientamoeba",
|
|
|
|
"Diphyllobothrium",
|
|
|
|
"Dirofilaria",
|
|
|
|
"Echinostoma",
|
|
|
|
"Entamoeba",
|
|
|
|
"Enterobius",
|
|
|
|
"Exophiala",
|
|
|
|
"Exserohilum",
|
|
|
|
"Fasciola",
|
|
|
|
"Fonsecaea",
|
|
|
|
"Fusarium",
|
|
|
|
"Geotrichum",
|
|
|
|
"Giardia",
|
|
|
|
"Haloarcula",
|
|
|
|
"Halobacterium",
|
|
|
|
"Halococcus",
|
|
|
|
"Hansenula",
|
|
|
|
"Hendersonula",
|
|
|
|
"Heterophyes",
|
|
|
|
"Histomonas",
|
|
|
|
"Histoplasma",
|
|
|
|
"Hymenolepis",
|
|
|
|
"Hypomyces",
|
|
|
|
"Hysterothylacium",
|
|
|
|
"Kloeckera",
|
|
|
|
"Kluyveromyces",
|
|
|
|
"Kodamaea",
|
|
|
|
"Leishmania",
|
|
|
|
"Lichtheimia",
|
|
|
|
"Lodderomyces",
|
|
|
|
"Lomentospora",
|
|
|
|
"Malassezia",
|
|
|
|
"Malbranchea",
|
|
|
|
"Metagonimus",
|
|
|
|
"Meyerozyma",
|
|
|
|
"Microsporidium",
|
|
|
|
"Microsporum",
|
|
|
|
"Millerozyma",
|
|
|
|
"Mortierella",
|
|
|
|
"Mucor",
|
|
|
|
"Mycocentrospora",
|
|
|
|
"Necator",
|
|
|
|
"Nectria",
|
|
|
|
"Ochroconis",
|
|
|
|
"Oesophagostomum",
|
|
|
|
"Oidiodendron",
|
|
|
|
"Opisthorchis",
|
|
|
|
"Paecilomyces",
|
|
|
|
"Pediculus",
|
|
|
|
"Penicillium",
|
|
|
|
"Phlebotomus",
|
|
|
|
"Phoma",
|
|
|
|
"Pichia",
|
|
|
|
"Piedraia",
|
|
|
|
"Pithomyces",
|
|
|
|
"Pityrosporum",
|
|
|
|
"Pneumocystis",
|
|
|
|
"Pseudallescheria",
|
|
|
|
"Pseudoscopulariopsis",
|
|
|
|
"Pseudoterranova",
|
|
|
|
"Pulex",
|
|
|
|
"Rhizomucor",
|
|
|
|
"Rhizopus",
|
|
|
|
"Rhodotorula",
|
|
|
|
"Saccharomyces",
|
|
|
|
"Saprochaete",
|
|
|
|
"Sarcoptes",
|
|
|
|
"Scedosporium",
|
|
|
|
"Scolecobasidium",
|
|
|
|
"Scopulariopsis",
|
|
|
|
"Scytalidium",
|
|
|
|
"Spirometra",
|
|
|
|
"Sporobolomyces",
|
|
|
|
"Sporotrichum",
|
|
|
|
"Stachybotrys",
|
|
|
|
"Strongyloides",
|
|
|
|
"Syngamus",
|
|
|
|
"Taenia",
|
|
|
|
"Talaromyces",
|
|
|
|
"Toxocara",
|
|
|
|
"Trichinella",
|
|
|
|
"Trichobilharzia",
|
|
|
|
"Trichoderma",
|
|
|
|
"Trichomonas",
|
|
|
|
"Trichophyton",
|
|
|
|
"Trichosporon",
|
|
|
|
"Trichostrongylus",
|
|
|
|
"Trichuris",
|
|
|
|
"Tritirachium",
|
|
|
|
"Trombicula",
|
|
|
|
"Trypanosoma",
|
|
|
|
"Tunga",
|
|
|
|
"Verticillium",
|
|
|
|
"Wuchereria"
|
2022-08-28 10:31:50 +02:00
|
|
|
)
|
2021-01-22 10:20:41 +01:00
|
|
|
|
2021-04-07 08:37:42 +02:00
|
|
|
# antibiotic groups
|
|
|
|
# (these will also be used for eucast_rules() and understanding data-raw/eucast_rules.tsv)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_AMINOGLYCOSIDES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "aminoglycoside") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_AMINOPENICILLINS <- as.ab(c("AMP", "AMX"))
|
|
|
|
pre_commit_lst$AB_ANTIFUNGALS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "antifungal") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_ANTIMYCOBACTERIALS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "antimycobacterial") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CARBAPENEMS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "carbapenem") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_1ST <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin.*1") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_2ND <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin.*2") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_3RD <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin.*3") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_4TH <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin.*4") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_5TH <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "cephalosporin.*5") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_CEPHALOSPORINS_EXCEPT_CAZ <- pre_commit_lst$AB_CEPHALOSPORINS[pre_commit_lst$AB_CEPHALOSPORINS != "CAZ"]
|
|
|
|
pre_commit_lst$AB_FLUOROQUINOLONES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(atc_group2 %like% "fluoroquinolone" | (group %like% "quinolone" & is.na(atc_group2))) %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_GLYCOPEPTIDES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "glycopeptide") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
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 <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(atc_group2 %like% "lincosamide" | (group %like% "lincosamide" & is.na(atc_group2))) %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_MACROLIDES <- antibiotics %>%
|
2024-06-08 17:35:25 +02:00
|
|
|
filter(atc_group2 %like% "macrolide" | (group %like% "macrolide" & is.na(atc_group2) & name %unlike% "screening|inducible")) %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_NITROFURANS <- antibiotics %>%
|
2024-06-08 17:35:25 +02:00
|
|
|
filter(name %like% "^furaz|nitrofura" | atc_group2 %like% "nitrofuran") %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_OXAZOLIDINONES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "oxazolidinone") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_PENICILLINS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "penicillin") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_POLYMYXINS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "polymyxin") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_QUINOLONES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "quinolone") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_RIFAMYCINS <- antibiotics %>%
|
2024-06-08 17:35:25 +02:00
|
|
|
filter(name %like% "Rifampi|Rifabutin|Rifapentine|rifamy") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_STREPTOGRAMINS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(atc_group2 %like% "streptogramin") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_TETRACYCLINES <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "tetracycline") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_TETRACYCLINES_EXCEPT_TGC <- pre_commit_lst$AB_TETRACYCLINES[pre_commit_lst$AB_TETRACYCLINES != "TGC"]
|
|
|
|
pre_commit_lst$AB_TRIMETHOPRIMS <- antibiotics %>%
|
2022-08-28 10:31:50 +02:00
|
|
|
filter(group %like% "trimethoprim") %>%
|
|
|
|
pull(ab)
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_UREIDOPENICILLINS <- as.ab(c("PIP", "TZP", "AZL", "MEZ"))
|
|
|
|
pre_commit_lst$AB_BETALACTAMS <- c(pre_commit_lst$AB_PENICILLINS, pre_commit_lst$AB_CEPHALOSPORINS, pre_commit_lst$AB_CARBAPENEMS)
|
2021-08-16 21:54:34 +02:00
|
|
|
# this will be used for documentation:
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$DEFINED_AB_GROUPS <- sort(names(pre_commit_lst)[names(pre_commit_lst) %like% "^AB_" & names(pre_commit_lst) != "AB_LOOKUP"])
|
2022-11-13 08:46:10 +01:00
|
|
|
create_AB_AV_lookup <- function(df) {
|
|
|
|
new_df <- df
|
|
|
|
new_df$generalised_name <- generalise_antibiotic_name(new_df$name)
|
|
|
|
new_df$generalised_synonyms <- lapply(new_df$synonyms, generalise_antibiotic_name)
|
|
|
|
if ("abbreviations" %in% colnames(df)) {
|
|
|
|
new_df$generalised_abbreviations <- lapply(new_df$abbreviations, generalise_antibiotic_name)
|
|
|
|
}
|
|
|
|
new_df$generalised_loinc <- lapply(new_df$loinc, generalise_antibiotic_name)
|
|
|
|
new_df$generalised_all <- unname(lapply(
|
2023-01-23 15:01:21 +01:00
|
|
|
as.list(as.data.frame(
|
|
|
|
t(new_df[,
|
|
|
|
c(
|
|
|
|
colnames(new_df)[colnames(new_df) %in% c("ab", "av", "atc", "cid", "name")],
|
|
|
|
colnames(new_df)[colnames(new_df) %like% "generalised"]
|
|
|
|
),
|
|
|
|
drop = FALSE
|
|
|
|
]),
|
|
|
|
stringsAsFactors = FALSE
|
2022-08-28 10:31:50 +02:00
|
|
|
)),
|
|
|
|
function(x) {
|
|
|
|
x <- generalise_antibiotic_name(unname(unlist(x)))
|
|
|
|
x[x != ""]
|
|
|
|
}
|
|
|
|
))
|
2022-11-13 08:46:10 +01:00
|
|
|
new_df[, colnames(new_df)[colnames(new_df) %like% "^generalised"]]
|
2022-03-14 16:36:10 +01:00
|
|
|
}
|
2024-07-16 14:51:57 +02:00
|
|
|
pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(AMR::antibiotics)
|
|
|
|
pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(AMR::antivirals)
|
2021-04-07 08:37:42 +02:00
|
|
|
|
2019-06-01 20:40:49 +02:00
|
|
|
# Export to package as internal data ----
|
2024-07-16 14:51:57 +02:00
|
|
|
# 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')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-01 20:40:49 +02:00
|
|
|
|
2021-01-22 10:20:41 +01:00
|
|
|
# Export data sets to the repository in different formats -----------------
|
2019-09-15 22:57:30 +02:00
|
|
|
|
2024-07-16 14:51:57 +02:00
|
|
|
for (pkg in c("haven", "openxlsx2", "arrow")) {
|
2022-08-26 22:25:15 +02:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:21:23 +02:00
|
|
|
write_md5 <- function(object) {
|
2020-09-24 00:30:11 +02:00
|
|
|
conn <- file(paste0("data-raw/", deparse(substitute(object)), ".md5"))
|
2022-08-26 22:25:15 +02:00
|
|
|
writeLines(md5(object), conn)
|
2020-09-24 00:30:11 +02:00
|
|
|
close(conn)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
|
|
|
changed_md5 <- function(object) {
|
2022-08-28 10:31:50 +02:00
|
|
|
tryCatch(
|
|
|
|
{
|
|
|
|
conn <- file(paste0("data-raw/", deparse(substitute(object)), ".md5"))
|
|
|
|
compared <- md5(object) != readLines(con = conn)
|
|
|
|
close(conn)
|
|
|
|
compared
|
|
|
|
},
|
|
|
|
error = function(e) TRUE
|
|
|
|
)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
2021-01-22 10:20:41 +01:00
|
|
|
|
2020-02-14 19:54:13 +01:00
|
|
|
# give official names to ABs and MOs
|
2023-01-21 23:47:20 +01:00
|
|
|
clin_break <- clinical_breakpoints %>%
|
2022-10-05 09:12:22 +02:00
|
|
|
mutate(mo_name = mo_name(mo, language = NULL, keep_synonyms = TRUE, info = FALSE), .after = mo) %>%
|
2022-05-11 10:26:58 +02:00
|
|
|
mutate(ab_name = ab_name(ab, language = NULL), .after = ab)
|
2023-01-21 23:47:20 +01:00
|
|
|
if (changed_md5(clin_break)) {
|
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}"))
|
|
|
|
write_md5(clin_break)
|
|
|
|
try(saveRDS(clin_break, "data-raw/clinical_breakpoints.rds", version = 2, compress = "xz"), silent = TRUE)
|
2023-07-10 19:04:12 +02:00
|
|
|
try(write.table(clinical_breakpoints, "data-raw/clinical_breakpoints.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(clin_break, "data-raw/clinical_breakpoints.xpt"), silent = TRUE)
|
2023-01-21 23:47:20 +01:00
|
|
|
try(haven::write_sav(clin_break, "data-raw/clinical_breakpoints.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(clin_break, "data-raw/clinical_breakpoints.dta"), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(clin_break, "data-raw/clinical_breakpoints.xlsx"), silent = TRUE)
|
2023-01-21 23:47:20 +01:00
|
|
|
try(arrow::write_feather(clin_break, "data-raw/clinical_breakpoints.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(clin_break, "data-raw/clinical_breakpoints.parquet"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
2020-08-16 21:38:42 +02:00
|
|
|
|
2022-08-26 22:25:15 +02:00
|
|
|
if (changed_md5(microorganisms)) {
|
2022-08-27 20:49:37 +02:00
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms')} to {usethis::ui_value('data-raw/')}"))
|
2022-08-26 22:25:15 +02:00
|
|
|
write_md5(microorganisms)
|
|
|
|
try(saveRDS(microorganisms, "data-raw/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
|
2022-08-28 10:31:50 +02:00
|
|
|
mo <- dplyr::mutate_if(mo, ~ !is.numeric(.), as.character)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(mo, "data-raw/microorganisms.xpt"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(haven::write_sav(mo, "data-raw/microorganisms.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(mo, "data-raw/microorganisms.dta"), silent = TRUE)
|
2022-10-29 16:08:18 +02:00
|
|
|
mo_all_snomed <- microorganisms %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
|
|
try(write.table(mo_all_snomed, "data-raw/microorganisms.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(mo_all_snomed, "data-raw/microorganisms.xlsx"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(arrow::write_feather(microorganisms, "data-raw/microorganisms.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(microorganisms, "data-raw/microorganisms.parquet"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
2020-08-16 21:38:42 +02:00
|
|
|
|
2023-07-08 17:30:05 +02:00
|
|
|
if (changed_md5(microorganisms.codes)) {
|
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('microorganisms.codes')} to {usethis::ui_value('data-raw/')}"))
|
|
|
|
write_md5(microorganisms.codes)
|
|
|
|
try(saveRDS(microorganisms.codes, "data-raw/microorganisms.codes.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
|
|
try(write.table(microorganisms.codes, "data-raw/microorganisms.codes.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
|
|
try(haven::write_xpt(microorganisms.codes, "data-raw/microorganisms.codes.xpt"), silent = TRUE)
|
|
|
|
try(haven::write_sav(microorganisms.codes, "data-raw/microorganisms.codes.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(microorganisms.codes, "data-raw/microorganisms.codes.dta"), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(microorganisms.codes, "data-raw/microorganisms.codes.xlsx"), silent = TRUE)
|
2023-07-08 17:30:05 +02:00
|
|
|
try(arrow::write_feather(microorganisms.codes, "data-raw/microorganisms.codes.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(microorganisms.codes, "data-raw/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/')}"))
|
|
|
|
write_md5(microorganisms.groups)
|
|
|
|
try(saveRDS(microorganisms.groups, "data-raw/microorganisms.groups.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
|
|
try(write.table(microorganisms.groups, "data-raw/microorganisms.groups.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
|
|
|
try(haven::write_xpt(microorganisms.groups, "data-raw/microorganisms.groups.xpt"), silent = TRUE)
|
|
|
|
try(haven::write_sav(microorganisms.groups, "data-raw/microorganisms.groups.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(microorganisms.groups, "data-raw/microorganisms.groups.dta"), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(microorganisms.groups, "data-raw/microorganisms.groups.xlsx"), silent = TRUE)
|
2023-07-08 17:30:05 +02:00
|
|
|
try(arrow::write_feather(microorganisms.groups, "data-raw/microorganisms.groups.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(microorganisms.groups, "data-raw/microorganisms.groups.parquet"), silent = TRUE)
|
|
|
|
}
|
|
|
|
|
2022-08-28 10:31:50 +02:00
|
|
|
ab <- dplyr::mutate_if(antibiotics, ~ !is.numeric(.), as.character)
|
2020-09-14 12:21:23 +02:00
|
|
|
if (changed_md5(ab)) {
|
2022-08-27 20:49:37 +02:00
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('antibiotics')} to {usethis::ui_value('data-raw/')}"))
|
2020-09-14 12:21:23 +02:00
|
|
|
write_md5(ab)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(saveRDS(antibiotics, "data-raw/antibiotics.rds", version = 2, compress = "xz"), silent = TRUE)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(ab, "data-raw/antibiotics.xpt"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
try(haven::write_sav(ab, "data-raw/antibiotics.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(ab, "data-raw/antibiotics.dta"), silent = TRUE)
|
2022-10-29 16:17:48 +02:00
|
|
|
ab_lists <- antibiotics %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
|
|
try(write.table(ab_lists, "data-raw/antibiotics.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(ab_lists, "data-raw/antibiotics.xlsx"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(arrow::write_feather(antibiotics, "data-raw/antibiotics.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(antibiotics, "data-raw/antibiotics.parquet"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
2020-08-16 21:38:42 +02:00
|
|
|
|
2022-08-28 10:31:50 +02:00
|
|
|
av <- dplyr::mutate_if(antivirals, ~ !is.numeric(.), as.character)
|
2020-09-14 12:21:23 +02:00
|
|
|
if (changed_md5(av)) {
|
2022-08-27 20:49:37 +02:00
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('antivirals')} to {usethis::ui_value('data-raw/')}"))
|
2020-09-14 12:21:23 +02:00
|
|
|
write_md5(av)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(saveRDS(antivirals, "data-raw/antivirals.rds", version = 2, compress = "xz"), silent = TRUE)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(av, "data-raw/antivirals.xpt"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
try(haven::write_sav(av, "data-raw/antivirals.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(av, "data-raw/antivirals.dta"), silent = TRUE)
|
2022-10-29 16:17:48 +02:00
|
|
|
av_lists <- antivirals %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
|
|
|
|
try(write.table(av_lists, "data-raw/antivirals.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(av_lists, "data-raw/antivirals.xlsx"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(arrow::write_feather(antivirals, "data-raw/antivirals.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(antivirals, "data-raw/antivirals.parquet"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 21:47:14 +01:00
|
|
|
# give official names to ABs and MOs
|
2022-08-28 10:31:50 +02:00
|
|
|
intrinsicR <- data.frame(
|
2022-10-05 09:12:22 +02:00
|
|
|
microorganism = mo_name(intrinsic_resistant$mo, language = NULL, keep_synonyms = TRUE, info = FALSE),
|
2022-08-28 10:31:50 +02:00
|
|
|
antibiotic = ab_name(intrinsic_resistant$ab, language = NULL),
|
|
|
|
stringsAsFactors = FALSE
|
|
|
|
)
|
2021-12-14 21:47:14 +01:00
|
|
|
if (changed_md5(intrinsicR)) {
|
2022-08-27 20:49:37 +02:00
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('intrinsic_resistant')} to {usethis::ui_value('data-raw/')}"))
|
2021-12-14 21:47:14 +01:00
|
|
|
write_md5(intrinsicR)
|
|
|
|
try(saveRDS(intrinsicR, "data-raw/intrinsic_resistant.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
|
|
try(write.table(intrinsicR, "data-raw/intrinsic_resistant.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(intrinsicR, "data-raw/intrinsic_resistant.xpt"), silent = TRUE)
|
2021-12-14 21:47:14 +01:00
|
|
|
try(haven::write_sav(intrinsicR, "data-raw/intrinsic_resistant.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(intrinsicR, "data-raw/intrinsic_resistant.dta"), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(intrinsicR, "data-raw/intrinsic_resistant.xlsx"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(arrow::write_feather(intrinsicR, "data-raw/intrinsic_resistant.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(intrinsicR, "data-raw/intrinsic_resistant.parquet"), silent = TRUE)
|
2020-09-14 12:21:23 +02:00
|
|
|
}
|
2020-08-16 21:38:42 +02:00
|
|
|
|
2021-01-18 16:57:56 +01:00
|
|
|
if (changed_md5(dosage)) {
|
2022-08-27 20:49:37 +02:00
|
|
|
usethis::ui_info(paste0("Saving {usethis::ui_value('dosage')} to {usethis::ui_value('data-raw/')}"))
|
2021-01-18 16:57:56 +01:00
|
|
|
write_md5(dosage)
|
|
|
|
try(saveRDS(dosage, "data-raw/dosage.rds", version = 2, compress = "xz"), silent = TRUE)
|
|
|
|
try(write.table(dosage, "data-raw/dosage.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
|
2023-05-12 10:07:55 +02:00
|
|
|
try(haven::write_xpt(dosage, "data-raw/dosage.xpt"), silent = TRUE)
|
2021-01-18 16:57:56 +01:00
|
|
|
try(haven::write_sav(dosage, "data-raw/dosage.sav"), silent = TRUE)
|
|
|
|
try(haven::write_dta(dosage, "data-raw/dosage.dta"), silent = TRUE)
|
2024-07-16 14:51:57 +02:00
|
|
|
try(openxlsx2::write_xlsx(dosage, "data-raw/dosage.xlsx"), silent = TRUE)
|
2022-08-26 22:25:15 +02:00
|
|
|
try(arrow::write_feather(dosage, "data-raw/dosage.feather"), silent = TRUE)
|
|
|
|
try(arrow::write_parquet(dosage, "data-raw/dosage.parquet"), silent = TRUE)
|
2021-01-18 16:57:56 +01:00
|
|
|
}
|
|
|
|
|
2022-08-27 20:49:37 +02:00
|
|
|
suppressMessages(reset_AMR_locale())
|
2022-08-19 12:33:14 +02:00
|
|
|
|
2022-08-26 22:25:15 +02:00
|
|
|
devtools::load_all(quiet = TRUE)
|
2022-08-28 22:38:08 +02:00
|
|
|
suppressMessages(set_AMR_locale("English"))
|
2022-08-28 10:31:50 +02:00
|
|
|
|
2022-08-28 19:17:12 +02:00
|
|
|
# Update URLs -------------------------------------------------------------
|
|
|
|
usethis::ui_info("Checking URLs for redirects")
|
|
|
|
invisible(capture.output(urlchecker::url_update()))
|
|
|
|
|
|
|
|
|
2022-08-28 10:31:50 +02:00
|
|
|
# Document pkg ------------------------------------------------------------
|
|
|
|
usethis::ui_info("Documenting package")
|
|
|
|
suppressMessages(devtools::document(quiet = TRUE))
|
|
|
|
|
|
|
|
|
|
|
|
# Finished ----------------------------------------------------------------
|
2022-08-28 11:17:53 +02:00
|
|
|
usethis::ui_done("All done")
|
2022-08-28 22:38:08 +02:00
|
|
|
suppressMessages(reset_AMR_locale())
|