mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 07:26:12 +01:00
new function get_locale
This commit is contained in:
parent
e548a7ad11
commit
d07e9b904e
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.4.0.9008
|
||||
Date: 2018-11-01
|
||||
Version: 0.4.0.9009
|
||||
Date: 2018-11-05
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(
|
||||
|
@ -72,6 +72,7 @@ export(frequency_tbl)
|
||||
export(full_join_microorganisms)
|
||||
export(g.test)
|
||||
export(geom_rsi)
|
||||
export(get_locale)
|
||||
export(ggplot_rsi)
|
||||
export(guess_atc)
|
||||
export(guess_bactid)
|
||||
|
1
NEWS.md
1
NEWS.md
@ -3,6 +3,7 @@
|
||||
#### New
|
||||
* Repository moved to GitLab: https://gitlab.com/msberends/AMR
|
||||
* Function `count_all` to get all available isolates (that like all `portion_*` and `count_*` functions also supports `summarise` and `group_by`), the old `n_rsi` is now an alias of `count_all`
|
||||
* Function `get_locale` to determine language for language-dependent output for some `mo_*` functions. This is now the default value for their `language` parameter, by which the system language will be used at default.
|
||||
* Data sets `microorganismsDT`, `microorganisms.prevDT`, `microorganisms.unprevDT` and `microorganisms.oldDT` to improve the speed of `as.mo`. They are for reference only, since they are primarily for internal use of `as.mo`.
|
||||
|
||||
#### Changed
|
||||
|
49
R/get_locale.R
Normal file
49
R/get_locale.R
Normal file
@ -0,0 +1,49 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# AUTHORS #
|
||||
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# LICENCE #
|
||||
# This program is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License version 2.0, #
|
||||
# as published by the Free Software Foundation. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Get language for AMR
|
||||
#'
|
||||
#' Determines the system language to be used for language-dependent output of AMR functions, like \code{\link{mo_gramstain}} and \code{\link{mo_type}}.
|
||||
#' @details The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
|
||||
#' @section Supported languages:
|
||||
#' Supported languages are \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish), \code{"it"} (Italian), \code{"fr"} (French), and \code{"pt"} (Portuguese).
|
||||
#' @export
|
||||
get_locale <- function() {
|
||||
if (!is.null(getOption("AMR_locale"))) {
|
||||
if (getOption("AMR_locale") %in% c("en", "de", "nl", "es", "it", "fr", "pt")) {
|
||||
return(getOption("AMR_locale"))
|
||||
}
|
||||
}
|
||||
lang <- Sys.getlocale("LC_COLLATE")
|
||||
# grepl with case = FALSE is faster than like
|
||||
if (grepl("(English|en_)", lang, ignore.case = FALSE)) {
|
||||
"en"
|
||||
} else if (grepl("(German|Deutsch|de_)", lang, ignore.case = FALSE)) {
|
||||
"de"
|
||||
} else if (grepl("(Dutch|Nederlands|nl_)", lang, ignore.case = FALSE)) {
|
||||
"nl"
|
||||
} else if (grepl("(Spanish|Espa.ol|es_)", lang, ignore.case = FALSE)) {
|
||||
"es"
|
||||
} else if (grepl("(Italian|Italiano|it_)", lang, ignore.case = FALSE)) {
|
||||
"it"
|
||||
} else if (grepl("(French|Fran.ais|fr_)", lang, ignore.case = FALSE)) {
|
||||
"fr"
|
||||
} else if (grepl("(Portuguese|Portugu.s|pt_)", lang, ignore.case = FALSE)) {
|
||||
"pt"
|
||||
}
|
||||
}
|
@ -21,8 +21,9 @@
|
||||
#' Use these functions to return a specific property of a microorganism from the \code{\link{microorganisms}} data set. All input values will be evaluated internally with \code{\link{as.mo}}.
|
||||
#' @param x any (vector of) text that can be coerced to a valid microorganism code with \code{\link{as.mo}}
|
||||
#' @param property one of the column names of one of the \code{\link{microorganisms}} data set or \code{"shortname"}
|
||||
#' @param language language of the returned text, defaults to English (\code{"en"}) and can also be set with \code{\link{getOption}("AMR_locale")}. Either one of \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish) or \code{"pt"} (Portuguese).
|
||||
#' @param language language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}.
|
||||
#' @param ... other parameters passed on to \code{\link{as.mo}}
|
||||
#' @inheritSection get_locale Supported languages
|
||||
#' @inheritSection as.mo ITIS
|
||||
#' @inheritSection as.mo Source
|
||||
#' @rdname mo_property
|
||||
@ -98,7 +99,7 @@
|
||||
#'
|
||||
#' # Complete taxonomy up to Subkingdom, returns a list
|
||||
#' mo_taxonomy("E. coli")
|
||||
mo_fullname <- function(x, language = NULL, ...) {
|
||||
mo_fullname <- function(x, language = get_locale(), ...) {
|
||||
x <- mo_validate(x = x, property = "fullname", ...)
|
||||
mo_translate(x, language = language)
|
||||
}
|
||||
@ -106,7 +107,7 @@ mo_fullname <- function(x, language = NULL, ...) {
|
||||
#' @rdname mo_property
|
||||
#' @importFrom dplyr %>% left_join mutate pull
|
||||
#' @export
|
||||
mo_shortname <- function(x, language = NULL, ...) {
|
||||
mo_shortname <- function(x, language = get_locale(), ...) {
|
||||
dots <- list(...)
|
||||
Becker <- dots$Becker
|
||||
if (is.null(Becker)) {
|
||||
@ -119,9 +120,13 @@ mo_shortname <- function(x, language = NULL, ...) {
|
||||
if (Becker %in% c(TRUE, "all") | Lancefield == TRUE) {
|
||||
res1 <- AMR::as.mo(x, Becker = FALSE, Lancefield = FALSE, reference_df = dots$reference_df)
|
||||
res2 <- suppressWarnings(AMR::as.mo(res1, ...))
|
||||
res2_fullname <- mo_fullname(res2)
|
||||
res2_fullname[res2_fullname %like% "\\(CoNS\\)"] <- "CoNS"
|
||||
res2_fullname[res2_fullname %like% "\\(CoPS\\)"] <- "CoPS"
|
||||
res2_fullname <- mo_fullname(res2, language = language)
|
||||
res2_fullname[res2_fullname %like% " \\(CoNS\\)"] <- "CoNS"
|
||||
res2_fullname[res2_fullname %like% " \\(CoPS\\)"] <- "CoPS"
|
||||
res2_fullname[res2_fullname %like% " \\(KNS\\)"] <- "KNS"
|
||||
res2_fullname[res2_fullname %like% " \\(KPS\\)"] <- "KPS"
|
||||
res2_fullname[res2_fullname %like% " \\(CNS\\)"] <- "CNS"
|
||||
res2_fullname[res2_fullname %like% " \\(CPS\\)"] <- "CPS"
|
||||
res2_fullname <- gsub("Streptococcus (group|Gruppe|gruppe|groep|grupo|gruppo|groupe) (.)",
|
||||
"G\\2S",
|
||||
res2_fullname) # turn "Streptococcus group A" and "Streptococcus grupo A" to "GAS"
|
||||
@ -150,19 +155,19 @@ mo_shortname <- function(x, language = NULL, ...) {
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_subspecies <- function(x, language = NULL, ...) {
|
||||
mo_subspecies <- function(x, language = get_locale(), ...) {
|
||||
mo_translate(mo_validate(x = x, property = "subspecies", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_species <- function(x, language = NULL, ...) {
|
||||
mo_species <- function(x, language = get_locale(), ...) {
|
||||
mo_translate(mo_validate(x = x, property = "species", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_genus <- function(x, language = NULL, ...) {
|
||||
mo_genus <- function(x, language = get_locale(), ...) {
|
||||
mo_translate(mo_validate(x = x, property = "genus", ...), language = language)
|
||||
}
|
||||
|
||||
@ -204,7 +209,7 @@ mo_ref <- function(x, ...) {
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_type <- function(x, language = NULL, ...) {
|
||||
mo_type <- function(x, language = get_locale(), ...) {
|
||||
mo_translate(mo_validate(x = x, property = "type", ...), language = language)
|
||||
}
|
||||
|
||||
@ -216,14 +221,14 @@ mo_TSN <- function(x, ...) {
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_gramstain <- function(x, language = NULL, ...) {
|
||||
mo_gramstain <- function(x, language = get_locale(), ...) {
|
||||
mo_translate(mo_validate(x = x, property = "gramstain", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @importFrom data.table data.table as.data.table setkey
|
||||
#' @export
|
||||
mo_property <- function(x, property = 'fullname', language = NULL, ...) {
|
||||
mo_property <- function(x, property = 'fullname', language = get_locale(), ...) {
|
||||
if (length(property) != 1L) {
|
||||
stop("'property' must be of length 1.")
|
||||
}
|
||||
@ -251,9 +256,7 @@ mo_taxonomy <- function(x, ...) {
|
||||
#' @importFrom dplyr %>% case_when
|
||||
mo_translate <- function(x, language) {
|
||||
if (is.null(language)) {
|
||||
language <- getOption("AMR_locale", default = "en")[1L]
|
||||
} else {
|
||||
language <- tolower(language[1L])
|
||||
return(x)
|
||||
}
|
||||
if (language %in% c("en", "")) {
|
||||
return(x)
|
||||
@ -270,6 +273,10 @@ mo_translate <- function(x, language) {
|
||||
gsub("Coagulase Negative Staphylococcus","Koagulase-negative Staphylococcus", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Koagulase-positive Staphylococcus", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Beta-h\u00e4molytischer Streptococcus", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "unbekannte Gramnegativen", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "unbekannte Grampositiven", ., fixed = TRUE) %>%
|
||||
gsub("(CoNS)", "(KNS)", ., fixed = TRUE) %>%
|
||||
gsub("(CoPS)", "(KPS)", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(kein MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gramnegativ", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Grampositiv", ., fixed = TRUE) %>%
|
||||
@ -287,7 +294,11 @@ mo_translate <- function(x, language) {
|
||||
gsub("Coagulase Negative Staphylococcus","Coagulase-negatieve Staphylococcus", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Coagulase-positieve Staphylococcus", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Beta-hemolytische Streptococcus", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "onbekende Gram-negatieven", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "onbekende Gram-positieven", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(geen MO)", ., fixed = TRUE) %>%
|
||||
gsub("(CoNS)", "(CNS)", ., fixed = TRUE) %>%
|
||||
gsub("(CoPS)", "(CPS)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram-negatief", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram-positief", ., fixed = TRUE) %>%
|
||||
gsub("Bacteria", "Bacteri\u00ebn", ., fixed = TRUE) %>%
|
||||
@ -304,6 +315,8 @@ mo_translate <- function(x, language) {
|
||||
gsub("Coagulase Negative Staphylococcus","Staphylococcus coagulasa negativo", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Staphylococcus coagulasa positivo", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Streptococcus Beta-hemol\u00edtico", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "Gram negativos desconocidos", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "Gram positivos desconocidos", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(sin MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram negativo", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram positivo", ., fixed = TRUE) %>%
|
||||
@ -316,28 +329,13 @@ mo_translate <- function(x, language) {
|
||||
gsub("([([ ]*?)group", "\\1grupo", .) %>%
|
||||
gsub("([([ ]*?)Group", "\\1Grupo", .),
|
||||
|
||||
# Portuguese
|
||||
language == "pt" ~ x %>%
|
||||
gsub("Coagulase Negative Staphylococcus","Staphylococcus coagulase negativo", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Staphylococcus coagulase positivo", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Streptococcus Beta-hemol\u00edtico", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(sem MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram negativo", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram positivo", ., fixed = TRUE) %>%
|
||||
gsub("Bacteria", "Bact\u00e9rias", ., fixed = TRUE) %>%
|
||||
gsub("Fungi", "Fungos", ., fixed = TRUE) %>%
|
||||
gsub("Protozoa", "Protozo\u00e1rios", ., fixed = TRUE) %>%
|
||||
gsub("biogroup", "biogrupo", ., fixed = TRUE) %>%
|
||||
gsub("biotype", "bi\u00f3tipo", ., fixed = TRUE) %>%
|
||||
gsub("vegetative", "vegetativo", ., fixed = TRUE) %>%
|
||||
gsub("([([ ]*?)group", "\\1grupo", .) %>%
|
||||
gsub("([([ ]*?)Group", "\\1Grupo", .),
|
||||
|
||||
# Italian
|
||||
language == "it" ~ x %>%
|
||||
gsub("Coagulase Negative Staphylococcus","Staphylococcus negativo coagulasi", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Staphylococcus positivo coagulasi", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Streptococcus Beta-emolitico", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "Gram negativi sconosciuti", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "Gram positivi sconosciuti", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(non MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram negativo", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram positivo", ., fixed = TRUE) %>%
|
||||
@ -355,6 +353,8 @@ mo_translate <- function(x, language) {
|
||||
gsub("Coagulase Negative Staphylococcus","Staphylococcus \u00e0 coagulase n\u00e9gative", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Staphylococcus \u00e0 coagulase positif", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Streptococcus B\u00eata-h\u00e9molytique", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "Gram n\u00e9gatifs inconnus", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "Gram positifs inconnus", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(pas MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram n\u00e9gatif", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram positif", ., fixed = TRUE) %>%
|
||||
@ -365,7 +365,26 @@ mo_translate <- function(x, language) {
|
||||
# gsub("biotype", "biotype", ., fixed = TRUE) %>%
|
||||
gsub("vegetative", "v\u00e9g\u00e9tatif", ., fixed = TRUE) %>%
|
||||
gsub("([([ ]*?)group", "\\1groupe", .) %>%
|
||||
gsub("([([ ]*?)Group", "\\1Groupe", .)
|
||||
gsub("([([ ]*?)Group", "\\1Groupe", .),
|
||||
|
||||
# Portuguese
|
||||
language == "pt" ~ x %>%
|
||||
gsub("Coagulase Negative Staphylococcus","Staphylococcus coagulase negativo", ., fixed = TRUE) %>%
|
||||
gsub("Coagulase Positive Staphylococcus","Staphylococcus coagulase positivo", ., fixed = TRUE) %>%
|
||||
gsub("Beta-haemolytic Streptococcus", "Streptococcus Beta-hemol\u00edtico", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram negatives", "Gram negativos desconhecidos", ., fixed = TRUE) %>%
|
||||
gsub("unknown Gram positives", "Gram positivos desconhecidos", ., fixed = TRUE) %>%
|
||||
gsub("(no MO)", "(sem MO)", ., fixed = TRUE) %>%
|
||||
gsub("Gram negative", "Gram negativo", ., fixed = TRUE) %>%
|
||||
gsub("Gram positive", "Gram positivo", ., fixed = TRUE) %>%
|
||||
gsub("Bacteria", "Bact\u00e9rias", ., fixed = TRUE) %>%
|
||||
gsub("Fungi", "Fungos", ., fixed = TRUE) %>%
|
||||
gsub("Protozoa", "Protozo\u00e1rios", ., fixed = TRUE) %>%
|
||||
gsub("biogroup", "biogrupo", ., fixed = TRUE) %>%
|
||||
gsub("biotype", "bi\u00f3tipo", ., fixed = TRUE) %>%
|
||||
gsub("vegetative", "vegetativo", ., fixed = TRUE) %>%
|
||||
gsub("([([ ]*?)group", "\\1grupo", .) %>%
|
||||
gsub("([([ ]*?)Group", "\\1Grupo", .)
|
||||
|
||||
)
|
||||
|
||||
|
40
README.md
40
README.md
@ -60,7 +60,7 @@ The `AMR` package basically does four important things:
|
||||
* Use `first_isolate` to identify the first isolates of every patient [using guidelines from the CLSI](https://clsi.org/standards/products/microbiology/documents/m39/) (Clinical and Laboratory Standards Institute).
|
||||
* You can also identify first *weighted* isolates of every patient, an adjusted version of the CLSI guideline. This takes into account key antibiotics of every strain and compares them.
|
||||
* Use `MDRO` (abbreviation of Multi Drug Resistant Organisms) to check your isolates for exceptional resistance with country-specific guidelines or EUCAST rules. Currently, national guidelines for Germany and the Netherlands are supported.
|
||||
* The data set `microorganisms` contains the complete taxonomic tree of more than 18,000 microorganisms (bacteria, fungi/yeasts and protozoa). Furthermore, the colloquial name and Gram stain are available, which enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like `mo_genus`, `mo_family`, `mo_gramstain` or even `mo_phylum`. As they use `as.mo` internally, they also use artificial intelligence. For example, `mo_genus("MRSA")` and `mo_genus("S. aureus")` will both return `"Staphylococcus"`. They also come with support for German, Dutch, French, Italian, Spanish and Portuguese. These functions can be used to add new variables to your data.
|
||||
* The data set `microorganisms` contains the complete taxonomic tree of more than 18,000 microorganisms (bacteria, fungi/yeasts and protozoa). Furthermore, the colloquial name and Gram stain are available, which enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like `mo_genus`, `mo_family`, `mo_gramstain` or even `mo_phylum`. As they use `as.mo` internally, they also use artificial intelligence. For example, `mo_genus("MRSA")` and `mo_genus("S. aureus")` will both return `"Staphylococcus"`. They also come with support for German, Dutch, Spanish, Italian, French and Portuguese. These functions can be used to add new variables to your data.
|
||||
* The data set `antibiotics` contains the ATC code, LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains a total of 298 trade names. Use functions like `ab_name` and `ab_tradenames` to look up values. The `ab_*` functions use `as.atc` internally so they support AI to guess your expected result. For example, `ab_name("Fluclox")`, `ab_name("Floxapen")` and `ab_name("J01CF05")` will all return `"Flucloxacillin"`. These functions can again be used to add new variables to your data.
|
||||
|
||||
3. It **analyses the data** with convenient functions that use well-known methods.
|
||||
@ -474,17 +474,17 @@ microbenchmark(A = as.mo("stau"),
|
||||
times = 10,
|
||||
unit = "ms")
|
||||
# Unit: milliseconds
|
||||
# expr min lq mean median uq max neval
|
||||
# A 38.864859 38.923316 42.5410391 39.172790 39.394955 70.512389 10
|
||||
# B 13.912175 14.002899 14.1044062 14.084962 14.254467 14.281845 10
|
||||
# C 11.492663 11.555520 76.6953055 11.652670 11.864149 662.026786 10
|
||||
# D 11.616702 11.683261 12.1807189 11.873159 12.142327 14.761724 10
|
||||
# E 13.761108 14.012048 14.1360584 14.106509 14.293229 14.547522 10
|
||||
# F 6.743735 6.785151 6.8962407 6.871335 7.000961 7.158383 10
|
||||
# G 0.119220 0.137030 0.1411503 0.142512 0.145061 0.176909 10
|
||||
# expr min lq mean median uq max neval
|
||||
# A 34.745551 34.798630 35.2596102 34.8994810 35.258325 38.067062 10
|
||||
# B 7.095386 7.125348 7.2219948 7.1613865 7.240377 7.495857 10
|
||||
# C 11.677114 11.733826 11.8304789 11.7715050 11.843756 12.317559 10
|
||||
# D 11.694435 11.730054 11.9859313 11.8775585 12.206371 12.750016 10
|
||||
# E 7.044402 7.117387 7.2271630 7.1923610 7.246104 7.742396 10
|
||||
# F 6.642326 6.778446 6.8988042 6.8753165 6.923577 7.513945 10
|
||||
# G 0.106788 0.131023 0.1351229 0.1357725 0.144014 0.146458 10
|
||||
```
|
||||
|
||||
In the table above, all measurements are shown in milliseconds (thousands of seconds), tested on a quite regular Linux server from 2007 (Core 2 Duo 2.7 GHz, 2 GB DDR2 RAM). A value of 6.9 milliseconds means it will roughly determine 144 different (unique) input values per second. It case of 39.2 milliseconds, this is only 26 input values per second. The more an input value resembles a full name (like C, D and F), the faster the result will be found. In case of G, the input is already a valid MO code, so it only almost takes no time at all (0.0001 seconds on our server).
|
||||
In the table above, all measurements are shown in milliseconds (thousands of seconds), tested on a quite regular Linux server from 2007 (Core 2 Duo 2.7 GHz, 2 GB DDR2 RAM). A value of 6.9 milliseconds means it will roughly determine 144 input values per second. It case of 39.2 milliseconds, this is only 26 input values per second. The more an input value resembles a full name (like C, D and F), the faster the result will be found. In case of G, the input is already a valid MO code, so it only almost takes no time at all (0.0001 seconds on our server).
|
||||
|
||||
To achieve this speed, the `as.mo` function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined far less faster. See this example for the ID of *Burkholderia nodosa* (`B_BRKHL_NOD`):
|
||||
|
||||
@ -591,6 +591,26 @@ microbenchmark(A = mo_species("aureus"),
|
||||
|
||||
Of course, when running `mo_phylum("Firmicutes")` the function has zero knowledge about the actual microorganism, namely *S. aureus*. But since the result would be `"Firmicutes"` too, there is no point in calculating the result. And because this package 'knows' all phyla of all known microorganisms (according to ITIS), it can just return the initial value immediately.
|
||||
|
||||
When the system language is non-English and supported by this `AMR` package, some functions take a little while longer:
|
||||
```r
|
||||
mo_fullname("CoNS", language = "en") # or just mo_fullname("CoNS") on an English system
|
||||
# "Coagulase Negative Staphylococcus (CoNS)"
|
||||
|
||||
mo_fullname("CoNS", language = "fr") # or just mo_fullname("CoNS") on a French system
|
||||
# "Staphylococcus à coagulase négative (CoNS)"
|
||||
|
||||
microbenchmark(A = mo_fullname("CoNS", language = "en"),
|
||||
B = mo_fullname("CoNS", language = "fr"),
|
||||
times = 10,
|
||||
unit = "ms")
|
||||
# Unit: milliseconds
|
||||
# expr min lq mean median uq max neval
|
||||
# A 6.080733 6.33684 6.467129 6.493773 6.593926 6.963666 10
|
||||
# B 14.076651 14.10452 14.446035 14.315893 14.636918 15.254106 10
|
||||
```
|
||||
|
||||
Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.
|
||||
|
||||
## Copyright
|
||||
|
||||
This R package is licensed under the [GNU General Public License (GPL) v2.0](https://gitlab.com/msberends/AMR/blob/master/LICENSE). In a nutshell, this means that this package:
|
||||
|
19
man/get_locale.Rd
Normal file
19
man/get_locale.Rd
Normal file
@ -0,0 +1,19 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/get_locale.R
|
||||
\name{get_locale}
|
||||
\alias{get_locale}
|
||||
\title{Get language for AMR}
|
||||
\usage{
|
||||
get_locale()
|
||||
}
|
||||
\description{
|
||||
Determines the system language to be used for language-dependent output of AMR functions, like \code{\link{mo_gramstain}} and \code{\link{mo_type}}.
|
||||
}
|
||||
\details{
|
||||
The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
|
||||
}
|
||||
\section{Supported languages}{
|
||||
|
||||
Supported languages are \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish), \code{"it"} (Italian), \code{"fr"} (French), and \code{"pt"} (Portuguese).
|
||||
}
|
||||
|
@ -19,15 +19,15 @@
|
||||
\alias{mo_taxonomy}
|
||||
\title{Property of a microorganism}
|
||||
\usage{
|
||||
mo_fullname(x, language = NULL, ...)
|
||||
mo_fullname(x, language = get_locale(), ...)
|
||||
|
||||
mo_shortname(x, language = NULL, ...)
|
||||
mo_shortname(x, language = get_locale(), ...)
|
||||
|
||||
mo_subspecies(x, language = NULL, ...)
|
||||
mo_subspecies(x, language = get_locale(), ...)
|
||||
|
||||
mo_species(x, language = NULL, ...)
|
||||
mo_species(x, language = get_locale(), ...)
|
||||
|
||||
mo_genus(x, language = NULL, ...)
|
||||
mo_genus(x, language = get_locale(), ...)
|
||||
|
||||
mo_family(x, ...)
|
||||
|
||||
@ -41,20 +41,20 @@ mo_subkingdom(x, ...)
|
||||
|
||||
mo_ref(x, ...)
|
||||
|
||||
mo_type(x, language = NULL, ...)
|
||||
mo_type(x, language = get_locale(), ...)
|
||||
|
||||
mo_TSN(x, ...)
|
||||
|
||||
mo_gramstain(x, language = NULL, ...)
|
||||
mo_gramstain(x, language = get_locale(), ...)
|
||||
|
||||
mo_property(x, property = "fullname", language = NULL, ...)
|
||||
mo_property(x, property = "fullname", language = get_locale(), ...)
|
||||
|
||||
mo_taxonomy(x, ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link{as.mo}}}
|
||||
|
||||
\item{language}{language of the returned text, defaults to English (\code{"en"}) and can also be set with \code{\link{getOption}("AMR_locale")}. Either one of \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish) or \code{"pt"} (Portuguese).}
|
||||
\item{language}{language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}.}
|
||||
|
||||
\item{...}{other parameters passed on to \code{\link{as.mo}}}
|
||||
|
||||
@ -66,6 +66,11 @@ A \code{list} (in case of \code{mo_taxonomy}) or a \code{character} otherwise
|
||||
\description{
|
||||
Use these functions to return a specific property of a microorganism from the \code{\link{microorganisms}} data set. All input values will be evaluated internally with \code{\link{as.mo}}.
|
||||
}
|
||||
\section{Supported languages}{
|
||||
|
||||
Supported languages are \code{"en"} (English), \code{"de"} (German), \code{"nl"} (Dutch), \code{"es"} (Spanish), \code{"it"} (Italian), \code{"fr"} (French), and \code{"pt"} (Portuguese).
|
||||
}
|
||||
|
||||
\section{ITIS}{
|
||||
|
||||
\if{html}{\figure{itis_logo.jpg}{options: height=60px style=margin-bottom:5px} \cr}
|
||||
|
15
tests/testthat/test-get_locale.R
Normal file
15
tests/testthat/test-get_locale.R
Normal file
@ -0,0 +1,15 @@
|
||||
context("get_locale.R")
|
||||
|
||||
test_that("get_locale works", {
|
||||
expect_identical(mo_genus("B_GRAMP", language = "pt"),
|
||||
"(Gram positivos desconhecidos)")
|
||||
|
||||
expect_identical(mo_fullname("CoNS", "en"), "Coagulase Negative Staphylococcus (CoNS)")
|
||||
expect_identical(mo_fullname("CoNS", "de"), "Koagulase-negative Staphylococcus (KNS)")
|
||||
expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)")
|
||||
expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (CoNS)")
|
||||
expect_identical(mo_fullname("CoNS", "it"), "Staphylococcus negativo coagulasi (CoNS)")
|
||||
expect_identical(mo_fullname("CoNS", "fr"), "Staphylococcus à coagulase négative (CoNS)")
|
||||
expect_identical(mo_fullname("CoNS", "pt"), "Staphylococcus coagulase negativo (CoNS)")
|
||||
|
||||
})
|
@ -21,7 +21,7 @@ test_that("mo_property works", {
|
||||
|
||||
expect_equal(mo_shortname("MRSA"), "S. aureus")
|
||||
expect_equal(mo_shortname("MRSA", Becker = TRUE), "S. aureus")
|
||||
expect_equal(mo_shortname("MRSA", Becker = "all"), "CoPS")
|
||||
expect_equal(mo_shortname("MRSA", Becker = "all", language = "en"), "CoPS")
|
||||
expect_equal(mo_shortname("S. aga"), "S. agalactiae")
|
||||
expect_equal(mo_shortname("S. aga", Lancefield = TRUE), "GBS")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user