mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 06:46:11 +01:00
(v0.9.0.9023) EUCAST 2020 guidelines
This commit is contained in:
parent
5a98e6b777
commit
9b8b02960e
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.9.0.9022
|
||||
Date: 2020-02-10
|
||||
Version: 0.9.0.9023
|
||||
Date: 2020-02-14
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(role = c("aut", "cre"),
|
||||
|
8
NEWS.md
8
NEWS.md
@ -1,7 +1,9 @@
|
||||
# AMR 0.9.0.9022
|
||||
## <small>Last updated: 10-Feb-2020</small>
|
||||
# AMR 0.9.0.9023
|
||||
## <small>Last updated: 14-Feb-2020</small>
|
||||
|
||||
### New
|
||||
* Support for the newest EUCAST Clinical Breakpoint Tables v.10.0, valid from 2020-01-01 (use `as.rsi()` to transform MICs or disk zones)
|
||||
* The repository of this package now contains a clean version of the EUCAST and CLSI guidelines from 2011-2020 to translate MIC and disk diffusion values to R/SI: https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt. This **allows for machine reading these guidelines**, which is almost impossible with the Excel and PDF files distributed by EUCAST and CLSI. This file is updated automatically.
|
||||
* Support for LOINC and SNOMED codes
|
||||
* Support for LOINC codes in the `antibiotics` data set. Use `ab_loinc()` to retrieve LOINC codes, or use a LOINC code for input in any `ab_*` function:
|
||||
```r
|
||||
@ -21,7 +23,6 @@
|
||||
mo_gramstain(115329001)
|
||||
#> [1] "Gram-positive"
|
||||
```
|
||||
* The repository of this package now contains a clean version of the EUCAST and CLSI guidelines from 2011-2019 to translate MIC and disk diffusion values to R/SI: https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt. This **allows for machine reading these guidelines**, which is almost impossible with the Excel and PDF files distributed by EUCAST and CLSI. This file is updated automatically.
|
||||
|
||||
### Changes
|
||||
* The `as.mo()` function previously wrote to the package folder to improve calculation speed for previously calculated results. This is no longer the case, to comply with CRAN policies. Consequently, the function `clear_mo_history()` was removed.
|
||||
@ -42,6 +43,7 @@
|
||||
### Other
|
||||
* Add a `CITATION` file
|
||||
* Full support for the upcoming R 4.0
|
||||
* Removed unnecessary `AMR::` calls
|
||||
|
||||
# AMR 0.9.0
|
||||
|
||||
|
39
R/ab.R
39
R/ab.R
@ -66,11 +66,14 @@
|
||||
#' ab_name("J01FA01") # "Erythromycin"
|
||||
#' ab_name("eryt") # "Erythromycin"
|
||||
as.ab <- function(x, ...) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (is.ab(x)) {
|
||||
return(x)
|
||||
}
|
||||
|
||||
if (all(toupper(x) %in% AMR::antibiotics$ab)) {
|
||||
if (all(toupper(x) %in% antibiotics$ab)) {
|
||||
# valid AB code, but not yet right class
|
||||
return(structure(.Data = toupper(x),
|
||||
class = "ab"))
|
||||
@ -117,67 +120,67 @@ as.ab <- function(x, ...) {
|
||||
}
|
||||
|
||||
# exact AB code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$ab == toupper(x[i])), ]$ab
|
||||
found <- antibiotics[which(antibiotics$ab == toupper(x[i])), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact ATC code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$atc == toupper(x[i])), ]$ab
|
||||
found <- antibiotics[which(antibiotics$atc == toupper(x[i])), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact CID code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$cid == x[i]), ]$ab
|
||||
found <- antibiotics[which(antibiotics$cid == x[i]), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact name
|
||||
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) == toupper(x[i])), ]$ab
|
||||
found <- antibiotics[which(toupper(antibiotics$name) == toupper(x[i])), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact LOINC code
|
||||
loinc_found <- unlist(lapply(AMR::antibiotics$loinc,
|
||||
loinc_found <- unlist(lapply(antibiotics$loinc,
|
||||
function(s) if (x[i] %in% s) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[loinc_found == TRUE]
|
||||
found <- antibiotics$ab[loinc_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact synonym
|
||||
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
|
||||
synonym_found <- unlist(lapply(antibiotics$synonyms,
|
||||
function(s) if (toupper(x[i]) %in% toupper(s)) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[synonym_found == TRUE]
|
||||
found <- antibiotics$ab[synonym_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact abbreviation
|
||||
abbr_found <- unlist(lapply(AMR::antibiotics$abbreviations,
|
||||
abbr_found <- unlist(lapply(antibiotics$abbreviations,
|
||||
function(a) if (toupper(x[i]) %in% toupper(a)) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[abbr_found == TRUE]
|
||||
found <- antibiotics$ab[abbr_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
@ -185,7 +188,7 @@ as.ab <- function(x, ...) {
|
||||
|
||||
# first >=4 characters of name
|
||||
if (nchar(x[i]) >= 4) {
|
||||
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) %like% paste0("^", x[i])), ]$ab
|
||||
found <- antibiotics[which(toupper(antibiotics$name) %like% paste0("^", x[i])), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
@ -215,19 +218,19 @@ as.ab <- function(x, ...) {
|
||||
x_spelling <- gsub("(.)\\1+", "\\1+", x_spelling)
|
||||
|
||||
# try if name starts with it
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$name %like% paste0("^", x_spelling)), ]$ab
|
||||
found <- antibiotics[which(antibiotics$name %like% paste0("^", x_spelling)), ]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
# and try if any synonym starts with it
|
||||
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
|
||||
synonym_found <- unlist(lapply(antibiotics$synonyms,
|
||||
function(s) if (any(s %like% paste0("^", x_spelling))) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[synonym_found == TRUE]
|
||||
found <- antibiotics$ab[synonym_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
@ -374,7 +377,7 @@ as.data.frame.ab <- function(x, ...) {
|
||||
"[<-.ab" <- function(i, j, ..., value) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab)
|
||||
class_integrity_check(y, "antimicrobial code", antibiotics$ab)
|
||||
}
|
||||
#' @exportMethod [[<-.ab
|
||||
#' @export
|
||||
@ -382,7 +385,7 @@ as.data.frame.ab <- function(x, ...) {
|
||||
"[[<-.ab" <- function(i, j, ..., value) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab)
|
||||
class_integrity_check(y, "antimicrobial code", antibiotics$ab)
|
||||
}
|
||||
#' @exportMethod c.ab
|
||||
#' @export
|
||||
@ -390,7 +393,7 @@ as.data.frame.ab <- function(x, ...) {
|
||||
c.ab <- function(x, ...) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(x)
|
||||
class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab)
|
||||
class_integrity_check(y, "antimicrobial code", antibiotics$ab)
|
||||
}
|
||||
|
||||
#' @importFrom pillar type_sum
|
||||
|
@ -168,7 +168,7 @@ ab_ddd <- function(x, administration = "oral", units = FALSE, ...) {
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_info <- function(x, language = get_locale(), ...) {
|
||||
x <- AMR::as.ab(x, ...)
|
||||
x <- as.ab(x, ...)
|
||||
base::list(ab = as.character(x),
|
||||
atc = ab_atc(x),
|
||||
cid = ab_cid(x),
|
||||
@ -189,7 +189,7 @@ ab_property <- function(x, property = "name", language = get_locale(), ...) {
|
||||
if (length(property) != 1L) {
|
||||
stop("'property' must be of length 1.")
|
||||
}
|
||||
if (!property %in% colnames(AMR::antibiotics)) {
|
||||
if (!property %in% colnames(antibiotics)) {
|
||||
stop("invalid property: '", property, "' - use a column name of the `antibiotics` data set")
|
||||
}
|
||||
|
||||
@ -197,14 +197,17 @@ ab_property <- function(x, property = "name", language = get_locale(), ...) {
|
||||
}
|
||||
|
||||
ab_validate <- function(x, property, ...) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
# try to catch an error when inputting an invalid parameter
|
||||
# so the 'call.' can be set to FALSE
|
||||
tryCatch(x[1L] %in% AMR::antibiotics[1, property],
|
||||
tryCatch(x[1L] %in% antibiotics[1, property],
|
||||
error = function(e) stop(e$message, call. = FALSE))
|
||||
x_bak <- x
|
||||
if (!all(x %in% AMR::antibiotics[, property])) {
|
||||
x <- data.frame(ab = AMR::as.ab(x, ...), stringsAsFactors = FALSE) %>%
|
||||
left_join(AMR::antibiotics, by = "ab") %>%
|
||||
if (!all(x %in% antibiotics[, property])) {
|
||||
x <- data.frame(ab = as.ab(x, ...), stringsAsFactors = FALSE) %>%
|
||||
left_join(antibiotics, by = "ab") %>%
|
||||
pull(property)
|
||||
}
|
||||
if (property == "ab") {
|
||||
|
@ -77,11 +77,13 @@ atc_online_property <- function(atc_code,
|
||||
administration = "O",
|
||||
url = "https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no") {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (!all(c("curl", "rvest", "xml2") %in% rownames(utils::installed.packages()))) {
|
||||
stop("Packages 'xml2', 'rvest' and 'curl' are required for this function")
|
||||
}
|
||||
|
||||
if (!all(atc_code %in% AMR::antibiotics)) {
|
||||
if (!all(atc_code %in% antibiotics)) {
|
||||
atc_code <- as.character(ab_atc(atc_code))
|
||||
}
|
||||
|
||||
|
@ -91,20 +91,23 @@ NULL
|
||||
#' microorganisms %>% freq(kingdom)
|
||||
#' microorganisms %>% group_by(kingdom) %>% freq(phylum, nmax = NULL)
|
||||
catalogue_of_life_version <- function() {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
# see the `catalogue_of_life` list in R/data.R
|
||||
lst <- list(catalogue_of_life =
|
||||
list(version = gsub("{year}", catalogue_of_life$year, catalogue_of_life$version, fixed = TRUE),
|
||||
url = gsub("{year}", catalogue_of_life$year, catalogue_of_life$url_CoL, fixed = TRUE),
|
||||
n = nrow(filter(AMR::microorganisms, source == "CoL"))),
|
||||
n = nrow(filter(microorganisms, source == "CoL"))),
|
||||
deutsche_sammlung_von_mikroorganismen_und_zellkulturen =
|
||||
list(version = "Prokaryotic Nomenclature Up-to-Date from DSMZ",
|
||||
url = catalogue_of_life$url_DSMZ,
|
||||
yearmonth = catalogue_of_life$yearmonth_DSMZ,
|
||||
n = nrow(filter(AMR::microorganisms, source == "DSMZ"))),
|
||||
n = nrow(filter(microorganisms, source == "DSMZ"))),
|
||||
total_included =
|
||||
list(
|
||||
n_total_species = nrow(AMR::microorganisms),
|
||||
n_total_synonyms = nrow(AMR::microorganisms.old)))
|
||||
n_total_species = nrow(microorganisms),
|
||||
n_total_synonyms = nrow(microorganisms.old)))
|
||||
|
||||
structure(.Data = lst,
|
||||
class = c("catalogue_of_life_version", "list"))
|
||||
|
@ -30,7 +30,7 @@
|
||||
#' @rdname AMR-deprecated
|
||||
p.symbol <- function(...) {
|
||||
.Deprecated("p_symbol()", package = "AMR")
|
||||
AMR::p_symbol(...)
|
||||
p_symbol(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
|
@ -202,6 +202,8 @@ eucast_rules <- function(x,
|
||||
verbose = FALSE,
|
||||
...) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (verbose == TRUE & interactive()) {
|
||||
txt <- paste0("WARNING: In Verbose mode, the eucast_rules() function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way.",
|
||||
"\n\nThis may overwrite your existing data if you use e.g.:",
|
||||
@ -564,7 +566,7 @@ eucast_rules <- function(x,
|
||||
strsplit(",") %>%
|
||||
unlist() %>%
|
||||
trimws() %>%
|
||||
sapply(function(x) if (x %in% AMR::antibiotics$ab) ab_name(x, language = NULL, tolower = TRUE) else x) %>%
|
||||
sapply(function(x) if (x %in% antibiotics$ab) ab_name(x, language = NULL, tolower = TRUE) else x) %>%
|
||||
sort() %>%
|
||||
paste(collapse = ", ")
|
||||
x <- gsub("_", " ", x, fixed = TRUE)
|
||||
@ -664,8 +666,8 @@ eucast_rules <- function(x,
|
||||
# Print rule -------------------------------------------------------------
|
||||
if (rule_current != rule_previous) {
|
||||
# is new rule within group, print its name
|
||||
if (rule_current %in% c(AMR::microorganisms$family,
|
||||
AMR::microorganisms$fullname)) {
|
||||
if (rule_current %in% c(microorganisms$family,
|
||||
microorganisms$fullname)) {
|
||||
cat(italic(rule_current))
|
||||
} else {
|
||||
cat(rule_current)
|
||||
@ -681,7 +683,7 @@ eucast_rules <- function(x,
|
||||
# be sure to comprise all coagulase-negative/-positive Staphylococci when they are mentioned
|
||||
if (eucast_rules_df[i, 3] %like% "coagulase-") {
|
||||
suppressWarnings(
|
||||
all_staph <- AMR::microorganisms %>%
|
||||
all_staph <- microorganisms %>%
|
||||
filter(genus == "Staphylococcus") %>%
|
||||
mutate(CNS_CPS = mo_name(mo, Becker = "all"))
|
||||
)
|
||||
|
@ -24,7 +24,7 @@
|
||||
#' Filter isolates on results in specific antibiotic variables based on their class (ATC groups). This makes it easy to get a list of isolates that were tested for e.g. any aminoglycoside.
|
||||
#' @inheritSection lifecycle Stable lifecycle
|
||||
#' @param x a data set
|
||||
#' @param ab_class an antimicrobial class, like `"carbapenems"`, as can be found in [`AMR::antibiotics$group`][antibiotics]
|
||||
#' @param ab_class an antimicrobial class, like `"carbapenems"`, as can be found in [`antibiotics$group`][antibiotics]
|
||||
#' @param result an antibiotic result: S, I or R (or a combination of more of them)
|
||||
#' @param scope the scope to check which variables to check, can be `"any"` (default) or `"all"`
|
||||
#' @param ... parameters passed on to `filter_at` from the `dplyr` package
|
||||
@ -67,6 +67,9 @@ filter_ab_class <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
scope <- scope[1L]
|
||||
if (is.null(result)) {
|
||||
result <- c("S", "I", "R")
|
||||
@ -276,7 +279,7 @@ filter_tetracyclines <- function(x,
|
||||
#' @importFrom dplyr %>% filter_at vars any_vars select
|
||||
ab_class_vars <- function(ab_class) {
|
||||
ab_class <- gsub("[^a-z0-9]+", ".*", ab_class)
|
||||
ab_vars <- AMR::antibiotics %>%
|
||||
ab_vars <- antibiotics %>%
|
||||
filter(group %like% ab_class) %>%
|
||||
select(ab:name, abbreviations, synonyms) %>%
|
||||
unlist() %>%
|
||||
@ -289,7 +292,7 @@ ab_class_vars <- function(ab_class) {
|
||||
ab_vars <- ab_vars[!ab_vars %in% c(NA, "", "NA") & nchar(ab_vars) > 2]
|
||||
if (length(ab_vars) == 0) {
|
||||
# try again, searching atc_group1 and atc_group2 columns
|
||||
ab_vars <- AMR::antibiotics %>%
|
||||
ab_vars <- antibiotics %>%
|
||||
filter_at(vars(c("atc_group1", "atc_group2")), any_vars(. %like% ab_class)) %>%
|
||||
select(ab:name, abbreviations, synonyms) %>%
|
||||
unlist() %>%
|
||||
@ -314,7 +317,7 @@ find_ab_group <- function(ab_class) {
|
||||
"macrolide",
|
||||
"tetracycline"),
|
||||
paste0(ab_class, "s"),
|
||||
AMR::antibiotics %>%
|
||||
antibiotics %>%
|
||||
filter(ab %in% ab_class_vars(ab_class)) %>%
|
||||
pull(group) %>%
|
||||
unique() %>%
|
||||
|
6
R/freq.R
6
R/freq.R
@ -58,14 +58,14 @@ freq.mo <- function(x, ...) {
|
||||
freq.rsi <- function(x, ...) {
|
||||
x_name <- deparse(substitute(x))
|
||||
x_name <- gsub(".*[$]", "", x_name)
|
||||
ab <- suppressMessages(suppressWarnings(AMR::as.ab(x_name)))
|
||||
ab <- suppressMessages(suppressWarnings(as.ab(x_name)))
|
||||
if (!is.na(ab)) {
|
||||
freq.default(x = x, ...,
|
||||
.add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"),
|
||||
group = ab_group(ab),
|
||||
`%SI` = AMR::susceptibility(x, minimum = 0, as_percent = TRUE)))
|
||||
`%SI` = susceptibility(x, minimum = 0, as_percent = TRUE)))
|
||||
} else {
|
||||
freq.default(x = x, ...,
|
||||
.add_header = list(`%SI` = AMR::susceptibility(x, minimum = 0, as_percent = TRUE)))
|
||||
.add_header = list(`%SI` = susceptibility(x, minimum = 0, as_percent = TRUE)))
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ geom_rsi <- function(position = NULL,
|
||||
ggplot2::layer(geom = "bar", stat = "identity", position = position,
|
||||
mapping = ggplot2::aes_string(x = x, y = y, fill = fill),
|
||||
params = list(...), data = function(x) {
|
||||
AMR::rsi_df(data = x,
|
||||
rsi_df(data = x,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
combine_SI = combine_SI,
|
||||
|
@ -126,7 +126,7 @@ get_column_abx <- function(x,
|
||||
# only check columns that are a valid AB code, ATC code, name, abbreviation or synonym,
|
||||
# or already have the rsi class (as.rsi)
|
||||
# and that have no more than 50% invalid values
|
||||
vectr_antibiotics <- unique(toupper(unlist(AMR::antibiotics[, c("ab", "atc", "name", "abbreviations", "synonyms")])))
|
||||
vectr_antibiotics <- unique(toupper(unlist(antibiotics[, c("ab", "atc", "name", "abbreviations", "synonyms")])))
|
||||
vectr_antibiotics <- vectr_antibiotics[!is.na(vectr_antibiotics) & nchar(vectr_antibiotics) >= 3]
|
||||
x_columns <- sapply(colnames(x), function(col, df = x_bak) {
|
||||
if (toupper(col) %in% vectr_antibiotics |
|
||||
@ -205,7 +205,7 @@ get_column_abx <- function(x,
|
||||
# missing a soft dependency may lower the reliability
|
||||
missing <- soft_dependencies[!soft_dependencies %in% names(x)]
|
||||
missing_txt <- data.frame(missing = missing,
|
||||
missing_names = AMR::ab_name(missing, tolower = TRUE),
|
||||
missing_names = ab_name(missing, tolower = TRUE),
|
||||
stringsAsFactors = FALSE) %>%
|
||||
mutate(txt = paste0(bold(missing), " (", missing_names, ")")) %>%
|
||||
arrange(missing_names) %>%
|
||||
|
@ -54,7 +54,7 @@ inner_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::inner_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
dplyr::inner_join(x = x, y = microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
|
||||
@ -69,7 +69,7 @@ left_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::left_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
dplyr::left_join(x = x, y = microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
|
||||
@ -84,7 +84,7 @@ right_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::right_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
dplyr::right_join(x = x, y = microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
|
||||
@ -99,7 +99,7 @@ full_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::full_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
dplyr::full_join(x = x, y = microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
|
||||
@ -114,7 +114,7 @@ semi_join_microorganisms <- function(x, by = NULL, ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
suppressWarnings(
|
||||
dplyr::semi_join(x = x, y = AMR::microorganisms, by = by, ...)
|
||||
dplyr::semi_join(x = x, y = microorganisms, by = by, ...)
|
||||
)
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ anti_join_microorganisms <- function(x, by = NULL, ...) {
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
suppressWarnings(
|
||||
dplyr::anti_join(x = x, y = AMR::microorganisms, by = by, ...)
|
||||
dplyr::anti_join(x = x, y = microorganisms, by = by, ...)
|
||||
)
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ joins_check_df <- function(x, by) {
|
||||
message('Joining, by = "', by, '"') # message same as dplyr::join functions
|
||||
}
|
||||
if (is.null(names(by))) {
|
||||
joinby <- colnames(AMR::microorganisms)[1]
|
||||
joinby <- colnames(microorganisms)[1]
|
||||
names(joinby) <- by
|
||||
} else {
|
||||
joinby <- by
|
||||
|
4
R/like.R
4
R/like.R
@ -52,8 +52,8 @@
|
||||
#' # get frequencies of bacteria whose name start with 'Ent' or 'ent'
|
||||
#' library(dplyr)
|
||||
#' example_isolates %>%
|
||||
#' filter(mo_genus(mo) %like% '^ent') %>%
|
||||
#' freq(mo_fullname(mo))
|
||||
#' filter(mo_name(mo) %like% '^ent') %>%
|
||||
#' freq(mo_genus(mo))
|
||||
like <- function(x, pattern, ignore.case = TRUE) {
|
||||
if (length(pattern) > 1) {
|
||||
if (length(x) != length(pattern)) {
|
||||
|
4
R/mdro.R
4
R/mdro.R
@ -90,6 +90,8 @@ mdro <- function(x,
|
||||
verbose = FALSE,
|
||||
...) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (verbose == TRUE & interactive()) {
|
||||
txt <- paste0("WARNING: In Verbose mode, the mdro() function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.",
|
||||
"\n\nThis may overwrite your existing data if you use e.g.:",
|
||||
@ -147,7 +149,7 @@ mdro <- function(x,
|
||||
if (is.null(col_mo) & guideline$code == "tb") {
|
||||
message(blue("NOTE: No column found as input for `col_mo`,",
|
||||
bold("assuming all records contain", italic("Mycobacterium tuberculosis.\n"))))
|
||||
x$mo <- AMR::as.mo("Mycobacterium tuberculosis")
|
||||
x$mo <- as.mo("Mycobacterium tuberculosis")
|
||||
col_mo <- "mo"
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
|
24
R/misc.R
24
R/misc.R
@ -29,12 +29,23 @@ addin_insert_like <- function() {
|
||||
rstudioapi::insertText(" %like% ")
|
||||
}
|
||||
|
||||
load_AMR_package <- function() {
|
||||
if (!"package:AMR" %in% base::search()) {
|
||||
require(AMR)
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
check_dataset_integrity <- function() {
|
||||
if (!all(colnames(microorganisms) %in% c("mo", "fullname", "kingdom", "phylum",
|
||||
"class", "order", "family", "genus",
|
||||
"species", "subspecies", "rank",
|
||||
"col_id", "species_id", "source",
|
||||
"ref", "prevalence", "snomed"),
|
||||
na.rm = TRUE) |
|
||||
NROW(microorganisms) != NROW(microorganismsDT) |
|
||||
!all(colnames(antibiotics) %in% c("ab", "atc", "cid", "name", "group",
|
||||
"atc_group1", "atc_group2", "abbreviations",
|
||||
"synonyms", "oral_ddd", "oral_units",
|
||||
"iv_ddd", "iv_units", "loinc"),
|
||||
na.rm = TRUE)) {
|
||||
stop("Data set `microorganisms` or data set `antibiotics` is overwritten by your global environment and prevents the AMR package from working correctly. Please rename your object before using this function.", call. = FALSE)
|
||||
}
|
||||
base::invisible()
|
||||
|
||||
invisible(TRUE)
|
||||
}
|
||||
|
||||
#' @importFrom crayon blue bold red
|
||||
@ -155,9 +166,6 @@ dataset_UTF8_to_ASCII <- function(df) {
|
||||
col <- df[, i]
|
||||
if (is.list(col)) {
|
||||
col <- lapply(col, function(j) trans(j))
|
||||
# for (j in seq_len(length(col))) {
|
||||
# col[[j]] <- trans(col[[j]])
|
||||
# }
|
||||
df[, i] <- list(col)
|
||||
} else {
|
||||
if (is.factor(col)) {
|
||||
|
30
R/mo.R
30
R/mo.R
@ -175,7 +175,7 @@ as.mo <- function(x,
|
||||
reference_df = get_mo_source(),
|
||||
...) {
|
||||
|
||||
load_AMR_package()
|
||||
check_dataset_integrity()
|
||||
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
@ -238,7 +238,7 @@ is.mo <- function(x) {
|
||||
#' @importFrom data.table data.table as.data.table setkey
|
||||
#' @importFrom crayon magenta red blue silver italic
|
||||
#' @importFrom cleaner percentage
|
||||
# param property a column name of AMR::microorganisms
|
||||
# param property a column name of microorganisms
|
||||
# param initial_search logical - is FALSE when coming from uncertain tries, which uses exec_as.mo internally too
|
||||
# param dyslexia_mode logical - also check for characters that resemble others
|
||||
# param debug logical - show different lookup texts while searching
|
||||
@ -254,7 +254,7 @@ exec_as.mo <- function(x,
|
||||
debug = FALSE,
|
||||
reference_data_to_use = microorganismsDT) {
|
||||
|
||||
load_AMR_package()
|
||||
check_dataset_integrity()
|
||||
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
@ -365,7 +365,7 @@ exec_as.mo <- function(x,
|
||||
suppressWarnings(
|
||||
x <- data.frame(x = x, stringsAsFactors = FALSE) %>%
|
||||
left_join(reference_df, by = "x") %>%
|
||||
left_join(AMR::microorganisms, by = "mo") %>%
|
||||
left_join(microorganisms, by = "mo") %>%
|
||||
pull(property)
|
||||
)
|
||||
|
||||
@ -393,9 +393,9 @@ exec_as.mo <- function(x,
|
||||
on = "fullname_lower",
|
||||
..property][[1]]
|
||||
|
||||
} else if (all(toupper(x) %in% AMR::microorganisms.codes$code)) {
|
||||
} else if (all(toupper(x) %in% microorganisms.codes$code)) {
|
||||
# commonly used MO codes
|
||||
y <- as.data.table(AMR::microorganisms.codes)[data.table(code = toupper(x)),
|
||||
y <- as.data.table(microorganisms.codes)[data.table(code = toupper(x)),
|
||||
on = "code", ]
|
||||
|
||||
x <- reference_data_to_use[data.table(mo = y[["mo"]]),
|
||||
@ -412,7 +412,7 @@ exec_as.mo <- function(x,
|
||||
..property][[1]]
|
||||
x <- y
|
||||
|
||||
} else if (!all(x %in% AMR::microorganisms[, property])) {
|
||||
} else if (!all(x %in% microorganisms[, property])) {
|
||||
|
||||
strip_whitespace <- function(x, dyslexia_mode) {
|
||||
# all whitespaces (tab, new lines, etc.) should be one space
|
||||
@ -632,8 +632,8 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
|
||||
# WHONET and other common LIS codes
|
||||
if (any(toupper(c(x_backup[i], x_backup_without_spp[i])) %in% AMR::microorganisms.codes$code)) {
|
||||
mo_found <- AMR::microorganisms.codes[which(AMR::microorganisms.codes$code %in% toupper(c(x_backup[i], x_backup_without_spp[i]))), "mo"][1L]
|
||||
if (any(toupper(c(x_backup[i], x_backup_without_spp[i])) %in% microorganisms.codes$code)) {
|
||||
mo_found <- microorganisms.codes[which(microorganisms.codes$code %in% toupper(c(x_backup[i], x_backup_without_spp[i]))), "mo"][1L]
|
||||
if (length(mo_found) > 0) {
|
||||
x[i] <- microorganismsDT[mo == mo_found,
|
||||
..property][[1]][1L]
|
||||
@ -1476,8 +1476,7 @@ exec_as.mo <- function(x,
|
||||
msg <- paste0(msg, ": ", paste('"', unique(failures), '"', sep = "", collapse = ", "))
|
||||
}
|
||||
msg <- paste0(msg, ". Use mo_failures() to review ", plural[2], ". Edit the `allow_uncertain` parameter if needed (see ?as.mo).")
|
||||
cat("\n")
|
||||
warning(red(msg),
|
||||
warning(red(paste0("\n", msg)),
|
||||
call. = FALSE,
|
||||
immediate. = TRUE) # thus will always be shown, even if >= warnings
|
||||
}
|
||||
@ -1491,8 +1490,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
msg <- paste0("Result", plural[1], " of ", nr2char(NROW(uncertainties)), " value", plural[1],
|
||||
" ", plural[3], " guessed with uncertainty. Use mo_uncertainties() to review ", plural[2], ".")
|
||||
cat("\n")
|
||||
warning(red(msg),
|
||||
warning(red(paste0("\n", msg)),
|
||||
call. = FALSE,
|
||||
immediate. = TRUE) # thus will always be shown, even if >= warnings
|
||||
}
|
||||
@ -1753,7 +1751,7 @@ as.data.frame.mo <- function(x, ...) {
|
||||
"[<-.mo" <- function(i, j, ..., value) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo),
|
||||
class_integrity_check(y, "microorganism code", c(as.character(microorganisms$mo),
|
||||
as.character(microorganisms.translation$mo_old)))
|
||||
}
|
||||
#' @exportMethod [[<-.mo
|
||||
@ -1762,7 +1760,7 @@ as.data.frame.mo <- function(x, ...) {
|
||||
"[[<-.mo" <- function(i, j, ..., value) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo),
|
||||
class_integrity_check(y, "microorganism code", c(as.character(microorganisms$mo),
|
||||
as.character(microorganisms.translation$mo_old)))
|
||||
}
|
||||
#' @exportMethod c.mo
|
||||
@ -1771,7 +1769,7 @@ as.data.frame.mo <- function(x, ...) {
|
||||
c.mo <- function(x, ...) {
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(x)
|
||||
class_integrity_check(y, "microorganism code", c(as.character(AMR::microorganisms$mo),
|
||||
class_integrity_check(y, "microorganism code", c(as.character(microorganisms$mo),
|
||||
as.character(microorganisms.translation$mo_old)))
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ mo_fullname <- mo_name
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_shortname <- function(x, language = get_locale(), ...) {
|
||||
x.mo <- AMR::as.mo(x, ...)
|
||||
x.mo <- as.mo(x, ...)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
replace_empty <- function(x) {
|
||||
@ -223,7 +223,7 @@ mo_type <- function(x, language = get_locale(), ...) {
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_gramstain <- function(x, language = get_locale(), ...) {
|
||||
x.mo <- AMR::as.mo(x, ...)
|
||||
x.mo <- as.mo(x, ...)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
x.phylum <- mo_phylum(x.mo)
|
||||
@ -290,17 +290,17 @@ mo_rank <- function(x, ...) {
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_taxonomy <- function(x, language = get_locale(), ...) {
|
||||
x <- AMR::as.mo(x, ...)
|
||||
x <- as.mo(x, ...)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
result <- base::list(kingdom = AMR::mo_kingdom(x, language = language),
|
||||
phylum = AMR::mo_phylum(x, language = language),
|
||||
class = AMR::mo_class(x, language = language),
|
||||
order = AMR::mo_order(x, language = language),
|
||||
family = AMR::mo_family(x, language = language),
|
||||
genus = AMR::mo_genus(x, language = language),
|
||||
species = AMR::mo_species(x, language = language),
|
||||
subspecies = AMR::mo_subspecies(x, language = language))
|
||||
result <- base::list(kingdom = mo_kingdom(x, language = language),
|
||||
phylum = mo_phylum(x, language = language),
|
||||
class = mo_class(x, language = language),
|
||||
order = mo_order(x, language = language),
|
||||
family = mo_family(x, language = language),
|
||||
genus = mo_genus(x, language = language),
|
||||
species = mo_species(x, language = language),
|
||||
subspecies = mo_subspecies(x, language = language))
|
||||
|
||||
load_mo_failures_uncertainties_renamed(metadata)
|
||||
result
|
||||
@ -309,12 +309,12 @@ mo_taxonomy <- function(x, language = get_locale(), ...) {
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_synonyms <- function(x, ...) {
|
||||
x <- AMR::as.mo(x, ...)
|
||||
x <- as.mo(x, ...)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
IDs <- AMR::mo_property(x = x, property = "col_id", language = NULL)
|
||||
IDs <- mo_property(x = x, property = "col_id", language = NULL)
|
||||
syns <- lapply(IDs, function(col_id) {
|
||||
res <- sort(AMR::microorganisms.old[which(AMR::microorganisms.old$col_id_new == col_id), "fullname"])
|
||||
res <- sort(microorganisms.old[which(microorganisms.old$col_id_new == col_id), "fullname"])
|
||||
if (length(res) == 0) {
|
||||
NULL
|
||||
} else {
|
||||
@ -335,7 +335,7 @@ mo_synonyms <- function(x, ...) {
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_info <- function(x, language = get_locale(), ...) {
|
||||
x <- AMR::as.mo(x, ...)
|
||||
x <- as.mo(x, ...)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
info <- lapply(x, function(y)
|
||||
@ -360,12 +360,12 @@ mo_info <- function(x, language = get_locale(), ...) {
|
||||
#' @importFrom dplyr %>% left_join select mutate case_when
|
||||
#' @export
|
||||
mo_url <- function(x, open = FALSE, ...) {
|
||||
mo <- AMR::as.mo(x = x, ... = ...)
|
||||
mo_names <- AMR::mo_name(mo)
|
||||
mo <- as.mo(x = x, ... = ...)
|
||||
mo_names <- mo_name(mo)
|
||||
metadata <- get_mo_failures_uncertainties_renamed()
|
||||
|
||||
df <- data.frame(mo, stringsAsFactors = FALSE) %>%
|
||||
left_join(select(AMR::microorganisms, mo, source, species_id), by = "mo") %>%
|
||||
left_join(select(microorganisms, mo, source, species_id), by = "mo") %>%
|
||||
mutate(url = case_when(source == "CoL" ~
|
||||
paste0(gsub("{year}", catalogue_of_life$year, catalogue_of_life$url_CoL, fixed = TRUE), "details/species/id/", species_id),
|
||||
source == "DSMZ" ~
|
||||
@ -394,7 +394,7 @@ mo_property <- function(x, property = "fullname", language = get_locale(), ...)
|
||||
if (length(property) != 1L) {
|
||||
stop("'property' must be of length 1.")
|
||||
}
|
||||
if (!property %in% colnames(AMR::microorganisms)) {
|
||||
if (!property %in% colnames(microorganisms)) {
|
||||
stop("invalid property: '", property, "' - use a column name of the `microorganisms` data set")
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ mo_property <- function(x, property = "fullname", language = get_locale(), ...)
|
||||
|
||||
mo_validate <- function(x, property, ...) {
|
||||
|
||||
load_AMR_package()
|
||||
check_dataset_integrity()
|
||||
|
||||
dots <- list(...)
|
||||
Becker <- dots$Becker
|
||||
@ -417,7 +417,7 @@ mo_validate <- function(x, property, ...) {
|
||||
|
||||
# try to catch an error when inputting an invalid parameter
|
||||
# so the 'call.' can be set to FALSE
|
||||
tryCatch(x[1L] %in% AMR::microorganisms[1, property],
|
||||
tryCatch(x[1L] %in% microorganisms[1, property],
|
||||
error = function(e) stop(e$message, call. = FALSE))
|
||||
|
||||
if (is.mo(x)
|
||||
@ -426,7 +426,7 @@ mo_validate <- function(x, property, ...) {
|
||||
# this will not reset mo_uncertainties and mo_failures
|
||||
# because it's already a valid MO
|
||||
x <- exec_as.mo(x, property = property, initial_search = FALSE, ...)
|
||||
} else if (!all(x %in% pull(AMR::microorganisms, property))
|
||||
} else if (!all(x %in% pull(microorganisms, property))
|
||||
| Becker %in% c(TRUE, "all")
|
||||
| Lancefield %in% c(TRUE, "all")) {
|
||||
x <- exec_as.mo(x, property = property, ...)
|
||||
|
@ -202,6 +202,9 @@ get_mo_source <- function() {
|
||||
}
|
||||
|
||||
mo_source_isvalid <- function(x) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (deparse(substitute(x)) == "get_mo_source()") {
|
||||
return(TRUE)
|
||||
}
|
||||
@ -217,5 +220,5 @@ mo_source_isvalid <- function(x) {
|
||||
if (!"mo" %in% colnames(x)) {
|
||||
return(FALSE)
|
||||
}
|
||||
all(x$mo %in% c("", AMR::microorganisms$mo, microorganisms.translation$mo_old), na.rm = TRUE)
|
||||
all(x$mo %in% c("", microorganisms$mo, microorganisms.translation$mo_old), na.rm = TRUE)
|
||||
}
|
||||
|
26
R/rsi.R
26
R/rsi.R
@ -28,10 +28,10 @@
|
||||
#' @param mo a microorganism code, generated with [as.mo()]
|
||||
#' @param ab an antimicrobial code, generated with [as.ab()]
|
||||
#' @inheritParams first_isolate
|
||||
#' @param guideline defaults to the latest included EUCAST guideline, run `unique(AMR::rsi_translation$guideline)` for all options
|
||||
#' @param guideline defaults to the latest included EUCAST guideline, run `unique(rsi_translation$guideline)` for all options
|
||||
#' @param threshold maximum fraction of invalid antimicrobial interpretations of `x`, please see *Examples*
|
||||
#' @param ... parameters passed on to methods
|
||||
#' @details Run `unique(AMR::rsi_translation$guideline)` for a list of all supported guidelines. The repository of this package contains [this machine readable version](https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt) of these guidelines.
|
||||
#' @details Run `unique(rsi_translation$guideline)` for a list of all supported guidelines. The repository of this package contains [this machine readable version](https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt) of these guidelines.
|
||||
#'
|
||||
#' These guidelines are machine readable, since [](https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt).
|
||||
#'
|
||||
@ -66,11 +66,12 @@
|
||||
#' # interpret MIC values
|
||||
#' as.rsi(x = as.mic(2),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' ab = "AMP",
|
||||
#' guideline = "EUCAST")
|
||||
#' as.rsi(x = as.mic(4),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#'
|
||||
#' as.rsi(x = as.disk(18),
|
||||
#' mo = "Strep pneu", # `mo` will be coerced with as.mo()
|
||||
#' ab = "ampicillin", # and `ab` with as.ab()
|
||||
#' guideline = "EUCAST")
|
||||
#'
|
||||
#' plot(rsi_data) # for percentages
|
||||
@ -188,7 +189,7 @@ as.rsi.disk <- function(x, mo, ab, guideline = "EUCAST", ...) {
|
||||
get_guideline <- function(guideline) {
|
||||
guideline_param <- toupper(guideline)
|
||||
if (guideline_param %in% c("CLSI", "EUCAST")) {
|
||||
guideline_param <- AMR::rsi_translation %>%
|
||||
guideline_param <- rsi_translation %>%
|
||||
filter(guideline %like% guideline_param) %>%
|
||||
pull(guideline) %>%
|
||||
sort() %>%
|
||||
@ -196,9 +197,9 @@ get_guideline <- function(guideline) {
|
||||
.[1]
|
||||
}
|
||||
|
||||
if (!guideline_param %in% AMR::rsi_translation$guideline) {
|
||||
if (!guideline_param %in% rsi_translation$guideline) {
|
||||
stop(paste0("invalid guideline: '", guideline,
|
||||
"'.\nValid guidelines are: ", paste0("'", rev(sort(unique(AMR::rsi_translation$guideline))), "'", collapse = ", ")),
|
||||
"'.\nValid guidelines are: ", paste0("'", rev(sort(unique(rsi_translation$guideline))), "'", collapse = ", ")),
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
@ -222,6 +223,7 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) {
|
||||
mo_order <- as.mo(mo_order(mo))
|
||||
mo_becker <- as.mo(mo, Becker = TRUE)
|
||||
mo_lancefield <- as.mo(mo, Lancefield = TRUE)
|
||||
mo_other <- as.mo("other")
|
||||
|
||||
guideline_coerced <- get_guideline(guideline)
|
||||
if (guideline_coerced != guideline) {
|
||||
@ -229,7 +231,7 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) {
|
||||
}
|
||||
|
||||
new_rsi <- rep(NA_character_, length(x))
|
||||
trans <- AMR::rsi_translation %>%
|
||||
trans <- rsi_translation %>%
|
||||
filter(guideline == guideline_coerced & method == method_param) %>%
|
||||
mutate(lookup = paste(mo, ab))
|
||||
|
||||
@ -239,6 +241,7 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) {
|
||||
lookup_order <- paste(mo_order, ab)
|
||||
lookup_becker <- paste(mo_becker, ab)
|
||||
lookup_lancefield <- paste(mo_lancefield, ab)
|
||||
lookup_other <- paste(mo_other, ab)
|
||||
|
||||
for (i in seq_len(length(x))) {
|
||||
get_record <- trans %>%
|
||||
@ -247,7 +250,8 @@ exec_as.rsi <- function(method, x, mo, ab, guideline) {
|
||||
lookup_family[i],
|
||||
lookup_order[i],
|
||||
lookup_becker[i],
|
||||
lookup_lancefield[i])) %>%
|
||||
lookup_lancefield[i],
|
||||
lookup_other[i])) %>%
|
||||
# be as specific as possible (i.e. prefer species over genus):
|
||||
arrange(desc(nchar(mo))) %>%
|
||||
.[1L, ]
|
||||
|
@ -179,6 +179,8 @@ rsi_calc_df <- function(type, # "proportion" or "count"
|
||||
combine_IR = FALSE,
|
||||
combine_SI_missing = FALSE) {
|
||||
|
||||
check_dataset_integrity()
|
||||
|
||||
if (!"data.frame" %in% class(data)) {
|
||||
stop(paste0("`", type, "_df` must be called on a data.frame"), call. = FALSE)
|
||||
}
|
||||
@ -252,7 +254,7 @@ rsi_calc_df <- function(type, # "proportion" or "count"
|
||||
arrange(antibiotic, interpretation)
|
||||
|
||||
if (!translate_ab == FALSE) {
|
||||
res <- res %>% mutate(antibiotic = AMR::ab_property(antibiotic, property = translate_ab, language = language))
|
||||
res <- res %>% mutate(antibiotic = ab_property(antibiotic, property = translate_ab, language = language))
|
||||
}
|
||||
|
||||
as.data.frame(res, stringsAsFactors = FALSE)
|
||||
|
@ -73,7 +73,8 @@ rm(microorganisms.translation)
|
||||
library(dplyr, warn.conflicts = FALSE, quietly = TRUE)
|
||||
usethis::ui_done(paste0("Saving raw data to {usethis::ui_value('/data-raw/')}"))
|
||||
devtools::load_all(quiet = TRUE)
|
||||
write.table(AMR::rsi_translation,
|
||||
# give official names to ABs and MOs
|
||||
write.table(rsi_translation %>% mutate(ab = ab_name(ab), mo = mo_name(mo)),
|
||||
"data-raw/rsi_translation.txt", sep = "\t", na = "", row.names = FALSE)
|
||||
write.table(microorganisms %>% mutate_if(~!is.numeric(.), as.character),
|
||||
"data-raw/microorganisms.txt", sep = "\t", na = "", row.names = FALSE)
|
||||
|
206
data-raw/read_EUCAST.R
Normal file
206
data-raw/read_EUCAST.R
Normal file
@ -0,0 +1,206 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# 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. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
library(openxlsx)
|
||||
library(dplyr)
|
||||
library(cleaner)
|
||||
library(AMR)
|
||||
|
||||
read_EUCAST <- function(sheet, file = "data-raw/v_10.0_Breakpoint_Tables.xlsx") {
|
||||
|
||||
message("Getting sheet ", sheet)
|
||||
sheet.bak <- sheet
|
||||
|
||||
raw_data <- read.xlsx(xlsxFile = file,
|
||||
sheet = sheet,
|
||||
colNames = FALSE,
|
||||
skipEmptyRows = FALSE,
|
||||
skipEmptyCols = FALSE,
|
||||
fillMergedCells = TRUE,
|
||||
na.strings = c("", "-", "NA", "IE", "IP"))
|
||||
|
||||
# in the info header in the Excel file, EUCAST mentions which genera are targeted
|
||||
if (sheet %like% "anaerob.*Gram.*posi") {
|
||||
sheet <- paste0(c("Actinomyces", "Bifidobacterium", "Clostridioides",
|
||||
"Clostridium", "Cutibacterium", "Eggerthella",
|
||||
"Eubacterium", "Lactobacillus", "Propionibacterium",
|
||||
"Staphylococcus saccharolyticus"),
|
||||
collapse = "_")
|
||||
} else if (sheet %like% "anaerob.*Gram.*nega") {
|
||||
sheet <- paste0(c("Bacteroides",
|
||||
"Bilophila",
|
||||
"Fusobacterium",
|
||||
"Mobiluncus",
|
||||
"Parabacteroides",
|
||||
"Porphyromonas",
|
||||
"Prevotella"),
|
||||
collapse = "_")
|
||||
} else if (sheet == "Streptococcus A,B,C,G") {
|
||||
sheet <- paste0(microorganisms %>%
|
||||
filter(genus == "Streptococcus") %>%
|
||||
mutate(lancefield = mo_name(mo, Lancefield = TRUE)) %>%
|
||||
filter(lancefield %like% "^Streptococcus group") %>%
|
||||
pull(fullname),
|
||||
collapse = "_")
|
||||
} else if (sheet %like% "PK.*PD") {
|
||||
sheet <- "UNKNOWN"
|
||||
}
|
||||
mo_sheet <- paste0(as.mo(unlist(strsplit(sheet, "_"))), collapse = "|")
|
||||
|
||||
set_columns_names <- function(x, cols) {
|
||||
colnames(x) <- cols[1:length(colnames(x))]
|
||||
x
|
||||
}
|
||||
|
||||
get_mo <- function(x) {
|
||||
for (i in seq_len(length(x))) {
|
||||
y <- trimws(unlist(strsplit(x[i], "(,|and)")))
|
||||
y <- trimws(gsub("[(].*[)]", "", y))
|
||||
y <- suppressWarnings(as.mo(y, allow_uncertain = FALSE))
|
||||
y <- y[!is.na(y) & y != "UNKNOWN"]
|
||||
x[i] <- paste(y, collapse = "|")
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
MICs_with_trailing_superscript <- c(0.0011:0.0019, 11:19, 21:29, 0.51:0.59, 41:49,
|
||||
81:89, 0.031:0.039, 0.061:0.069, 0.251:0.259,
|
||||
0.1251:0.1259, 161:169, 321:329)
|
||||
|
||||
has_zone_diameters <- rep(any(unlist(raw_data) %like% "zone diameter"), nrow(raw_data))
|
||||
|
||||
cleaned <- raw_data %>%
|
||||
as_tibble() %>%
|
||||
set_columns_names(LETTERS) %>%
|
||||
transmute(drug = A,
|
||||
MIC_S = B,
|
||||
MIC_R = C,
|
||||
disk_dose = ifelse(has_zone_diameters, E, NA_character_),
|
||||
disk_S = ifelse(has_zone_diameters, `F`, NA_character_),
|
||||
disk_R = ifelse(has_zone_diameters, G, NA_character_)) %>%
|
||||
filter(!is.na(drug),
|
||||
!(is.na(MIC_S) & is.na(MIC_R) & is.na(disk_S) & is.na(disk_R)),
|
||||
!MIC_S %like% "(MIC|S ≤|note)",
|
||||
drug != MIC_S) %>%
|
||||
mutate(administration = case_when(drug %like% "[( ]oral" ~ "oral",
|
||||
drug %like% "[( ]iv" ~ "iv",
|
||||
TRUE ~ NA_character_),
|
||||
uti = ifelse(drug %like% "(UTI|urinary|urine)", TRUE, FALSE),
|
||||
systemic = ifelse(drug %like% "(systemic|septic)", TRUE, FALSE),
|
||||
mo = ifelse(drug %like% "([.]|spp)", get_mo(drug), mo_sheet)) %>%
|
||||
# clean disk doses
|
||||
mutate(disk_dose = clean_character(disk_dose, remove = "[^0-9.-]")) %>%
|
||||
# clean MIC and disk values
|
||||
mutate(MIC_S = gsub(".,.", "", MIC_S), # remove superscript notes with comma, like 0.5^2,3
|
||||
MIC_R = gsub(".,.", "", MIC_R),
|
||||
disk_S = gsub(".,.", "", disk_S),
|
||||
disk_R = gsub(".,.", "", disk_R),
|
||||
MIC_S = clean_double(MIC_S), # make them valid numeric values
|
||||
MIC_R = clean_double(MIC_R),
|
||||
disk_S = clean_integer(disk_S),
|
||||
disk_R = clean_integer(disk_R),
|
||||
# invalid MIC values have a superscript text, delete those
|
||||
MIC_S = ifelse(MIC_S %in% MICs_with_trailing_superscript,
|
||||
substr(MIC_S, 1, nchar(MIC_S) - 1),
|
||||
MIC_S),
|
||||
MIC_R = ifelse(MIC_R %in% MICs_with_trailing_superscript,
|
||||
substr(MIC_R, 1, nchar(MIC_R) - 1),
|
||||
MIC_R)
|
||||
) %>%
|
||||
# clean drug names
|
||||
mutate(drug = gsub(" ?[(, ].*$", "", drug),
|
||||
drug = gsub("[1-9]+$", "", drug),
|
||||
ab = as.ab(drug)) %>%
|
||||
select(ab, mo, everything(), -drug)
|
||||
|
||||
# new row for every different MO mentioned
|
||||
for (i in 1:nrow(cleaned)) {
|
||||
mo <- cleaned[i, "mo", drop = TRUE]
|
||||
if (grepl(pattern = "|", mo, fixed = TRUE)) {
|
||||
mo_vect <- unlist(strsplit(mo, "|", fixed = TRUE))
|
||||
cleaned[i, "mo"] <- mo_vect[1]
|
||||
for (j in seq_len(length(mo_vect))) {
|
||||
cleaned <- bind_rows(cleaned, cleaned[i ,])
|
||||
cleaned[nrow(cleaned), "mo"] <- mo_vect[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleaned <- cleaned %>%
|
||||
distinct(ab, mo, administration, uti, systemic, .keep_all = TRUE) %>%
|
||||
arrange(ab, mo) %>%
|
||||
mutate_at(c("MIC_S", "MIC_R", "disk_S", "disk_R"), as.double) %>%
|
||||
pivot_longer(c("MIC_S", "MIC_R", "disk_S", "disk_R"), "type") %>%
|
||||
mutate(method = ifelse(type %like% "MIC", "MIC", "DISK"),
|
||||
type = gsub("^.*_", "breakpoint_", type)) %>%
|
||||
pivot_wider(names_from = type, values_from = value) %>%
|
||||
mutate(guideline = "EUCAST 2020",
|
||||
disk_dose = ifelse(method == "DISK", disk_dose, NA_character_),
|
||||
mo = ifelse(mo == "", mo_sheet, mo)) %>%
|
||||
filter(!(is.na(breakpoint_S) & is.na(breakpoint_R))) %>%
|
||||
# comply with rsi_translation for now
|
||||
transmute(guideline,
|
||||
method,
|
||||
site = case_when(uti ~ "UTI",
|
||||
systemic ~ "Systemic",
|
||||
TRUE ~ administration),
|
||||
mo, ab,
|
||||
ref_tbl = sheet.bak,
|
||||
disk_dose = ifelse(!is.na(disk_dose), paste0(disk_dose, "ug"), NA_character_),
|
||||
breakpoint_S,
|
||||
breakpoint_R)
|
||||
|
||||
cleaned
|
||||
}
|
||||
|
||||
sheets_to_analyse <- c("Enterobacterales",
|
||||
"Pseudomonas",
|
||||
"S.maltophilia",
|
||||
"Acinetobacter",
|
||||
"Staphylococcus",
|
||||
"Enterococcus",
|
||||
"Streptococcus A,B,C,G",
|
||||
"S.pneumoniae",
|
||||
"Viridans group streptococci",
|
||||
"H.influenzae",
|
||||
"M.catarrhalis",
|
||||
"N.gonorrhoeae",
|
||||
"N.meningitidis",
|
||||
"Anaerobes, Grampositive",
|
||||
"C.difficile",
|
||||
"Anaerobes, Gramnegative",
|
||||
"H.pylori",
|
||||
"L.monocytogenes",
|
||||
"P.multocida",
|
||||
"C.jejuni_C.coli",
|
||||
"Corynebacterium",
|
||||
"A.sanguinicola_A.urinae",
|
||||
"K.kingae",
|
||||
"Aeromonas",
|
||||
"B.pseudomallei",
|
||||
"M.tuberculosis",
|
||||
"PK PD breakpoints")
|
||||
|
||||
new_EUCAST <- read_EUCAST(sheets_to_analyse[1]) # takes the longest time
|
||||
for (i in 2:length(sheets_to_analyse)) {
|
||||
new_EUCAST <<- new_EUCAST %>% bind_rows(read_EUCAST(sheets_to_analyse[i]))
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ library(dplyr)
|
||||
# Installed WHONET 2019 software on Windows (http://www.whonet.org/software.html),
|
||||
# opened C:\WHONET\Codes\WHONETCodes.mdb in MS Access
|
||||
# and exported table 'DRGLST1' to MS Excel
|
||||
DRGLST1 <- readxl::read_excel("data-raw/DRGLST1.xlsx")
|
||||
DRGLST1 <- readxl::read_excel("data-raw/DRGLST1.xlsx", na = c("", "NA", "-"))
|
||||
rsi_translation <- DRGLST1 %>%
|
||||
# only keep CLSI and EUCAST guidelines:
|
||||
filter(GUIDELINES %like% "^(CLSI|EUCST)") %>%
|
||||
@ -38,11 +38,17 @@ tbl_disk <- rsi_translation %>%
|
||||
rsi_translation <- bind_rows(tbl_mic, tbl_disk) %>%
|
||||
rename(disk_dose = dose_disk) %>%
|
||||
mutate(disk_dose = gsub("µ", "u", disk_dose)) %>%
|
||||
select(-ends_with("_mic"), -ends_with("_disk")) %>%
|
||||
select(-ends_with("_mic"), -ends_with("_disk"))
|
||||
|
||||
# add new EUCAST with read_EUCAST.R
|
||||
rsi_translation <- rsi_translation %>%
|
||||
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))
|
||||
ab = as.ab(ab)) %>%
|
||||
arrange(desc(guideline), ab, mo, method)
|
||||
|
||||
# save to package
|
||||
usethis::use_data(rsi_translation, overwrite = TRUE)
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -84,7 +84,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -187,9 +187,9 @@
|
||||
|
||||
</header><div class="row">
|
||||
<div class="contents col-md-9">
|
||||
<div id="amr-for-r" class="section level1">
|
||||
<div id="amr-for-r-" class="section level1">
|
||||
<div class="page-header"><h1 class="hasAnchor">
|
||||
<a href="#amr-for-r" class="anchor"></a><code>AMR</code> (for R) <img src="./logo.png" align="right" height="120px">
|
||||
<a href="#amr-for-r-" class="anchor"></a><code>AMR</code> (for R) <img src="./logo.png" align="right" height="120px">
|
||||
</h1></div>
|
||||
<blockquote>
|
||||
<p><em>18 October 2019</em><br><strong>METHODS PAPER PREPRINTED</strong><br>
|
||||
@ -265,7 +265,7 @@ A methods paper about this package has been preprinted at bioRxiv (DOI: 10.1101/
|
||||
<h4 class="hasAnchor">
|
||||
<a href="#latest-released-version" class="anchor"></a>Latest released version</h4>
|
||||
<p>This package is available <a href="https://cran.r-project.org/package=AMR">here on the official R network (CRAN)</a>, which has a peer-reviewed submission process. Install this package in R from CRAN by using the command:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span>(<span class="st">"AMR"</span>)</a></code></pre></div>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1"></a><span class="kw"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span>(<span class="st">"AMR"</span>)</span></code></pre></div>
|
||||
<p>It will be downloaded and installed automatically. For RStudio, click on the menu <em>Tools</em> > <em>Install Packages…</em> and then type in “AMR” and press <kbd>Install</kbd>.</p>
|
||||
<p><strong>Note:</strong> Not all functions on this website may be available in this latest release. To use all functions and data sets mentioned on this website, install the latest development version.</p>
|
||||
</div>
|
||||
@ -273,8 +273,8 @@ A methods paper about this package has been preprinted at bioRxiv (DOI: 10.1101/
|
||||
<h4 class="hasAnchor">
|
||||
<a href="#latest-development-version" class="anchor"></a>Latest development version</h4>
|
||||
<p>The latest and unpublished development version can be installed with (<strong>precaution: may be unstable</strong>):</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="kw"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span>(<span class="st">"devtools"</span>)</a>
|
||||
<a class="sourceLine" id="cb2-2" data-line-number="2">devtools<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/devtools/man/remote-reexports.html">install_gitlab</a></span>(<span class="st">"msberends/AMR"</span>)</a></code></pre></div>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1"></a><span class="kw"><a href="https://rdrr.io/r/utils/install.packages.html">install.packages</a></span>(<span class="st">"devtools"</span>)</span>
|
||||
<span id="cb2-2"><a href="#cb2-2"></a>devtools<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/devtools/man/remote-reexports.html">install_gitlab</a></span>(<span class="st">"msberends/AMR"</span>)</span></code></pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="get-started" class="section level3">
|
||||
@ -298,9 +298,9 @@ A methods paper about this package has been preprinted at bioRxiv (DOI: 10.1101/
|
||||
<p><strong>NOTE: The WHOCC copyright does not allow use for commercial purposes, unlike any other info from this package. See <a href="https://www.whocc.no/copyright_disclaimer/" class="uri">https://www.whocc.no/copyright_disclaimer/</a>.</strong></p>
|
||||
<p>Read more about the data from WHOCC <a href="./reference/WHOCC.html">in our manual</a>.</p>
|
||||
</div>
|
||||
<div id="whonet-ears-net" class="section level4">
|
||||
<div id="whonet--ears-net" class="section level4">
|
||||
<h4 class="hasAnchor">
|
||||
<a href="#whonet-ears-net" class="anchor"></a>WHONET / EARS-Net</h4>
|
||||
<a href="#whonet--ears-net" class="anchor"></a>WHONET / EARS-Net</h4>
|
||||
<p>We support WHONET and EARS-Net data. Exported files from WHONET can be imported into R and can be analysed easily using this package. For education purposes, we created an <a href="./reference/WHONET.html">example data set <code>WHONET</code></a> with the exact same structure as a WHONET export file. Furthermore, this package also contains a <a href="./reference/antibiotics.html">data set antibiotics</a> with all EARS-Net antibiotic abbreviations, and knows almost all WHONET abbreviations for microorganisms. When using WHONET data as input for analysis, all input parameters will be set automatically.</p>
|
||||
<p>Read our tutorial about <a href="./articles/WHONET.html">how to work with WHONET data here</a>.</p>
|
||||
</div>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
pandoc: 2.3.1
|
||||
pandoc: 2.7.3
|
||||
pkgdown: 1.4.1
|
||||
pkgdown_sha: ~
|
||||
articles:
|
||||
|
@ -85,7 +85,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9016</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -273,7 +273,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>guideline</th>
|
||||
<td><p>defaults to the latest included EUCAST guideline, run <code><a href='https://rdrr.io/r/base/unique.html'>unique(AMR::rsi_translation$guideline)</a></code> for all options</p></td>
|
||||
<td><p>defaults to the latest included EUCAST guideline, run <code><a href='https://rdrr.io/r/base/unique.html'>unique(rsi_translation$guideline)</a></code> for all options</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>col_mo</th>
|
||||
@ -290,7 +290,7 @@
|
||||
<p>Ordered factor with new class <code>rsi</code></p>
|
||||
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
|
||||
|
||||
<p>Run <code><a href='https://rdrr.io/r/base/unique.html'>unique(AMR::rsi_translation$guideline)</a></code> for a list of all supported guidelines. The repository of this package contains <a href='https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt'>this machine readable version</a> of these guidelines.</p>
|
||||
<p>Run <code><a href='https://rdrr.io/r/base/unique.html'>unique(rsi_translation$guideline)</a></code> for a list of all supported guidelines. The repository of this package contains <a href='https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt'>this machine readable version</a> of these guidelines.</p>
|
||||
<p>These guidelines are machine readable, since <a href='https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt'></a>.</p>
|
||||
<p>After using <code>as.rsi()</code>, you can use <code><a href='eucast_rules.html'>eucast_rules()</a></code> to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.</p>
|
||||
<p>The function <code>is.rsi.eligible()</code> returns <code>TRUE</code> when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and <code>FALSE</code> otherwise. The threshold of 5% can be set with the <code>threshold</code> parameter.</p>
|
||||
@ -335,11 +335,12 @@ The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>stable</s
|
||||
<span class='co'># interpret MIC values</span>
|
||||
<span class='fu'>as.rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='fu'><a href='as.mic.html'>as.mic</a></span>(<span class='fl'>2</span>),
|
||||
<span class='kw'>mo</span> <span class='kw'>=</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='st'>"S. pneumoniae"</span>),
|
||||
<span class='kw'>ab</span> <span class='kw'>=</span> <span class='st'>"AMX"</span>,
|
||||
<span class='kw'>ab</span> <span class='kw'>=</span> <span class='st'>"AMP"</span>,
|
||||
<span class='kw'>guideline</span> <span class='kw'>=</span> <span class='st'>"EUCAST"</span>)
|
||||
<span class='fu'>as.rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='fu'><a href='as.mic.html'>as.mic</a></span>(<span class='fl'>4</span>),
|
||||
<span class='kw'>mo</span> <span class='kw'>=</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='st'>"S. pneumoniae"</span>),
|
||||
<span class='kw'>ab</span> <span class='kw'>=</span> <span class='st'>"AMX"</span>,
|
||||
|
||||
<span class='fu'>as.rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='fu'><a href='as.disk.html'>as.disk</a></span>(<span class='fl'>18</span>),
|
||||
<span class='kw'>mo</span> <span class='kw'>=</span> <span class='st'>"Strep pneu"</span>, <span class='co'># `mo` will be coerced with as.mo()</span>
|
||||
<span class='kw'>ab</span> <span class='kw'>=</span> <span class='st'>"ampicillin"</span>, <span class='co'># and `ab` with as.ab()</span>
|
||||
<span class='kw'>guideline</span> <span class='kw'>=</span> <span class='st'>"EUCAST"</span>)
|
||||
|
||||
<span class='fu'><a href='https://rdrr.io/r/graphics/plot.html'>plot</a></span>(<span class='no'>rsi_data</span>) <span class='co'># for percentages</span>
|
||||
|
@ -85,7 +85,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9013</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -272,7 +272,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ab_class</th>
|
||||
<td><p>an antimicrobial class, like <code>"carbapenems"</code>, as can be found in <code><a href='antibiotics.html'>AMR::antibiotics$group</a></code></p></td>
|
||||
<td><p>an antimicrobial class, like <code>"carbapenems"</code>, as can be found in <code><a href='antibiotics.html'>antibiotics$group</a></code></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>result</th>
|
||||
|
@ -84,7 +84,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9022</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -85,7 +85,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9013</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.9.0.9023</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -303,8 +303,8 @@ The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>stable</s
|
||||
<span class='co'># get frequencies of bacteria whose name start with 'Ent' or 'ent'</span>
|
||||
<span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>dplyr</span>)
|
||||
<span class='no'>example_isolates</span> <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='fu'><a href='mo_property.html'>mo_genus</a></span>(<span class='no'>mo</span>) <span class='kw'>%like%</span> <span class='st'>'^ent'</span>) <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='https://rdrr.io/pkg/cleaner/man/freq.html'>freq</a></span>(<span class='fu'><a href='mo_property.html'>mo_fullname</a></span>(<span class='no'>mo</span>))</pre>
|
||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='fu'><a href='mo_property.html'>mo_name</a></span>(<span class='no'>mo</span>) <span class='kw'>%like%</span> <span class='st'>'^ent'</span>) <span class='kw'>%>%</span>
|
||||
<span class='fu'><a href='https://rdrr.io/pkg/cleaner/man/freq.html'>freq</a></span>(<span class='fu'><a href='mo_property.html'>mo_genus</a></span>(<span class='no'>mo</span>))</pre>
|
||||
</div>
|
||||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||||
<h2>Contents</h2>
|
||||
|
@ -31,7 +31,7 @@ is.rsi.eligible(x, threshold = 0.05)
|
||||
|
||||
\item{ab}{an antimicrobial code, generated with \code{\link[=as.ab]{as.ab()}}}
|
||||
|
||||
\item{guideline}{defaults to the latest included EUCAST guideline, run \code{unique(AMR::rsi_translation$guideline)} for all options}
|
||||
\item{guideline}{defaults to the latest included EUCAST guideline, run \code{unique(rsi_translation$guideline)} for all options}
|
||||
|
||||
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
|
||||
|
||||
@ -44,7 +44,7 @@ Ordered factor with new class \code{\link{rsi}}
|
||||
Interpret MIC values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing R/SI values. This transforms the input to a new class \code{\link{rsi}}, which is an ordered factor with levels \verb{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning.
|
||||
}
|
||||
\details{
|
||||
Run \code{unique(AMR::rsi_translation$guideline)} for a list of all supported guidelines. The repository of this package contains \href{https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt}{this machine readable version} of these guidelines.
|
||||
Run \code{unique(rsi_translation$guideline)} for a list of all supported guidelines. The repository of this package contains \href{https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt}{this machine readable version} of these guidelines.
|
||||
|
||||
These guidelines are machine readable, since \href{https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt}{}.
|
||||
|
||||
@ -91,11 +91,12 @@ as.rsi("<= 0.002; S") # will return S
|
||||
# interpret MIC values
|
||||
as.rsi(x = as.mic(2),
|
||||
mo = as.mo("S. pneumoniae"),
|
||||
ab = "AMX",
|
||||
ab = "AMP",
|
||||
guideline = "EUCAST")
|
||||
as.rsi(x = as.mic(4),
|
||||
mo = as.mo("S. pneumoniae"),
|
||||
ab = "AMX",
|
||||
|
||||
as.rsi(x = as.disk(18),
|
||||
mo = "Strep pneu", # `mo` will be coerced with as.mo()
|
||||
ab = "ampicillin", # and `ab` with as.ab()
|
||||
guideline = "EUCAST")
|
||||
|
||||
plot(rsi_data) # for percentages
|
||||
|
@ -45,7 +45,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...)
|
||||
\arguments{
|
||||
\item{x}{a data set}
|
||||
|
||||
\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{\link[=antibiotics]{AMR::antibiotics$group}}}
|
||||
\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{\link[=antibiotics]{antibiotics$group}}}
|
||||
|
||||
\item{result}{an antibiotic result: S, I or R (or a combination of more of them)}
|
||||
|
||||
|
@ -62,8 +62,8 @@ a \%like\% b
|
||||
# get frequencies of bacteria whose name start with 'Ent' or 'ent'
|
||||
library(dplyr)
|
||||
example_isolates \%>\%
|
||||
filter(mo_genus(mo) \%like\% '^ent') \%>\%
|
||||
freq(mo_fullname(mo))
|
||||
filter(mo_name(mo) \%like\% '^ent') \%>\%
|
||||
freq(mo_genus(mo))
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[base:grep]{base::grep()}}
|
||||
|
@ -22,6 +22,9 @@
|
||||
context("data.R")
|
||||
|
||||
test_that("data sets are valid", {
|
||||
|
||||
expect_true(check_dataset_integrity()) # in misc.R
|
||||
|
||||
# IDs should always be unique
|
||||
expect_identical(nrow(microorganisms), length(unique(microorganisms$mo)))
|
||||
expect_identical(class(microorganisms$mo), "mo")
|
||||
|
@ -26,7 +26,7 @@ test_that("as.mo works", {
|
||||
skip_on_cran()
|
||||
|
||||
library(dplyr)
|
||||
MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
|
||||
MOs <- microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
|
||||
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo)))
|
||||
|
||||
expect_identical(
|
||||
|
@ -63,7 +63,7 @@ test_that("mo_property works", {
|
||||
expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org")
|
||||
|
||||
# test integrity
|
||||
MOs <- AMR::microorganisms
|
||||
MOs <- microorganisms
|
||||
expect_identical(MOs$fullname, mo_fullname(MOs$fullname, language = "en"))
|
||||
|
||||
# check languages
|
||||
|
Loading…
Reference in New Issue
Block a user