<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://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>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>
<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>
<spanclass="fu"><ahref="https://docs.ropensci.org/skimr/reference/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 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>
<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>
times <spanclass="op">=</span><spanclass="fl">10</span><spanclass="op">)</span>
<spanclass="fu"><ahref="https://docs.ropensci.org/skimr/reference/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.207 seconds. 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>
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://docs.ropensci.org/skimr/reference/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"># A 8.76 8.96 9.39 9.31 9.86 10.10 10</span>
<spanclass="co"># B 27.60 28.20 33.00 28.90 29.40 71.20 10</span>
<spanclass="co"># C 2.28 2.32 2.47 2.45 2.48 2.85 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.0025 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://docs.ropensci.org/skimr/reference/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 ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), 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">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>,
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://docs.ropensci.org/skimr/reference/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>