diff --git a/DESCRIPTION b/DESCRIPTION index 78eac206..8097d6e5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.7.1.9076 +Version: 0.7.1.9077 Date: 2019-09-20 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 84a260f8..35028efd 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9076 +# AMR 0.7.1.9077 Last updated: 20-Sep-2019 ### Breaking diff --git a/R/data.R b/R/data.R index 58c9d1bd..e4c4477d 100755 --- a/R/data.R +++ b/R/data.R @@ -98,12 +98,13 @@ catalogue_of_life <- list( #' #' A data set containing old (previously valid or accepted) taxonomic names according to the Catalogue of Life. This data set is used internally by \code{\link{as.mo}}. #' @inheritSection catalogue_of_life Catalogue of Life -#' @format A \code{\link{data.frame}} with 24,246 observations and 4 variables: +#' @format A \code{\link{data.frame}} with 24,246 observations and 5 variables: #' \describe{ #' \item{\code{col_id}}{Catalogue of Life ID that was originally given} #' \item{\code{col_id_new}}{New Catalogue of Life ID that responds to an entry in the \code{\link{microorganisms}} data set} #' \item{\code{fullname}}{Old full taxonomic name of the microorganism} #' \item{\code{ref}}{Author(s) and year of concerning scientific publication} +#' \item{\code{prevalence}}{Prevalence of the microorganism, see \code{?as.mo}} #' } #' @source Catalogue of Life: Annual Checklist (public online taxonomic database), \url{http://www.catalogueoflife.org} (check included annual version with \code{\link{catalogue_of_life_version}()}). #' @inheritSection AMR Read more on our website! diff --git a/R/mo.R b/R/mo.R index 4e03f138..fc2f2642 100755 --- a/R/mo.R +++ b/R/mo.R @@ -71,9 +71,10 @@ #' \itemize{ #' \item{Valid MO codes and full names: it first searches in already valid MO code and known genus/species combinations} #' \item{Human pathogenic prevalence: it first searches in more prevalent microorganisms, then less prevalent ones (see \emph{Microbial prevalence of pathogens in humans} below)} -#' \item{Taxonomic kingdom: it first searches in Bacteria/Chromista, then Fungi, then Protozoa} +#' \item{Taxonomic kingdom: it first searches in Bacteria, then Fungi, then Protozoa, then Archaea, then others} #' \item{Breakdown of input values: from here it starts to breakdown input values to find possible matches} #' } +#' #' #' A couple of effects because of these rules: #' \itemize{ @@ -258,7 +259,6 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, y <- mo_validate(x = x, property = "mo", Becker = Becker, Lancefield = Lancefield, allow_uncertain = uncertainty_level, reference_df = reference_df, - #force_mo_history = isTRUE(list(...)$force_mo_history), ...) } @@ -285,7 +285,7 @@ is.mo <- function(x) { # param force_mo_history logical - whether found result must be saved with set_mo_history (default FALSE on non-interactive sessions) # param disable_mo_history logical - whether set_mo_history and get_mo_history should be ignored # param debug logical - show different lookup texts while searching -# param uncertain_check_prevalence integer - the prevalence to check for when running for uncertain results, follows microorganisms$prevalence +# param reference_data_to_use data.frame - the data set to check for exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, @@ -936,6 +936,7 @@ exec_as.mo <- function(x, # NOW RUN THROUGH DIFFERENT PREVALENCE LEVELS check_per_prevalence <- function(data_to_check, + data.old_to_check, a.x_backup, b.x_trimmed, c.x_trimmed_without_group, @@ -1065,33 +1066,31 @@ exec_as.mo <- function(x, } # MISCELLANEOUS ---- - + # look for old taxonomic names ---- # wait until prevalence == 2 to run the old taxonomic results on both prevalence == 1 and prevalence == 2 - if (nrow(data_to_check) == nrow(microorganismsDT[prevalence == 2])) { - found <- microorganisms.oldDT[fullname_lower == tolower(a.x_backup) - | fullname_lower %like_case% d.x_withspaces_start_end,] - if (NROW(found) > 0) { - col_id_new <- found[1, col_id_new] - # when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so: - # mo_ref("Chlamydia psittaci") = "Page, 1968" (with warning) - # mo_ref("Chlamydophila psittaci") = "Everett et al., 1999" - if (property == "ref") { - x[i] <- found[1, ref] - } else { - x[i] <- microorganismsDT[col_id == found[1, col_id_new], ..property][[1]] - } - options(mo_renamed_last_run = found[1, fullname]) - was_renamed(name_old = found[1, fullname], - name_new = microorganismsDT[col_id == found[1, col_id_new], fullname], - ref_old = found[1, ref], - ref_new = microorganismsDT[col_id == found[1, col_id_new], ref], - mo = microorganismsDT[col_id == found[1, col_id_new], mo]) - if (initial_search == TRUE) { - set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) - } - return(x[i]) + found <- data.old_to_check[fullname_lower == tolower(a.x_backup) + | fullname_lower %like_case% d.x_withspaces_start_end,] + if (NROW(found) > 0) { + col_id_new <- found[1, col_id_new] + # when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so: + # mo_ref("Chlamydia psittaci") = "Page, 1968" (with warning) + # mo_ref("Chlamydophila psittaci") = "Everett et al., 1999" + if (property == "ref") { + x[i] <- found[1, ref] + } else { + x[i] <- microorganismsDT[col_id == found[1, col_id_new], ..property][[1]] } + options(mo_renamed_last_run = found[1, fullname]) + was_renamed(name_old = found[1, fullname], + name_new = microorganismsDT[col_id == found[1, col_id_new], fullname], + ref_old = found[1, ref], + ref_new = microorganismsDT[col_id == found[1, col_id_new], ref], + mo = microorganismsDT[col_id == found[1, col_id_new], mo]) + if (initial_search == TRUE) { + set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) + } + return(x[i]) } # check for uncertain results ---- @@ -1119,7 +1118,7 @@ exec_as.mo <- function(x, if (isTRUE(debug)) { message("Running '", d.x_withspaces_start_end, "' and '", e.x_withspaces_start_only, "'") } - found <- microorganisms.oldDT[fullname_lower %like_case% d.x_withspaces_start_end + found <- data.old_to_check[fullname_lower %like_case% d.x_withspaces_start_end | fullname_lower %like_case% e.x_withspaces_start_only] if (NROW(found) > 0 & nchar(g.x_backup_without_spp) >= 6) { if (property == "ref") { @@ -1521,6 +1520,7 @@ exec_as.mo <- function(x, # FIRST TRY VERY PREVALENT IN HUMAN INFECTIONS ---- x[i] <- check_per_prevalence(data_to_check = reference_data_to_use[prevalence == 1], + data.old_to_check = microorganisms.oldDT[prevalence == 1], a.x_backup = x_backup[i], b.x_trimmed = x_trimmed[i], c.x_trimmed_without_group = x_trimmed_without_group[i], @@ -1539,6 +1539,7 @@ exec_as.mo <- function(x, # THEN TRY PREVALENT IN HUMAN INFECTIONS ---- x[i] <- check_per_prevalence(data_to_check = reference_data_to_use[prevalence == 2], + data.old_to_check = microorganisms.oldDT[prevalence == 2], a.x_backup = x_backup[i], b.x_trimmed = x_trimmed[i], c.x_trimmed_without_group = x_trimmed_without_group[i], @@ -1557,6 +1558,7 @@ exec_as.mo <- function(x, # THEN UNPREVALENT IN HUMAN INFECTIONS ---- x[i] <- check_per_prevalence(data_to_check = reference_data_to_use[prevalence == 3], + data.old_to_check = microorganisms.oldDT[prevalence == 3], a.x_backup = x_backup[i], b.x_trimmed = x_trimmed[i], c.x_trimmed_without_group = x_trimmed_without_group[i], diff --git a/R/mo_history.R b/R/mo_history.R index 445d9fea..ce38e719 100644 --- a/R/mo_history.R +++ b/R/mo_history.R @@ -55,7 +55,7 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA # if (tryCatch(nrow(getOption("mo_remembered_results")), error = function(e) 1001) > 1000) { # return(base::invisible()) # } - if (is.null(mo_hist)) { + if (is.null(mo_hist) & interactive()) { message(blue(paste0("NOTE: results are saved to ", mo_history_file(), "."))) } tryCatch(write.csv(rbind(mo_hist, diff --git a/R/sysdata.rda b/R/sysdata.rda index 62f80d47..4f28c4f4 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/zzz.R b/R/zzz.R index 626ae0eb..be3be7f4 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -28,7 +28,7 @@ microorganisms.oldDT <- as.data.table(AMR::microorganisms.old) # for fullname_lower: keep only dots, letters, numbers, slashes, spaces and dashes microorganisms.oldDT$fullname_lower <- gsub("[^.a-z0-9/ \\-]+", "", tolower(microorganisms.oldDT$fullname)) - setkey(microorganisms.oldDT, col_id, fullname) + setkey(microorganisms.oldDT, prevalence, fullname) assign(x = "microorganismsDT", value = make_DT(), @@ -81,12 +81,17 @@ #' @importFrom data.table as.data.table setkey make_DT <- function() { - microorganismsDT <- as.data.table(AMR::microorganisms) + microorganismsDT <- as.data.table(AMR::microorganisms %>% + mutate(kingdom_index = case_when(kingdom == "Bacteria" ~ 1, + kingdom == "Fungi" ~ 2, + kingdom == "Protozoa" ~ 3, + kingdom == "Archaea" ~ 4, + TRUE ~ 6))) # for fullname_lower: keep only dots, letters, numbers, slashes, spaces and dashes microorganismsDT$fullname_lower <- gsub("[^.a-z0-9/ \\-]+", "", tolower(microorganismsDT$fullname)) setkey(microorganismsDT, prevalence, - kingdom, + kingdom_index, fullname) microorganismsDT } diff --git a/data-raw/microorganisms.translation.rds b/data-raw/microorganisms.translation.rds index 65377f50..c4509704 100644 Binary files a/data-raw/microorganisms.translation.rds and b/data-raw/microorganisms.translation.rds differ diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index f1864d97..36dddc00 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -636,6 +636,9 @@ MOs <- MOs %>% ungroup() %>% filter(fullname != "") +MOs.old <- MOs.old %>% + left_join(MOs %>% select(col_id, prevalence), by = c("col_id_new" = "col_id")) + # everything distinct? sum(duplicated(MOs$mo)) sum(duplicated(MOs$fullname)) diff --git a/data/microorganisms.old.rda b/data/microorganisms.old.rda index 73c3609c..4be20397 100644 Binary files a/data/microorganisms.old.rda and b/data/microorganisms.old.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 206af166..407b1ee8 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 0f74654a..32ea701b 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ @@ -199,7 +199,7 @@Using the microbenchmark
package, we can review the calculation performance of this function. Its function microbenchmark()
runs different input expressions independently of each other and measures their time-to-result.
In the next test, we try to ‘coerce’ different input values for Staphylococcus aureus. The actual result is the same every time: it returns its MO code B_STPHY_AURS
(B stands for Bacteria, the taxonomic kingdom).
In the next test, we try to ‘coerce’ different input values for Staphylococcus aureus. The actual result is the same every time: it returns its microorganism code B_STPHY_AURS
(B stands for Bacteria, the taxonomic kingdom).
But the calculation time differs a lot:
S.aureus <- microbenchmark(
as.mo("sau"), # WHONET code
@@ -219,193 +219,167 @@
times = 10)
print(S.aureus, unit = "ms", signif = 2)
# Unit: milliseconds
-# expr min lq mean median uq max
-# as.mo("sau") 8.4 8.8 23.0 8.8 30.0 100
-# as.mo("stau") 31.0 31.0 42.0 35.0 54.0 60
-# as.mo("STAU") 31.0 32.0 39.0 33.0 53.0 56
-# as.mo("staaur") 8.5 8.9 11.0 9.0 9.2 33
-# as.mo("STAAUR") 8.6 8.8 9.4 9.3 9.4 11
-# as.mo("S. aureus") 23.0 24.0 28.0 26.0 28.0 51
-# as.mo("S aureus") 23.0 24.0 29.0 25.0 25.0 51
-# as.mo("Staphylococcus aureus") 28.0 29.0 30.0 29.0 30.0 32
-# as.mo("Staphylococcus aureus (MRSA)") 600.0 620.0 640.0 620.0 640.0 800
-# as.mo("Sthafilokkockus aaureuz") 320.0 340.0 370.0 350.0 400.0 450
-# as.mo("MRSA") 8.7 8.7 11.0 9.2 9.9 31
-# as.mo("VISA") 19.0 19.0 20.0 19.0 20.0 23
-# as.mo("VRSA") 19.0 19.0 25.0 20.0 28.0 44
-# as.mo(22242419) 18.0 19.0 47.0 31.0 48.0 190
-# neval
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
-# 10
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.
-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 less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISLN
), a bug probably never found before in humans:
T.islandicus <- microbenchmark(as.mo("theisl"),
- as.mo("THEISL"),
- as.mo("T. islandicus"),
- as.mo("T. islandicus"),
- as.mo("Thermus islandicus"),
+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 less fast. See this example for the ID of Methanosarcina semesiae (B_MTHNSR_SEMS
), a bug probably never found before in humans:
+M.semesiae <- microbenchmark(as.mo("metsem"),
+ as.mo("METSEM"),
+ as.mo("M. semesiae"),
+ as.mo("M. semesiae"),
+ as.mo("Methanosarcina semesiae"),
times = 10)
-print(T.islandicus, unit = "ms", signif = 2)
+print(M.semesiae, unit = "ms", signif = 4)
# Unit: milliseconds
-# expr min lq mean median uq max neval
-# as.mo("theisl") 1300 1500 1500 1500 1500 1600 10
-# as.mo("THEISL") 1400 1500 1500 1500 1500 1600 10
-# as.mo("T. islandicus") 410 410 430 410 450 500 10
-# as.mo("T. islandicus") 410 420 430 420 440 440 10
-# as.mo("Thermus islandicus") 30 30 31 31 32 35 10
-That takes 8.2 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 Thermus islandicus) are almost fast - these are the most probable input from most data sets.
-In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is uncommon):
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
+# expr min lq mean median uq
+# as.mo("metsem") 1201.00 1327.00 1331.00 1340.00 1359.00
+# as.mo("METSEM") 1255.00 1298.00 1333.00 1340.00 1363.00
+# as.mo("M. semesiae") 1927.00 1943.00 1985.00 1995.00 2014.00
+# as.mo("M. semesiae") 1914.00 1953.00 1979.00 1977.00 1987.00
+# as.mo("Methanosarcina semesiae") 27.84 30.71 31.59 31.12 31.44
+# max neval
+# 1371.00 10
+# 1398.00 10
+# 2040.00 10
+# 2058.00 10
+# 39.75 10
That takes 15.7 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 Methanosarcina semesiae) are almost fast - these are the most probable input from most data sets.
+In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Methanosarcina semesiae (which is uncommon):
+In reality, the as.mo()
functions learns from its own output to speed up determinations for next times. In above figure, this effect was disabled to show the difference with the boxplot below - when you would use as.mo()
yourself:
# NOTE: results are saved to /Users/msberends/Library/R/3.6/library/AMR/mo_history/mo_history.csv.
-# Warning:
-# Result of one value was guessed with uncertainty. Use mo_uncertainties() to review it.
-
+
The highest outliers are the first times. All next determinations were done in only thousands of seconds.
Uncommon microorganisms take a lot more time than common microorganisms. To relieve this pitfall and further improve performance, two important calculations take almost no time at all: repetitive results and already precalculated results.
Repetitive results are unique values that are present more than once. Unique values will only be calculated once by as.mo()
. We will use mo_name()
for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses as.mo()
internally.
library(dplyr)
-# take all MO codes from the example_isolates data set
-x <- example_isolates$mo %>%
- # keep only the unique ones
- unique() %>%
- # pick 50 of them at random
- sample(50) %>%
- # paste that 10,000 times
- rep(10000) %>%
- # scramble it
- sample()
-
-# got indeed 50 times 10,000 = half a million?
-length(x)
-# [1] 500000
-
-# and how many unique values do we have?
-n_distinct(x)
-# [1] 50
-
-# now let's see:
-run_it <- microbenchmark(mo_name(x),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# mo_name(x) 604 632 655 644 660 764 10
So transforming 500,000 values (!!) of 50 unique values only takes 0.64 seconds (644 ms). You only lose time on your unique input values.
+library(dplyr)
+# take all MO codes from the example_isolates data set
+x <- example_isolates$mo %>%
+ # keep only the unique ones
+ unique() %>%
+ # pick 50 of them at random
+ sample(50) %>%
+ # paste that 10,000 times
+ rep(10000) %>%
+ # scramble it
+ sample()
+
+# got indeed 50 times 10,000 = half a million?
+length(x)
+# [1] 500000
+
+# and how many unique values do we have?
+n_distinct(x)
+# [1] 50
+
+# now let's see:
+run_it <- microbenchmark(mo_name(x),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# mo_name(x) 610 637 653 652 668 718 10
So transforming 500,000 values (!!) of 50 unique values only takes 0.65 seconds (652 ms). You only lose time on your unique input values.
What about precalculated results? If the input is an already precalculated result of a helper function like mo_name()
, it almost doesn’t take any time at all (see ‘C’ below):
run_it <- microbenchmark(A = mo_name("B_STPHY_AURS"),
- B = mo_name("S. aureus"),
- C = mo_name("Staphylococcus aureus"),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# A 6.190 6.270 6.560 6.290 7.160 7.280 10
-# B 22.600 23.100 26.700 23.400 24.300 51.600 10
-# C 0.704 0.765 0.827 0.829 0.906 0.913 10
run_it <- microbenchmark(A = mo_name("B_STPHY_AURS"),
+ B = mo_name("S. aureus"),
+ C = mo_name("Staphylococcus aureus"),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# A 6.280 6.560 9.940 6.720 6.860 39.30 10
+# B 22.500 22.900 24.300 23.000 24.900 30.90 10
+# C 0.805 0.829 0.871 0.847 0.869 1.09 10
So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0008 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
run_it <- microbenchmark(A = mo_species("aureus"),
- B = mo_genus("Staphylococcus"),
- C = mo_name("Staphylococcus aureus"),
- D = mo_family("Staphylococcaceae"),
- E = mo_order("Bacillales"),
- F = mo_class("Bacilli"),
- G = mo_phylum("Firmicutes"),
- H = mo_kingdom("Bacteria"),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# A 0.456 0.476 0.484 0.483 0.488 0.516 10
-# B 0.613 0.620 0.639 0.628 0.642 0.723 10
-# C 0.675 0.700 0.763 0.796 0.807 0.816 10
-# D 0.443 0.454 0.466 0.467 0.477 0.497 10
-# E 0.453 0.459 0.465 0.464 0.472 0.483 10
-# F 0.433 0.447 0.464 0.463 0.484 0.498 10
-# G 0.453 0.460 0.469 0.464 0.478 0.502 10
-# H 0.433 0.451 0.477 0.459 0.470 0.662 10
run_it <- microbenchmark(A = mo_species("aureus"),
+ B = mo_genus("Staphylococcus"),
+ C = mo_name("Staphylococcus aureus"),
+ D = mo_family("Staphylococcaceae"),
+ E = mo_order("Bacillales"),
+ F = mo_class("Bacilli"),
+ G = mo_phylum("Firmicutes"),
+ H = mo_kingdom("Bacteria"),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# A 0.456 0.457 0.472 0.465 0.493 0.498 10
+# B 0.629 0.640 0.713 0.668 0.752 0.956 10
+# C 0.798 0.811 0.840 0.832 0.840 0.965 10
+# D 0.428 0.453 0.473 0.464 0.503 0.518 10
+# E 0.446 0.477 0.513 0.495 0.525 0.648 10
+# F 0.466 0.473 0.496 0.484 0.521 0.545 10
+# G 0.457 0.461 0.477 0.468 0.486 0.545 10
+# H 0.456 0.467 0.478 0.477 0.482 0.512 10
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 bacteria (according to the Catalogue of Life), it can just return the initial value immediately.
When the system language is non-English and supported by this AMR
package, some functions will have a translated result. This almost does’t take extra time:
mo_name("CoNS", language = "en") # or just mo_name("CoNS") on an English system
-# [1] "Coagulase-negative Staphylococcus (CoNS)"
-
-mo_name("CoNS", language = "es") # or just mo_name("CoNS") on a Spanish system
-# [1] "Staphylococcus coagulasa negativo (SCN)"
-
-mo_name("CoNS", language = "nl") # or just mo_name("CoNS") on a Dutch system
-# [1] "Coagulase-negatieve Staphylococcus (CNS)"
-
-run_it <- microbenchmark(en = mo_name("CoNS", language = "en"),
- de = mo_name("CoNS", language = "de"),
- nl = mo_name("CoNS", language = "nl"),
- es = mo_name("CoNS", language = "es"),
- it = mo_name("CoNS", language = "it"),
- fr = mo_name("CoNS", language = "fr"),
- pt = mo_name("CoNS", language = "pt"),
- times = 10)
-print(run_it, unit = "ms", signif = 4)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# en 18.18 18.24 18.54 18.44 18.58 19.41 10
-# de 19.52 19.79 20.03 19.90 20.15 20.95 10
-# nl 24.54 24.94 26.29 25.70 26.35 31.90 10
-# es 19.52 19.69 22.29 19.86 20.27 44.03 10
-# it 19.52 19.57 22.05 19.74 20.46 41.43 10
-# fr 19.61 19.67 22.28 20.04 20.30 42.90 10
-# pt 19.51 19.79 25.16 20.01 20.73 49.48 10
mo_name("CoNS", language = "en") # or just mo_name("CoNS") on an English system
+# [1] "Coagulase-negative Staphylococcus (CoNS)"
+
+mo_name("CoNS", language = "es") # or just mo_name("CoNS") on a Spanish system
+# [1] "Staphylococcus coagulasa negativo (SCN)"
+
+mo_name("CoNS", language = "nl") # or just mo_name("CoNS") on a Dutch system
+# [1] "Coagulase-negatieve Staphylococcus (CNS)"
+
+run_it <- microbenchmark(en = mo_name("CoNS", language = "en"),
+ de = mo_name("CoNS", language = "de"),
+ nl = mo_name("CoNS", language = "nl"),
+ es = mo_name("CoNS", language = "es"),
+ it = mo_name("CoNS", language = "it"),
+ fr = mo_name("CoNS", language = "fr"),
+ pt = mo_name("CoNS", language = "pt"),
+ times = 10)
+print(run_it, unit = "ms", signif = 4)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# en 18.04 18.47 18.79 18.54 19.25 19.70 10
+# de 19.36 19.88 22.78 20.17 20.39 47.73 10
+# nl 24.57 25.38 28.46 25.63 26.12 54.82 10
+# es 19.50 19.89 25.49 20.51 25.79 44.96 10
+# it 19.52 19.82 20.44 20.11 20.80 23.09 10
+# fr 19.50 19.79 20.42 19.86 20.53 23.35 10
+# pt 19.25 19.55 22.50 19.59 20.04 47.50 10
Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.
Last updated: 20-Sep-2019
as.mo(..., allow_uncertain = 3)
Contents
as.mo()
function gains experience from previously determined mi
This function uses intelligent rules to help getting fast and logical results. It tries to find matches in this order:Valid MO codes and full names: it first searches in already valid MO code and known genus/species combinations
Human pathogenic prevalence: it first searches in more prevalent microorganisms, then less prevalent ones (see Microbial prevalence of pathogens in humans below)
Taxonomic kingdom: it first searches in Bacteria/Chromista, then Fungi, then Protozoa
Taxonomic kingdom: it first searches in Bacteria, then Fungi, then Protozoa, then Archaea, then others
Breakdown of input values: from here it starts to breakdown input values to find possible matches
A couple of effects because of these rules:
A data.frame
with 24,246 observations and 4 variables:
A data.frame
with 24,246 observations and 5 variables:
col_id
Catalogue of Life ID that was originally given
col_id_new
New Catalogue of Life ID that responds to an entry in the microorganisms
data set
fullname
Old full taxonomic name of the microorganism
ref
Author(s) and year of concerning scientific publication
prevalence
Prevalence of the microorganism, see ?as.mo