<scriptsrc="../bootstrap-toc.js"></script><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous">
<p>One of the most important features of this package is the complete microbial taxonomic database, supplied by the <ahref="http://www.catalogueoflife.org"class="external-link">Catalogue of Life</a> (CoL) and the <ahref="https://lpsn.dsmz.de"class="external-link">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"class="external-link">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>, its taxonomic kingdom).</p>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html"class="external-link">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>
<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 69 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 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>as.mo(c("E. coli", "E. coli"))</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>
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html"class="external-link">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>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.299 seconds. That is 149 nanoseconds 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 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"class="external-link">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"># expr min lq mean median uq max neval</span>
<spanclass="co"># A 11.90 12.10 13.0 13.50 13.70 13.80 10</span>
<spanclass="co"># B 60.90 61.20 67.7 66.20 66.90 99.70 10</span>
<spanclass="co"># C 2.91 2.94 3.2 3.32 3.38 3.46 10</span></code></pre></div>
<p>So going from <code>mo_name("Staphylococcus aureus")</code> to <code>"Staphylococcus aureus"</code> takes 0.0033 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>,
E <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_order</a></span><spanclass="op">(</span><spanclass="st">"Bacillales"</span><spanclass="op">)</span>,
F <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_class</a></span><spanclass="op">(</span><spanclass="st">"Bacilli"</span><spanclass="op">)</span>,
G <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_phylum</a></span><spanclass="op">(</span><spanclass="st">"Firmicutes"</span><spanclass="op">)</span>,
H <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_kingdom</a></span><spanclass="op">(</span><spanclass="st">"Bacteria"</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"class="external-link">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"># A 2.92 2.93 3.02 2.94 3.02 3.40 10</span>
<spanclass="co"># B 2.87 2.90 3.14 3.09 3.32 3.71 10</span>
<spanclass="co"># C 2.91 2.94 3.15 3.12 3.33 3.46 10</span>
<spanclass="co"># D 2.86 2.90 3.05 2.96 3.27 3.30 10</span>
<spanclass="co"># E 2.87 2.88 3.03 2.96 3.16 3.29 10</span>
<spanclass="co"># F 2.92 2.95 3.08 2.98 3.29 3.35 10</span>
<spanclass="co"># G 2.89 2.96 3.04 2.99 3.11 3.29 10</span>
<spanclass="co"># H 2.85 2.95 3.11 3.08 3.31 3.38 10</span></code></pre></div>
<p>Of course, when running <code>mo_phylum("Firmicutes")</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>
<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 does’t take extra time (compare “en” from the table below with the other languages):</p>
<spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"en"</span><spanclass="op">)</span><spanclass="co"># or just mo_name(CoNS) on an English system</span>
<spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"es"</span><spanclass="op">)</span><spanclass="co"># or just mo_name(CoNS) on a Spanish system</span>
<spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">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"><ahref="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html"class="external-link">microbenchmark</a></span><spanclass="op">(</span>da <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"da"</span><spanclass="op">)</span>,
de <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"de"</span><spanclass="op">)</span>,
en <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"en"</span><spanclass="op">)</span>,
es <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"es"</span><spanclass="op">)</span>,
fr <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"fr"</span><spanclass="op">)</span>,
it <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"it"</span><spanclass="op">)</span>,
nl <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"nl"</span><spanclass="op">)</span>,
pt <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"pt"</span><spanclass="op">)</span>,
ru <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"ru"</span><spanclass="op">)</span>,
sv <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_name</a></span><spanclass="op">(</span><spanclass="va">CoNS</span>, language <spanclass="op">=</span><spanclass="st">"sv"</span><spanclass="op">)</span>,
<spanclass="fu"><ahref="https://rdrr.io/r/base/print.html"class="external-link">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>