(v0.7.1.9077) mo codes fix

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-09-20 14:18:29 +02:00
parent 3596adb295
commit 40e6b3e8f6
26 changed files with 256 additions and 256 deletions

View File

@ -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(

View File

@ -1,4 +1,4 @@
# AMR 0.7.1.9076
# AMR 0.7.1.9077
<small>Last updated: 20-Sep-2019</small>
### Breaking

View File

@ -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!

58
R/mo.R
View File

@ -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],

View File

@ -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,

Binary file not shown.

11
R/zzz.R
View File

@ -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
}

View File

@ -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))

Binary file not shown.

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>
@ -199,7 +199,7 @@
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark()</a></code> runs different input expressions independently of each other and measures their time-to-result.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(microbenchmark)</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR)</a></code></pre></div>
<p>In the next test, we try to coerce different input values for <em>Staphylococcus aureus</em>. The actual result is the same every time: it returns its MO code <code>B_STPHY_AURS</code> (<em>B</em> stands for <em>Bacteria</em>, the taxonomic kingdom).</p>
<p>In the next test, we try to coerce different input values for <em>Staphylococcus aureus</em>. The actual result is the same every time: it returns its microorganism code <code>B_STPHY_AURS</code> (<em>B</em> stands for <em>Bacteria</em>, the taxonomic kingdom).</p>
<p>But the calculation time differs a lot:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1">S.aureus &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"sau"</span>), <span class="co"># WHONET code</span></a>
@ -219,193 +219,167 @@
<a class="sourceLine" id="cb2-16" data-line-number="16"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb2-17" data-line-number="17"><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-18" data-line-number="18"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb2-19" data-line-number="19"><span class="co"># expr min lq mean median uq max</span></a>
<a class="sourceLine" id="cb2-20" data-line-number="20"><span class="co"># as.mo("sau") 8.4 8.8 23.0 8.8 30.0 100</span></a>
<a class="sourceLine" id="cb2-21" data-line-number="21"><span class="co"># as.mo("stau") 31.0 31.0 42.0 35.0 54.0 60</span></a>
<a class="sourceLine" id="cb2-22" data-line-number="22"><span class="co"># as.mo("STAU") 31.0 32.0 39.0 33.0 53.0 56</span></a>
<a class="sourceLine" id="cb2-23" data-line-number="23"><span class="co"># as.mo("staaur") 8.5 8.9 11.0 9.0 9.2 33</span></a>
<a class="sourceLine" id="cb2-24" data-line-number="24"><span class="co"># as.mo("STAAUR") 8.6 8.8 9.4 9.3 9.4 11</span></a>
<a class="sourceLine" id="cb2-25" data-line-number="25"><span class="co"># as.mo("S. aureus") 23.0 24.0 28.0 26.0 28.0 51</span></a>
<a class="sourceLine" id="cb2-26" data-line-number="26"><span class="co"># as.mo("S aureus") 23.0 24.0 29.0 25.0 25.0 51</span></a>
<a class="sourceLine" id="cb2-27" data-line-number="27"><span class="co"># as.mo("Staphylococcus aureus") 28.0 29.0 30.0 29.0 30.0 32</span></a>
<a class="sourceLine" id="cb2-28" data-line-number="28"><span class="co"># as.mo("Staphylococcus aureus (MRSA)") 600.0 620.0 640.0 620.0 640.0 800</span></a>
<a class="sourceLine" id="cb2-29" data-line-number="29"><span class="co"># as.mo("Sthafilokkockus aaureuz") 320.0 340.0 370.0 350.0 400.0 450</span></a>
<a class="sourceLine" id="cb2-30" data-line-number="30"><span class="co"># as.mo("MRSA") 8.7 8.7 11.0 9.2 9.9 31</span></a>
<a class="sourceLine" id="cb2-31" data-line-number="31"><span class="co"># as.mo("VISA") 19.0 19.0 20.0 19.0 20.0 23</span></a>
<a class="sourceLine" id="cb2-32" data-line-number="32"><span class="co"># as.mo("VRSA") 19.0 19.0 25.0 20.0 28.0 44</span></a>
<a class="sourceLine" id="cb2-33" data-line-number="33"><span class="co"># as.mo(22242419) 18.0 19.0 47.0 31.0 48.0 190</span></a>
<a class="sourceLine" id="cb2-34" data-line-number="34"><span class="co"># neval</span></a>
<a class="sourceLine" id="cb2-35" data-line-number="35"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-36" data-line-number="36"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-37" data-line-number="37"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-38" data-line-number="38"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-39" data-line-number="39"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-40" data-line-number="40"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-41" data-line-number="41"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-42" data-line-number="42"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-43" data-line-number="43"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-44" data-line-number="44"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-45" data-line-number="45"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-46" data-line-number="46"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-47" data-line-number="47"><span class="co"># 10</span></a>
<a class="sourceLine" id="cb2-48" data-line-number="48"><span class="co"># 10</span></a></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="562.5"></p>
<a class="sourceLine" id="cb2-19" data-line-number="19"><span class="co"># expr min lq mean median uq</span></a>
<a class="sourceLine" id="cb2-20" data-line-number="20"><span class="co"># as.mo("sau") 8.6 8.8 9.0 9.0 9.2</span></a>
<a class="sourceLine" id="cb2-21" data-line-number="21"><span class="co"># as.mo("stau") 31.0 31.0 32.0 32.0 33.0</span></a>
<a class="sourceLine" id="cb2-22" data-line-number="22"><span class="co"># as.mo("STAU") 31.0 32.0 39.0 33.0 38.0</span></a>
<a class="sourceLine" id="cb2-23" data-line-number="23"><span class="co"># as.mo("staaur") 8.6 9.1 17.0 9.7 31.0</span></a>
<a class="sourceLine" id="cb2-24" data-line-number="24"><span class="co"># as.mo("STAAUR") 8.7 9.0 14.0 9.3 9.6</span></a>
<a class="sourceLine" id="cb2-25" data-line-number="25"><span class="co"># as.mo("S. aureus") 23.0 23.0 45.0 24.0 25.0</span></a>
<a class="sourceLine" id="cb2-26" data-line-number="26"><span class="co"># as.mo("S aureus") 23.0 23.0 29.0 24.0 26.0</span></a>
<a class="sourceLine" id="cb2-27" data-line-number="27"><span class="co"># as.mo("Staphylococcus aureus") 28.0 28.0 32.0 29.0 30.0</span></a>
<a class="sourceLine" id="cb2-28" data-line-number="28"><span class="co"># as.mo("Staphylococcus aureus (MRSA)") 530.0 560.0 580.0 570.0 580.0</span></a>
<a class="sourceLine" id="cb2-29" data-line-number="29"><span class="co"># as.mo("Sthafilokkockus aaureuz") 270.0 300.0 310.0 310.0 320.0</span></a>
<a class="sourceLine" id="cb2-30" data-line-number="30"><span class="co"># as.mo("MRSA") 8.6 9.0 9.3 9.2 9.3</span></a>
<a class="sourceLine" id="cb2-31" data-line-number="31"><span class="co"># as.mo("VISA") 19.0 20.0 27.0 20.0 43.0</span></a>
<a class="sourceLine" id="cb2-32" data-line-number="32"><span class="co"># as.mo("VRSA") 19.0 20.0 26.0 21.0 23.0</span></a>
<a class="sourceLine" id="cb2-33" data-line-number="33"><span class="co"># as.mo(22242419) 18.0 18.0 24.0 19.0 22.0</span></a>
<a class="sourceLine" id="cb2-34" data-line-number="34"><span class="co"># max neval</span></a>
<a class="sourceLine" id="cb2-35" data-line-number="35"><span class="co"># 9.5 10</span></a>
<a class="sourceLine" id="cb2-36" data-line-number="36"><span class="co"># 38.0 10</span></a>
<a class="sourceLine" id="cb2-37" data-line-number="37"><span class="co"># 61.0 10</span></a>
<a class="sourceLine" id="cb2-38" data-line-number="38"><span class="co"># 38.0 10</span></a>
<a class="sourceLine" id="cb2-39" data-line-number="39"><span class="co"># 35.0 10</span></a>
<a class="sourceLine" id="cb2-40" data-line-number="40"><span class="co"># 210.0 10</span></a>
<a class="sourceLine" id="cb2-41" data-line-number="41"><span class="co"># 56.0 10</span></a>
<a class="sourceLine" id="cb2-42" data-line-number="42"><span class="co"># 57.0 10</span></a>
<a class="sourceLine" id="cb2-43" data-line-number="43"><span class="co"># 660.0 10</span></a>
<a class="sourceLine" id="cb2-44" data-line-number="44"><span class="co"># 380.0 10</span></a>
<a class="sourceLine" id="cb2-45" data-line-number="45"><span class="co"># 10.0 10</span></a>
<a class="sourceLine" id="cb2-46" data-line-number="46"><span class="co"># 46.0 10</span></a>
<a class="sourceLine" id="cb2-47" data-line-number="47"><span class="co"># 48.0 10</span></a>
<a class="sourceLine" id="cb2-48" data-line-number="48"><span class="co"># 42.0 10</span></a></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-5-1.png" width="562.5"></p>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. 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_ISLN</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 &lt;-<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>
<a class="sourceLine" id="cb3-2" data-line-number="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"THEISL"</span>),</a>
<a class="sourceLine" id="cb3-3" data-line-number="3"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"T. islandicus"</span>),</a>
<a class="sourceLine" id="cb3-4" data-line-number="4"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"T. islandicus"</span>),</a>
<a class="sourceLine" id="cb3-5" data-line-number="5"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Thermus islandicus"</span>),</a>
<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>Methanosarcina semesiae</em> (<code>B_MTHNSR_SEMS</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">M.semesiae &lt;-<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">"metsem"</span>),</a>
<a class="sourceLine" id="cb3-2" data-line-number="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"METSEM"</span>),</a>
<a class="sourceLine" id="cb3-3" data-line-number="3"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"M. semesiae"</span>),</a>
<a class="sourceLine" id="cb3-4" data-line-number="4"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"M. semesiae"</span>),</a>
<a class="sourceLine" id="cb3-5" data-line-number="5"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Methanosarcina semesiae"</span>),</a>
<a class="sourceLine" id="cb3-6" data-line-number="6"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<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-7" data-line-number="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(M.semesiae, <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="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") 1300 1500 1500 1500 1500 1600 10</span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("THEISL") 1400 1500 1500 1500 1500 1600 10</span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("T. islandicus") 410 410 430 410 450 500 10</span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("T. islandicus") 410 420 430 420 440 440 10</span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Thermus islandicus") 30 30 31 31 32 35 10</span></a></code></pre></div>
<p>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 <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 uncommon):</p>
<pre><code># 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.</code></pre>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-6-1.png" width="562.5"></p>
<a class="sourceLine" id="cb3-9" data-line-number="9"><span class="co"># expr min lq mean median uq</span></a>
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># as.mo("metsem") 1201.00 1327.00 1331.00 1340.00 1359.00</span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># as.mo("METSEM") 1255.00 1298.00 1333.00 1340.00 1363.00</span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># as.mo("M. semesiae") 1927.00 1943.00 1985.00 1995.00 2014.00</span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># as.mo("M. semesiae") 1914.00 1953.00 1979.00 1977.00 1987.00</span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># as.mo("Methanosarcina semesiae") 27.84 30.71 31.59 31.12 31.44</span></a>
<a class="sourceLine" id="cb3-15" data-line-number="15"><span class="co"># max neval</span></a>
<a class="sourceLine" id="cb3-16" data-line-number="16"><span class="co"># 1371.00 10</span></a>
<a class="sourceLine" id="cb3-17" data-line-number="17"><span class="co"># 1398.00 10</span></a>
<a class="sourceLine" id="cb3-18" data-line-number="18"><span class="co"># 2040.00 10</span></a>
<a class="sourceLine" id="cb3-19" data-line-number="19"><span class="co"># 2058.00 10</span></a>
<a class="sourceLine" id="cb3-20" data-line-number="20"><span class="co"># 39.75 10</span></a></code></pre></div>
<p>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 <em>Methanosarcina semesiae</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>Methanosarcina semesiae</em> (which is uncommon):</p>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-9-1.png" width="562.5"></p>
<p>In reality, the <code><a href="../reference/as.mo.html">as.mo()</a></code> functions <strong>learns from its own output to speed up determinations for next times</strong>. In above figure, this effect was disabled to show the difference with the boxplot below - when you would use <code><a href="../reference/as.mo.html">as.mo()</a></code> yourself:</p>
<pre><code># 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.</code></pre>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-7-1.png" width="562.5"></p>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-11-1.png" width="562.5"></p>
<p>The highest outliers are the first times. All next determinations were done in only thousands of seconds.</p>
<p>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: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<div id="repetitive-results" class="section level3">
<h3 class="hasAnchor">
<a href="#repetitive-results" class="anchor"></a>Repetitive results</h3>
<p>Repetitive results are unique values that are present more than once. Unique values will only be calculated once by <code><a href="../reference/as.mo.html">as.mo()</a></code>. We will use <code><a href="../reference/mo_property.html">mo_name()</a></code> for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses <code><a href="../reference/as.mo.html">as.mo()</a></code> internally.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)</a>
<a class="sourceLine" id="cb6-2" data-line-number="2"><span class="co"># take all MO codes from the example_isolates data set</span></a>
<a class="sourceLine" id="cb6-3" data-line-number="3">x &lt;-<span class="st"> </span>example_isolates<span class="op">$</span>mo <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="st"> </span><span class="co"># keep only the unique ones</span></a>
<a class="sourceLine" id="cb6-5" data-line-number="5"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/unique">unique</a></span>() <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-6" data-line-number="6"><span class="st"> </span><span class="co"># pick 50 of them at random</span></a>
<a class="sourceLine" id="cb6-7" data-line-number="7"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(<span class="dv">50</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-8" data-line-number="8"><span class="st"> </span><span class="co"># paste that 10,000 times</span></a>
<a class="sourceLine" id="cb6-9" data-line-number="9"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">10000</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb6-10" data-line-number="10"><span class="st"> </span><span class="co"># scramble it</span></a>
<a class="sourceLine" id="cb6-11" data-line-number="11"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>()</a>
<a class="sourceLine" id="cb6-12" data-line-number="12"> </a>
<a class="sourceLine" id="cb6-13" data-line-number="13"><span class="co"># got indeed 50 times 10,000 = half a million?</span></a>
<a class="sourceLine" id="cb6-14" data-line-number="14"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/length">length</a></span>(x)</a>
<a class="sourceLine" id="cb6-15" data-line-number="15"><span class="co"># [1] 500000</span></a>
<a class="sourceLine" id="cb6-16" data-line-number="16"></a>
<a class="sourceLine" id="cb6-17" data-line-number="17"><span class="co"># and how many unique values do we have?</span></a>
<a class="sourceLine" id="cb6-18" data-line-number="18"><span class="kw"><a href="https://dplyr.tidyverse.org/reference/n_distinct.html">n_distinct</a></span>(x)</a>
<a class="sourceLine" id="cb6-19" data-line-number="19"><span class="co"># [1] 50</span></a>
<a class="sourceLine" id="cb6-20" data-line-number="20"></a>
<a class="sourceLine" id="cb6-21" data-line-number="21"><span class="co"># now let's see:</span></a>
<a class="sourceLine" id="cb6-22" data-line-number="22">run_it &lt;-<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/mo_property.html">mo_name</a></span>(x),</a>
<a class="sourceLine" id="cb6-23" data-line-number="23"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb6-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="cb6-25" data-line-number="25"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-26" data-line-number="26"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-27" data-line-number="27"><span class="co"># mo_name(x) 604 632 655 644 660 764 10</span></a></code></pre></div>
<p>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.</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/base/topics/library">library</a></span>(dplyr)</a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="co"># take all MO codes from the example_isolates data set</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3">x &lt;-<span class="st"> </span>example_isolates<span class="op">$</span>mo <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="st"> </span><span class="co"># keep only the unique ones</span></a>
<a class="sourceLine" id="cb4-5" data-line-number="5"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/unique">unique</a></span>() <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-6" data-line-number="6"><span class="st"> </span><span class="co"># pick 50 of them at random</span></a>
<a class="sourceLine" id="cb4-7" data-line-number="7"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(<span class="dv">50</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-8" data-line-number="8"><span class="st"> </span><span class="co"># paste that 10,000 times</span></a>
<a class="sourceLine" id="cb4-9" data-line-number="9"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">10000</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-10" data-line-number="10"><span class="st"> </span><span class="co"># scramble it</span></a>
<a class="sourceLine" id="cb4-11" data-line-number="11"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>()</a>
<a class="sourceLine" id="cb4-12" data-line-number="12"> </a>
<a class="sourceLine" id="cb4-13" data-line-number="13"><span class="co"># got indeed 50 times 10,000 = half a million?</span></a>
<a class="sourceLine" id="cb4-14" data-line-number="14"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/length">length</a></span>(x)</a>
<a class="sourceLine" id="cb4-15" data-line-number="15"><span class="co"># [1] 500000</span></a>
<a class="sourceLine" id="cb4-16" data-line-number="16"></a>
<a class="sourceLine" id="cb4-17" data-line-number="17"><span class="co"># and how many unique values do we have?</span></a>
<a class="sourceLine" id="cb4-18" data-line-number="18"><span class="kw"><a href="https://dplyr.tidyverse.org/reference/n_distinct.html">n_distinct</a></span>(x)</a>
<a class="sourceLine" id="cb4-19" data-line-number="19"><span class="co"># [1] 50</span></a>
<a class="sourceLine" id="cb4-20" data-line-number="20"></a>
<a class="sourceLine" id="cb4-21" data-line-number="21"><span class="co"># now let's see:</span></a>
<a class="sourceLine" id="cb4-22" data-line-number="22">run_it &lt;-<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/mo_property.html">mo_name</a></span>(x),</a>
<a class="sourceLine" id="cb4-23" data-line-number="23"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb4-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="cb4-25" data-line-number="25"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb4-26" data-line-number="26"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb4-27" data-line-number="27"><span class="co"># mo_name(x) 610 637 653 652 668 718 10</span></a></code></pre></div>
<p>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.</p>
</div>
<div id="precalculated-results" class="section level3">
<h3 class="hasAnchor">
<a href="#precalculated-results" class="anchor"></a>Precalculated results</h3>
<p>What about precalculated results? If the input is an already precalculated result of a helper function like <code><a href="../reference/mo_property.html">mo_name()</a></code>, it almost doesnt take any time at all (see C below):</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 &lt;-<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_name</a></span>(<span class="st">"B_STPHY_AURS"</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_name</a></span>(<span class="st">"S. aureus"</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>
<a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb7-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="cb7-6" data-line-number="6"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-8" data-line-number="8"><span class="co"># A 6.190 6.270 6.560 6.290 7.160 7.280 10</span></a>
<a class="sourceLine" id="cb7-9" data-line-number="9"><span class="co"># B 22.600 23.100 26.700 23.400 24.300 51.600 10</span></a>
<a class="sourceLine" id="cb7-10" data-line-number="10"><span class="co"># C 0.704 0.765 0.827 0.829 0.906 0.913 10</span></a></code></pre></div>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1">run_it &lt;-<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_name</a></span>(<span class="st">"B_STPHY_AURS"</span>),</a>
<a class="sourceLine" id="cb5-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb5-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>
<a class="sourceLine" id="cb5-4" data-line-number="4"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb5-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="cb5-6" data-line-number="6"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb5-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="co"># A 6.280 6.560 9.940 6.720 6.860 39.30 10</span></a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="co"># B 22.500 22.900 24.300 23.000 24.900 30.90 10</span></a>
<a class="sourceLine" id="cb5-10" data-line-number="10"><span class="co"># C 0.805 0.829 0.871 0.847 0.869 1.09 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 doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">run_it &lt;-<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="cb8-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="cb8-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>
<a class="sourceLine" id="cb8-4" data-line-number="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="st">"Staphylococcaceae"</span>),</a>
<a class="sourceLine" id="cb8-5" data-line-number="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="st">"Bacillales"</span>),</a>
<a class="sourceLine" id="cb8-6" data-line-number="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/mo_property.html">mo_class</a></span>(<span class="st">"Bacilli"</span>),</a>
<a class="sourceLine" id="cb8-7" data-line-number="7"> <span class="dt">G =</span> <span class="kw"><a href="../reference/mo_property.html">mo_phylum</a></span>(<span class="st">"Firmicutes"</span>),</a>
<a class="sourceLine" id="cb8-8" data-line-number="8"> <span class="dt">H =</span> <span class="kw"><a href="../reference/mo_property.html">mo_kingdom</a></span>(<span class="st">"Bacteria"</span>),</a>
<a class="sourceLine" id="cb8-9" data-line-number="9"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb8-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="cb8-11" data-line-number="11"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb8-12" data-line-number="12"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb8-13" data-line-number="13"><span class="co"># A 0.456 0.476 0.484 0.483 0.488 0.516 10</span></a>
<a class="sourceLine" id="cb8-14" data-line-number="14"><span class="co"># B 0.613 0.620 0.639 0.628 0.642 0.723 10</span></a>
<a class="sourceLine" id="cb8-15" data-line-number="15"><span class="co"># C 0.675 0.700 0.763 0.796 0.807 0.816 10</span></a>
<a class="sourceLine" id="cb8-16" data-line-number="16"><span class="co"># D 0.443 0.454 0.466 0.467 0.477 0.497 10</span></a>
<a class="sourceLine" id="cb8-17" data-line-number="17"><span class="co"># E 0.453 0.459 0.465 0.464 0.472 0.483 10</span></a>
<a class="sourceLine" id="cb8-18" data-line-number="18"><span class="co"># F 0.433 0.447 0.464 0.463 0.484 0.498 10</span></a>
<a class="sourceLine" id="cb8-19" data-line-number="19"><span class="co"># G 0.453 0.460 0.469 0.464 0.478 0.502 10</span></a>
<a class="sourceLine" id="cb8-20" data-line-number="20"><span class="co"># H 0.433 0.451 0.477 0.459 0.470 0.662 10</span></a></code></pre></div>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1">run_it &lt;-<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="cb6-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="cb6-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>
<a class="sourceLine" id="cb6-4" data-line-number="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="st">"Staphylococcaceae"</span>),</a>
<a class="sourceLine" id="cb6-5" data-line-number="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="st">"Bacillales"</span>),</a>
<a class="sourceLine" id="cb6-6" data-line-number="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/mo_property.html">mo_class</a></span>(<span class="st">"Bacilli"</span>),</a>
<a class="sourceLine" id="cb6-7" data-line-number="7"> <span class="dt">G =</span> <span class="kw"><a href="../reference/mo_property.html">mo_phylum</a></span>(<span class="st">"Firmicutes"</span>),</a>
<a class="sourceLine" id="cb6-8" data-line-number="8"> <span class="dt">H =</span> <span class="kw"><a href="../reference/mo_property.html">mo_kingdom</a></span>(<span class="st">"Bacteria"</span>),</a>
<a class="sourceLine" id="cb6-9" data-line-number="9"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb6-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="cb6-11" data-line-number="11"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-12" data-line-number="12"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-13" data-line-number="13"><span class="co"># A 0.456 0.457 0.472 0.465 0.493 0.498 10</span></a>
<a class="sourceLine" id="cb6-14" data-line-number="14"><span class="co"># B 0.629 0.640 0.713 0.668 0.752 0.956 10</span></a>
<a class="sourceLine" id="cb6-15" data-line-number="15"><span class="co"># C 0.798 0.811 0.840 0.832 0.840 0.965 10</span></a>
<a class="sourceLine" id="cb6-16" data-line-number="16"><span class="co"># D 0.428 0.453 0.473 0.464 0.503 0.518 10</span></a>
<a class="sourceLine" id="cb6-17" data-line-number="17"><span class="co"># E 0.446 0.477 0.513 0.495 0.525 0.648 10</span></a>
<a class="sourceLine" id="cb6-18" data-line-number="18"><span class="co"># F 0.466 0.473 0.496 0.484 0.521 0.545 10</span></a>
<a class="sourceLine" id="cb6-19" data-line-number="19"><span class="co"># G 0.457 0.461 0.477 0.468 0.486 0.545 10</span></a>
<a class="sourceLine" id="cb6-20" data-line-number="20"><span class="co"># H 0.456 0.467 0.478 0.477 0.482 0.512 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">
<h3 class="hasAnchor">
<a href="#results-in-other-languages" class="anchor"></a>Results in other languages</h3>
<p>When the system language is non-English and supported by this <code>AMR</code> package, some functions will have a translated result. This almost doest take extra time:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>) <span class="co"># or just mo_name("CoNS") on an English system</span></a>
<a class="sourceLine" id="cb9-2" data-line-number="2"><span class="co"># [1] "Coagulase-negative Staphylococcus (CoNS)"</span></a>
<a class="sourceLine" id="cb9-3" data-line-number="3"></a>
<a class="sourceLine" id="cb9-4" data-line-number="4"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"es"</span>) <span class="co"># or just mo_name("CoNS") on a Spanish system</span></a>
<a class="sourceLine" id="cb9-5" data-line-number="5"><span class="co"># [1] "Staphylococcus coagulasa negativo (SCN)"</span></a>
<a class="sourceLine" id="cb9-6" data-line-number="6"></a>
<a class="sourceLine" id="cb9-7" data-line-number="7"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"nl"</span>) <span class="co"># or just mo_name("CoNS") on a Dutch system</span></a>
<a class="sourceLine" id="cb9-8" data-line-number="8"><span class="co"># [1] "Coagulase-negatieve Staphylococcus (CNS)"</span></a>
<a class="sourceLine" id="cb9-9" data-line-number="9"></a>
<a class="sourceLine" id="cb9-10" data-line-number="10">run_it &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">en =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>),</a>
<a class="sourceLine" id="cb9-11" data-line-number="11"> <span class="dt">de =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"de"</span>),</a>
<a class="sourceLine" id="cb9-12" data-line-number="12"> <span class="dt">nl =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"nl"</span>),</a>
<a class="sourceLine" id="cb9-13" data-line-number="13"> <span class="dt">es =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"es"</span>),</a>
<a class="sourceLine" id="cb9-14" data-line-number="14"> <span class="dt">it =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"it"</span>),</a>
<a class="sourceLine" id="cb9-15" data-line-number="15"> <span class="dt">fr =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"fr"</span>),</a>
<a class="sourceLine" id="cb9-16" data-line-number="16"> <span class="dt">pt =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"pt"</span>),</a>
<a class="sourceLine" id="cb9-17" data-line-number="17"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb9-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="cb9-19" data-line-number="19"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb9-20" data-line-number="20"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb9-21" data-line-number="21"><span class="co"># en 18.18 18.24 18.54 18.44 18.58 19.41 10</span></a>
<a class="sourceLine" id="cb9-22" data-line-number="22"><span class="co"># de 19.52 19.79 20.03 19.90 20.15 20.95 10</span></a>
<a class="sourceLine" id="cb9-23" data-line-number="23"><span class="co"># nl 24.54 24.94 26.29 25.70 26.35 31.90 10</span></a>
<a class="sourceLine" id="cb9-24" data-line-number="24"><span class="co"># es 19.52 19.69 22.29 19.86 20.27 44.03 10</span></a>
<a class="sourceLine" id="cb9-25" data-line-number="25"><span class="co"># it 19.52 19.57 22.05 19.74 20.46 41.43 10</span></a>
<a class="sourceLine" id="cb9-26" data-line-number="26"><span class="co"># fr 19.61 19.67 22.28 20.04 20.30 42.90 10</span></a>
<a class="sourceLine" id="cb9-27" data-line-number="27"><span class="co"># pt 19.51 19.79 25.16 20.01 20.73 49.48 10</span></a></code></pre></div>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>) <span class="co"># or just mo_name("CoNS") on an English system</span></a>
<a class="sourceLine" id="cb7-2" data-line-number="2"><span class="co"># [1] "Coagulase-negative Staphylococcus (CoNS)"</span></a>
<a class="sourceLine" id="cb7-3" data-line-number="3"></a>
<a class="sourceLine" id="cb7-4" data-line-number="4"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"es"</span>) <span class="co"># or just mo_name("CoNS") on a Spanish system</span></a>
<a class="sourceLine" id="cb7-5" data-line-number="5"><span class="co"># [1] "Staphylococcus coagulasa negativo (SCN)"</span></a>
<a class="sourceLine" id="cb7-6" data-line-number="6"></a>
<a class="sourceLine" id="cb7-7" data-line-number="7"><span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"nl"</span>) <span class="co"># or just mo_name("CoNS") on a Dutch system</span></a>
<a class="sourceLine" id="cb7-8" data-line-number="8"><span class="co"># [1] "Coagulase-negatieve Staphylococcus (CNS)"</span></a>
<a class="sourceLine" id="cb7-9" data-line-number="9"></a>
<a class="sourceLine" id="cb7-10" data-line-number="10">run_it &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">en =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>),</a>
<a class="sourceLine" id="cb7-11" data-line-number="11"> <span class="dt">de =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"de"</span>),</a>
<a class="sourceLine" id="cb7-12" data-line-number="12"> <span class="dt">nl =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"nl"</span>),</a>
<a class="sourceLine" id="cb7-13" data-line-number="13"> <span class="dt">es =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"es"</span>),</a>
<a class="sourceLine" id="cb7-14" data-line-number="14"> <span class="dt">it =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"it"</span>),</a>
<a class="sourceLine" id="cb7-15" data-line-number="15"> <span class="dt">fr =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"fr"</span>),</a>
<a class="sourceLine" id="cb7-16" data-line-number="16"> <span class="dt">pt =</span> <span class="kw"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"pt"</span>),</a>
<a class="sourceLine" id="cb7-17" data-line-number="17"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb7-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="cb7-19" data-line-number="19"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-20" data-line-number="20"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-21" data-line-number="21"><span class="co"># en 18.04 18.47 18.79 18.54 19.25 19.70 10</span></a>
<a class="sourceLine" id="cb7-22" data-line-number="22"><span class="co"># de 19.36 19.88 22.78 20.17 20.39 47.73 10</span></a>
<a class="sourceLine" id="cb7-23" data-line-number="23"><span class="co"># nl 24.57 25.38 28.46 25.63 26.12 54.82 10</span></a>
<a class="sourceLine" id="cb7-24" data-line-number="24"><span class="co"># es 19.50 19.89 25.49 20.51 25.79 44.96 10</span></a>
<a class="sourceLine" id="cb7-25" data-line-number="25"><span class="co"># it 19.52 19.82 20.44 20.11 20.80 23.09 10</span></a>
<a class="sourceLine" id="cb7-26" data-line-number="26"><span class="co"># fr 19.50 19.79 20.42 19.86 20.53 23.35 10</span></a>
<a class="sourceLine" id="cb7-27" data-line-number="27"><span class="co"># pt 19.25 19.55 22.50 19.59 20.04 47.50 10</span></a></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>
@ -225,9 +225,9 @@
</div>
<div id="amr-0-7-1-9076" class="section level1">
<div id="amr-0-7-1-9077" class="section level1">
<h1 class="page-header">
<a href="#amr-0-7-1-9076" class="anchor"></a>AMR 0.7.1.9076<small> Unreleased </small>
<a href="#amr-0-7-1-9077" class="anchor"></a>AMR 0.7.1.9077<small> Unreleased </small>
</h1>
<p><small>Last updated: 20-Sep-2019</small></p>
<div id="breaking" class="section level3">
@ -1267,7 +1267,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-9076">0.7.1.9076</a></li>
<li><a href="#amr-0-7-1-9077">0.7.1.9077</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>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>
@ -309,7 +309,7 @@ The <code>as.mo()</code> 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:</p><ul>
<li><p>Valid MO codes and full names: it first searches in already valid MO code and known genus/species combinations</p></li>
<li><p>Human pathogenic prevalence: it first searches in more prevalent microorganisms, then less prevalent ones (see <em>Microbial prevalence of pathogens in humans</em> below)</p></li>
<li><p>Taxonomic kingdom: it first searches in Bacteria/Chromista, then Fungi, then Protozoa</p></li>
<li><p>Taxonomic kingdom: it first searches in Bacteria, then Fungi, then Protozoa, then Archaea, then others</p></li>
<li><p>Breakdown of input values: from here it starts to breakdown input values to find possible matches</p></li>
</ul>
<p>A couple of effects because of these rules:</p><ul>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>

View File

@ -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.9076</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9077</span>
</span>
</div>
@ -238,11 +238,12 @@
<h2 class="hasAnchor" id="format"><a class="anchor" href="#format"></a>Format</h2>
<p>A <code><a href='https://www.rdocumentation.org/packages/base/topics/data.frame'>data.frame</a></code> with 24,246 observations and 4 variables:</p><dl class='dl-horizontal'>
<p>A <code><a href='https://www.rdocumentation.org/packages/base/topics/data.frame'>data.frame</a></code> with 24,246 observations and 5 variables:</p><dl class='dl-horizontal'>
<dt><code>col_id</code></dt><dd><p>Catalogue of Life ID that was originally given</p></dd>
<dt><code>col_id_new</code></dt><dd><p>New Catalogue of Life ID that responds to an entry in the <code><a href='microorganisms.html'>microorganisms</a></code> data set</p></dd>
<dt><code>fullname</code></dt><dd><p>Old full taxonomic name of the microorganism</p></dd>
<dt><code>ref</code></dt><dd><p>Author(s) and year of concerning scientific publication</p></dd>
<dt><code>prevalence</code></dt><dd><p>Prevalence of the microorganism, see <code><a href='as.mo.html'>?as.mo</a></code></p></dd>
</dl>
<h2 class="hasAnchor" id="source"><a class="anchor" href="#source"></a>Source</h2>

View File

@ -1 +1,8 @@
"","x","mo","uncertainty_level","package_v"
"x","mo","uncertainty_level","package_version"
"M. SEMESIAE","B_MTHNSR_SEMS",0,"0.7.1.9077"
"METSEM","B_MTHNSR_SEMS",0,"0.7.1.9077"
"METHANOSARCINA SEMESIAE","B_MTHNSR_SEMS",0,"0.7.1.9077"
"PREVOTELLA BREVIS","B_PRVTL_BRVS",0,"0.7.1.9077"
"P. BREVIS","B_PRVTL_BRVS",0,"0.7.1.9077"
"E. COLI","B_ESCHR_COLI",0,"0.7.1.9077"
"ESCHERICHIA COLI","B_ESCHR_COLI",0,"0.7.1.9077"

1 x mo uncertainty_level package_version package_v
2 M. SEMESIAE B_MTHNSR_SEMS 0 0.7.1.9077
3 METSEM B_MTHNSR_SEMS 0 0.7.1.9077
4 METHANOSARCINA SEMESIAE B_MTHNSR_SEMS 0 0.7.1.9077
5 PREVOTELLA BREVIS B_PRVTL_BRVS 0 0.7.1.9077
6 P. BREVIS B_PRVTL_BRVS 0 0.7.1.9077
7 E. COLI B_ESCHR_COLI 0 0.7.1.9077
8 ESCHERICHIA COLI B_ESCHR_COLI 0 0.7.1.9077

View File

@ -81,10 +81,11 @@ This function uses intelligent rules to help getting fast and logical results. I
\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{
\item{\code{"E. coli"} will return the ID of \emph{Escherichia coli} and not \emph{Entamoeba coli}, although the latter would alphabetically come first}

View File

@ -4,12 +4,13 @@
\name{microorganisms.old}
\alias{microorganisms.old}
\title{Data set with previously accepted taxonomic names}
\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}()}).

View File

@ -64,10 +64,13 @@ library(microbenchmark)
library(AMR)
```
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:
```{r, echo = FALSE}
clear_mo_history()
```
```{r, warning=FALSE}
S.aureus <- microbenchmark(
as.mo("sau"), # WHONET code
@ -93,68 +96,61 @@ ggplot.bm(S.aureus)
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:
```{r, warning=FALSE}
T.islandicus <- microbenchmark(as.mo("theisl"),
as.mo("THEISL"),
as.mo("T. islandicus"),
as.mo("T. islandicus"),
as.mo("Thermus islandicus"),
times = 10)
print(T.islandicus, unit = "ms", signif = 2)
```
That takes `r round(mean(T.islandicus$time, na.rm = TRUE) / mean(S.aureus$time, na.rm = TRUE), 1)` 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):
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:
```{r, echo = FALSE}
# ggplot.bm(
# microbenchmark(as.mo("Escherichia coli"),
# as.mo("E. coli"),
# times = 10), title = "Very common")
#
# ggplot.bm(
# microbenchmark(as.mo("Prevotella brevis"),
# as.mo("P. brevis"),
# times = 10), title = "Moderately common")
#
# ggplot.bm(
# microbenchmark(as.mo("Thermus islandicus"),
# as.mo("T. islandicus"),
# times = 10), title = "Uncommon")
clear_mo_history()
```
```{r, warning=FALSE}
M.semesiae <- microbenchmark(as.mo("metsem"),
as.mo("METSEM"),
as.mo("M. semesiae"),
as.mo("M. semesiae"),
as.mo("Methanosarcina semesiae"),
times = 10)
print(M.semesiae, unit = "ms", signif = 4)
```
That takes `r round(mean(M.semesiae$time, na.rm = TRUE) / mean(S.aureus$time, na.rm = TRUE), 1)` 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):
```{r, echo = FALSE}
clear_mo_history()
```
```{r, echo = FALSE}
par(mar = c(5, 16, 4, 2))
boxplot(microbenchmark(
'as.mo("Thermus islandicus")' = as.mo("Thermus islandicus"),
'as.mo("Methanosarcina semesiae")' = as.mo("Methanosarcina semesiae"),
'as.mo("Prevotella brevis")' = as.mo("Prevotella brevis"),
'as.mo("Escherichia coli")' = as.mo("Escherichia coli"),
'as.mo("T. islandicus")' = as.mo("T. islandicus"),
'as.mo("M. semesiae")' = as.mo("M. semesiae"),
'as.mo("P. brevis")' = as.mo("P. brevis"),
'as.mo("E. coli")' = as.mo("E. coli"),
times = 10),
horizontal = TRUE, las = 1, unit = "s", log = FALSE,
xlab = "", ylab = "Time in seconds", ylim = c(0, 0.5),
horizontal = TRUE, las = 1, unit = "s", log = TRUE,
xlab = "", ylab = "Time in seconds (log)",
main = "Benchmarks per prevalence")
```
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:
```{r, echo = FALSE}
clear_mo_history()
```
```{r, echo = FALSE}
par(mar = c(5, 16, 4, 2))
boxplot(microbenchmark(
'as.mo("Thermus islandicus")' = as.mo("Thermus islandicus", force_mo_history = TRUE),
'as.mo("Methanosarcina semesiae")' = as.mo("Methanosarcina semesiae", force_mo_history = TRUE),
'as.mo("Prevotella brevis")' = as.mo("Prevotella brevis", force_mo_history = TRUE),
'as.mo("Escherichia coli")' = as.mo("Escherichia coli", force_mo_history = TRUE),
'as.mo("T. islandicus")' = as.mo("T. islandicus", force_mo_history = TRUE),
'as.mo("M. semesiae")' = as.mo("M. semesiae", force_mo_history = TRUE),
'as.mo("P. brevis")' = as.mo("P. brevis", force_mo_history = TRUE),
'as.mo("E. coli")' = as.mo("E. coli", force_mo_history = TRUE),
times = 10),
horizontal = TRUE, las = 1, unit = "s", log = FALSE,
xlab = "", ylab = "Time in seconds", ylim = c(0, 0.5),
xlab = "", ylab = "Time in seconds",
main = "Benchmarks per prevalence")
```
@ -197,6 +193,9 @@ So transforming 500,000 values (!!) of `r n_distinct(x)` unique values only take
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):
```{r, echo = FALSE}
clear_mo_history()
```
```{r}
run_it <- microbenchmark(A = mo_name("B_STPHY_AURS"),
B = mo_name("S. aureus"),
@ -207,6 +206,9 @@ print(run_it, unit = "ms", signif = 3)
So going from `mo_name("Staphylococcus aureus")` to `"Staphylococcus aureus"` takes `r format(round(run_it %>% filter(expr == "C") %>% pull(time) %>% median() / 1e9, 4), scientific = FALSE)` 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:
```{r, echo = FALSE}
clear_mo_history()
```
```{r}
run_it <- microbenchmark(A = mo_species("aureus"),
B = mo_genus("Staphylococcus"),
@ -226,6 +228,9 @@ Of course, when running `mo_phylum("Firmicutes")` the function has zero knowledg
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:
```{r, echo = FALSE}
clear_mo_history()
```
```{r}
mo_name("CoNS", language = "en") # or just mo_name("CoNS") on an English system