2020-01-05 17:22:09 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
# TITLE #
|
|
|
|
# Antimicrobial Resistance (AMR) Analysis #
|
|
|
|
# #
|
|
|
|
# SOURCE #
|
2020-07-09 20:07:39 +02:00
|
|
|
# https://github.com/msberends/AMR #
|
2020-01-05 17:22:09 +01:00
|
|
|
# #
|
|
|
|
# LICENCE #
|
|
|
|
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
|
|
|
# #
|
|
|
|
# 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-07-09 20:07:39 +02:00
|
|
|
# Visit our website for more info: https://msberends.github.io/AMR. #
|
2020-01-05 17:22:09 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
|
|
|
|
# Run this file to update the package using: -------------------------------
|
2019-10-23 14:48:25 +02:00
|
|
|
# source("data-raw/internals.R")
|
2020-01-05 17:22:09 +01:00
|
|
|
# --------------------------------------------------------------------------
|
2019-10-23 14:48:25 +02:00
|
|
|
|
|
|
|
# See 'data-raw/eucast_rules.tsv' for the EUCAST reference file
|
2019-11-15 15:25:03 +01:00
|
|
|
eucast_rules_file <- utils::read.delim(file = "data-raw/eucast_rules.tsv",
|
2019-08-06 14:39:22 +02:00
|
|
|
skip = 10,
|
2019-06-01 20:40:49 +02:00
|
|
|
sep = "\t",
|
|
|
|
stringsAsFactors = FALSE,
|
|
|
|
header = TRUE,
|
|
|
|
strip.white = TRUE,
|
2019-11-15 15:25:03 +01:00
|
|
|
na = c(NA, "", NULL))
|
2020-02-17 14:38:01 +01:00
|
|
|
# take the order of the reference.rule_group column in the original data file
|
2019-11-15 15:25:03 +01:00
|
|
|
eucast_rules_file$reference.rule_group <- factor(eucast_rules_file$reference.rule_group,
|
|
|
|
levels = unique(eucast_rules_file$reference.rule_group),
|
|
|
|
ordered = TRUE)
|
|
|
|
eucast_rules_file <- dplyr::arrange(eucast_rules_file,
|
2019-06-01 20:40:49 +02:00
|
|
|
reference.rule_group,
|
|
|
|
reference.rule)
|
2019-11-28 22:32:17 +01:00
|
|
|
eucast_rules_file$reference.rule_group <- as.character(eucast_rules_file$reference.rule_group)
|
2019-10-23 14:48:25 +02:00
|
|
|
|
2019-09-15 22:57:30 +02:00
|
|
|
# Translations ----
|
2019-06-07 22:47:37 +02:00
|
|
|
translations_file <- utils::read.delim(file = "data-raw/translations.tsv",
|
2019-06-01 20:40:49 +02:00
|
|
|
sep = "\t",
|
|
|
|
stringsAsFactors = FALSE,
|
|
|
|
header = TRUE,
|
|
|
|
blank.lines.skip = TRUE,
|
|
|
|
fill = TRUE,
|
|
|
|
strip.white = TRUE,
|
|
|
|
encoding = "UTF-8",
|
|
|
|
fileEncoding = "UTF-8",
|
2019-06-07 22:47:37 +02:00
|
|
|
na.strings = c(NA, "", NULL),
|
|
|
|
allowEscapes = TRUE, # else "\\1" will be imported as "\\\\1"
|
|
|
|
quote = "")
|
2019-06-01 20:40:49 +02:00
|
|
|
|
2019-09-18 15:46:09 +02:00
|
|
|
# Old microorganism codes -------------------------------------------------
|
|
|
|
|
|
|
|
microorganisms.translation <- readRDS("data-raw/microorganisms.translation.rds")
|
|
|
|
|
2019-06-01 20:40:49 +02:00
|
|
|
# Export to package as internal data ----
|
2019-09-18 15:46:09 +02:00
|
|
|
usethis::use_data(eucast_rules_file, translations_file, microorganisms.translation,
|
2019-06-01 20:40:49 +02:00
|
|
|
internal = TRUE,
|
|
|
|
overwrite = TRUE,
|
|
|
|
version = 2)
|
|
|
|
|
|
|
|
# Remove from global environment ----
|
|
|
|
rm(eucast_rules_file)
|
|
|
|
rm(translations_file)
|
2019-09-18 15:46:09 +02:00
|
|
|
rm(microorganisms.translation)
|
2019-09-15 22:57:30 +02:00
|
|
|
|
2020-02-01 15:09:36 +01:00
|
|
|
# Save to raw data to repository ----
|
|
|
|
usethis::ui_done(paste0("Saving raw data to {usethis::ui_value('/data-raw/')}"))
|
|
|
|
devtools::load_all(quiet = TRUE)
|
2020-02-14 19:54:13 +01:00
|
|
|
# give official names to ABs and MOs
|
2020-05-16 13:05:47 +02:00
|
|
|
write.table(dplyr::mutate(rsi_translation, ab = ab_name(ab), mo = mo_name(mo)),
|
2020-02-01 15:09:36 +01:00
|
|
|
"data-raw/rsi_translation.txt", sep = "\t", na = "", row.names = FALSE)
|
2020-05-16 13:05:47 +02:00
|
|
|
write.table(dplyr::mutate_if(microorganisms, ~!is.numeric(.), as.character),
|
2020-02-01 15:09:36 +01:00
|
|
|
"data-raw/microorganisms.txt", sep = "\t", na = "", row.names = FALSE)
|
2020-05-16 13:05:47 +02:00
|
|
|
write.table(dplyr::mutate_if(antibiotics, ~!is.numeric(.), as.character),
|
2020-02-01 15:09:36 +01:00
|
|
|
"data-raw/antibiotics.txt", sep = "\t", na = "", row.names = FALSE)
|
2020-05-16 13:05:47 +02:00
|
|
|
write.table(dplyr::mutate_all(antivirals, as.character),
|
2020-02-01 15:09:36 +01:00
|
|
|
"data-raw/antivirals.txt", sep = "\t", na = "", row.names = FALSE)
|