<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">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>, its taxonomic kingdom).</p>
<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>
<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 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>
<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>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.204 seconds. That is 102 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">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 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>,
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">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>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>
<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:</p>
<codeclass="sourceCode R"><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="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="st">"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="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"><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>,
it <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">"it"</span><spanclass="op">)</span>,
fr <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">"fr"</span><spanclass="op">)</span>,
pt <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">"pt"</span><spanclass="op">)</span>,
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>
<p>Developed by <ahref="https://www.rug.nl/staff/m.s.berends/">Matthijs S. Berends</a>, <ahref="https://www.rug.nl/staff/c.f.luz/">Christian F. Luz</a>, <ahref="https://www.rug.nl/staff/a.w.friedrich/">Alexander W. Friedrich</a>, <ahref="https://www.rug.nl/staff/b.sinha/">Bhanu N. M. Sinha</a>, <ahref="https://www.rug.nl/staff/c.j.albers/">Casper J. Albers</a>, <ahref="https://www.rug.nl/staff/c.glasner/">Corinna Glasner</a>.</p>