* Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package.
message_("Matching scores are based on human pathogenic prevalence and the resemblance between the input and the full taxonomic name. See ?mo_matching_score.",as_note=FALSE)
message_("Matching scores are based on human pathogenic prevalence and the resemblance between the input and the full taxonomic name. See `?mo_matching_score`.",as_note=FALSE)
<spanclass="version label label-default"data-toggle="tooltip"data-placement="bottom"title="Latest development version">1.5.0.9023</span>
<spanclass="version label label-default"data-toggle="tooltip"data-placement="bottom"title="Latest development version">1.5.0.9024</span>
</span>
</div>
@ -200,17 +200,17 @@
<p>One of the most important features of this package is the complete microbial taxonomic database, supplied by the <ahref="http://catalogueoflife.org">Catalogue of Life</a>. We created a function <code><ahref="../reference/as.mo.html">as.mo()</a></code> that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.</p>
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code>microbenchmark()</code> runs different input expressions independently of each other and measures their time-to-result.</p>
<p>One of the most important features of this package is the complete microbial taxonomic database, supplied by the <ahref="http://www.catalogueoflife.org">Catalogue of Life</a> (CoL) and the <ahref="https://lpsn.dsmz.de">List of Prokaryotic names with Standing in Nomenclature</a> (LPSN). We created a function <code><ahref="../reference/as.mo.html">as.mo()</a></code> that transforms any user input value to a valid microbial ID by using intelligent rules combined with the microbial taxonomy.</p>
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><ahref="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html">microbenchmark()</a></code> runs different input expressions independently of each other and measures their time-to-result.</p>
<p>In the next test, we try to ‘coerce’ different input values into the microbial code of <em>Staphylococcus aureus</em>. Coercion is a computational process of forcing output based on an input. For microorganism names, coercing user input to taxonomically valid microorganism names is crucial to ensure correct interpretation and to enable grouping based on taxonomic properties.</p>
<p>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>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>, its taxonomic kingdom).</p>
<spanclass="fu"><ahref="../reference/as.mo.html">as.mo</a></span><spanclass="op">(</span><spanclass="st">"MRSA"</span><spanclass="op">)</span>, <spanclass="co"># Methicillin Resistant S. aureus</span>
<spanclass="fu"><ahref="../reference/as.mo.html">as.mo</a></span><spanclass="op">(</span><spanclass="st">"VISA"</span><spanclass="op">)</span>, <spanclass="co"># Vancomycin Intermediate S. aureus</span>
<spanclass="fu"><ahref="../reference/as.mo.html">as.mo</a></span><spanclass="op">(</span><spanclass="st">"VRSA"</span><spanclass="op">)</span>, <spanclass="co"># Vancomycin Resistant S. aureus</span>
times <spanclass="op">=</span><spanclass="fl">10</span><spanclass="op">)</span>
times <spanclass="op">=</span><spanclass="fl">25</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html">print</a></span><spanclass="op">(</span><spanclass="va">S.aureus</span>, unit <spanclass="op">=</span><spanclass="st">"ms"</span>, signif <spanclass="op">=</span><spanclass="fl">2</span><spanclass="op">)</span>
<spanclass="co"># Unit: milliseconds</span>
<spanclass="co"># expr min lq mean median uq max neval</span>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations can take up to 500-1000 times as much time.</p>
<p>To improve performance, two important calculations take almost no time at all: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<spanclass="co"># expr min lq mean median uq max neval</span>
<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 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 200 times slower to determine.</p>
<p>To improve performance, we implemented two important algorithms to save unnecessary calculations: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<p>Repetitive results are unique values that are present more than once. Unique values will only be calculated once by <code><ahref="../reference/as.mo.html">as.mo()</a></code>. We will use <code><ahref="../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><ahref="../reference/as.mo.html">as.mo()</a></code> internally.</p>
<p>Repetitive results are values that are present more than once in a vector. Unique values will only be calculated once by <code><ahref="../reference/as.mo.html">as.mo()</a></code>. So running <code><ahref="../reference/as.mo.html">as.mo(c("E. coli", "E. coli"))</a></code> will check the value <code>"E. coli"</code> only once.</p>
<p>To prove this, we will use <code><ahref="../reference/mo_property.html">mo_name()</a></code> for testing - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses <code><ahref="../reference/as.mo.html">as.mo()</a></code> internally.</p>
times <spanclass="op">=</span><spanclass="fl">10</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html">print</a></span><spanclass="op">(</span><spanclass="va">run_it</span>, unit <spanclass="op">=</span><spanclass="st">"ms"</span>, signif <spanclass="op">=</span><spanclass="fl">3</span><spanclass="op">)</span>
<spanclass="co"># Unit: milliseconds</span>
<spanclass="co"># expr min lq mean median uq max neval</span>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.172 seconds. You only lose time on your unique input values.</p>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.206 seconds. That is 2.471 milliseconds per unique item on average. You only lose time on your unique input values.</p>
<p>What about precalculated results? If the input is an already precalculated result of a helper function like<code><ahref="../reference/mo_property.html">mo_name()</a></code>, it almost doesn’t take any time at all (see ‘C’ below):</p>
<p>What about precalculated results? If the input is an already precalculated result of a helper function such as<code><ahref="../reference/mo_property.html">mo_name()</a></code>, it almost doesn’t take any time at all. In other words, if you run <code><ahref="../reference/mo_property.html">mo_name()</a></code> on a valid taxonomic name, it will return the results immediately (see ‘C’ below):</p>
B <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"S. aureus"</span><spanclass="op">)</span>,
C <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"Staphylococcus aureus"</span><spanclass="op">)</span>,
times <spanclass="op">=</span><spanclass="fl">10</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html">print</a></span><spanclass="op">(</span><spanclass="va">run_it</span>, unit <spanclass="op">=</span><spanclass="st">"ms"</span>, signif <spanclass="op">=</span><spanclass="fl">3</span><spanclass="op">)</span>
<spanclass="co"># Unit: milliseconds</span>
<spanclass="co"># expr min lq mean median uq max neval</span>
<spanclass="co"># A 7.12 7.56 7.89 7.7 8.39 8.69 10</span>
<spanclass="co"># B 23.90 24.50 35.10 24.8 27.40 77.50 10</span>
<spanclass="co"># C 1.73 1.84 1.95 1.9 2.09 2.36 10</span></code></pre></div>
<p>So going from <code><ahref="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0019 seconds - it doesn’t even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<spanclass="co"># A 6.97 7.10 7.55 7.21 8.18 8.32 10</span>
<spanclass="co"># B 23.70 24.20 36.30 26.30 29.00 89.70 10</span>
<spanclass="co"># C 1.53 1.65 1.80 1.76 2.00 2.19 10</span></code></pre></div>
<p>So going from <code><ahref="../reference/mo_property.html">mo_name("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0018 seconds - it doesn’t even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
B <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_genus</a></span><spanclass="op">(</span><spanclass="st">"Staphylococcus"</span><spanclass="op">)</span>,
C <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"Staphylococcus aureus"</span><spanclass="op">)</span>,
D <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_family</a></span><spanclass="op">(</span><spanclass="st">"Staphylococcaceae"</span><spanclass="op">)</span>,
@ -302,15 +309,15 @@
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html">print</a></span><spanclass="op">(</span><spanclass="va">run_it</span>, unit <spanclass="op">=</span><spanclass="st">"ms"</span>, signif <spanclass="op">=</span><spanclass="fl">3</span><spanclass="op">)</span>
<spanclass="co"># Unit: milliseconds</span>
<spanclass="co"># expr min lq mean median uq max neval</span>
<spanclass="co"># A 1.54 1.57 1.73 1.69 1.88 2.00 10</span>
<spanclass="co"># B 1.51 1.52 1.75 1.70 1.86 2.41 10</span>
<spanclass="co"># C 1.55 1.60 1.70 1.70 1.81 1.86 10</span>
<spanclass="co"># D 1.55 1.59 1.71 1.66 1.83 1.94 10</span>
<spanclass="co"># E 1.50 1.55 1.68 1.61 1.78 2.10 10</span>
<spanclass="co"># F 1.51 1.62 1.75 1.79 1.82 2.02 10</span>
<spanclass="co"># G 1.52 1.53 1.68 1.60 1.80 2.02 10</span>
<spanclass="co"># H 1.53 1.54 1.63 1.60 1.67 1.84 10</span></code></pre></div>
<p>Of course, when running <code><ahref="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.</p>
<spanclass="co"># A 1.44 1.72 1.69 1.74 1.75 1.78 10</span>
<spanclass="co"># B 1.47 1.55 1.67 1.73 1.74 1.89 10</span>
<spanclass="co"># C 1.52 1.59 1.73 1.74 1.89 1.91 10</span>
<spanclass="co"># D 1.46 1.51 1.64 1.64 1.75 1.89 10</span>
<spanclass="co"># E 1.42 1.47 1.60 1.52 1.71 1.97 10</span>
<spanclass="co"># F 1.44 1.71 1.69 1.72 1.75 1.88 10</span>
<spanclass="co"># G 1.42 1.50 1.68 1.61 1.73 2.36 10</span>
<spanclass="co"># H 1.52 1.54 1.66 1.71 1.73 1.87 10</span></code></pre></div>
<p>Of course, when running <code><ahref="../reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.</p>
<spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"nl"</span><spanclass="op">)</span><spanclass="co"># or just mo_name("CoNS") on a Dutch system</span>
<spanclass="va">run_it</span><spanclass="op"><-</span><spanclass="fu">microbenchmark</span><spanclass="op">(</span>en <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"en"</span><spanclass="op">)</span>,
<spanclass="va">run_it</span><spanclass="op"><-</span><spanclass="fu"><ahref="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html">microbenchmark</a></span><spanclass="op">(</span>en <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"en"</span><spanclass="op">)</span>,
de <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"de"</span><spanclass="op">)</span>,
nl <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"nl"</span><spanclass="op">)</span>,
es <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="st">"CoNS"</span>, language <spanclass="op">=</span><spanclass="st">"es"</span><spanclass="op">)</span>,
@ -336,15 +343,15 @@
times <spanclass="op">=</span><spanclass="fl">100</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html">print</a></span><spanclass="op">(</span><spanclass="va">run_it</span>, unit <spanclass="op">=</span><spanclass="st">"ms"</span>, signif <spanclass="op">=</span><spanclass="fl">4</span><spanclass="op">)</span>
<spanclass="co"># Unit: milliseconds</span>
<spanclass="co"># expr min lq mean median uq max neval</span>
<spanclass="co"># en 17.38 17.71 25.63 18.11 19.75 81.61 100</span>
<spanclass="co"># de 20.14 20.61 24.87 20.91 21.57 85.23 100</span>
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://www.catalogueoflife.org) (CoL) and the [List of Prokaryotic names with Standing in Nomenclature](https://lpsn.dsmz.de) (LPSN). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the microbial taxonomy.
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 into the microbial code of *Staphylococcus aureus*. Coercion is a computational process of forcing output based on an input. For microorganism names, coercing user input to taxonomically valid microorganism names is crucial to ensure correct interpretation and to enable grouping based on taxonomic properties.
The actual result is the same every time: it returns its microorganism code ``r as.character(as.mo("Staphylococcus aureus"))`` (*B* stands for *Bacteria*, the taxonomic kingdom).
The actual result is the same every time: it returns its microorganism code ``r as.character(as.mo("Staphylococcus aureus"))`` (*B* stands for *Bacteria*, its taxonomic kingdom).
as.mo("VISA"), # Vancomycin Intermediate S. aureus
as.mo("VRSA"), # Vancomycin Resistant S. aureus
times = 10)
times = 25)
print(S.aureus, unit = "ms", signif = 2)
```
```{r, echo = FALSE}
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. It is clear that accepted taxonomic names are extremely fast, but some variations can take up to 500-1000 times as much time.
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 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 200 times slower to determine.
To improve performance, two important calculations take almost no time at all: **repetitive results** and **already precalculated results**.
To improve performance, we implemented two important algorithms to save unnecessary calculations: **repetitive results** and **already precalculated results**.
### Repetitive 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.
Repetitive results are values that are present more than once in a vector. Unique values will only be calculated once by `as.mo()`. So running `as.mo(c("E. coli", "E. coli"))` will check the value `"E. coli"` only once.
To prove this, we will use `mo_name()` for testing - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses `as.mo()` internally.
```{r, message = FALSE}
# take all MO codes from the example_isolates data set
x <- example_isolates$mo %>%
# start with the example_isolates data set
x <- example_isolates %>%
# take all MO codes from the 'mo' column
pull(mo) %>%
# and copy them a thousand times
rep(1000) %>%
# then scramble them
sample()
# what do these values look like? They are of class <mo>:
head(x)
# as the example_isolates has 2,000 rows, we should have 2 million items
# as the example_isolates data set has 2,000 rows, we should have 2 million items
So getting official taxonomic names of `r format(length(x), big.mark = ",")` (!!) items consisting of `r n_distinct(x)` unique values only takes `r round(median(run_it$time, na.rm = TRUE) / 1e9, 3)` seconds. You only lose time on your unique input values.
So getting official taxonomic names of `r format(length(x), big.mark = ",")` (!!) items consisting of `r n_distinct(x)` unique values only takes `r round(median(run_it$time, na.rm = TRUE) / 1e9, 3)` seconds. That is `r round(mean(run_it$time, na.rm = TRUE) / 1e6 / n_distinct(x), 3)` milliseconds per unique item on average. You only lose time on your unique input values.
### Precalculated results
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):
What about precalculated results? If the input is an already precalculated result of a helper function such as `mo_name()`, it almost doesn't take any time at all. In other words, if you run `mo_name()` on a valid taxonomic name, it will return the results immediately (see 'C' below):
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"` anyway, there is no point in calculating the result. And because this package 'knows' all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.
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"` anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.