1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-12 01:42:08 +02:00

(v2.1.1.9123) add EFF code to antibiotics data set

This commit is contained in:
2025-01-15 16:14:09 +01:00
parent 2e31ec19c3
commit 08ddbaa930
32 changed files with 522 additions and 461 deletions

27
R/ab.R
View File

@ -687,3 +687,30 @@ get_translate_ab <- function(translate_ab) {
translate_ab
}
}
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(
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
)),
function(x) {
x <- generalise_antibiotic_name(unname(unlist(x)))
x[x != ""]
}
))
new_df[, colnames(new_df)[colnames(new_df) %like% "^generalised"]]
}

View File

@ -48,7 +48,7 @@
#' `r paste0(" * ", na.omit(sapply(DEFINED_AB_GROUPS, function(ab) ifelse(tolower(gsub("^AB_", "", ab)) %in% ls(envir = asNamespace("AMR")), paste0("[", tolower(gsub("^AB_", "", ab)), "()] can select: \\cr ", vector_and(paste0(ab_name(eval(parse(text = ab), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), " (", eval(parse(text = ab), envir = asNamespace("AMR")), ")"), quotes = FALSE, sort = TRUE)), character(0)), USE.NAMES = FALSE)), "\n", collapse = "")`
#' @rdname antibiotic_class_selectors
#' @name antibiotic_class_selectors
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"ab_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobial that the function would be able to select or filter.
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"ab_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobials that the function would be able to select or filter.
#' @export
#' @inheritSection AMR Reference Data Publicly Available
#' @examples
@ -418,6 +418,13 @@ penicillins <- function(only_sir_columns = FALSE, ...) {
ab_select_exec("penicillins", only_sir_columns = only_sir_columns)
}
#' @rdname antibiotic_class_selectors
#' @export
phenicols <- function(only_sir_columns = FALSE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("phenicols", only_sir_columns = only_sir_columns)
}
#' @rdname antibiotic_class_selectors
#' @export
polymyxins <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
@ -675,17 +682,16 @@ ab_select_exec <- function(function_name,
}
if (is.null(vars_df)) {
# no data found, no antimicrobials, so no input. Can happen if users run e.g. `aminoglycosides()` as a separate command.
# no data found, no antimicrobials, so no input. Happens if users run e.g. `aminoglycosides()` as a separate command.
examples <- paste0(
", e.g.:\n",
" ", AMR_env$bullet_icon, " your_data %>% select(", function_name, "())\n",
" ", AMR_env$bullet_icon, " your_data %>% select(column_a, column_b, ", function_name, "())\n",
" ", AMR_env$bullet_icon, " your_data %>% filter(any(", function_name, "() == \"R\"))\n",
" ", AMR_env$bullet_icon, " your_data[, ", function_name, "()]\n",
" ", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]"
)
message_("The function `" , function_name, "()` should be used inside a `dplyr` verb or `data.frame` call",
examples, "\n\nNow returning a vector of all possible antimicrobials that `" , function_name, "()` can select.")
" ", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]")
message_("The function `" , function_name, "()` should be used inside a `dplyr` verb or `data.frame` call, e.g.:\n",
examples,
"\n\nNow returning a vector of all possible antimicrobials that `" , function_name, "()` can select.")
return(sort(abx))
}

Binary file not shown.

View File

@ -200,10 +200,14 @@ AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE)
if (pkg_is_available("tibble")) {
try(loadNamespace("tibble"), silent = TRUE)
}
# reference data - they have additional data to improve algorithm speed
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
if (NROW(AB_LOOKUP) != NROW(AMR::antibiotics)) {
# antibiotics data set was updated - run create_AB_AV_lookup() again
AB_LOOKUP <- create_AB_AV_lookup(AMR::antibiotics)
}
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
}