mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 19:26:13 +01:00
Merge branch 'premaster'
This commit is contained in:
commit
6c4822164c
@ -34,7 +34,7 @@ before_script:
|
||||
# install dependencies for packages
|
||||
- apt-get install -y wget locales libxml2-dev libssl-dev libcurl4-openssl-dev zlib1g-dev > /dev/null
|
||||
# recent pandoc
|
||||
- wget --quiet https://github.com/jgm/pandoc/releases/download/2.7.2/pandoc-2.7.2-1-amd64.deb
|
||||
- wget --quiet https://github.com/jgm/pandoc/releases/download/2.7.3/pandoc-2.7.3-1-amd64.deb
|
||||
- dpkg -i pandoc*.deb
|
||||
- rm pandoc*.deb
|
||||
# set R system language
|
||||
|
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.7.1.9035
|
||||
Date: 2019-08-11
|
||||
Version: 0.7.1.9038
|
||||
Date: 2019-08-12
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(role = c("aut", "cre"),
|
||||
|
11
NAMESPACE
11
NAMESPACE
@ -1,5 +1,7 @@
|
||||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
S3method("[",ab)
|
||||
S3method("[",mo)
|
||||
S3method(as.data.frame,ab)
|
||||
S3method(as.data.frame,mo)
|
||||
S3method(as.double,mic)
|
||||
@ -19,6 +21,7 @@ S3method(kurtosis,data.frame)
|
||||
S3method(kurtosis,default)
|
||||
S3method(kurtosis,matrix)
|
||||
S3method(pillar_shaft,ab)
|
||||
S3method(pillar_shaft,disk)
|
||||
S3method(pillar_shaft,mic)
|
||||
S3method(pillar_shaft,mo)
|
||||
S3method(pillar_shaft,rsi)
|
||||
@ -33,8 +36,6 @@ S3method(print,mo)
|
||||
S3method(print,mo_renamed)
|
||||
S3method(print,mo_uncertainties)
|
||||
S3method(print,rsi)
|
||||
S3method(pull,ab)
|
||||
S3method(pull,mo)
|
||||
S3method(skewness,data.frame)
|
||||
S3method(skewness,default)
|
||||
S3method(skewness,matrix)
|
||||
@ -42,6 +43,7 @@ S3method(summary,mic)
|
||||
S3method(summary,mo)
|
||||
S3method(summary,rsi)
|
||||
S3method(type_sum,ab)
|
||||
S3method(type_sum,disk)
|
||||
S3method(type_sum,mic)
|
||||
S3method(type_sum,mo)
|
||||
S3method(type_sum,rsi)
|
||||
@ -86,6 +88,7 @@ export(filter_1st_cephalosporins)
|
||||
export(filter_2nd_cephalosporins)
|
||||
export(filter_3rd_cephalosporins)
|
||||
export(filter_4th_cephalosporins)
|
||||
export(filter_5th_cephalosporins)
|
||||
export(filter_ab_class)
|
||||
export(filter_aminoglycosides)
|
||||
export(filter_carbapenems)
|
||||
@ -167,6 +170,8 @@ export(semi_join_microorganisms)
|
||||
export(set_mo_source)
|
||||
export(skewness)
|
||||
export(theme_rsi)
|
||||
exportMethods("[.ab")
|
||||
exportMethods("[.mo")
|
||||
exportMethods(as.data.frame.ab)
|
||||
exportMethods(as.data.frame.mo)
|
||||
exportMethods(as.double.mic)
|
||||
@ -192,8 +197,6 @@ exportMethods(print.mo)
|
||||
exportMethods(print.mo_renamed)
|
||||
exportMethods(print.mo_uncertainties)
|
||||
exportMethods(print.rsi)
|
||||
exportMethods(pull.ab)
|
||||
exportMethods(pull.mo)
|
||||
exportMethods(scale_type.ab)
|
||||
exportMethods(scale_type.mo)
|
||||
exportMethods(skewness)
|
||||
|
19
NEWS.md
19
NEWS.md
@ -1,4 +1,4 @@
|
||||
# AMR 0.7.1.9035
|
||||
# AMR 0.7.1.9038
|
||||
|
||||
### Breaking
|
||||
* Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too.
|
||||
@ -46,16 +46,13 @@
|
||||
* Printed info now distinguishes between added and changes values
|
||||
* Using Verbose mode (i.e. `eucast_rules(..., verbose = TRUE)`) returns more informative and readable output
|
||||
* Using factors as input now adds missing factors levels when the function changes antibiotic results
|
||||
* Added tibble printing support for classes `rsi`, `mic`, `ab` and `mo`. When using tibbles containing antibiotic columns, values `S` will print in green, values `I` will print in yellow and values `R` will print in red:
|
||||
* Added tibble printing support for classes `rsi`, `mic`, `disk`, `ab` `mo`. When using tibbles containing antibiotic columns, values `S` will print in green, values `I` will print in yellow and values `R` will print in red. Microbial IDs (class `mo`) will emphasise on the genus and species, not on the kingdom.
|
||||
```r
|
||||
# (run this on your own console, as this page does not support colour printing)
|
||||
tibble(mo = sample(AMR::microorganisms$fullname, 10),
|
||||
drug1 = as.rsi(sample(c("S", "I", "R"), 10, replace = TRUE,
|
||||
prob = c(0.6, 0.1, 0.3))),
|
||||
drug2 = as.rsi(sample(c("S", "I", "R"), 10, replace = TRUE,
|
||||
prob = c(0.6, 0.1, 0.3))),
|
||||
drug3 = as.rsi(sample(c("S", "I", "R"), 10, replace = TRUE,
|
||||
prob = c(0.6, 0.1, 0.3))))
|
||||
library(dplyr)
|
||||
septic_patients %>%
|
||||
select(mo:AMC) %>%
|
||||
as_tibble()
|
||||
```
|
||||
* Removed class `atc` - using `as.atc()` is now deprecated in favour of `ab_atc()` and this will return a character, not the `atc` class anymore
|
||||
* Removed deprecated functions `abname()`, `ab_official()`, `atc_name()`, `atc_official()`, `atc_property()`, `atc_tradenames()`, `atc_trivial_nl()`
|
||||
@ -69,8 +66,10 @@
|
||||
* Fix for using `mo_*` functions where the coercion uncertainties and failures would not be available through `mo_uncertainties()` and `mo_failures()` anymore
|
||||
* Deprecated the `country` parameter of `mdro()` in favour of the already existing `guideline` parameter to support multiple guidelines within one country
|
||||
* The `name` of `RIF` is now Rifampicin instead of Rifampin
|
||||
* The `antibiotics` data set is now sorted by name and all cephalosporines now have their generation between brackets
|
||||
* The `antibiotics` data set is now sorted by name and all cephalosporins now have their generation between brackets
|
||||
* Speed improvement for `guess_ab_col()` which is now 30 times faster for antibiotic abbreviations
|
||||
* Improved `filter_ab_class()` to be more reliable and to support 5th generation cephalosporins
|
||||
* Classes `ab` and `mo` will now be preserved in any subsetting
|
||||
|
||||
#### Other
|
||||
* Added Dr Bart Meijer, Dr Dennis Souverein and Annick Lenglet as contributors
|
||||
|
9
R/ab.R
9
R/ab.R
@ -279,12 +279,13 @@ as.data.frame.ab <- function (x, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod pull.ab
|
||||
#' @exportMethod [.ab
|
||||
#' @export
|
||||
#' @importFrom dplyr pull
|
||||
#' @noRd
|
||||
pull.ab <- function(.data, ...) {
|
||||
pull(as.data.frame(.data), ...)
|
||||
"[.ab" <- function (x, ...) {
|
||||
# this function is needed to preserve the "ab" class for any subsetting, like df %>% filter(...)
|
||||
y <- NextMethod()
|
||||
structure(y, class = "ab")
|
||||
}
|
||||
|
||||
#' @importFrom pillar type_sum
|
||||
|
14
R/disk.R
14
R/disk.R
@ -90,3 +90,17 @@ print.disk <- function(x, ...) {
|
||||
cat("Class 'disk'\n")
|
||||
print(as.integer(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @importFrom pillar type_sum
|
||||
#' @export
|
||||
type_sum.disk <- function(x) {
|
||||
"disk"
|
||||
}
|
||||
|
||||
#' @importFrom pillar pillar_shaft
|
||||
#' @export
|
||||
pillar_shaft.disk <- function(x, ...) {
|
||||
out <- trimws(format(x))
|
||||
out[is.na(x)] <- pillar::style_na(NA)
|
||||
pillar::new_pillar_shaft_simple(out, align = "right", min_width = 3)
|
||||
}
|
||||
|
@ -22,12 +22,12 @@
|
||||
#' Filter isolates on result in antibiotic class
|
||||
#'
|
||||
#' 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.
|
||||
#' @param tbl a data set
|
||||
#' @param ab_class an antimicrobial class, like \code{"carbapenems"}. More specifically, this should be a text that can be found in a 4th level ATC group (chemical subgroup) or a 5th level ATC group (chemical substance), please see \href{https://www.whocc.no/atc/structure_and_principles/}{this explanation on the WHOCC website}.
|
||||
#' @param x a data set
|
||||
#' @param ab_class an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{AMR::antibiotics$group}
|
||||
#' @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 \code{"any"} (default) or \code{"all"}
|
||||
#' @param ... parameters passed on to \code{\link[dplyr]{filter_at}}
|
||||
#' @details The \code{\link{antibiotics}} data set will be searched for \code{ab_class} in the columns \code{atc_group1} and \code{atc_group2} (case-insensitive). Next, \code{tbl} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set.
|
||||
#' @details The \code{group} column in \code{\link{antibiotics}} data set will be searched for \code{ab_class} (case-insensitive). If no results are found, the \code{atc_group1} and \code{atc_group2} columns will be searched. Next, \code{x} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set.
|
||||
#' @rdname filter_ab_class
|
||||
#' @keywords filter fillter_class
|
||||
#' @importFrom dplyr filter_at %>% select vars any_vars all_vars
|
||||
@ -62,7 +62,7 @@
|
||||
#' septic_patients %>%
|
||||
#' filter_aminoglycosides("R", "all") %>%
|
||||
#' filter_fluoroquinolones("R", "all")
|
||||
filter_ab_class <- function(tbl,
|
||||
filter_ab_class <- function(x,
|
||||
ab_class,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
@ -71,7 +71,7 @@ filter_ab_class <- function(tbl,
|
||||
if (is.null(result)) {
|
||||
result <- c("S", "I", "R")
|
||||
}
|
||||
# make result = "IR" work too:
|
||||
# make result = "SI" work too:
|
||||
result <- unlist(strsplit(result, ""))
|
||||
|
||||
if (!all(result %in% c("S", "I", "R"))) {
|
||||
@ -81,8 +81,8 @@ filter_ab_class <- function(tbl,
|
||||
stop("`scope` must be one of: any, all", call. = FALSE)
|
||||
}
|
||||
|
||||
vars_df <- colnames(tbl)[tolower(colnames(tbl)) %in% tolower(ab_class_vars(ab_class))]
|
||||
atc_groups <- ab_class_atcgroups(ab_class)
|
||||
vars_df <- colnames(x)[tolower(colnames(x)) %in% tolower(ab_class_vars(ab_class))]
|
||||
ab_group <- find_ab_group(ab_class)
|
||||
|
||||
if (length(vars_df) > 0) {
|
||||
if (length(result) == 1) {
|
||||
@ -101,29 +101,29 @@ filter_ab_class <- function(tbl,
|
||||
}
|
||||
}
|
||||
if (length(vars_df) > 1) {
|
||||
scope <- paste(scope, "of ")
|
||||
scope <- paste(scope, "of columns ")
|
||||
} else {
|
||||
scope <- ""
|
||||
scope <- "column "
|
||||
}
|
||||
message(blue(paste0("Filtering on ", atc_groups, ": ", scope,
|
||||
message(blue(paste0("Filtering on ", ab_group, ": ", scope,
|
||||
paste(bold(paste0("`", vars_df, "`")), collapse = scope_txt), operator, toString(result))))
|
||||
tbl %>%
|
||||
x %>%
|
||||
filter_at(vars(vars_df),
|
||||
scope_fn(. %in% result),
|
||||
...)
|
||||
} else {
|
||||
warning(paste0("no antibiotics of class ", atc_groups, " found, leaving data unchanged"), call. = FALSE)
|
||||
tbl
|
||||
warning(paste0("no antibiotics of class ", ab_group, " found, leaving data unchanged"), call. = FALSE)
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_aminoglycosides <- function(tbl,
|
||||
filter_aminoglycosides <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "aminoglycoside",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -132,11 +132,11 @@ filter_aminoglycosides <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_carbapenems <- function(tbl,
|
||||
filter_carbapenems <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "carbapenem",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -145,11 +145,11 @@ filter_carbapenems <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_cephalosporins <- function(tbl,
|
||||
filter_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -158,12 +158,12 @@ filter_cephalosporins <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_1st_cephalosporins <- function(tbl,
|
||||
filter_1st_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "first-generation cephalosporin",
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporins (1st gen.)",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
@ -171,12 +171,12 @@ filter_1st_cephalosporins <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_2nd_cephalosporins <- function(tbl,
|
||||
filter_2nd_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "second-generation cephalosporin",
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporins (2nd gen.)",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
@ -184,12 +184,12 @@ filter_2nd_cephalosporins <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_3rd_cephalosporins <- function(tbl,
|
||||
filter_3rd_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "third-generation cephalosporin",
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporins (3rd gen.)",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
@ -197,12 +197,12 @@ filter_3rd_cephalosporins <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_4th_cephalosporins <- function(tbl,
|
||||
filter_4th_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "fourth-generation cephalosporin",
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporins (4th gen.)",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
@ -210,11 +210,24 @@ filter_4th_cephalosporins <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_fluoroquinolones <- function(tbl,
|
||||
filter_5th_cephalosporins <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "cephalosporins (5th gen.)",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_fluoroquinolones <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "fluoroquinolone",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -223,11 +236,11 @@ filter_fluoroquinolones <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_glycopeptides <- function(tbl,
|
||||
filter_glycopeptides <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "glycopeptide",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -236,11 +249,11 @@ filter_glycopeptides <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_macrolides <- function(tbl,
|
||||
filter_macrolides <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "macrolide",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -249,11 +262,11 @@ filter_macrolides <- function(tbl,
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_tetracyclines <- function(tbl,
|
||||
filter_tetracyclines <- function(x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
filter_ab_class(x = x,
|
||||
ab_class = "tetracycline",
|
||||
result = result,
|
||||
scope = scope,
|
||||
@ -262,8 +275,9 @@ filter_tetracyclines <- function(tbl,
|
||||
|
||||
#' @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 %>%
|
||||
filter_at(vars(c("atc_group1", "atc_group2")), any_vars(. %like% ab_class)) %>%
|
||||
filter(group %like% ab_class) %>%
|
||||
select(ab:name, abbreviations, synonyms) %>%
|
||||
unlist() %>%
|
||||
as.matrix() %>%
|
||||
@ -272,18 +286,29 @@ ab_class_vars <- function(ab_class) {
|
||||
strsplit("|", fixed = TRUE) %>%
|
||||
unlist() %>%
|
||||
unique()
|
||||
ab_vars[!is.na(ab_vars)]
|
||||
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 %>%
|
||||
filter_at(vars(c("atc_group1", "atc_group2")), any_vars(. %like% ab_class)) %>%
|
||||
select(ab:name, abbreviations, synonyms) %>%
|
||||
unlist() %>%
|
||||
as.matrix() %>%
|
||||
as.character() %>%
|
||||
paste(collapse = "|") %>%
|
||||
strsplit("|", fixed = TRUE) %>%
|
||||
unlist() %>%
|
||||
unique()
|
||||
ab_vars <- ab_vars[!ab_vars %in% c(NA, "", "NA") & nchar(ab_vars) > 2]
|
||||
}
|
||||
ab_vars
|
||||
}
|
||||
|
||||
#' @importFrom dplyr %>% filter pull
|
||||
ab_class_atcgroups <- function(ab_class) {
|
||||
find_ab_group <- function(ab_class) {
|
||||
ifelse(ab_class %in% c("aminoglycoside",
|
||||
"carbapenem",
|
||||
"cephalosporin",
|
||||
"first-generation cephalosporin",
|
||||
"second-generation cephalosporin",
|
||||
"third-generation cephalosporin",
|
||||
"fourth-generation cephalosporin",
|
||||
"fluoroquinolone",
|
||||
"glycopeptide",
|
||||
"macrolide",
|
||||
@ -291,7 +316,7 @@ ab_class_atcgroups <- function(ab_class) {
|
||||
paste0(ab_class, "s"),
|
||||
AMR::antibiotics %>%
|
||||
filter(ab %in% ab_class_vars(ab_class)) %>%
|
||||
pull("atc_group2") %>%
|
||||
pull(group) %>%
|
||||
unique() %>%
|
||||
tolower() %>%
|
||||
paste(collapse = "/")
|
||||
|
@ -36,6 +36,7 @@ globalVariables(c(".",
|
||||
"fullname_lower",
|
||||
"genus",
|
||||
"gramstain",
|
||||
"group",
|
||||
"index",
|
||||
"input",
|
||||
"interpretation",
|
||||
|
2
R/mic.R
2
R/mic.R
@ -289,6 +289,6 @@ type_sum.mic <- function(x) {
|
||||
#' @export
|
||||
pillar_shaft.mic <- function(x, ...) {
|
||||
out <- trimws(format(x))
|
||||
out[is.na(x)] <- NA
|
||||
out[is.na(x)] <- pillar::style_na(NA)
|
||||
pillar::new_pillar_shaft_simple(out, align = "right", min_width = 4)
|
||||
}
|
||||
|
351
R/mo.R
351
R/mo.R
@ -193,19 +193,19 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
require("AMR")
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
|
||||
|
||||
uncertainty_level <- translate_allow_uncertain(allow_uncertain)
|
||||
# mo_hist <- get_mo_history(x, uncertainty_level, force = isTRUE(list(...)$force_mo_history))
|
||||
|
||||
|
||||
if (mo_source_isvalid(reference_df)
|
||||
& isFALSE(Becker)
|
||||
& isFALSE(Lancefield)
|
||||
& !is.null(reference_df)
|
||||
& all(x %in% reference_df[,1][[1]])) {
|
||||
|
||||
|
||||
# has valid own reference_df
|
||||
# (data.table not faster here)
|
||||
reference_df <- reference_df %>% filter(!is.na(mo))
|
||||
@ -225,18 +225,18 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
left_join(reference_df, by = "x") %>%
|
||||
pull("mo")
|
||||
)
|
||||
|
||||
|
||||
} else if (all(x %in% AMR::microorganisms$mo)
|
||||
& isFALSE(Becker)
|
||||
& isFALSE(Lancefield)) {
|
||||
y <- x
|
||||
|
||||
|
||||
# } else if (!any(is.na(mo_hist))
|
||||
# & isFALSE(Becker)
|
||||
# & isFALSE(Lancefield)) {
|
||||
# # check previously found results
|
||||
# y <- mo_hist
|
||||
|
||||
|
||||
} else if (all(tolower(x) %in% microorganismsDT$fullname_lower)
|
||||
& isFALSE(Becker)
|
||||
& isFALSE(Lancefield)) {
|
||||
@ -257,7 +257,7 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
}
|
||||
# save them to history
|
||||
set_mo_history(x, y, 0, force = isTRUE(list(...)$force_mo_history))
|
||||
|
||||
|
||||
} else {
|
||||
# will be checked for mo class in validation and uses exec_as.mo internally if necessary
|
||||
y <- mo_validate(x = x, property = "mo",
|
||||
@ -266,8 +266,8 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
force_mo_history = isTRUE(list(...)$force_mo_history),
|
||||
...)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
to_class_mo(y)
|
||||
}
|
||||
|
||||
@ -286,6 +286,7 @@ is.mo <- function(x) {
|
||||
#' @importFrom crayon magenta red blue silver italic
|
||||
# param property a column name of AMR::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 force_mo_history logical - whether found result must be saved with set_mo_history (default FALSE on non-interactive sessions)
|
||||
# param debug logical - show different lookup texts while searching
|
||||
exec_as.mo <- function(x,
|
||||
@ -295,23 +296,24 @@ exec_as.mo <- function(x,
|
||||
reference_df = get_mo_source(),
|
||||
property = "mo",
|
||||
initial_search = TRUE,
|
||||
dyslexia_mode = FALSE,
|
||||
force_mo_history = FALSE,
|
||||
debug = FALSE) {
|
||||
|
||||
|
||||
if (!"AMR" %in% base::.packages()) {
|
||||
require("AMR")
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
|
||||
|
||||
if (initial_search == TRUE) {
|
||||
options(mo_failures = NULL)
|
||||
options(mo_uncertainties = NULL)
|
||||
options(mo_renamed = NULL)
|
||||
}
|
||||
|
||||
|
||||
if (NCOL(x) == 2) {
|
||||
# support tidyverse selection like: df %>% select(colA, colB)
|
||||
# paste these columns together
|
||||
@ -325,20 +327,20 @@ exec_as.mo <- function(x,
|
||||
stop('`x` can be 2 columns at most', call. = FALSE)
|
||||
}
|
||||
x[is.null(x)] <- NA
|
||||
|
||||
|
||||
# support tidyverse selection like: df %>% select(colA)
|
||||
if (!is.vector(x) & !is.null(dim(x))) {
|
||||
x <- pull(x, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
notes <- character(0)
|
||||
uncertainties <- data.frame(input = character(0),
|
||||
fullname = character(0),
|
||||
mo = character(0))
|
||||
failures <- character(0)
|
||||
uncertainty_level <- translate_allow_uncertain(allow_uncertain)
|
||||
|
||||
|
||||
x_input <- x
|
||||
# already strip leading and trailing spaces
|
||||
x <- trimws(x, which = "both")
|
||||
@ -350,7 +352,7 @@ exec_as.mo <- function(x,
|
||||
& !is.null(x)
|
||||
& !identical(x, "")
|
||||
& !identical(x, "xxx")]
|
||||
|
||||
|
||||
# conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life)
|
||||
if (any(x %like% "^[BFP]_[A-Z]{3,7}") & !all(x %in% microorganisms$mo)) {
|
||||
leftpart <- gsub("^([BFP]_[A-Z]{3,7}).*", "\\1", x)
|
||||
@ -372,7 +374,7 @@ exec_as.mo <- function(x,
|
||||
pull(new)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# defined df to check for
|
||||
if (!is.null(reference_df)) {
|
||||
if (!mo_source_isvalid(reference_df)) {
|
||||
@ -391,7 +393,7 @@ exec_as.mo <- function(x,
|
||||
reference_df[] <- lapply(reference_df, as.character)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
# all empty
|
||||
if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0)) {
|
||||
if (property == "mo") {
|
||||
@ -399,7 +401,7 @@ exec_as.mo <- function(x,
|
||||
} else {
|
||||
return(rep(NA_character_, length(x_input)))
|
||||
}
|
||||
|
||||
|
||||
} else if (all(x %in% reference_df[, 1][[1]])) {
|
||||
# all in reference df
|
||||
colnames(reference_df)[1] <- "x"
|
||||
@ -409,7 +411,7 @@ exec_as.mo <- function(x,
|
||||
left_join(AMR::microorganisms, by = "mo") %>%
|
||||
pull(property)
|
||||
)
|
||||
|
||||
|
||||
} else if (all(x %in% AMR::microorganisms$mo)) {
|
||||
# existing mo codes when not looking for property "mo", like mo_genus("B_ESCHR_COL")
|
||||
y <- microorganismsDT[prevalence == 1][data.table(mo = x), on = "mo", ..property][[1]]
|
||||
@ -424,7 +426,7 @@ exec_as.mo <- function(x,
|
||||
..property][[1]]
|
||||
}
|
||||
x <- y
|
||||
|
||||
|
||||
} else if (all(x %in% read_mo_history(uncertainty_level,
|
||||
force = force_mo_history)$x)) {
|
||||
# previously found code
|
||||
@ -432,7 +434,7 @@ exec_as.mo <- function(x,
|
||||
uncertainty_level,
|
||||
force = force_mo_history)),
|
||||
on = "mo", ..property][[1]]
|
||||
|
||||
|
||||
} else if (all(tolower(x) %in% microorganismsDT$fullname_lower)) {
|
||||
# we need special treatment for very prevalent full names, they are likely!
|
||||
# e.g. as.mo("Staphylococcus aureus")
|
||||
@ -448,30 +450,30 @@ exec_as.mo <- function(x,
|
||||
..property][[1]]
|
||||
}
|
||||
x <- y
|
||||
|
||||
|
||||
} else if (all(toupper(x) %in% AMR::microorganisms.codes$code)) {
|
||||
# commonly used MO codes
|
||||
y <- as.data.table(AMR::microorganisms.codes)[data.table(code = toupper(x)), on = "code", ]
|
||||
# save them to history
|
||||
set_mo_history(x, y$mo, 0, force = force_mo_history)
|
||||
|
||||
|
||||
x <- microorganismsDT[data.table(mo = y[["mo"]]), on = "mo", ..property][[1]]
|
||||
|
||||
|
||||
} else if (!all(x %in% AMR::microorganisms[, property])) {
|
||||
|
||||
|
||||
strip_whitespace <- function(x) {
|
||||
# all whitespaces (tab, new lines, etc.) should be one space
|
||||
# and spaces before and after should be omitted
|
||||
trimws(gsub("[\\s]+", " ", x, perl = TRUE), which = "both")
|
||||
}
|
||||
|
||||
|
||||
x <- strip_whitespace(x)
|
||||
x_backup <- x
|
||||
|
||||
|
||||
# remove spp and species
|
||||
x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x_backup, ignore.case = TRUE)
|
||||
x <- strip_whitespace(x)
|
||||
|
||||
|
||||
x_backup_without_spp <- x
|
||||
x_species <- paste(x, "species")
|
||||
# translate to English for supported languages of mo_property
|
||||
@ -490,7 +492,7 @@ exec_as.mo <- function(x,
|
||||
# remove genus as first word
|
||||
x <- gsub("^Genus ", "", x)
|
||||
# allow characters that resemble others ----
|
||||
if (initial_search == FALSE) {
|
||||
if (dyslexia_mode == TRUE) {
|
||||
x <- tolower(x)
|
||||
x <- gsub("[iy]+", "[iy]+", x)
|
||||
x <- gsub("(c|k|q|qu|s|z|x|ks)+", "(c|k|q|qu|s|z|x|ks)+", x)
|
||||
@ -512,7 +514,7 @@ exec_as.mo <- function(x,
|
||||
x <- gsub("e\\+n(?![a-z[])", "(e+n|u+(c|k|q|qu|s|z|x|ks)+)", x, ignore.case = TRUE, perl = TRUE)
|
||||
}
|
||||
x <- strip_whitespace(x)
|
||||
|
||||
|
||||
x_trimmed <- x
|
||||
x_trimmed_species <- paste(x_trimmed, "species")
|
||||
x_trimmed_without_group <- gsub(" gro.u.p$", "", x_trimmed, ignore.case = TRUE)
|
||||
@ -526,7 +528,7 @@ exec_as.mo <- function(x,
|
||||
x_withspaces_start_only <- paste0('^', x_withspaces)
|
||||
x_withspaces_end_only <- paste0(x_withspaces, '$')
|
||||
x_withspaces_start_end <- paste0('^', x_withspaces, '$')
|
||||
|
||||
|
||||
if (isTRUE(debug)) {
|
||||
cat(paste0('x "', x, '"\n'))
|
||||
cat(paste0('x_species "', x_species, '"\n'))
|
||||
@ -539,13 +541,13 @@ exec_as.mo <- function(x,
|
||||
cat(paste0('x_trimmed_species "', x_trimmed_species, '"\n'))
|
||||
cat(paste0('x_trimmed_without_group "', x_trimmed_without_group, '"\n'))
|
||||
}
|
||||
|
||||
|
||||
progress <- progress_estimated(n = length(x), min_time = 3)
|
||||
|
||||
|
||||
for (i in 1:length(x)) {
|
||||
|
||||
|
||||
progress$tick()$print()
|
||||
|
||||
|
||||
if (initial_search == TRUE) {
|
||||
found <- microorganismsDT[mo == get_mo_history(x_backup[i],
|
||||
uncertainty_level,
|
||||
@ -557,14 +559,14 @@ exec_as.mo <- function(x,
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
found <- microorganismsDT[mo == toupper(x_backup[i]), ..property][[1]]
|
||||
# is a valid MO code
|
||||
if (length(found) > 0) {
|
||||
x[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
found <- microorganismsDT[fullname_lower %in% tolower(c(x_backup[i], x_backup_without_spp[i])), ..property][[1]]
|
||||
# most probable: is exact match in fullname
|
||||
if (length(found) > 0) {
|
||||
@ -574,7 +576,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
found <- microorganismsDT[col_id == x_backup[i], ..property][[1]]
|
||||
# is a valid Catalogue of Life ID
|
||||
if (NROW(found) > 0) {
|
||||
@ -584,14 +586,14 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# WHONET: xxx = no growth
|
||||
if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) {
|
||||
x[i] <- NA_character_
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
if (tolower(x_backup_without_spp[i]) %in% c("other", "none", "unknown")) {
|
||||
# empty and nonsense values, ignore without warning
|
||||
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
|
||||
@ -600,7 +602,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
# check for very small input, but ignore the O antigens of E. coli
|
||||
if (nchar(gsub("[^a-zA-Z]", "", x_trimmed[i])) < 3
|
||||
& !x_backup_without_spp[i] %like% "O?(26|103|104|104|111|121|145|157)") {
|
||||
@ -629,7 +631,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
if (x_backup_without_spp[i] %like% "virus") {
|
||||
# there is no fullname like virus, so don't try to coerce it
|
||||
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
|
||||
@ -639,7 +641,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
# translate known trivial abbreviations to genus + species ----
|
||||
if (!is.na(x_trimmed[i])) {
|
||||
if (toupper(x_backup_without_spp[i]) %in% c('MRSA', 'MSSA', 'VISA', 'VRSA')) {
|
||||
@ -830,7 +832,7 @@ exec_as.mo <- function(x,
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# FIRST TRY FULLNAMES AND CODES ----
|
||||
# if only genus is available, return only genus
|
||||
if (all(!c(x[i], x_trimmed[i]) %like% " ")) {
|
||||
@ -854,7 +856,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
# rest of genus only is in allow_uncertain part.
|
||||
}
|
||||
|
||||
|
||||
# TRY OTHER SOURCES ----
|
||||
# WHONET and other common LIS codes
|
||||
if (toupper(x_backup[i]) %in% AMR::microorganisms.codes[, 1]) {
|
||||
@ -879,7 +881,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# allow no codes less than 4 characters long, was already checked for WHONET above
|
||||
if (nchar(x_backup_without_spp[i]) < 4) {
|
||||
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
|
||||
@ -889,7 +891,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
check_per_prevalence <- function(data_to_check,
|
||||
a.x_backup,
|
||||
b.x_trimmed,
|
||||
@ -898,19 +900,19 @@ exec_as.mo <- function(x,
|
||||
e.x_withspaces_start_only,
|
||||
f.x_withspaces_end_only,
|
||||
g.x_backup_without_spp) {
|
||||
|
||||
|
||||
# try probable: trimmed version of fullname ----
|
||||
found <- data_to_check[fullname_lower %in% tolower(g.x_backup_without_spp), ..property][[1]]
|
||||
if (length(found) > 0) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# try any match keeping spaces ----
|
||||
found <- data_to_check[fullname %like% d.x_withspaces_start_end, ..property][[1]]
|
||||
if (length(found) > 0 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# try any match keeping spaces, not ending with $ ----
|
||||
found <- data_to_check[fullname %like% paste0(trimws(e.x_withspaces_start_only), " "), ..property][[1]]
|
||||
if (length(found) > 0) {
|
||||
@ -920,21 +922,21 @@ exec_as.mo <- function(x,
|
||||
if (length(found) > 0 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# try any match keeping spaces, not start with ^ ----
|
||||
found <- data_to_check[fullname %like% paste0(" ", trimws(f.x_withspaces_end_only)), ..property][[1]]
|
||||
if (length(found) > 0) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# try a trimmed version
|
||||
found <- data_to_check[fullname_lower %like% b.x_trimmed
|
||||
| fullname_lower %like% c.x_trimmed_without_group, ..property][[1]]
|
||||
if (length(found) > 0 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# try splitting of characters in the middle and then find ID ----
|
||||
# only when text length is 6 or lower
|
||||
# like esco = E. coli, klpn = K. pneumoniae, stau = S. aureus, staaur = S. aureus
|
||||
@ -949,18 +951,18 @@ exec_as.mo <- function(x,
|
||||
return(found[1L])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# try fullname without start and without nchar limit of >= 6 ----
|
||||
# like "K. pneu rhino" >> "Klebsiella pneumoniae (rhinoscleromatis)" = KLEPNERH
|
||||
found <- data_to_check[fullname %like% e.x_withspaces_start_only, ..property][[1]]
|
||||
if (length(found) > 0) {
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# didn't found any
|
||||
return(NA_character_)
|
||||
}
|
||||
|
||||
|
||||
# FIRST TRY VERY PREVALENT IN HUMAN INFECTIONS ----
|
||||
x[i] <- check_per_prevalence(data_to_check = microorganismsDT[prevalence == 1],
|
||||
a.x_backup = x_backup[i],
|
||||
@ -1006,9 +1008,9 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
# MISCELLANEOUS ----
|
||||
|
||||
|
||||
# look for old taxonomic names ----
|
||||
found <- microorganisms.oldDT[fullname_lower == tolower(x_backup[i])
|
||||
| fullname %like% x_withspaces_start_end[i],]
|
||||
@ -1032,7 +1034,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
# check for uncertain results ----
|
||||
uncertain_fn <- function(a.x_backup,
|
||||
b.x_trimmed,
|
||||
@ -1040,17 +1042,22 @@ exec_as.mo <- function(x,
|
||||
d.x_withspaces_start_only,
|
||||
f.x_withspaces_end_only,
|
||||
g.x_backup_without_spp) {
|
||||
|
||||
|
||||
if (uncertainty_level == 0) {
|
||||
# do not allow uncertainties
|
||||
return(NA_character_)
|
||||
}
|
||||
|
||||
|
||||
if (uncertainty_level >= 1) {
|
||||
now_checks_for_uncertainty_level <- 1
|
||||
|
||||
# (1) look again for old taxonomic names, now for G. species ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 1] (1) look again for old taxonomic names, now for G. species\n")
|
||||
}
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", c.x_withspaces_start_end, "' and '", d.x_withspaces_start_only, "'")
|
||||
}
|
||||
found <- microorganisms.oldDT[fullname %like% c.x_withspaces_start_end
|
||||
| fullname %like% d.x_withspaces_start_only]
|
||||
if (NROW(found) > 0 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
@ -1068,7 +1075,7 @@ exec_as.mo <- function(x,
|
||||
ref_new = microorganismsDT[col_id == found[1, col_id_new], ref],
|
||||
mo = microorganismsDT[col_id == found[1, col_id_new], mo])
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 1,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = found[1, fullname],
|
||||
mo = paste("CoL", found[1, col_id])))
|
||||
@ -1077,18 +1084,26 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
return(x)
|
||||
}
|
||||
|
||||
|
||||
# (2) Try with misspelled input ----
|
||||
# just rerun with initial_search = FALSE will used the extensive regex part above
|
||||
# just rerun with dyslexia_mode = TRUE will used the extensive regex part above
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 1] (2) Try with misspelled input\n")
|
||||
}
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", a.x_backup, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 1,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1098,21 +1113,25 @@ exec_as.mo <- function(x,
|
||||
return(found[1L])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uncertainty_level >= 2) {
|
||||
|
||||
now_checks_for_uncertainty_level <- 2
|
||||
|
||||
# (3) look for genus only, part of name ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 2] (3) look for genus only, part of name\n")
|
||||
}
|
||||
if (nchar(g.x_backup_without_spp) > 4 & !b.x_trimmed %like% " ") {
|
||||
if (!grepl("^[A-Z][a-z]+", b.x_trimmed, ignore.case = FALSE)) {
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", paste(b.x_trimmed, "species"), "'")
|
||||
}
|
||||
# not when input is like Genustext, because then Neospora would lead to Actinokineospora
|
||||
found <- microorganismsDT[fullname_lower %like% paste(b.x_trimmed, "species"), ..property][[1]]
|
||||
if (length(found) > 0) {
|
||||
x[i] <- found[1L]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found[1L], fullname][[1]],
|
||||
mo = found[1L]))
|
||||
@ -1123,19 +1142,27 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# (4) strip values between brackets ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 2] (4) strip values between brackets\n")
|
||||
}
|
||||
a.x_backup_stripped <- gsub("( *[(].*[)] *)", " ", a.x_backup)
|
||||
a.x_backup_stripped <- trimws(gsub(" +", " ", a.x_backup_stripped))
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup_stripped, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", a.x_backup_stripped, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup_stripped, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(a.x_backup_stripped, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found) & nchar(g.x_backup_without_spp) >= 6) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1144,7 +1171,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
return(found[1L])
|
||||
}
|
||||
|
||||
|
||||
# (5a) try to strip off half an element from end and check the remains ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 2] (5a) try to strip off half an element from end and check the remains\n")
|
||||
@ -1156,13 +1183,21 @@ exec_as.mo <- function(x,
|
||||
lastword_half <- substr(lastword, 1, as.integer(nchar(lastword) / 2))
|
||||
# remove last half of the second term
|
||||
x_strip_collapsed <- paste(c(x_strip[1:(length(x_strip) - i)], lastword_half), collapse = " ")
|
||||
if (nchar(x_strip_collapsed) >= 4) {
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (nchar(x_strip_collapsed) >= 4 & nchar(lastword_half) > 2) {
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", x_strip_collapsed, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1181,13 +1216,21 @@ exec_as.mo <- function(x,
|
||||
if (length(x_strip) > 1) {
|
||||
for (i in 1:(length(x_strip) - 1)) {
|
||||
x_strip_collapsed <- paste(x_strip[1:(length(x_strip) - i)], collapse = " ")
|
||||
if (nchar(x_strip_collapsed) >= 4) {
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (nchar(x_strip_collapsed) >= 6) {
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", x_strip_collapsed, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1208,7 +1251,7 @@ exec_as.mo <- function(x,
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1222,7 +1265,7 @@ exec_as.mo <- function(x,
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1239,14 +1282,22 @@ exec_as.mo <- function(x,
|
||||
if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
for (i in 2:(length(x_strip))) {
|
||||
x_strip_collapsed <- paste(x_strip[i:length(x_strip)], collapse = " ")
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", x_strip_collapsed, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found_result[1L], ..property][[1]]
|
||||
# uncertainty level 2 only if searched part contains a space (otherwise it will be found with lvl 3)
|
||||
if (x_strip_collapsed %like% " ") {
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 2,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1259,22 +1310,32 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uncertainty_level >= 3) {
|
||||
# (7) try to strip off one element from start and check the remains ----
|
||||
now_checks_for_uncertainty_level <- 3
|
||||
|
||||
# (7a) try to strip off one element from start and check the remains (any text size) ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 3] (7) try to strip off one element from start and check the remains\n")
|
||||
cat("\n[UNCERTAINLY LEVEL 3] (7a) try to strip off one element from start and check the remains (any text size)\n")
|
||||
}
|
||||
x_strip <- a.x_backup %>% strsplit(" ") %>% unlist()
|
||||
if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) {
|
||||
for (i in 2:(length(x_strip))) {
|
||||
x_strip_collapsed <- paste(x_strip[i:length(x_strip)], collapse = " ")
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", x_strip_collapsed, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 3,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1285,18 +1346,53 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# (7b) try to strip off one element from end and check the remains (any text size) ----
|
||||
# (this is in fact 5b but without nchar limit of >=6)
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 3] (7b) try to strip off one element from end and check the remains (any text size)\n")
|
||||
}
|
||||
if (length(x_strip) > 1) {
|
||||
for (i in 1:(length(x_strip) - 1)) {
|
||||
x_strip_collapsed <- paste(x_strip[1:(length(x_strip) - i)], collapse = " ")
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", x_strip_collapsed, "'")
|
||||
}
|
||||
# first try without dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug)))
|
||||
if (empty_result(found)) {
|
||||
# then with dyslexia mode
|
||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug)))
|
||||
}
|
||||
if (!empty_result(found)) {
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
if (initial_search == TRUE) {
|
||||
set_mo_history(a.x_backup, get_mo_code(found[1L], property), 2, force = force_mo_history)
|
||||
}
|
||||
return(found[1L])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# (8) part of a name (very unlikely match) ----
|
||||
if (isTRUE(debug)) {
|
||||
cat("\n[UNCERTAINLY LEVEL 3] (8) part of a name (very unlikely match)\n")
|
||||
}
|
||||
if (isTRUE(debug)) {
|
||||
message("Running '", f.x_withspaces_end_only, "'")
|
||||
}
|
||||
found <- microorganismsDT[fullname %like% f.x_withspaces_end_only]
|
||||
if (nrow(found) > 0) {
|
||||
found_result <- found[["mo"]]
|
||||
if (!empty_result(found_result) & nchar(g.x_backup_without_spp) >= 6) {
|
||||
found <- microorganismsDT[mo == found_result[1L], ..property][[1]]
|
||||
uncertainties <<- rbind(uncertainties,
|
||||
data.frame(uncertainty = 3,
|
||||
data.frame(uncertainty = now_checks_for_uncertainty_level,
|
||||
input = a.x_backup,
|
||||
fullname = microorganismsDT[mo == found_result[1L], fullname][[1]],
|
||||
mo = found_result[1L]))
|
||||
@ -1307,7 +1403,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# didn't found in uncertain results too
|
||||
return(NA_character_)
|
||||
}
|
||||
@ -1321,7 +1417,7 @@ exec_as.mo <- function(x,
|
||||
# no set_mo_history here - it is already set in uncertain_fn()
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
# no results found: make them UNKNOWN ----
|
||||
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
|
||||
if (initial_search == TRUE) {
|
||||
@ -1330,7 +1426,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# handling failures ----
|
||||
failures <- failures[!failures %in% c(NA, NULL, NaN)]
|
||||
if (length(failures) > 0 & initial_search == TRUE) {
|
||||
@ -1355,7 +1451,7 @@ exec_as.mo <- function(x,
|
||||
# handling uncertainties ----
|
||||
if (NROW(uncertainties) > 0 & initial_search == TRUE) {
|
||||
options(mo_uncertainties = as.list(distinct(uncertainties, input, .keep_all = TRUE)))
|
||||
|
||||
|
||||
plural <- c("", "it")
|
||||
if (NROW(uncertainties) > 1) {
|
||||
plural <- c("s", "them")
|
||||
@ -1366,7 +1462,7 @@ exec_as.mo <- function(x,
|
||||
call. = FALSE,
|
||||
immediate. = TRUE) # thus will always be shown, even if >= warnings
|
||||
}
|
||||
|
||||
|
||||
# Becker ----
|
||||
if (Becker == TRUE | Becker == "all") {
|
||||
# See Source. It's this figure:
|
||||
@ -1391,11 +1487,11 @@ exec_as.mo <- function(x,
|
||||
"pseudintermedius", "pseudointermedius",
|
||||
"schweitzeri", "argenteus")
|
||||
| (species == "schleiferi" & subspecies == "coagulans"), ..property][[1]]
|
||||
|
||||
|
||||
# warn when species found that are not in Becker (2014, PMID 25278577) and Becker (2019, PMID 30872103)
|
||||
post_Becker <- c("argensis", "caeli", "cornubiensis", "edaphicus")
|
||||
if (any(x %in% MOs_staph[species %in% post_Becker, ..property][[1]])) {
|
||||
|
||||
|
||||
warning("Becker ", italic("et al."), " (2014, 2019) does not contain these species named after their publication: ",
|
||||
italic(paste("S.",
|
||||
sort(mo_species(unique(x[x %in% MOs_staph[species %in% post_Becker, ..property][[1]]]))),
|
||||
@ -1404,14 +1500,14 @@ exec_as.mo <- function(x,
|
||||
call. = FALSE,
|
||||
immediate. = TRUE)
|
||||
}
|
||||
|
||||
|
||||
x[x %in% CoNS] <- microorganismsDT[mo == 'B_STPHY_CNS', ..property][[1]][1L]
|
||||
x[x %in% CoPS] <- microorganismsDT[mo == 'B_STPHY_CPS', ..property][[1]][1L]
|
||||
if (Becker == "all") {
|
||||
x[x %in% microorganismsDT[mo %like% '^B_STPHY_AUR', ..property][[1]]] <- microorganismsDT[mo == 'B_STPHY_CPS', ..property][[1]][1L]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Lancefield ----
|
||||
if (Lancefield == TRUE | Lancefield == "all") {
|
||||
# group A - S. pyogenes
|
||||
@ -1435,37 +1531,37 @@ exec_as.mo <- function(x,
|
||||
# group K - S. salivarius
|
||||
x[x == microorganismsDT[mo == 'B_STRPT_SAL', ..property][[1]][1L]] <- microorganismsDT[mo == 'B_STRPT_GRK', ..property][[1]][1L]
|
||||
}
|
||||
|
||||
|
||||
# Wrap up ----------------------------------------------------------------
|
||||
|
||||
|
||||
# comply to x, which is also unique and without empty values
|
||||
x_input_unique_nonempty <- unique(x_input[!is.na(x_input)
|
||||
& !is.null(x_input)
|
||||
& !identical(x_input, "")
|
||||
& !identical(x_input, "xxx")])
|
||||
|
||||
|
||||
# left join the found results to the original input values (x_input)
|
||||
df_found <- data.frame(input = as.character(x_input_unique_nonempty),
|
||||
found = as.character(x),
|
||||
stringsAsFactors = FALSE)
|
||||
df_input <- data.frame(input = as.character(x_input),
|
||||
stringsAsFactors = FALSE)
|
||||
|
||||
|
||||
suppressWarnings(
|
||||
x <- df_input %>%
|
||||
left_join(df_found,
|
||||
by = "input") %>%
|
||||
pull(found)
|
||||
)
|
||||
|
||||
|
||||
if (property == "mo") {
|
||||
x <- to_class_mo(x)
|
||||
}
|
||||
|
||||
|
||||
if (length(mo_renamed()) > 0) {
|
||||
print(mo_renamed())
|
||||
}
|
||||
|
||||
|
||||
x
|
||||
}
|
||||
|
||||
@ -1494,7 +1590,7 @@ was_renamed <- function(name_old, name_new, ref_old = "", ref_new = "", mo = "")
|
||||
old_values <- gsub("et al.", italic("et al."), old_values)
|
||||
new_values <- paste0(italic(name_new), ref_new, mo)
|
||||
new_values <- gsub("et al.", italic("et al."), new_values)
|
||||
|
||||
|
||||
names(new_values) <- old_values
|
||||
total <- c(getOption("mo_renamed"), new_values)
|
||||
options(mo_renamed = total[order(names(total))])
|
||||
@ -1521,8 +1617,18 @@ type_sum.mo <- function(x) {
|
||||
#' @export
|
||||
pillar_shaft.mo <- function(x, ...) {
|
||||
out <- format(x)
|
||||
out[is.na(x)] <- pillar::style_na("NA")
|
||||
pillar::new_pillar_shaft_simple(out, align = "left", min_width = 11)
|
||||
# grey out the kingdom (part before first "_")
|
||||
first_parts <- unlist(lapply(gregexpr(pattern = '_', x[!is.na(x)], fixed = TRUE), min))
|
||||
first_parts[first_parts < 0] <- 0
|
||||
out[!is.na(x)] <- paste0(pillar::style_subtle(substr(x[!is.na(x)], 0, first_parts)),
|
||||
substr(x[!is.na(x)], first_parts + 1, nchar(x)))
|
||||
|
||||
out[is.na(x)] <- pillar::style_na(" NA")
|
||||
out[x == "UNKNOWN"] <- pillar::style_na(" UNKNOWN")
|
||||
|
||||
out <- gsub("_", pillar::style_subtle("_"), out)
|
||||
|
||||
pillar::new_pillar_shaft_simple(out, align = "left", min_width = 12)
|
||||
}
|
||||
|
||||
#' @exportMethod summary.mo
|
||||
@ -1556,12 +1662,13 @@ as.data.frame.mo <- function(x, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod pull.mo
|
||||
#' @exportMethod [.mo
|
||||
#' @export
|
||||
#' @importFrom dplyr pull
|
||||
#' @noRd
|
||||
pull.mo <- function(.data, ...) {
|
||||
pull(as.data.frame(.data), ...)
|
||||
"[.mo" <- function (x, ...) {
|
||||
# this function is needed to preserve the "mo" class for any subsetting, like df %>% filter(...)
|
||||
y <- NextMethod()
|
||||
to_class_mo(y)
|
||||
}
|
||||
|
||||
#' @rdname as.mo
|
||||
@ -1593,7 +1700,7 @@ print.mo_uncertainties <- function(x, ...) {
|
||||
"\n(1 = ", green("renamed/misspelled"),
|
||||
", 2 = ", yellow("uncertain"),
|
||||
", 3 = ", red("very uncertain"), ")\n"))
|
||||
|
||||
|
||||
msg <- ""
|
||||
for (i in 1:nrow(x)) {
|
||||
if (x[i, "uncertainty"] == 1) {
|
||||
@ -1622,11 +1729,11 @@ mo_renamed <- function() {
|
||||
if (is.null(items)) {
|
||||
return(NULL)
|
||||
}
|
||||
|
||||
|
||||
items <- strip_style(items)
|
||||
names(items) <- strip_style(names(items))
|
||||
structure(.Data = items,
|
||||
class = c("mo_renamed", "character"))
|
||||
class = c("mo_renamed", "character"))
|
||||
}
|
||||
|
||||
#' @exportMethod print.mo_renamed
|
||||
@ -1655,7 +1762,7 @@ unregex <- function(x) {
|
||||
get_mo_code <- function(x, property) {
|
||||
# don't use right now
|
||||
return(NULL)
|
||||
|
||||
|
||||
if (property == "mo") {
|
||||
unique(x)
|
||||
} else {
|
||||
|
4
R/rsi.R
4
R/rsi.R
@ -486,9 +486,9 @@ type_sum.rsi <- function(x) {
|
||||
#' @export
|
||||
pillar_shaft.rsi <- function(x, ...) {
|
||||
out <- trimws(format(x))
|
||||
out[is.na(x)] <- pillar::style_subtle("NA")
|
||||
out[is.na(x)] <- pillar::style_subtle(" NA")
|
||||
out[x == "S"] <- bgGreen(white(" S "))
|
||||
out[x == "I"] <- bgYellow(black(" I "))
|
||||
out[x == "R"] <- bgRed(white(" R "))
|
||||
pillar::new_pillar_shaft_simple(out, align = "left", min_width = 4)
|
||||
pillar::new_pillar_shaft_simple(out, align = "left", min_width = 3)
|
||||
}
|
||||
|
@ -78,7 +78,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -40,7 +40,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9036</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -185,7 +185,7 @@
|
||||
<h1>Benchmarks</h1>
|
||||
<h4 class="author">Matthijs S. Berends</h4>
|
||||
|
||||
<h4 class="date">11 August 2019</h4>
|
||||
<h4 class="date">12 August 2019</h4>
|
||||
|
||||
|
||||
<div class="hidden name"><code>benchmarks.Rmd</code></div>
|
||||
@ -210,14 +210,14 @@
|
||||
<a class="sourceLine" id="cb2-8" data-line-number="8"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
|
||||
<a class="sourceLine" id="cb2-9" data-line-number="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(S.aureus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
|
||||
<a class="sourceLine" id="cb2-10" data-line-number="10"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb2-12" data-line-number="12"><span class="co"># as.mo("sau") 8.3 8.5 14.0 9.1 9.2 39.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="co"># as.mo("stau") 31.0 32.0 38.0 32.0 47.0 53.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-14" data-line-number="14"><span class="co"># as.mo("staaur") 8.2 8.4 20.0 8.7 40.0 55.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-15" data-line-number="15"><span class="co"># as.mo("STAAUR") 8.2 8.4 10.0 8.9 9.4 24.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-16" data-line-number="16"><span class="co"># as.mo("S. aureus") 23.0 24.0 33.0 24.0 24.0 99.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-17" data-line-number="17"><span class="co"># as.mo("S. aureus") 23.0 23.0 29.0 24.0 40.0 42.0 10</span></a>
|
||||
<a class="sourceLine" id="cb2-18" data-line-number="18"><span class="co"># as.mo("Staphylococcus aureus") 3.7 3.9 4.1 4.1 4.2 4.6 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb2-12" data-line-number="12"><span class="co"># as.mo("sau") 8.6 9.2 9.9 9.7 11.0 12 10</span></a>
|
||||
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="co"># as.mo("stau") 32.0 33.0 33.0 33.0 34.0 35 10</span></a>
|
||||
<a class="sourceLine" id="cb2-14" data-line-number="14"><span class="co"># as.mo("staaur") 8.7 9.0 13.0 9.6 11.0 26 10</span></a>
|
||||
<a class="sourceLine" id="cb2-15" data-line-number="15"><span class="co"># as.mo("STAAUR") 8.6 9.1 13.0 9.5 9.7 28 10</span></a>
|
||||
<a class="sourceLine" id="cb2-16" data-line-number="16"><span class="co"># as.mo("S. aureus") 24.0 24.0 28.0 25.0 26.0 41 10</span></a>
|
||||
<a class="sourceLine" id="cb2-17" data-line-number="17"><span class="co"># as.mo("S. aureus") 24.0 24.0 37.0 24.0 39.0 120 10</span></a>
|
||||
<a class="sourceLine" id="cb2-18" data-line-number="18"><span class="co"># as.mo("Staphylococcus aureus") 4.0 4.2 6.0 4.3 4.6 21 10</span></a></code></pre></div>
|
||||
<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. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.</p>
|
||||
<p>To achieve this speed, the <code>as.mo</code> function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of <em>Thermus islandicus</em> (<code>B_THERMS_ISL</code>), a bug probably never found before in humans:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1">T.islandicus <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"theisl"</span>),</a>
|
||||
@ -229,12 +229,12 @@
|
||||
<a class="sourceLine" id="cb3-7" data-line-number="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(T.islandicus, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">2</span>)</a>
|
||||
<a class="sourceLine" id="cb3-8" data-line-number="8"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb3-9" data-line-number="9"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># as.mo("theisl") 270 270 280 290 290 300 10</span></a>
|
||||
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("THEISL") 280 290 290 290 300 300 10</span></a>
|
||||
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("T. islandicus") 130 130 150 150 160 160 10</span></a>
|
||||
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("T. islandicus") 130 130 150 150 150 160 10</span></a>
|
||||
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Thermus islandicus") 46 48 54 50 63 71 10</span></a></code></pre></div>
|
||||
<p>That takes 8.8 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
|
||||
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># as.mo("theisl") 270 280 290 290 310 320 10</span></a>
|
||||
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("THEISL") 280 290 300 290 300 310 10</span></a>
|
||||
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("T. islandicus") 140 140 150 140 160 170 10</span></a>
|
||||
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("T. islandicus") 140 150 160 160 160 170 10</span></a>
|
||||
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Thermus islandicus") 48 49 60 60 68 77 10</span></a></code></pre></div>
|
||||
<p>That takes 9.5 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like <em>Thermus islandicus</em>) are almost fast - these are the most probable input from most data sets.</p>
|
||||
<p>In the figure below, we compare <em>Escherichia coli</em> (which is very common) with <em>Prevotella brevis</em> (which is moderately common) and with <em>Thermus islandicus</em> (which is very uncommon):</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/par">par</a></span>(<span class="dt">mar =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">16</span>, <span class="dv">4</span>, <span class="dv">2</span>)) <span class="co"># set more space for left margin text (16)</span></a>
|
||||
<a class="sourceLine" id="cb4-2" data-line-number="2"></a>
|
||||
@ -280,8 +280,8 @@
|
||||
<a class="sourceLine" id="cb5-24" data-line-number="24"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb5-25" data-line-number="25"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb5-26" data-line-number="26"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb5-27" data-line-number="27"><span class="co"># mo_name(x) 623 631 659 637 697 729 10</span></a></code></pre></div>
|
||||
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.64 seconds (637 ms). You only lose time on your unique input values.</p>
|
||||
<a class="sourceLine" id="cb5-27" data-line-number="27"><span class="co"># mo_name(x) 596 622 635 626 635 704 10</span></a></code></pre></div>
|
||||
<p>So transforming 500,000 values (!!) of 50 unique values only takes 0.63 seconds (626 ms). You only lose time on your unique input values.</p>
|
||||
</div>
|
||||
<div id="precalculated-results" class="section level3">
|
||||
<h3 class="hasAnchor">
|
||||
@ -294,10 +294,10 @@
|
||||
<a class="sourceLine" id="cb6-5" data-line-number="5"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb6-6" data-line-number="6"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb6-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb6-8" data-line-number="8"><span class="co"># A 6.290 6.730 7.170 7.010 7.760 8.09 10</span></a>
|
||||
<a class="sourceLine" id="cb6-9" data-line-number="9"><span class="co"># B 22.600 22.700 26.200 23.000 25.400 44.30 10</span></a>
|
||||
<a class="sourceLine" id="cb6-10" data-line-number="10"><span class="co"># C 0.798 0.806 0.874 0.844 0.891 1.05 10</span></a></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.0008 seconds - it doesn’t even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
|
||||
<a class="sourceLine" id="cb6-8" data-line-number="8"><span class="co"># A 6.700 6.950 7.410 7.600 7.730 8.06 10</span></a>
|
||||
<a class="sourceLine" id="cb6-9" data-line-number="9"><span class="co"># B 22.900 23.900 27.000 24.100 24.200 46.00 10</span></a>
|
||||
<a class="sourceLine" id="cb6-10" data-line-number="10"><span class="co"># C 0.772 0.833 0.876 0.874 0.918 1.03 10</span></a></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.0009 seconds - it doesn’t 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="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">run_it <-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="../reference/mo_property.html">mo_species</a></span>(<span class="st">"aureus"</span>),</a>
|
||||
<a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),</a>
|
||||
<a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
|
||||
@ -310,14 +310,14 @@
|
||||
<a class="sourceLine" id="cb7-10" data-line-number="10"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">3</span>)</a>
|
||||
<a class="sourceLine" id="cb7-11" data-line-number="11"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb7-12" data-line-number="12"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb7-13" data-line-number="13"><span class="co"># A 0.455 0.458 0.471 0.465 0.482 0.504 10</span></a>
|
||||
<a class="sourceLine" id="cb7-14" data-line-number="14"><span class="co"># B 0.480 0.482 0.497 0.491 0.497 0.554 10</span></a>
|
||||
<a class="sourceLine" id="cb7-15" data-line-number="15"><span class="co"># C 0.662 0.687 0.754 0.750 0.788 0.964 10</span></a>
|
||||
<a class="sourceLine" id="cb7-16" data-line-number="16"><span class="co"># D 0.484 0.484 0.496 0.488 0.501 0.544 10</span></a>
|
||||
<a class="sourceLine" id="cb7-17" data-line-number="17"><span class="co"># E 0.442 0.450 0.459 0.456 0.462 0.492 10</span></a>
|
||||
<a class="sourceLine" id="cb7-18" data-line-number="18"><span class="co"># F 0.440 0.447 0.456 0.452 0.463 0.486 10</span></a>
|
||||
<a class="sourceLine" id="cb7-19" data-line-number="19"><span class="co"># G 0.450 0.452 0.462 0.459 0.463 0.485 10</span></a>
|
||||
<a class="sourceLine" id="cb7-20" data-line-number="20"><span class="co"># H 0.455 0.461 0.467 0.467 0.471 0.492 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb7-13" data-line-number="13"><span class="co"># A 0.472 0.475 0.553 0.562 0.607 0.675 10</span></a>
|
||||
<a class="sourceLine" id="cb7-14" data-line-number="14"><span class="co"># B 0.474 0.482 0.560 0.493 0.577 0.973 10</span></a>
|
||||
<a class="sourceLine" id="cb7-15" data-line-number="15"><span class="co"># C 0.766 0.820 0.899 0.881 0.941 1.070 10</span></a>
|
||||
<a class="sourceLine" id="cb7-16" data-line-number="16"><span class="co"># D 0.459 0.485 0.539 0.503 0.569 0.744 10</span></a>
|
||||
<a class="sourceLine" id="cb7-17" data-line-number="17"><span class="co"># E 0.421 0.448 0.470 0.456 0.488 0.543 10</span></a>
|
||||
<a class="sourceLine" id="cb7-18" data-line-number="18"><span class="co"># F 0.430 0.457 0.534 0.495 0.592 0.738 10</span></a>
|
||||
<a class="sourceLine" id="cb7-19" data-line-number="19"><span class="co"># G 0.420 0.450 0.477 0.463 0.491 0.586 10</span></a>
|
||||
<a class="sourceLine" id="cb7-20" data-line-number="20"><span class="co"># H 0.426 0.437 0.500 0.447 0.461 0.776 10</span></a></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> too, 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 id="results-in-other-languages" class="section level3">
|
||||
@ -344,13 +344,13 @@
|
||||
<a class="sourceLine" id="cb8-18" data-line-number="18"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(run_it, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">signif =</span> <span class="dv">4</span>)</a>
|
||||
<a class="sourceLine" id="cb8-19" data-line-number="19"><span class="co"># Unit: milliseconds</span></a>
|
||||
<a class="sourceLine" id="cb8-20" data-line-number="20"><span class="co"># expr min lq mean median uq max neval</span></a>
|
||||
<a class="sourceLine" id="cb8-21" data-line-number="21"><span class="co"># en 17.66 17.86 18.50 18.49 19.14 19.36 10</span></a>
|
||||
<a class="sourceLine" id="cb8-22" data-line-number="22"><span class="co"># de 19.03 19.38 19.64 19.49 20.01 20.42 10</span></a>
|
||||
<a class="sourceLine" id="cb8-23" data-line-number="23"><span class="co"># nl 24.40 25.23 30.77 25.78 41.94 44.93 10</span></a>
|
||||
<a class="sourceLine" id="cb8-24" data-line-number="24"><span class="co"># es 19.18 19.22 23.30 19.53 21.34 39.20 10</span></a>
|
||||
<a class="sourceLine" id="cb8-25" data-line-number="25"><span class="co"># it 19.02 19.24 23.53 19.57 20.35 50.89 10</span></a>
|
||||
<a class="sourceLine" id="cb8-26" data-line-number="26"><span class="co"># fr 19.28 19.33 19.87 19.57 20.19 21.25 10</span></a>
|
||||
<a class="sourceLine" id="cb8-27" data-line-number="27"><span class="co"># pt 18.89 19.14 19.77 19.67 20.21 20.99 10</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb8-21" data-line-number="21"><span class="co"># en 18.77 19.83 25.36 20.44 28.51 45.88 10</span></a>
|
||||
<a class="sourceLine" id="cb8-22" data-line-number="22"><span class="co"># de 20.37 20.86 23.19 21.45 22.23 39.08 10</span></a>
|
||||
<a class="sourceLine" id="cb8-23" data-line-number="23"><span class="co"># nl 26.50 27.09 27.74 27.58 28.10 29.74 10</span></a>
|
||||
<a class="sourceLine" id="cb8-24" data-line-number="24"><span class="co"># es 20.82 21.18 21.66 21.27 22.04 23.64 10</span></a>
|
||||
<a class="sourceLine" id="cb8-25" data-line-number="25"><span class="co"># it 19.82 20.65 25.98 21.22 22.13 50.42 10</span></a>
|
||||
<a class="sourceLine" id="cb8-26" data-line-number="26"><span class="co"># fr 20.07 21.20 21.68 21.47 21.89 23.76 10</span></a>
|
||||
<a class="sourceLine" id="cb8-27" data-line-number="27"><span class="co"># pt 19.87 20.63 22.76 21.07 21.68 38.11 10</span></a></code></pre></div>
|
||||
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 84 KiB |
@ -78,7 +78,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -78,7 +78,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -42,7 +42,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -78,7 +78,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -225,9 +225,9 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div id="amr-0-7-1-9035" class="section level1">
|
||||
<div id="amr-0-7-1-9038" class="section level1">
|
||||
<h1 class="page-header">
|
||||
<a href="#amr-0-7-1-9035" class="anchor"></a>AMR 0.7.1.9035<small> Unreleased </small>
|
||||
<a href="#amr-0-7-1-9038" class="anchor"></a>AMR 0.7.1.9038<small> Unreleased </small>
|
||||
</h1>
|
||||
<div id="breaking" class="section level3">
|
||||
<h3 class="hasAnchor">
|
||||
@ -289,15 +289,12 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p>Added tibble printing support for classes <code>rsi</code>, <code>mic</code>, <code>ab</code> and <code>mo</code>. When using tibbles containing antibiotic columns, values <code>S</code> will print in green, values <code>I</code> will print in yellow and values <code>R</code> will print in red:</p>
|
||||
<p>Added tibble printing support for classes <code>rsi</code>, <code>mic</code>, <code>disk</code>, <code>ab</code> <code>mo</code>. When using tibbles containing antibiotic columns, values <code>S</code> will print in green, values <code>I</code> will print in yellow and values <code>R</code> will print in red. Microbial IDs (class <code>mo</code>) will emphasise on the genus and species, not on the kingdom.</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="co"># (run this on your own console, as this page does not support colour printing)</span></a>
|
||||
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="kw">tibble</span>(<span class="dt">mo =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(AMR<span class="op">::</span>microorganisms<span class="op">$</span>fullname, <span class="dv">10</span>),</a>
|
||||
<a class="sourceLine" id="cb3-3" data-line-number="3"> <span class="dt">drug1 =</span> <span class="kw"><a href="../reference/as.rsi.html">as.rsi</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"S"</span>, <span class="st">"I"</span>, <span class="st">"R"</span>), <span class="dv">10</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, </a>
|
||||
<a class="sourceLine" id="cb3-4" data-line-number="4"> <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.6</span>, <span class="fl">0.1</span>, <span class="fl">0.3</span>))),</a>
|
||||
<a class="sourceLine" id="cb3-5" data-line-number="5"> <span class="dt">drug2 =</span> <span class="kw"><a href="../reference/as.rsi.html">as.rsi</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"S"</span>, <span class="st">"I"</span>, <span class="st">"R"</span>), <span class="dv">10</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>,</a>
|
||||
<a class="sourceLine" id="cb3-6" data-line-number="6"> <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.6</span>, <span class="fl">0.1</span>, <span class="fl">0.3</span>))),</a>
|
||||
<a class="sourceLine" id="cb3-7" data-line-number="7"> <span class="dt">drug3 =</span> <span class="kw"><a href="../reference/as.rsi.html">as.rsi</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"S"</span>, <span class="st">"I"</span>, <span class="st">"R"</span>), <span class="dv">10</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>,</a>
|
||||
<a class="sourceLine" id="cb3-8" data-line-number="8"> <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.6</span>, <span class="fl">0.1</span>, <span class="fl">0.3</span>))))</a></code></pre></div>
|
||||
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)</a>
|
||||
<a class="sourceLine" id="cb3-3" data-line-number="3">septic_patients <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(mo<span class="op">:</span>AMC) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb3-5" data-line-number="5"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/reexports.html">as_tibble</a></span>()</a></code></pre></div>
|
||||
</li>
|
||||
<li>Removed class <code>atc</code> - using <code><a href="../reference/AMR-deprecated.html">as.atc()</a></code> is now deprecated in favour of <code><a href="../reference/ab_property.html">ab_atc()</a></code> and this will return a character, not the <code>atc</code> class anymore</li>
|
||||
<li>Removed deprecated functions <code>abname()</code>, <code>ab_official()</code>, <code>atc_name()</code>, <code>atc_official()</code>, <code>atc_property()</code>, <code>atc_tradenames()</code>, <code>atc_trivial_nl()</code>
|
||||
@ -316,8 +313,10 @@
|
||||
<li>Fix for using <code>mo_*</code> functions where the coercion uncertainties and failures would not be available through <code><a href="../reference/as.mo.html">mo_uncertainties()</a></code> and <code><a href="../reference/as.mo.html">mo_failures()</a></code> anymore</li>
|
||||
<li>Deprecated the <code>country</code> parameter of <code><a href="../reference/mdro.html">mdro()</a></code> in favour of the already existing <code>guideline</code> parameter to support multiple guidelines within one country</li>
|
||||
<li>The <code>name</code> of <code>RIF</code> is now Rifampicin instead of Rifampin</li>
|
||||
<li>The <code>antibiotics</code> data set is now sorted by name and all cephalosporines now have their generation between brackets</li>
|
||||
<li><p>Speed improvement for <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code> which is now 30 times faster for antibiotic abbreviations</p></li>
|
||||
<li>The <code>antibiotics</code> data set is now sorted by name and all cephalosporins now have their generation between brackets</li>
|
||||
<li>Speed improvement for <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code> which is now 30 times faster for antibiotic abbreviations</li>
|
||||
<li>Improved <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code> to be more reliable and to support 5th generation cephalosporins</li>
|
||||
<li><p>Classes <code>ab</code> and <code>mo</code> will now be preserved in any subsetting</p></li>
|
||||
</ul>
|
||||
<div id="other" class="section level4">
|
||||
<h4 class="hasAnchor">
|
||||
@ -339,7 +338,7 @@
|
||||
<li>
|
||||
<p>Function <code><a href="../reference/portion.html">rsi_df()</a></code> to transform a <code>data.frame</code> to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions <code><a href="../reference/count.html">count_df()</a></code> and <code><a href="../reference/portion.html">portion_df()</a></code> to immediately show resistance percentages and number of available isolates:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1">septic_patients <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="st"> </span><span class="kw">select</span>(AMX, CIP) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(AMX, CIP) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="../reference/portion.html">rsi_df</a></span>()</a>
|
||||
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="co"># antibiotic interpretation value isolates</span></a>
|
||||
<a class="sourceLine" id="cb4-5" data-line-number="5"><span class="co"># 1 Amoxicillin SI 0.4442636 546</span></a>
|
||||
@ -472,7 +471,7 @@ Please <a href="https://gitlab.com/msberends/AMR/issues/new?issue%5Btitle%5D=Tra
|
||||
<a class="sourceLine" id="cb6-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/boxplot">boxplot</a></span>()</a>
|
||||
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="co"># grouped boxplots:</span></a>
|
||||
<a class="sourceLine" id="cb6-5" data-line-number="5">septic_patients <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb6-6" data-line-number="6"><span class="st"> </span><span class="kw">group_by</span>(hospital_id) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb6-6" data-line-number="6"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital_id) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb6-7" data-line-number="7"><span class="st"> </span><span class="kw">freq</span>(age) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb6-8" data-line-number="8"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/boxplot">boxplot</a></span>()</a></code></pre></div>
|
||||
</li>
|
||||
@ -607,9 +606,9 @@ These functions use <code><a href="../reference/AMR-deprecated.html">as.atc()</a
|
||||
<a class="sourceLine" id="cb11-3" data-line-number="3"><span class="kw"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>(septic_patients, ...)</a></code></pre></div>
|
||||
<p>is equal to:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1">septic_patients <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="st"> </span><span class="kw">mutate</span>(<span class="dt">only_firsts =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(septic_patients, ...)) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb12-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/stats/topics/filter">filter</a></span>(only_firsts <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb12-4" data-line-number="4"><span class="st"> </span><span class="kw">select</span>(<span class="op">-</span>only_firsts)</a></code></pre></div>
|
||||
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">only_firsts =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(septic_patients, ...)) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb12-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(only_firsts <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb12-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span>only_firsts)</a></code></pre></div>
|
||||
</li>
|
||||
<li>New function <code><a href="../reference/availability.html">availability()</a></code> to check the number of available (non-empty) results in a <code>data.frame</code>
|
||||
</li>
|
||||
@ -713,7 +712,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb16-1" data-line-number="1"><span class="co"># Determine genus of microorganisms (mo) in `septic_patients` data set:</span></a>
|
||||
<a class="sourceLine" id="cb16-2" data-line-number="2"><span class="co"># OLD WAY</span></a>
|
||||
<a class="sourceLine" id="cb16-3" data-line-number="3">septic_patients <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb16-4" data-line-number="4"><span class="st"> </span><span class="kw">mutate</span>(<span class="dt">genus =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(mo)) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb16-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">genus =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(mo)) <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb16-5" data-line-number="5"><span class="st"> </span><span class="kw">freq</span>(genus)</a>
|
||||
<a class="sourceLine" id="cb16-6" data-line-number="6"><span class="co"># NEW WAY</span></a>
|
||||
<a class="sourceLine" id="cb16-7" data-line-number="7">septic_patients <span class="op">%>%</span><span class="st"> </span></a>
|
||||
@ -721,7 +720,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
<a class="sourceLine" id="cb16-9" data-line-number="9"></a>
|
||||
<a class="sourceLine" id="cb16-10" data-line-number="10"><span class="co"># Even supports grouping variables:</span></a>
|
||||
<a class="sourceLine" id="cb16-11" data-line-number="11">septic_patients <span class="op">%>%</span></a>
|
||||
<a class="sourceLine" id="cb16-12" data-line-number="12"><span class="st"> </span><span class="kw">group_by</span>(gender) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb16-12" data-line-number="12"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(gender) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb16-13" data-line-number="13"><span class="st"> </span><span class="kw">freq</span>(<span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(mo))</a></code></pre></div>
|
||||
</li>
|
||||
<li>Header info is now available as a list, with the <code>header</code> function</li>
|
||||
@ -734,7 +733,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
</li>
|
||||
<li>New parameter <code>droplevels</code> to exclude empty factor levels when input is a factor</li>
|
||||
<li>Factor levels will be in header when present in input data (maximum of 5)</li>
|
||||
<li>Fix for using <code>select()</code> on frequency tables</li>
|
||||
<li>Fix for using <code><a href="https://dplyr.tidyverse.org/reference/select.html">select()</a></code> on frequency tables</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Function <code><a href="../reference/ggplot_rsi.html">scale_y_percent()</a></code> now contains the <code>limits</code> parameter</li>
|
||||
@ -814,14 +813,14 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
<li>
|
||||
<p>Support for grouping variables, test with:</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb18-1" data-line-number="1">septic_patients <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb18-2" data-line-number="2"><span class="st"> </span><span class="kw">group_by</span>(hospital_id) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb18-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital_id) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb18-3" data-line-number="3"><span class="st"> </span><span class="kw">freq</span>(gender)</a></code></pre></div>
|
||||
</li>
|
||||
<li>
|
||||
<p>Support for (un)selecting columns:</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" data-line-number="1">septic_patients <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb19-2" data-line-number="2"><span class="st"> </span><span class="kw">freq</span>(hospital_id) <span class="op">%>%</span><span class="st"> </span></a>
|
||||
<a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw">select</span>(<span class="op">-</span>count, <span class="op">-</span>cum_count) <span class="co"># only get item, percent, cum_percent</span></a></code></pre></div>
|
||||
<a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span>count, <span class="op">-</span>cum_count) <span class="co"># only get item, percent, cum_percent</span></a></code></pre></div>
|
||||
</li>
|
||||
<li>Check for <code><a href="https://www.rdocumentation.org/packages/hms/topics/Deprecated">hms::is.hms</a></code>
|
||||
</li>
|
||||
@ -978,7 +977,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
</li>
|
||||
<li>
|
||||
<p>Support for quasiquotation in the functions series <code>count_*</code> and <code>portions_*</code>, and <code>n_rsi</code>. This allows to check for more than 2 vectors or columns.</p>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" data-line-number="1">septic_patients <span class="op">%>%</span><span class="st"> </span><span class="kw">select</span>(amox, cipr) <span class="op">%>%</span><span class="st"> </span><span class="kw"><a href="../reference/count.html">count_IR</a></span>()</a>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" data-line-number="1">septic_patients <span class="op">%>%</span><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(amox, cipr) <span class="op">%>%</span><span class="st"> </span><span class="kw"><a href="../reference/count.html">count_IR</a></span>()</a>
|
||||
<a class="sourceLine" id="cb25-2" data-line-number="2"><span class="co"># which is the same as:</span></a>
|
||||
<a class="sourceLine" id="cb25-3" data-line-number="3">septic_patients <span class="op">%>%</span><span class="st"> </span><span class="kw"><a href="../reference/count.html">count_IR</a></span>(amox, cipr)</a>
|
||||
<a class="sourceLine" id="cb25-4" data-line-number="4"></a>
|
||||
@ -1237,7 +1236,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
|
||||
<div id="tocnav">
|
||||
<h2>Contents</h2>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li><a href="#amr-0-7-1-9035">0.7.1.9035</a></li>
|
||||
<li><a href="#amr-0-7-1-9038">0.7.1.9038</a></li>
|
||||
<li><a href="#amr-0-7-1">0.7.1</a></li>
|
||||
<li><a href="#amr-0-7-0">0.7.0</a></li>
|
||||
<li><a href="#amr-0-6-1">0.6.1</a></li>
|
||||
|
@ -80,7 +80,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9036</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -80,7 +80,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.7.1.9029</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9036</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -234,40 +234,42 @@
|
||||
|
||||
</div>
|
||||
|
||||
<pre class="usage"><span class='fu'>filter_ab_class</span>(<span class='no'>tbl</span>, <span class='no'>ab_class</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<pre class="usage"><span class='fu'>filter_ab_class</span>(<span class='no'>x</span>, <span class='no'>ab_class</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_aminoglycosides</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_aminoglycosides</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_carbapenems</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_carbapenems</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_cephalosporins</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_1st_cephalosporins</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_1st_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_2nd_cephalosporins</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_2nd_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_3rd_cephalosporins</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_3rd_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_4th_cephalosporins</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_4th_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_fluoroquinolones</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_5th_cephalosporins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_glycopeptides</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_fluoroquinolones</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_macrolides</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
<span class='fu'>filter_glycopeptides</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_tetracyclines</span>(<span class='no'>tbl</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)</pre>
|
||||
<span class='fu'>filter_macrolides</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
|
||||
|
||||
<span class='fu'>filter_tetracyclines</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)</pre>
|
||||
|
||||
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
|
||||
<table class="ref-arguments">
|
||||
<colgroup><col class="name" /><col class="desc" /></colgroup>
|
||||
<tr>
|
||||
<th>tbl</th>
|
||||
<th>x</th>
|
||||
<td><p>a data set</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ab_class</th>
|
||||
<td><p>an antimicrobial class, like <code>"carbapenems"</code>. More specifically, this should be a text that can be found in a 4th level ATC group (chemical subgroup) or a 5th level ATC group (chemical substance), please see <a href='https://www.whocc.no/atc/structure_and_principles/'>this explanation on the WHOCC website</a>.</p></td>
|
||||
<td><p>an antimicrobial class, like <code>"carbapenems"</code>, as can be found in <code>AMR::antibiotics$group</code></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>result</th>
|
||||
@ -285,7 +287,7 @@
|
||||
|
||||
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
|
||||
|
||||
<p>The <code><a href='antibiotics.html'>antibiotics</a></code> data set will be searched for <code>ab_class</code> in the columns <code>atc_group1</code> and <code>atc_group2</code> (case-insensitive). Next, <code>tbl</code> will be checked for column names with a value in any abbreviations, codes or official names found in the <code>antibiotics</code> data set.</p>
|
||||
<p>The <code>group</code> column in <code><a href='antibiotics.html'>antibiotics</a></code> data set will be searched for <code>ab_class</code> (case-insensitive). If no results are found, the <code>atc_group1</code> and <code>atc_group2</code> columns will be searched. Next, <code>x</code> will be checked for column names with a value in any abbreviations, codes or official names found in the <code>antibiotics</code> data set.</p>
|
||||
|
||||
|
||||
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
|
||||
|
@ -78,7 +78,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9038</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -428,7 +428,7 @@
|
||||
</tr><tr>
|
||||
|
||||
<td>
|
||||
<p><code><a href="filter_ab_class.html">filter_ab_class()</a></code> <code><a href="filter_ab_class.html">filter_aminoglycosides()</a></code> <code><a href="filter_ab_class.html">filter_carbapenems()</a></code> <code><a href="filter_ab_class.html">filter_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_1st_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_2nd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_3rd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_4th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_fluoroquinolones()</a></code> <code><a href="filter_ab_class.html">filter_glycopeptides()</a></code> <code><a href="filter_ab_class.html">filter_macrolides()</a></code> <code><a href="filter_ab_class.html">filter_tetracyclines()</a></code> </p>
|
||||
<p><code><a href="filter_ab_class.html">filter_ab_class()</a></code> <code><a href="filter_ab_class.html">filter_aminoglycosides()</a></code> <code><a href="filter_ab_class.html">filter_carbapenems()</a></code> <code><a href="filter_ab_class.html">filter_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_1st_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_2nd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_3rd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_4th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_5th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_fluoroquinolones()</a></code> <code><a href="filter_ab_class.html">filter_glycopeptides()</a></code> <code><a href="filter_ab_class.html">filter_macrolides()</a></code> <code><a href="filter_ab_class.html">filter_tetracyclines()</a></code> </p>
|
||||
</td>
|
||||
<td><p>Filter isolates on result in antibiotic class</p></td>
|
||||
</tr><tr>
|
||||
|
@ -80,7 +80,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9036</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -80,7 +80,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.7.1.9035</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9036</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -9,40 +9,43 @@
|
||||
\alias{filter_2nd_cephalosporins}
|
||||
\alias{filter_3rd_cephalosporins}
|
||||
\alias{filter_4th_cephalosporins}
|
||||
\alias{filter_5th_cephalosporins}
|
||||
\alias{filter_fluoroquinolones}
|
||||
\alias{filter_glycopeptides}
|
||||
\alias{filter_macrolides}
|
||||
\alias{filter_tetracyclines}
|
||||
\title{Filter isolates on result in antibiotic class}
|
||||
\usage{
|
||||
filter_ab_class(tbl, ab_class, result = NULL, scope = "any", ...)
|
||||
filter_ab_class(x, ab_class, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_aminoglycosides(tbl, result = NULL, scope = "any", ...)
|
||||
filter_aminoglycosides(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_carbapenems(tbl, result = NULL, scope = "any", ...)
|
||||
filter_carbapenems(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_cephalosporins(tbl, result = NULL, scope = "any", ...)
|
||||
filter_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_1st_cephalosporins(tbl, result = NULL, scope = "any", ...)
|
||||
filter_1st_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_2nd_cephalosporins(tbl, result = NULL, scope = "any", ...)
|
||||
filter_2nd_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_3rd_cephalosporins(tbl, result = NULL, scope = "any", ...)
|
||||
filter_3rd_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_4th_cephalosporins(tbl, result = NULL, scope = "any", ...)
|
||||
filter_4th_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_fluoroquinolones(tbl, result = NULL, scope = "any", ...)
|
||||
filter_5th_cephalosporins(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_glycopeptides(tbl, result = NULL, scope = "any", ...)
|
||||
filter_fluoroquinolones(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_macrolides(tbl, result = NULL, scope = "any", ...)
|
||||
filter_glycopeptides(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_tetracyclines(tbl, result = NULL, scope = "any", ...)
|
||||
filter_macrolides(x, result = NULL, scope = "any", ...)
|
||||
|
||||
filter_tetracyclines(x, result = NULL, scope = "any", ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{tbl}{a data set}
|
||||
\item{x}{a data set}
|
||||
|
||||
\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}. More specifically, this should be a text that can be found in a 4th level ATC group (chemical subgroup) or a 5th level ATC group (chemical substance), please see \href{https://www.whocc.no/atc/structure_and_principles/}{this explanation on the WHOCC website}.}
|
||||
\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{AMR::antibiotics$group}}
|
||||
|
||||
\item{result}{an antibiotic result: S, I or R (or a combination of more of them)}
|
||||
|
||||
@ -54,7 +57,7 @@ filter_tetracyclines(tbl, result = NULL, scope = "any", ...)
|
||||
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.
|
||||
}
|
||||
\details{
|
||||
The \code{\link{antibiotics}} data set will be searched for \code{ab_class} in the columns \code{atc_group1} and \code{atc_group2} (case-insensitive). Next, \code{tbl} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set.
|
||||
The \code{group} column in \code{\link{antibiotics}} data set will be searched for \code{ab_class} (case-insensitive). If no results are found, the \code{atc_group1} and \code{atc_group2} columns will be searched. Next, \code{x} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set.
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
|
@ -159,8 +159,7 @@ test_that("as.mo works", {
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus, species) %>%
|
||||
as.mo() %>%
|
||||
as.character())
|
||||
as.mo())
|
||||
|
||||
# unknown results
|
||||
expect_warning(as.mo(c("INVALID", "Yeah, unknown")))
|
||||
@ -198,8 +197,8 @@ test_that("as.mo works", {
|
||||
print(mo_renamed())
|
||||
|
||||
# check uncertain names
|
||||
expect_equal(suppressWarnings(as.character(as.mo("esco extra_text", allow_uncertain = FALSE))), "UNKNOWN")
|
||||
expect_equal(suppressWarnings(as.character(as.mo("esco extra_text", allow_uncertain = TRUE))), "B_ESCHR_COL")
|
||||
expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AUR")
|
||||
expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = FALSE))), "UNKNOWN")
|
||||
expect_warning(as.mo("esco extra_text", allow_uncertain = TRUE))
|
||||
expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AUR")
|
||||
expect_equal(suppressWarnings(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY")
|
||||
@ -271,7 +270,7 @@ test_that("as.mo works", {
|
||||
expect_equal(as.character(as.mo("F_CANDD_GLB")), "F_CANDD_GLA")
|
||||
|
||||
# debug mode
|
||||
expect_warning(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3))
|
||||
expect_output(print(suppressMessages(suppressWarnings(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3)))))
|
||||
|
||||
# ..coccus
|
||||
expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))),
|
||||
|
Loading…
Reference in New Issue
Block a user