1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 18:06:11 +01:00

Compare commits

...

3 Commits

28 changed files with 176 additions and 160 deletions

View File

@ -53,9 +53,11 @@ jobs:
- {os: macOS-latest, r: 'devel', allowfail: false} - {os: macOS-latest, r: 'devel', allowfail: false}
- {os: macOS-latest, r: 'release', allowfail: false} - {os: macOS-latest, r: 'release', allowfail: false}
- {os: macOS-latest, r: 'oldrel', allowfail: false} - {os: macOS-latest, r: 'oldrel', allowfail: false}
- {os: windows-latest, r: 'devel', allowfail: false} - {os: windows-latest, r: 'devel', allowfail: false}
- {os: windows-latest, r: 'release', allowfail: false} - {os: windows-latest, r: 'release', allowfail: false}
- {os: windows-latest, r: 'oldrel', allowfail: false} - {os: windows-latest, r: 'oldrel', allowfail: false}
- {os: ubuntu-20.04, r: 'devel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: 'devel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'release', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: 'release', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'oldrel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: 'oldrel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
@ -66,7 +68,8 @@ jobs:
- {os: ubuntu-20.04, r: '3.3', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: '3.3', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
# - {os: ubuntu-20.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} # - {os: ubuntu-20.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
# - {os: ubuntu-20.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} # - {os: ubuntu-20.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: '3.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: '3.0', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-16.04, r: 'devel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'devel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'release', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'release', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'oldrel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'oldrel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
@ -77,7 +80,7 @@ jobs:
- {os: ubuntu-16.04, r: '3.3', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.3', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
# - {os: ubuntu-16.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} # - {os: ubuntu-16.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
# - {os: ubuntu-16.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} # - {os: ubuntu-16.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.0', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
env: env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
@ -159,7 +162,7 @@ jobs:
_R_CHECK_LENGTH_1_CONDITION_: verbose _R_CHECK_LENGTH_1_CONDITION_: verbose
_R_CHECK_LENGTH_1_LOGIC2_: verbose _R_CHECK_LENGTH_1_LOGIC2_: verbose
run: | run: |
R CMD check data-raw/AMR_*.tar.gz --no-manual --no-build-vignettes R CMD check data-raw/AMR_latest.tar.gz --no-manual --no-build-vignettes
- name: Show testthat output - name: Show testthat output
if: always() if: always()

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.5.0.9020 Version: 1.5.0.9023
Date: 2021-02-18 Date: 2021-02-21
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Authors@R: c( Authors@R: c(
person(role = c("aut", "cre"), person(role = c("aut", "cre"),

View File

@ -1,5 +1,5 @@
# AMR 1.5.0.9020 # AMR 1.5.0.9023
## <small>Last updated: 18 February 2021</small> ## <small>Last updated: 21 February 2021</small>
### New ### New
* Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package. * Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package.
@ -58,6 +58,8 @@
* Functions `print()` and `summary()` on a Principal Components Analysis object (`pca()`) now print additional group info if the original data was grouped using `dplyr::group_by()` * Functions `print()` and `summary()` on a Principal Components Analysis object (`pca()`) now print additional group info if the original data was grouped using `dplyr::group_by()`
* Improved speed and reliability of `guess_ab_col()`. As this also internally improves the reliability of `first_isolate()` and `mdro()`, this might have a slight impact on the results of those functions. * Improved speed and reliability of `guess_ab_col()`. As this also internally improves the reliability of `first_isolate()` and `mdro()`, this might have a slight impact on the results of those functions.
* Fix for `mo_name()` when used in other languages than English * Fix for `mo_name()` when used in other languages than English
* The `like()` function (and its fast alias `%like%`) now always use Perl compatibility, improving speed for many functions in this package (e.g., `as.mo()` is now up to 4 times faster)
* *Staphylococcus cornubiensis* is now correctly categorised as coagulase-positive
### Other ### Other
* Big documentation updates * Big documentation updates

View File

@ -112,7 +112,7 @@ check_dataset_integrity <- function() {
require("AMR") require("AMR")
}) })
stop_if(!valid_microorganisms | !valid_antibiotics, stop_if(!valid_microorganisms | !valid_antibiotics,
"the data set `microorganisms` or `antibiotics` was overwritten in your environment because another package with the same object names was loaded _after_ the AMR package, preventing the AMR package from working correctly. Please load the AMR package last.") "the data set `microorganisms` or `antibiotics` was overwritten in your environment because another package with the same object name(s) was loaded _after_ the AMR package, preventing the AMR package from working correctly. Please load the AMR package last.")
invisible(TRUE) invisible(TRUE)
} }
@ -538,7 +538,7 @@ meet_criteria <- function(object,
if (!is.null(pkg_env$meet_criteria_error_txt)) { if (!is.null(pkg_env$meet_criteria_error_txt)) {
error_txt <- pkg_env$meet_criteria_error_txt error_txt <- pkg_env$meet_criteria_error_txt
pkg_env$meet_criteria_error_txt <- NULL pkg_env$meet_criteria_error_txt <- NULL
stop(error_txt, call. = FALSE) stop(error_txt, call. = FALSE) # don't use stop_() here, pkg may not be loaded yet
} }
pkg_env$meet_criteria_error_txt <- NULL pkg_env$meet_criteria_error_txt <- NULL
@ -867,7 +867,13 @@ font_grey <- function(..., collapse = " ") {
try_colour(..., before = "\033[38;5;249m", after = "\033[39m", collapse = collapse) try_colour(..., before = "\033[38;5;249m", after = "\033[39m", collapse = collapse)
} }
font_grey_bg <- function(..., collapse = " ") { font_grey_bg <- function(..., collapse = " ") {
try_colour(..., before = "\033[48;5;254m", after = "\033[49m", collapse = collapse) if (tryCatch(rstudioapi::getThemeInfo()$dark == TRUE, error = function(e) FALSE)) {
# similar to HTML #444444
try_colour(..., before = "\033[48;5;238m", after = "\033[49m", collapse = collapse)
} else {
# similar to HTML #eeeeee
try_colour(..., before = "\033[48;5;254m", after = "\033[49m", collapse = collapse)
}
} }
font_green_bg <- function(..., collapse = " ") { font_green_bg <- function(..., collapse = " ") {
try_colour(..., before = "\033[42m", after = "\033[49m", collapse = collapse) try_colour(..., before = "\033[42m", after = "\033[49m", collapse = collapse)
@ -1077,6 +1083,14 @@ percentage <- function(x, digits = NULL, ...) {
digits = digits, ...) digits = digits, ...)
} }
time_start_tracking <- function() {
pkg_env$time_start <- round(as.numeric(Sys.time()) * 1000)
}
time_track <- function(name = NULL) {
paste("(until now:", trimws(round(as.numeric(Sys.time()) * 1000) - pkg_env$time_start), "ms)")
}
# prevent dependency on package 'backports' # prevent dependency on package 'backports'
# these functions were not available in previous versions of R (last checked: R 4.0.3) # these functions were not available in previous versions of R (last checked: R 4.0.3)
# see here for the full list: https://github.com/r-lib/backports # see here for the full list: https://github.com/r-lib/backports

View File

@ -896,7 +896,7 @@ eucast_rules <- function(x,
target_value <- eucast_rules_df[i, "to_value", drop = TRUE] target_value <- eucast_rules_df[i, "to_value", drop = TRUE]
if (is.na(source_antibiotics)) { if (is.na(source_antibiotics)) {
rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like_perl% mo_value), rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value),
error = function(e) integer(0)) error = function(e) integer(0))
} else { } else {
source_antibiotics <- get_antibiotic_columns(source_antibiotics, x) source_antibiotics <- get_antibiotic_columns(source_antibiotics, x)
@ -906,17 +906,17 @@ eucast_rules <- function(x,
if (length(source_antibiotics) == 0) { if (length(source_antibiotics) == 0) {
rows <- integer(0) rows <- integer(0)
} else if (length(source_antibiotics) == 1) { } else if (length(source_antibiotics) == 1) {
rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like_perl% mo_value rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value
& as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]), & as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]),
error = function(e) integer(0)) error = function(e) integer(0))
} else if (length(source_antibiotics) == 2) { } else if (length(source_antibiotics) == 2) {
rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like_perl% mo_value rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value
& as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] & as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]
& as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L]), & as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L]),
error = function(e) integer(0)) error = function(e) integer(0))
# nolint start # nolint start
# } else if (length(source_antibiotics) == 3) { # } else if (length(source_antibiotics) == 3) {
# rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like_perl% mo_value # rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value
# & as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] # & as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]
# & as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L] # & as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L]
# & as.rsi_no_warning(x[, source_antibiotics[3L]]) == source_value[3L]), # & as.rsi_no_warning(x[, source_antibiotics[3L]]) == source_value[3L]),

View File

@ -26,6 +26,7 @@
globalVariables(c(".rowid", globalVariables(c(".rowid",
"ab", "ab",
"ab_txt", "ab_txt",
"affect_mo_name",
"angle", "angle",
"antibiotic", "antibiotic",
"antibiotics", "antibiotics",

View File

@ -39,7 +39,7 @@
#' * Is case-insensitive (use `%like_case%` for case-sensitive matching) #' * Is case-insensitive (use `%like_case%` for case-sensitive matching)
#' * Supports multiple patterns #' * Supports multiple patterns
#' * Checks if `pattern` is a regular expression and sets `fixed = TRUE` if not, to greatly improve speed #' * Checks if `pattern` is a regular expression and sets `fixed = TRUE` if not, to greatly improve speed
#' * Tries again with `perl = TRUE` if regex fails #' * Always uses compatibility with Perl
#' #'
#' Using RStudio? The text `%like%` can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like `Ctrl+Shift+L` or `Cmd+Shift+L` (see `Tools` > `Modify Keyboard Shortcuts...`). #' Using RStudio? The text `%like%` can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like `Ctrl+Shift+L` or `Cmd+Shift+L` (see `Tools` > `Modify Keyboard Shortcuts...`).
#' @source Idea from the [`like` function from the `data.table` package](https://github.com/Rdatatable/data.table/blob/master/R/like.R) #' @source Idea from the [`like` function from the `data.table` package](https://github.com/Rdatatable/data.table/blob/master/R/like.R)
@ -99,7 +99,7 @@ like <- function(x, pattern, ignore.case = TRUE) {
if (is.factor(x[i])) { if (is.factor(x[i])) {
res[i] <- as.integer(x[i]) %in% grep(pattern[i], levels(x[i]), ignore.case = FALSE, fixed = fixed) res[i] <- as.integer(x[i]) %in% grep(pattern[i], levels(x[i]), ignore.case = FALSE, fixed = fixed)
} else { } else {
res[i] <- grepl(pattern[i], x[i], ignore.case = FALSE, fixed = fixed) res[i] <- grepl(pattern[i], x[i], ignore.case = FALSE, fixed = fixed, perl = !fixed)
} }
} }
res <- vapply(FUN.VALUE = logical(1), pattern, function(pttrn) grepl(pttrn, x, ignore.case = FALSE, fixed = fixed)) res <- vapply(FUN.VALUE = logical(1), pattern, function(pttrn) grepl(pttrn, x, ignore.case = FALSE, fixed = fixed))
@ -112,9 +112,9 @@ like <- function(x, pattern, ignore.case = TRUE) {
# x and pattern are of same length, so items with each other # x and pattern are of same length, so items with each other
for (i in seq_len(length(res))) { for (i in seq_len(length(res))) {
if (is.factor(x[i])) { if (is.factor(x[i])) {
res[i] <- as.integer(x[i]) %in% grep(pattern[i], levels(x[i]), ignore.case = FALSE, fixed = fixed) res[i] <- as.integer(x[i]) %in% grep(pattern[i], levels(x[i]), ignore.case = FALSE, fixed = fixed, perl = !fixed)
} else { } else {
res[i] <- grepl(pattern[i], x[i], ignore.case = FALSE, fixed = fixed) res[i] <- grepl(pattern[i], x[i], ignore.case = FALSE, fixed = fixed, perl = !fixed)
} }
} }
return(res) return(res)
@ -123,22 +123,9 @@ like <- function(x, pattern, ignore.case = TRUE) {
# the regular way how grepl works; just one pattern against one or more x # the regular way how grepl works; just one pattern against one or more x
if (is.factor(x)) { if (is.factor(x)) {
as.integer(x) %in% grep(pattern, levels(x), ignore.case = FALSE, fixed = fixed) as.integer(x) %in% grep(pattern, levels(x), ignore.case = FALSE, fixed = fixed, perl = !fixed)
} else { } else {
tryCatch(grepl(pattern, x, ignore.case = FALSE, fixed = fixed), grepl(pattern, x, ignore.case = FALSE, fixed = fixed, perl = !fixed)
error = function(e) {
if (grepl("invalid reg(ular )?exp", e$message, ignore.case = TRUE)) {
# try with perl = TRUE:
return(grepl(pattern = pattern,
x = x,
ignore.case = FALSE,
fixed = fixed,
perl = TRUE))
} else {
# stop otherwise
stop(e$message)
}
})
} }
} }
@ -157,15 +144,3 @@ like <- function(x, pattern, ignore.case = TRUE) {
meet_criteria(pattern, allow_NA = FALSE) meet_criteria(pattern, allow_NA = FALSE)
like(x, pattern, ignore.case = FALSE) like(x, pattern, ignore.case = FALSE)
} }
"%like_perl%" <- function(x, pattern) {
meet_criteria(x, allow_NA = TRUE)
meet_criteria(pattern, allow_NA = FALSE)
# convenient for e.g. matching all Klebsiella and Raoultella, but not
# K. aerogenes: fullname %like_perl% "^(Klebsiella(?! aerogenes)|Raoultella)"
grepl(x = tolower(x),
pattern = tolower(pattern),
perl = TRUE,
fixed = FALSE,
ignore.case = TRUE)
}

74
R/mo.R
View File

@ -178,13 +178,6 @@ as.mo <- function(x,
return(set_clean_class(x, new_class = c("mo", "character"))) return(set_clean_class(x, new_class = c("mo", "character")))
} }
if (tryCatch(all(x == "" | gsub(".*(unknown ).*", "unknown name", tolower(x), perl = TRUE) %in% MO_lookup$fullname_lower, na.rm = TRUE)
& isFALSE(Becker)
& isFALSE(Lancefield), error = function(e) FALSE)) {
# to improve speed, special case for taxonomically correct full names (case-insensitive)
return(MO_lookup[match(gsub(".*(unknown ).*", "unknown name", tolower(x), perl = TRUE), MO_lookup$fullname_lower), "mo", drop = TRUE])
}
# start off with replaced language-specific non-ASCII characters with ASCII characters # start off with replaced language-specific non-ASCII characters with ASCII characters
x <- parse_and_convert(x) x <- parse_and_convert(x)
# replace mo codes used in older package versions # replace mo codes used in older package versions
@ -198,6 +191,13 @@ as.mo <- function(x,
x[trimws2(x) %like% translate_AMR("no .*growth", language = language)] <- NA_character_ x[trimws2(x) %like% translate_AMR("no .*growth", language = language)] <- NA_character_
x[trimws2(x) %like% paste0("^(", translate_AMR("no|not", language = language), ") [a-z]+")] <- "UNKNOWN" x[trimws2(x) %like% paste0("^(", translate_AMR("no|not", language = language), ") [a-z]+")] <- "UNKNOWN"
uncertainty_level <- translate_allow_uncertain(allow_uncertain) uncertainty_level <- translate_allow_uncertain(allow_uncertain)
if (tryCatch(all(x == "" | gsub(".*(unknown ).*", "unknown name", tolower(x), perl = TRUE) %in% MO_lookup$fullname_lower, na.rm = TRUE)
& isFALSE(Becker)
& isFALSE(Lancefield), error = function(e) FALSE)) {
# to improve speed, special case for taxonomically correct full names (case-insensitive)
return(MO_lookup[match(gsub(".*(unknown ).*", "unknown name", tolower(x), perl = TRUE), MO_lookup$fullname_lower), "mo", drop = TRUE])
}
if (!is.null(reference_df) if (!is.null(reference_df)
&& check_validity_mo_source(reference_df) && check_validity_mo_source(reference_df)
@ -277,6 +277,10 @@ exec_as.mo <- function(x,
check_dataset_integrity() check_dataset_integrity()
if (isTRUE(debug) && initial_search == TRUE) {
time_start_tracking()
}
lookup <- function(needle, lookup <- function(needle,
column = property, column = property,
haystack = reference_data_to_use, haystack = reference_data_to_use,
@ -295,7 +299,8 @@ exec_as.mo <- function(x,
# `column` can be NULL for all columns, or a selection # `column` can be NULL for all columns, or a selection
# returns a character (vector) - if `column` > length 1 then with columns as names # returns a character (vector) - if `column` > length 1 then with columns as names
if (isTRUE(debug_mode)) { if (isTRUE(debug_mode)) {
cat(font_silver("looking up: ", substitute(needle), collapse = "")) cat(font_silver("Looking up: ", substitute(needle), collapse = ""),
"\n ", time_track())
} }
if (length(column) == 1) { if (length(column) == 1) {
res_df <- haystack[which(eval(substitute(needle), envir = haystack, enclos = parent.frame())), , drop = FALSE] res_df <- haystack[which(eval(substitute(needle), envir = haystack, enclos = parent.frame())), , drop = FALSE]
@ -313,7 +318,7 @@ exec_as.mo <- function(x,
NA_character_ NA_character_
} else { } else {
if (isTRUE(debug_mode)) { if (isTRUE(debug_mode)) {
cat(font_green(paste0(" **MATCH** (", NROW(res_df), " results)\n"))) cat(font_green(paste0(" MATCH (", NROW(res_df), " results)\n")))
} }
if ((length(res) > n | uncertainty > 1) & uncertainty != -1) { if ((length(res) > n | uncertainty > 1) & uncertainty != -1) {
# save the other possible results as well, but not for forced certain results (then uncertainty == -1) # save the other possible results as well, but not for forced certain results (then uncertainty == -1)
@ -327,16 +332,20 @@ exec_as.mo <- function(x,
res[seq_len(min(n, length(res)))] res[seq_len(min(n, length(res)))]
} }
} else { } else {
if (isTRUE(debug_mode)) {
cat("\n")
}
if (is.null(column)) { if (is.null(column)) {
column <- names(haystack) column <- names(haystack)
} }
res <- haystack[which(eval(substitute(needle), envir = haystack, enclos = parent.frame())), , drop = FALSE] res <- haystack[which(eval(substitute(needle), envir = haystack, enclos = parent.frame())), , drop = FALSE]
res <- res[seq_len(min(n, nrow(res))), column, drop = TRUE] res <- res[seq_len(min(n, nrow(res))), column, drop = TRUE]
if (NROW(res) == 0) { if (NROW(res) == 0) {
if (isTRUE(debug_mode)) {
cat(font_red(" (no rows)\n"))
}
res <- rep(NA_character_, length(column)) res <- rep(NA_character_, length(column))
} else {
if (isTRUE(debug_mode)) {
cat(font_green(paste0(" MATCH (", NROW(res), " rows)\n")))
}
} }
res <- as.character(res) res <- as.character(res)
names(res) <- column names(res) <- column
@ -394,7 +403,7 @@ exec_as.mo <- function(x,
check_validity_mo_source(reference_df) check_validity_mo_source(reference_df)
reference_df <- repair_reference_df(reference_df) reference_df <- repair_reference_df(reference_df)
} }
# all empty # all empty
if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0)) { if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0)) {
if (property == "mo") { if (property == "mo") {
@ -471,12 +480,12 @@ exec_as.mo <- function(x,
x_backup[x_backup_untouched == "Fungi"] <- "Fungi" # is literally the kingdom x_backup[x_backup_untouched == "Fungi"] <- "Fungi" # is literally the kingdom
# Fill in fullnames and MO codes at once # Fill in fullnames and MO codes at once
known_names <- x_backup %in% MO_lookup$fullname known_names <- tolower(x_backup) %in% MO_lookup$fullname_lower
x[known_names] <- MO_lookup[match(x_backup[known_names], MO_lookup$fullname), property, drop = TRUE] x[known_names] <- MO_lookup[match(tolower(x_backup)[known_names], MO_lookup$fullname_lower), property, drop = TRUE]
known_codes <- x_backup %in% MO_lookup$mo known_codes <- toupper(x_backup) %in% MO_lookup$mo
x[known_codes] <- MO_lookup[match(x_backup[known_codes], MO_lookup$mo), property, drop = TRUE] x[known_codes] <- MO_lookup[match(toupper(x_backup)[known_codes], MO_lookup$mo), property, drop = TRUE]
already_known <- known_names | known_codes already_known <- known_names | known_codes
# now only continue where the right taxonomic output is not already known # now only continue where the right taxonomic output is not already known
if (any(!already_known)) { if (any(!already_known)) {
x_known <- x[already_known] x_known <- x[already_known]
@ -757,21 +766,24 @@ exec_as.mo <- function(x,
# Streptococci, like GBS = Group B Streptococci (B_STRPT_GRPB) # Streptococci, like GBS = Group B Streptococci (B_STRPT_GRPB)
x[i] <- lookup(mo == toupper(gsub("g([abcdfghk])s", x[i] <- lookup(mo == toupper(gsub("g([abcdfghk])s",
"B_STRPT_GRP\\1", "B_STRPT_GRP\\1",
x_backup_without_spp[i])), uncertainty = -1) x_backup_without_spp[i],
perl = TRUE)), uncertainty = -1)
next next
} }
if (x_backup_without_spp[i] %like_case% "(streptococ|streptokok).* [abcdfghk]$") { if (x_backup_without_spp[i] %like_case% "(streptococ|streptokok).* [abcdfghk]$") {
# Streptococci in different languages, like "estreptococos grupo B" # Streptococci in different languages, like "estreptococos grupo B"
x[i] <- lookup(mo == toupper(gsub(".*(streptococ|streptokok|estreptococ).* ([abcdfghk])$", x[i] <- lookup(mo == toupper(gsub(".*(streptococ|streptokok|estreptococ).* ([abcdfghk])$",
"B_STRPT_GRP\\2", "B_STRPT_GRP\\2",
x_backup_without_spp[i])), uncertainty = -1) x_backup_without_spp[i],
perl = TRUE)), uncertainty = -1)
next next
} }
if (x_backup_without_spp[i] %like_case% "group [abcdfghk] (streptococ|streptokok|estreptococ)") { if (x_backup_without_spp[i] %like_case% "group [abcdfghk] (streptococ|streptokok|estreptococ)") {
# Streptococci in different languages, like "Group A Streptococci" # Streptococci in different languages, like "Group A Streptococci"
x[i] <- lookup(mo == toupper(gsub(".*group ([abcdfghk]) (streptococ|streptokok|estreptococ).*", x[i] <- lookup(mo == toupper(gsub(".*group ([abcdfghk]) (streptococ|streptokok|estreptococ).*",
"B_STRPT_GRP\\1", "B_STRPT_GRP\\1",
x_backup_without_spp[i])), uncertainty = -1) x_backup_without_spp[i],
perl = TRUE)), uncertainty = -1)
next next
} }
if (x_backup_without_spp[i] %like_case% "haemoly.*strep") { if (x_backup_without_spp[i] %like_case% "haemoly.*strep") {
@ -834,7 +846,7 @@ exec_as.mo <- function(x,
# Salmonella Group A to Z, just return S. species for now # Salmonella Group A to Z, just return S. species for now
x[i] <- lookup(genus == "Salmonella", uncertainty = -1) x[i] <- lookup(genus == "Salmonella", uncertainty = -1)
next next
} else if (grepl("[sS]almonella [A-Z][a-z]+ ?.*", x_backup[i], ignore.case = FALSE) & } else if (x_backup[i] %like_case% "[sS]almonella [A-Z][a-z]+ ?.*" &
!x_backup[i] %like% "t[iy](ph|f)[iy]") { !x_backup[i] %like% "t[iy](ph|f)[iy]") {
# Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica # Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica
# except for S. typhi, S. paratyphi, S. typhimurium # except for S. typhi, S. paratyphi, S. typhimurium
@ -1099,7 +1111,7 @@ exec_as.mo <- function(x,
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (3) look for genus only, part of name\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (3) look for genus only, part of name\n"))
} }
if (nchar(g.x_backup_without_spp) > 4 & !b.x_trimmed %like_case% " ") { if (nchar(g.x_backup_without_spp) > 4 & !b.x_trimmed %like_case% " ") {
if (!grepl("^[A-Z][a-z]+", b.x_trimmed, ignore.case = FALSE)) { if (!b.x_trimmed %like_case% "^[A-Z][a-z]+") {
if (isTRUE(debug)) { if (isTRUE(debug)) {
message("Running '", paste(b.x_trimmed, "species"), "'") message("Running '", paste(b.x_trimmed, "species"), "'")
} }
@ -1414,6 +1426,10 @@ exec_as.mo <- function(x,
close(progress) close(progress)
} }
if (isTRUE(debug) && initial_search == TRUE) {
cat("Ended search", time_track(), "\n")
}
# handling failures ---- # handling failures ----
failures <- failures[!failures %in% c(NA, NULL, NaN)] failures <- failures[!failures %in% c(NA, NULL, NaN)]
@ -1571,6 +1587,10 @@ exec_as.mo <- function(x,
} }
} }
if (isTRUE(debug) && initial_search == TRUE) {
cat("Finished function", time_track(), "\n")
}
x x
} }
@ -1835,7 +1855,7 @@ print.mo_uncertainties <- function(x, ...) {
width = 0.98 * getOption("width")), width = 0.98 * getOption("width")),
collapse = "") collapse = "")
# after strwrap, make taxonomic names italic # after strwrap, make taxonomic names italic
candidates <- gsub("([A-Za-z]+)", font_italic("\\1"), candidates) candidates <- gsub("([A-Za-z]+)", font_italic("\\1"), candidates, perl = TRUE)
candidates <- gsub(paste(font_italic(c("Also", "matched"), collapse = NULL), collapse = " "), candidates <- gsub(paste(font_italic(c("Also", "matched"), collapse = NULL), collapse = " "),
"Also matched", "Also matched",
candidates, fixed = TRUE) candidates, fixed = TRUE)
@ -1959,13 +1979,13 @@ parse_and_convert <- function(x) {
if (NCOL(x) > 2) { if (NCOL(x) > 2) {
stop("a maximum of two columns is allowed", call. = FALSE) stop("a maximum of two columns is allowed", call. = FALSE)
} else if (NCOL(x) == 2) { } else if (NCOL(x) == 2) {
# support Tidyverse selection like: df %pm>% select(colA, colB) # support Tidyverse selection like: df %>% select(colA, colB)
# paste these columns together # paste these columns together
x <- as.data.frame(x, stringsAsFactors = FALSE) x <- as.data.frame(x, stringsAsFactors = FALSE)
colnames(x) <- c("A", "B") colnames(x) <- c("A", "B")
x <- paste(x$A, x$B) x <- paste(x$A, x$B)
} else { } else {
# support Tidyverse selection like: df %pm>% select(colA) # support Tidyverse selection like: df %>% select(colA)
x <- as.data.frame(x, stringsAsFactors = FALSE)[[1]] x <- as.data.frame(x, stringsAsFactors = FALSE)[[1]]
} }
} }
@ -1973,6 +1993,8 @@ parse_and_convert <- function(x) {
parsed <- iconv(x, to = "UTF-8") parsed <- iconv(x, to = "UTF-8")
parsed[is.na(parsed) & !is.na(x)] <- iconv(x[is.na(parsed) & !is.na(x)], from = "Latin1", to = "ASCII//TRANSLIT") parsed[is.na(parsed) & !is.na(x)] <- iconv(x[is.na(parsed) & !is.na(x)], from = "Latin1", to = "ASCII//TRANSLIT")
parsed <- gsub('"', "", parsed, fixed = TRUE) parsed <- gsub('"', "", parsed, fixed = TRUE)
parsed <- gsub(" +", " ", parsed, perl = TRUE)
parsed <- trimws(parsed)
}, error = function(e) stop(e$message, call. = FALSE)) # this will also be thrown when running `as.mo(no_existing_object)` }, error = function(e) stop(e$message, call. = FALSE)) # this will also be thrown when running `as.mo(no_existing_object)`
parsed parsed
} }

View File

@ -694,22 +694,22 @@ mo_property <- function(x, property = "fullname", language = get_locale(), ...)
mo_validate <- function(x, property, language, ...) { mo_validate <- function(x, property, language, ...) {
check_dataset_integrity() check_dataset_integrity()
if (tryCatch(all(x[!is.na(x)] %in% MO_lookup$mo) & length(list(...)) == 0, error = function(e) FALSE)) {
# special case for mo_* functions where class is already <mo>
return(MO_lookup[match(x, MO_lookup$mo), property, drop = TRUE])
}
dots <- list(...) dots <- list(...)
Becker <- dots$Becker Becker <- dots$Becker
if (is.null(Becker)) { if (is.null(Becker) | property %in% c("kingdom", "phylum", "class", "order", "family", "genus")) {
Becker <- FALSE Becker <- FALSE
} }
Lancefield <- dots$Lancefield Lancefield <- dots$Lancefield
if (is.null(Lancefield)) { if (is.null(Lancefield) | property %in% c("kingdom", "phylum", "class", "order", "family", "genus")) {
Lancefield <- FALSE Lancefield <- FALSE
} }
has_Becker_or_Lancefield <- Becker %in% c(TRUE, "all") | Lancefield %in% c(TRUE, "all")
if (tryCatch(all(x[!is.na(x)] %in% MO_lookup$mo) & !has_Becker_or_Lancefield, error = function(e) FALSE)) {
# special case for mo_* functions where class is already <mo>
return(MO_lookup[match(x, MO_lookup$mo), property, drop = TRUE])
}
# try to catch an error when inputting an invalid argument # try to catch an error when inputting an invalid argument
# so the 'call.' can be set to FALSE # so the 'call.' can be set to FALSE
tryCatch(x[1L] %in% MO_lookup[1, property, drop = TRUE], tryCatch(x[1L] %in% MO_lookup[1, property, drop = TRUE],
@ -722,8 +722,7 @@ mo_validate <- function(x, property, language, ...) {
# because it's already a valid MO # because it's already a valid MO
x <- exec_as.mo(x, property = property, initial_search = FALSE, language = language, ...) x <- exec_as.mo(x, property = property, initial_search = FALSE, language = language, ...)
} else if (!all(x %in% MO_lookup[, property, drop = TRUE]) } else if (!all(x %in% MO_lookup[, property, drop = TRUE])
| Becker %in% c(TRUE, "all") | has_Becker_or_Lancefield) {
| Lancefield %in% c(TRUE, "all")) {
x <- exec_as.mo(x, property = property, language = language, ...) x <- exec_as.mo(x, property = property, language = language, ...)
} }

Binary file not shown.

Binary file not shown.

View File

@ -51,18 +51,19 @@ create_species_cons_cops <- function(type = c("CoNS", "CoPS")) {
"lentus", "lugdunensis", "massiliensis", "microti", "lentus", "lugdunensis", "massiliensis", "microti",
"muscae", "nepalensis", "pasteuri", "petrasii", "muscae", "nepalensis", "pasteuri", "petrasii",
"pettenkoferi", "piscifermentans", "pseudoxylosus", "pettenkoferi", "piscifermentans", "pseudoxylosus",
"rostri", "saccharolyticus", "saprophyticus", "pulvereri", "rostri", "saccharolyticus", "saprophyticus",
"sciuri", "simulans", "stepanovicii", "succinus", "sciuri", "simulans", "stepanovicii", "succinus",
"vitulinus", "warneri", "xylosus") "vitulinus", "vitulus", "warneri", "xylosus")
| (MO_staph$species == "schleiferi" & MO_staph$subspecies %in% c("schleiferi", ""))), | (MO_staph$species == "schleiferi" & MO_staph$subspecies %in% c("schleiferi", ""))),
"mo", drop = TRUE] "mo", drop = TRUE]
} else if (type == "CoPS") { } else if (type == "CoPS") {
MO_staph[which(MO_staph$species %in% c("coagulase-positive", MO_staph[which(MO_staph$species %in% c("coagulase-positive",
"simiae", "agnetis", "agnetis", "argenteus",
"cornubiensis",
"delphini", "lutrae", "delphini", "lutrae",
"hyicus", "intermedius", "hyicus", "intermedius",
"pseudintermedius", "pseudointermedius", "pseudintermedius", "pseudointermedius",
"schweitzeri", "argenteus") "schweitzeri", "simiae")
| (MO_staph$species == "schleiferi" & MO_staph$subspecies == "coagulans")), | (MO_staph$species == "schleiferi" & MO_staph$subspecies == "coagulans")),
"mo", drop = TRUE] "mo", drop = TRUE]
} }

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.io/AMR//index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.github.io/AMR//index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -39,7 +39,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>
@ -225,36 +225,22 @@
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VISA"</span><span class="op">)</span>, <span class="co"># Vancomycin Intermediate S. aureus</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VISA"</span><span class="op">)</span>, <span class="co"># Vancomycin Intermediate S. aureus</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VRSA"</span><span class="op">)</span>, <span class="co"># Vancomycin Resistant S. aureus</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VRSA"</span><span class="op">)</span>, <span class="co"># Vancomycin Resistant S. aureus</span>
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html">print</a></span><span class="op">(</span><span class="va">S.aureus</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">2</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">S.aureus</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">2</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># as.mo("sau") 13.0 14.0 25.0 15.0 44.0 65</span> <span class="co"># as.mo("sau") 11.0 12.0 27.0 13.0 49.0 51 10</span>
<span class="co"># as.mo("stau") 120.0 130.0 140.0 140.0 160.0 160</span> <span class="co"># as.mo("stau") 53.0 57.0 76.0 74.0 93.0 100 10</span>
<span class="co"># as.mo("STAU") 120.0 130.0 150.0 160.0 160.0 180</span> <span class="co"># as.mo("STAU") 53.0 54.0 69.0 56.0 58.0 190 10</span>
<span class="co"># as.mo("staaur") 13.0 13.0 14.0 14.0 14.0 15</span> <span class="co"># as.mo("staaur") 11.0 12.0 21.0 13.0 42.0 44 10</span>
<span class="co"># as.mo("STAAUR") 13.0 14.0 17.0 15.0 15.0 43</span> <span class="co"># as.mo("STAAUR") 11.0 12.0 16.0 13.0 14.0 48 10</span>
<span class="co"># as.mo("S. aureus") 30.0 32.0 45.0 34.0 62.0 68</span> <span class="co"># as.mo("S. aureus") 27.0 27.0 38.0 32.0 35.0 75 10</span>
<span class="co"># as.mo("S aureus") 31.0 34.0 42.0 35.0 61.0 63</span> <span class="co"># as.mo("S aureus") 27.0 29.0 38.0 30.0 36.0 73 10</span>
<span class="co"># as.mo("Staphylococcus aureus") 2.5 2.6 2.8 2.8 2.9 3</span> <span class="co"># as.mo("Staphylococcus aureus") 3.1 3.2 6.9 3.5 3.7 38 10</span>
<span class="co"># as.mo("Staphylococcus aureus (MRSA)") 1200.0 1200.0 1200.0 1200.0 1200.0 1200</span> <span class="co"># as.mo("Staphylococcus aureus (MRSA)") 250.0 260.0 270.0 260.0 280.0 290 10</span>
<span class="co"># as.mo("Sthafilokkockus aaureuz") 550.0 560.0 570.0 560.0 570.0 610</span> <span class="co"># as.mo("Sthafilokkockus aaureuz") 160.0 200.0 200.0 200.0 210.0 230 10</span>
<span class="co"># as.mo("MRSA") 13.0 13.0 17.0 15.0 15.0 42</span> <span class="co"># as.mo("MRSA") 10.0 11.0 12.0 11.0 13.0 14 10</span>
<span class="co"># as.mo("VISA") 21.0 22.0 26.0 23.0 23.0 52</span> <span class="co"># as.mo("VISA") 19.0 20.0 26.0 22.0 24.0 61 10</span>
<span class="co"># as.mo("VRSA") 21.0 23.0 35.0 24.0 52.0 54</span> <span class="co"># as.mo("VRSA") 19.0 20.0 24.0 21.0 22.0 56 10</span></code></pre></div>
<span class="co"># neval</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span>
<span class="co"># 10</span></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="562.5"></p> <p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="562.5"></p>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations can take up to 500-1000 times as much time.</p> <p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations can take up to 500-1000 times as much time.</p>
<p>To improve performance, two important calculations take almost no time at all: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p> <p>To improve performance, two important calculations take almost no time at all: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
@ -281,11 +267,11 @@
<span class="co"># now let's see:</span> <span class="co"># now let's see:</span>
<span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu">microbenchmark</span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>, <span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu">microbenchmark</span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># mo_name(x) 141 180 218 207 245 312 10</span></code></pre></div> <span class="co"># mo_name(x) 137 146 178 172 193 282 10</span></code></pre></div>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.207 seconds. You only lose time on your unique input values.</p> <p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.172 seconds. You only lose time on your unique input values.</p>
</div> </div>
<div id="precalculated-results" class="section level3"> <div id="precalculated-results" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -296,13 +282,13 @@
B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"S. aureus"</span><span class="op">)</span>, B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"S. aureus"</span><span class="op">)</span>,
C <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span><span class="op">)</span>, C <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 8.76 8.96 9.39 9.31 9.86 10.10 10</span> <span class="co"># A 7.12 7.56 7.89 7.7 8.39 8.69 10</span>
<span class="co"># B 27.60 28.20 33.00 28.90 29.40 71.20 10</span> <span class="co"># B 23.90 24.50 35.10 24.8 27.40 77.50 10</span>
<span class="co"># C 2.28 2.32 2.47 2.45 2.48 2.85 10</span></code></pre></div> <span class="co"># C 1.73 1.84 1.95 1.9 2.09 2.36 10</span></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0025 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p> <p>So going from <code><a href="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0019 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu">microbenchmark</span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span><span class="op">(</span><span class="st">"aureus"</span><span class="op">)</span>, <code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu">microbenchmark</span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span><span class="op">(</span><span class="st">"aureus"</span><span class="op">)</span>,
B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"Staphylococcus"</span><span class="op">)</span>, B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"Staphylococcus"</span><span class="op">)</span>,
@ -313,17 +299,17 @@
G <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_phylum</a></span><span class="op">(</span><span class="st">"Firmicutes"</span><span class="op">)</span>, G <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_phylum</a></span><span class="op">(</span><span class="st">"Firmicutes"</span><span class="op">)</span>,
H <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_kingdom</a></span><span class="op">(</span><span class="st">"Bacteria"</span><span class="op">)</span>, H <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_kingdom</a></span><span class="op">(</span><span class="st">"Bacteria"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 1.91 1.95 2.06 1.99 2.09 2.62 10</span> <span class="co"># A 1.54 1.57 1.73 1.69 1.88 2.00 10</span>
<span class="co"># B 1.83 1.91 2.09 2.04 2.20 2.45 10</span> <span class="co"># B 1.51 1.52 1.75 1.70 1.86 2.41 10</span>
<span class="co"># C 1.79 1.90 2.03 1.99 2.22 2.30 10</span> <span class="co"># C 1.55 1.60 1.70 1.70 1.81 1.86 10</span>
<span class="co"># D 1.90 2.01 2.18 2.12 2.25 2.71 10</span> <span class="co"># D 1.55 1.59 1.71 1.66 1.83 1.94 10</span>
<span class="co"># E 1.91 2.02 2.14 2.08 2.15 2.81 10</span> <span class="co"># E 1.50 1.55 1.68 1.61 1.78 2.10 10</span>
<span class="co"># F 1.86 1.92 2.00 2.01 2.06 2.16 10</span> <span class="co"># F 1.51 1.62 1.75 1.79 1.82 2.02 10</span>
<span class="co"># G 1.81 1.96 2.09 2.08 2.22 2.41 10</span> <span class="co"># G 1.52 1.53 1.68 1.60 1.80 2.02 10</span>
<span class="co"># H 1.90 1.93 2.05 2.00 2.22 2.29 10</span></code></pre></div> <span class="co"># H 1.53 1.54 1.63 1.60 1.67 1.84 10</span></code></pre></div>
<p>Of course, when running <code><a href="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package knows all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.</p> <p>Of course, when running <code><a href="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package knows all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.</p>
</div> </div>
<div id="results-in-other-languages" class="section level3"> <div id="results-in-other-languages" class="section level3">
@ -348,16 +334,16 @@
fr <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"CoNS"</span>, language <span class="op">=</span> <span class="st">"fr"</span><span class="op">)</span>, fr <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"CoNS"</span>, language <span class="op">=</span> <span class="st">"fr"</span><span class="op">)</span>,
pt <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"CoNS"</span>, language <span class="op">=</span> <span class="st">"pt"</span><span class="op">)</span>, pt <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"CoNS"</span>, language <span class="op">=</span> <span class="st">"pt"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">100</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">100</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">4</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">4</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># en 17.45 18.01 19.69 18.53 19.14 55.30 100</span> <span class="co"># en 17.38 17.71 25.63 18.11 19.75 81.61 100</span>
<span class="co"># de 20.58 21.54 26.69 22.08 23.96 67.16 100</span> <span class="co"># de 20.14 20.61 24.87 20.91 21.57 85.23 100</span>
<span class="co"># nl 33.79 34.67 39.13 35.39 36.72 74.60 100</span> <span class="co"># nl 25.02 25.46 28.40 25.83 26.58 78.47 100</span>
<span class="co"># es 20.71 21.42 24.36 21.88 22.65 58.57 100</span> <span class="co"># es 19.90 20.41 24.86 20.77 21.78 81.38 100</span>
<span class="co"># it 20.65 21.18 26.50 21.53 22.68 61.96 100</span> <span class="co"># it 20.01 20.44 24.40 20.80 21.57 76.08 100</span>
<span class="co"># fr 20.68 21.27 25.05 21.64 22.37 58.82 100</span> <span class="co"># fr 19.85 20.23 29.97 20.89 23.56 192.40 100</span>
<span class="co"># pt 20.69 21.44 24.36 21.94 22.99 59.66 100</span></code></pre></div> <span class="co"># pt 19.90 20.26 26.53 20.75 22.56 85.69 100</span></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p> <p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div> </div>
</div> </div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -43,7 +43,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>
@ -236,13 +236,13 @@
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small> <small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div> </div>
<div id="amr-1509020" class="section level1"> <div id="amr-1509023" class="section level1">
<h1 class="page-header" data-toc-text="1.5.0.9020"> <h1 class="page-header" data-toc-text="1.5.0.9023">
<a href="#amr-1509020" class="anchor"></a>AMR 1.5.0.9020<small> Unreleased </small> <a href="#amr-1509023" class="anchor"></a>AMR 1.5.0.9023<small> Unreleased </small>
</h1> </h1>
<div id="last-updated-18-february-2021" class="section level2"> <div id="last-updated-21-february-2021" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-18-february-2021" class="anchor"></a><small>Last updated: 18 February 2021</small> <a href="#last-updated-21-february-2021" class="anchor"></a><small>Last updated: 21 February 2021</small>
</h2> </h2>
<div id="new" class="section level3"> <div id="new" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -326,6 +326,9 @@
</li> </li>
<li>Improved speed and reliability of <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code>. As this also internally improves the reliability of <code><a href="../reference/first_isolate.html">first_isolate()</a></code> and <code><a href="../reference/mdro.html">mdro()</a></code>, this might have a slight impact on the results of those functions.</li> <li>Improved speed and reliability of <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code>. As this also internally improves the reliability of <code><a href="../reference/first_isolate.html">first_isolate()</a></code> and <code><a href="../reference/mdro.html">mdro()</a></code>, this might have a slight impact on the results of those functions.</li>
<li>Fix for <code><a href="../reference/mo_property.html">mo_name()</a></code> when used in other languages than English</li> <li>Fix for <code><a href="../reference/mo_property.html">mo_name()</a></code> when used in other languages than English</li>
<li>The <code><a href="../reference/like.html">like()</a></code> function (and its fast alias <code><a href="../reference/like.html">%like%</a></code>) now always use Perl compatibility, improving speed for many functions in this package (e.g., <code><a href="../reference/as.mo.html">as.mo()</a></code> is now up to 4 times faster)</li>
<li>
<em>Staphylococcus cornubiensis</em> is now correctly categorised as coagulase-positive</li>
</ul> </ul>
</div> </div>
<div id="other" class="section level3"> <div id="other" class="section level3">

View File

@ -12,7 +12,7 @@ articles:
datasets: datasets.html datasets: datasets.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
welcome_to_AMR: welcome_to_AMR.html welcome_to_AMR: welcome_to_AMR.html
last_built: 2021-02-18T22:21Z last_built: 2021-02-21T22:18Z
urls: urls:
reference: https://msberends.github.io/AMR//reference reference: https://msberends.github.io/AMR//reference
article: https://msberends.github.io/AMR//articles article: https://msberends.github.io/AMR//articles

View File

@ -83,7 +83,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9021</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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">1.5.0.9016</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9021</span>
</span> </span>
</div> </div>
@ -277,7 +277,7 @@
<li><p>Is case-insensitive (use <code>%like_case%</code> for case-sensitive matching)</p></li> <li><p>Is case-insensitive (use <code>%like_case%</code> for case-sensitive matching)</p></li>
<li><p>Supports multiple patterns</p></li> <li><p>Supports multiple patterns</p></li>
<li><p>Checks if <code>pattern</code> is a regular expression and sets <code>fixed = TRUE</code> if not, to greatly improve speed</p></li> <li><p>Checks if <code>pattern</code> is a regular expression and sets <code>fixed = TRUE</code> if not, to greatly improve speed</p></li>
<li><p>Tries again with <code>perl = TRUE</code> if regex fails</p></li> <li><p>Always uses compatibility with Perl</p></li>
</ul> </ul>
<p>Using RStudio? The text <code>%like%</code> can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like <code>Ctrl+Shift+L</code> or <code>Cmd+Shift+L</code> (see <code>Tools</code> &gt; <code>Modify Keyboard Shortcuts...</code>).</p> <p>Using RStudio? The text <code>%like%</code> can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like <code>Ctrl+Shift+L</code> or <code>Cmd+Shift+L</code> (see <code>Tools</code> &gt; <code>Modify Keyboard Shortcuts...</code>).</p>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <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">1.5.0.9020</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9023</span>
</span> </span>
</div> </div>

View File

@ -34,7 +34,7 @@ The \verb{\%like\%} function:
\item Is case-insensitive (use \verb{\%like_case\%} for case-sensitive matching) \item Is case-insensitive (use \verb{\%like_case\%} for case-sensitive matching)
\item Supports multiple patterns \item Supports multiple patterns
\item Checks if \code{pattern} is a regular expression and sets \code{fixed = TRUE} if not, to greatly improve speed \item Checks if \code{pattern} is a regular expression and sets \code{fixed = TRUE} if not, to greatly improve speed
\item Tries again with \code{perl = TRUE} if regex fails \item Always uses compatibility with Perl
} }
Using RStudio? The text \verb{\%like\%} can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like \code{Ctrl+Shift+L} or \code{Cmd+Shift+L} (see \code{Tools} > \verb{Modify Keyboard Shortcuts...}). Using RStudio? The text \verb{\%like\%} can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like \code{Ctrl+Shift+L} or \code{Cmd+Shift+L} (see \code{Tools} > \verb{Modify Keyboard Shortcuts...}).

View File

@ -86,3 +86,13 @@ test_that("CoL version info works", {
expect_output(print(catalogue_of_life_version())) expect_output(print(catalogue_of_life_version()))
}) })
test_that("CoNS/CoPS are up to date", {
uncategorised <- subset(microorganisms,
genus == "Staphylococcus" &
!species %in% c("", "aureus") &
!mo %in% c(MO_CONS, MO_COPS))
expect(NROW(uncategorised) == 0,
failure_message = paste0("Staphylococcal species not categorised as CoNS/CoPS: S. ",
uncategorised$species, " (", uncategorised$mo, ")"))
})

View File

@ -19,7 +19,7 @@ knitr::opts_chunk$set(
fig.width = 7.5, fig.width = 7.5,
fig.height = 4.5, fig.height = 4.5,
dpi = 75 dpi = 75
) )
``` ```
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life. One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.