2019-05-10 16:44:59 +02:00
|
|
|
library(dplyr)
|
2020-07-29 10:33:47 +02:00
|
|
|
library(readr)
|
|
|
|
library(tidyr)
|
2019-05-10 16:44:59 +02:00
|
|
|
|
2021-06-01 15:33:06 +02:00
|
|
|
# Installed WHONET software on Windows (http://www.whonet.org/software.html),
|
|
|
|
# imported C:\WHONET\Codes\DRGLST1.txt
|
|
|
|
DRGLST1 <- readr::read_tsv("data-raw/DRGLST1.txt", na = c("", "NA", "-"))
|
2020-07-29 10:33:47 +02:00
|
|
|
rsi_trans <- DRGLST1 %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
# only keep CLSI and EUCAST guidelines:
|
2020-07-29 10:33:47 +02:00
|
|
|
filter(GUIDELINES %like% "^(CLSI|EUCST)")
|
|
|
|
if (any(is.na(rsi_trans$BREAKPOINT_TYPE)) | !"Human" %in% rsi_trans$BREAKPOINT_TYPE) {
|
|
|
|
stop("Check column BREAKPOINT_TYPE - something is WRONG!")
|
|
|
|
}
|
|
|
|
rsi_trans <- rsi_trans %>%
|
2021-06-01 15:33:06 +02:00
|
|
|
##### If looking for adding a specific guideline, do it here!
|
|
|
|
# filter(GUIDELINES == "CLSI20") %>%
|
|
|
|
#####
|
2020-07-29 10:33:47 +02:00
|
|
|
filter(BREAKPOINT_TYPE == "Human") %>%
|
2020-01-27 11:37:00 +01:00
|
|
|
mutate(DISK_S = ifelse(as.double(DISK_S) > 50, 50, DISK_S),
|
|
|
|
MIC_R = ifelse(as.double(MIC_R) %in% c(1025, 129, 513), as.double(MIC_R) - 1, MIC_R)) %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
# set a nice layout:
|
|
|
|
transmute(guideline = gsub("([0-9]+)$", " 20\\1", gsub("EUCST", "EUCAST", GUIDELINES)),
|
|
|
|
method = TESTMETHOD,
|
2019-10-23 14:48:25 +02:00
|
|
|
site = SITE_INF,
|
2019-05-10 16:44:59 +02:00
|
|
|
mo = as.mo(ORG_CODE),
|
|
|
|
ab = as.ab(WHON5_CODE),
|
|
|
|
ref_tbl = REF_TABLE,
|
|
|
|
dose_disk = POTENCY,
|
2020-01-27 11:37:00 +01:00
|
|
|
S_disk = as.disk(DISK_S),
|
2019-05-10 16:44:59 +02:00
|
|
|
R_disk = as.disk(DISK_R),
|
|
|
|
S_mic = as.mic(MIC_S),
|
2020-01-27 11:37:00 +01:00
|
|
|
R_mic = as.mic(MIC_R)) %>%
|
2020-02-20 13:19:23 +01:00
|
|
|
filter(!is.na(mo),
|
|
|
|
!is.na(ab),
|
|
|
|
!mo %in% c("UNKNOWN", "B_GRAMN", "B_GRAMP", "F_FUNGUS", "F_YEAST")) %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
arrange(desc(guideline), mo, ab)
|
|
|
|
|
2019-09-18 15:46:09 +02:00
|
|
|
print(mo_failures())
|
|
|
|
|
2019-05-10 16:44:59 +02:00
|
|
|
# create 2 tables: MIC and disk
|
2020-07-29 10:33:47 +02:00
|
|
|
tbl_mic <- rsi_trans %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
filter(method == "MIC") %>%
|
2019-10-23 14:48:25 +02:00
|
|
|
mutate(breakpoint_S = as.double(S_mic), breakpoint_R = as.double(R_mic))
|
2020-07-29 10:33:47 +02:00
|
|
|
tbl_disk <- rsi_trans %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
filter(method == "DISK") %>%
|
2019-10-23 14:48:25 +02:00
|
|
|
mutate(breakpoint_S = as.double(S_disk), breakpoint_R = as.double(R_disk))
|
2019-05-10 16:44:59 +02:00
|
|
|
|
|
|
|
# merge them so every record is a unique combination of method, mo and ab
|
2020-07-29 10:33:47 +02:00
|
|
|
rsi_trans <- bind_rows(tbl_mic, tbl_disk) %>%
|
2019-10-23 14:48:25 +02:00
|
|
|
rename(disk_dose = dose_disk) %>%
|
|
|
|
mutate(disk_dose = gsub("µ", "u", disk_dose)) %>%
|
2020-02-14 19:54:13 +01:00
|
|
|
select(-ends_with("_mic"), -ends_with("_disk"))
|
|
|
|
|
2020-04-14 14:12:31 +02:00
|
|
|
# add extra CLSI general guidelines
|
2021-06-01 15:33:06 +02:00
|
|
|
clsi_general <- readr::read_tsv("data-raw/DRGLST.txt") %>%
|
2020-04-14 14:12:31 +02:00
|
|
|
filter(CLSI == "X") %>%
|
|
|
|
select(WHON5_CODE,
|
|
|
|
disk_dose = POTENCY,
|
|
|
|
starts_with("CLSI"),
|
|
|
|
-c(CLSI, CLSI_ORDER)) %>%
|
|
|
|
mutate_at(vars(matches("CLSI")), as.double) %>%
|
|
|
|
pivot_longer(-c(WHON5_CODE, disk_dose)) %>%
|
|
|
|
mutate(method = ifelse(name %like% "_D", "DISK", "MIC"),
|
|
|
|
breakpoint = paste0("breakpoint_", gsub(".*([A-Z])$", "\\1", name)),
|
|
|
|
guideline = paste0("CLSI 20", cleaner::clean_integer(name))) %>%
|
|
|
|
filter(breakpoint != "breakpoint_I", !is.na(value)) %>%
|
|
|
|
select(-name) %>%
|
|
|
|
pivot_wider(names_from = breakpoint, values_from = value) %>%
|
|
|
|
transmute(guideline,
|
|
|
|
method,
|
|
|
|
site = NA_character_,
|
|
|
|
mo = as.mo("UNKNOWN"),
|
|
|
|
ab = as.ab(WHON5_CODE),
|
|
|
|
ref_tbl = "Generic CLSI rules",
|
|
|
|
disk_dose = gsub("/", "-", disk_dose, fixed = TRUE),
|
|
|
|
breakpoint_S,
|
|
|
|
breakpoint_R)
|
|
|
|
|
|
|
|
|
2020-02-14 19:54:13 +01:00
|
|
|
# add new EUCAST with read_EUCAST.R
|
2021-01-12 22:08:04 +01:00
|
|
|
|
2021-06-01 15:33:06 +02:00
|
|
|
# 2020-04-14 did that now for 2019 and 2020
|
2020-07-29 10:33:47 +02:00
|
|
|
rsi_trans <- rsi_trans %>%
|
|
|
|
filter(guideline != "EUCAST 2019") %>%
|
2020-02-14 19:54:13 +01:00
|
|
|
bind_rows(new_EUCAST) %>%
|
2020-04-14 14:12:31 +02:00
|
|
|
bind_rows(clsi_general) %>%
|
2021-06-01 15:33:06 +02:00
|
|
|
mutate(uti = site %like% "(UTI|urinary|urine)") %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
as.data.frame(stringsAsFactors = FALSE) %>%
|
|
|
|
# force classes again
|
|
|
|
mutate(mo = as.mo(mo),
|
2020-02-14 19:54:13 +01:00
|
|
|
ab = as.ab(ab)) %>%
|
|
|
|
arrange(desc(guideline), ab, mo, method)
|
2019-05-10 16:44:59 +02:00
|
|
|
|
2021-01-12 22:08:04 +01:00
|
|
|
# 2021-01-12 did that now for 2021
|
|
|
|
rsi_trans <- rsi_trans %>%
|
|
|
|
mutate(mo = as.character(mo)) %>%
|
|
|
|
bind_rows(new_EUCAST) %>%
|
|
|
|
mutate(uti = site %like% "(UTI|urinary)") %>%
|
|
|
|
as.data.frame(stringsAsFactors = FALSE) %>%
|
|
|
|
# force classes again
|
|
|
|
mutate(mo = as.mo(mo),
|
|
|
|
ab = as.ab(ab)) %>%
|
|
|
|
arrange(desc(guideline), ab, mo, method)
|
|
|
|
|
2019-05-10 16:44:59 +02:00
|
|
|
# save to package
|
2020-07-29 10:33:47 +02:00
|
|
|
rsi_translation <- rsi_trans
|
2019-05-10 16:44:59 +02:00
|
|
|
usethis::use_data(rsi_translation, overwrite = TRUE)
|
2020-07-29 10:33:47 +02:00
|
|
|
rm(rsi_trans)
|
2019-05-10 16:44:59 +02:00
|
|
|
rm(rsi_translation)
|
2019-09-20 12:33:05 +02:00
|
|
|
devtools::load_all(".")
|