1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 11:51:59 +02:00
This commit is contained in:
2019-05-13 12:21:57 +02:00
parent 38a4421450
commit 0dc0715dc6
21 changed files with 137 additions and 68 deletions

View File

@ -374,42 +374,42 @@ eucast_exceptional_phenotypes <- function(x, country = "EUCAST", ...) {
mdro(x = x, country = "EUCAST", ...)
}
is_ESBL <- function(x, col_mo = NULL, ...) {
col_mo <- get_column_mo(tbl = x, col_mo = col_mo)
cols_ab <- get_column_abx(tbl = x,
soft_dependencies = c("AMX", "AMP"),
hard_dependencies = c("CAZ"),
...)
if (!any(c("AMX", "AMP") %in% names(cols_ab))) {
# both ampicillin and amoxicillin are missing
generate_warning_abs_missing(c("AMX", "AMP"), any = TRUE)
return(rep(NA, nrow(x)))
}
ESBLs <- rep(NA, nrow(x))
# first make all eligible cases FALSE
ESBLs[which(mo_family(x[, col_mo]) == "Enterobacteriaceae"
& x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
& x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
& x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
)] <- FALSE
# now make the positives cases TRUE
ESBLs[which(!is.na(ESBLs)
& x[, get_ab_col(cols_ab, "AMX")] == "R"
& x[, get_ab_col(cols_ab, "CAZ")] == "R")] <- TRUE
ESBLs
}
is_3MRGN <- function(x, ...) {
}
is_4MRGN <- function(x, ...) {
}
# is_ESBL <- function(x, col_mo = NULL, ...) {
# col_mo <- get_column_mo(tbl = x, col_mo = col_mo)
# cols_ab <- get_column_abx(tbl = x,
# soft_dependencies = c("AMX", "AMP"),
# hard_dependencies = c("CAZ"),
# ...)
#
# if (!any(c("AMX", "AMP") %in% names(cols_ab))) {
# # both ampicillin and amoxicillin are missing
# generate_warning_abs_missing(c("AMX", "AMP"), any = TRUE)
# return(rep(NA, nrow(x)))
# }
#
# ESBLs <- rep(NA, nrow(x))
#
# # first make all eligible cases FALSE
# ESBLs[which(mo_family(x[, col_mo]) == "Enterobacteriaceae"
# & x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
# & x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
# & x[, get_ab_col(cols_ab, "AMX")] %in% c("R", "I", "S")
# )] <- FALSE
# # now make the positives cases TRUE
# ESBLs[which(!is.na(ESBLs)
# & x[, get_ab_col(cols_ab, "AMX")] == "R"
# & x[, get_ab_col(cols_ab, "CAZ")] == "R")] <- TRUE
# ESBLs
#
# }
#
# is_3MRGN <- function(x, ...) {
#
# }
#
# is_4MRGN <- function(x, ...) {
#
# }
get_column_mo <- function(tbl, col_mo = NULL) {
# throws a blue note about which column will be used if guessed

View File

@ -306,17 +306,17 @@ get_column_abx <- function(tbl,
TOB = TOB, TMP = TMP, SXT = SXT, VAN = VAN)
if (!is.null(hard_dependencies)) {
if (!all(hard_dependencies %in% names(columns_available))) {
if (!all(hard_dependencies %in% names(columns_available[!is.na(columns_available)]))) {
# missing a hard dependency will return NA and consequently the data will not be analysed
missing <- hard_dependencies[!hard_dependencies %in% names(columns_available)]
missing <- hard_dependencies[!hard_dependencies %in% names(columns_available[!is.na(columns_available)])]
generate_warning_abs_missing(missing, any = FALSE)
return(NA)
}
}
if (!is.null(soft_dependencies)) {
if (!all(soft_dependencies %in% names(columns_available))) {
if (!all(soft_dependencies %in% names(columns_available[!is.na(columns_available)]))) {
# missing a soft dependency may lower the reliability
missing <- soft_dependencies[!soft_dependencies %in% names(columns_available)]
missing <- soft_dependencies[!soft_dependencies %in% names(columns_available[!is.na(columns_available)])]
missing <- paste0("`", missing, "` (", ab_name(missing, tolower = TRUE), ")")
warning('Reliability might be improved if these antimicrobial results would be available too: ', paste(missing, collapse = ", "),
immediate. = TRUE,

32
R/mo.R
View File

@ -557,22 +557,22 @@ exec_as.mo <- function(x,
if (nchar(gsub("[^a-zA-Z]", "", x_trimmed[i])) < 3
& !x_backup_without_spp[i] %like% "O?(26|103|104|104|111|121|145|157)") {
# check if search term was like "A. species", then return first genus found with ^A
if (x_backup[i] %like% "[a-z]+ species" | x_backup[i] %like% "[a-z] spp[.]?") {
# get mo code of first hit
found <- microorganismsDT[fullname %like% x_withspaces_start_only[i], mo]
if (length(found) > 0) {
mo_code <- found[1L] %>% strsplit("_") %>% unlist() %>% .[1:2] %>% paste(collapse = "_")
found <- microorganismsDT[mo == mo_code, ..property][[1]]
# return first genus that begins with x_trimmed, e.g. when "E. spp."
if (length(found) > 0) {
x[i] <- found[1L]
if (initial_search == TRUE) {
set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history)
}
next
}
}
}
# if (x_backup[i] %like% "[a-z]+ species" | x_backup[i] %like% "[a-z] spp[.]?") {
# # get mo code of first hit
# found <- microorganismsDT[fullname %like% x_withspaces_start_only[i], mo]
# if (length(found) > 0) {
# mo_code <- found[1L] %>% strsplit("_") %>% unlist() %>% .[1:2] %>% paste(collapse = "_")
# found <- microorganismsDT[mo == mo_code, ..property][[1]]
# # return first genus that begins with x_trimmed, e.g. when "E. spp."
# if (length(found) > 0) {
# x[i] <- found[1L]
# if (initial_search == TRUE) {
# set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history)
# }
# next
# }
# }
# }
# fewer than 3 chars and not looked for species, add as failure
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
if (initial_search == TRUE) {

View File

@ -64,7 +64,8 @@
#' mo_subspecies("E. coli") # ""
#'
#' ## colloquial properties
#' mo_fullname("E. coli") # "Escherichia coli"
#' mo_name("E. coli") # "Escherichia coli"
#' mo_fullname("E. coli") # "Escherichia coli", same as mo_name()
#' mo_shortname("E. coli") # "E. coli"
#'
#' ## other properties
@ -131,6 +132,12 @@
#'
#' # get a list with the complete taxonomy (from kingdom to subspecies)
#' mo_taxonomy("E. coli")
mo_name <- function(x, language = get_locale(), ...) {
mo_fullname(x = x, language = language, ... = ...)
}
#' @rdname mo_property
#' @export
mo_fullname <- function(x, language = get_locale(), ...) {
x <- mo_validate(x = x, property = "fullname", ...)
t(x, language = language)

View File

@ -31,7 +31,8 @@
#' @param data a \code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}})
#' @param translate_ab a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations to, using \code{\link{ab_property}}
#' @inheritParams ab_property
#' @param combine_SI a logical to indicate whether all values of I and S must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}.
#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see below. Default is now \code{TRUE}.
#' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}.
#' @inheritSection as.rsi Interpretation of S, I and R
#' @details \strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set.
#'