1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 18:46:11 +01:00

unit tests

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-02-21 23:32:30 +01:00
parent bd2a256969
commit 6c542268be
16 changed files with 534 additions and 296 deletions

10
NEWS.md
View File

@ -11,10 +11,14 @@ We've got a new website: [https://msberends.gitlab.io/AMR](https://msberends.git
#### New
* **BREAKING**: removed deprecated functions, parameters and references to 'bactid'. Use `as.mo()` to identify an MO code.
* Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The `microorganisms` data set now contains:
* All ~55,000 species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses
* All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales. The kingdom of Fungi is a very large taxon with almost 300,000 different species, of which most are not microbial. Including everything tremendously slows down our algortihms, and not all fungi fit the scope of this package. By only including the aforementioned taxonomic orders, the most relevant species are covered (like genera *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*).
* All ~15,000 previously accepted names of species that have been taxonomically renamed
* All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses
* All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales.
The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant (sub)species are covered (like all species of *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*).
* All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed
* The responsible author(s) and year of scientific publication
This data is updated annually - check the included version with `catalogue_of_life_version()`.
* Due to this change, some `mo` codes changed (e.g. *Streptococcus* changed from `B_STRPTC` to `B_STRPT`). A translation table is used internally to support older microorganism IDs, so users will not notice this difference.
* Support for data from [WHONET](https://whonet.org/) and [EARS-Net](https://ecdc.europa.eu/en/about-us/partnerships-and-networks/disease-and-laboratory-networks/ears-net) (European Antimicrobial Resistance Surveillance Network):
* Exported files from WHONET can be read and used in this package. For functions like `first_isolate()` and `eucast_rules()`, all parameters will be filled in automatically.

15
R/mo.R
View File

@ -372,7 +372,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
x[i] <- microorganismsDT[mo == 'B_ENTRC', ..property][[1]][1L]
next
}
if (toupper(x_trimmed[i]) %in% c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC')) {
if (toupper(x_trimmed[i]) %in% c("EHEC", "EPEC", "EIEC", "STEC", "ATEC")) {
x[i] <- microorganismsDT[mo == 'B_ESCHR_COL', ..property][[1]][1L]
next
}
@ -614,8 +614,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
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"
# 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 {
@ -632,7 +632,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
# check for uncertain results ----
if (allow_uncertain == TRUE) {
uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only, e.x) {
uncertain_fn <- function(a.x_backup, b.x_trimmed, c.x_withspaces_start_end, d.x_withspaces_start_only) {
# (1) look for genus only, part of name ----
if (nchar(b.x_trimmed) > 4 & !b.x_trimmed %like% " ") {
@ -650,8 +650,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
# (2) look again for old taxonomic names, now for G. species ----
found <- microorganisms.oldDT[fullname %like% c.x_withspaces_start_end
| fullname %like% d.x_withspaces_start_only
| fullname %like% e.x,]
| fullname %like% d.x_withspaces_start_only]
if (NROW(found) > 0 & nchar(b.x_trimmed) >= 6) {
if (property == "ref") {
# when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so:
@ -715,7 +714,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
}
}
# (6) not yet implemented taxonomic changes in ITIS ----
# (6) not yet implemented taxonomic changes in Catalogue of Life ----
found <- suppressMessages(suppressWarnings(exec_as.mo(TEMPORARY_TAXONOMY(b.x_trimmed), clear_options = FALSE, allow_uncertain = FALSE)))
if (!is.na(found)) {
found_result <- found
@ -732,7 +731,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
return(NA_character_)
}
x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i], x[i])
x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces_start_end[i], x_withspaces_start_only[i])
if (!is.na(x[i])) {
next
}

258
R/zzz.R

File diff suppressed because one or more lines are too long

View File

@ -327,19 +327,41 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2012-08-08</td>
<td align="center">P2</td>
<td align="center">Hospital B</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">S</td>
<td align="center">2010-03-19</td>
<td align="center">Z1</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="even">
<td align="center">2011-03-05</td>
<td align="center">D8</td>
<td align="center">2012-12-24</td>
<td align="center">Z8</td>
<td align="center">Hospital A</td>
<td align="center">Klebsiella pneumoniae</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="odd">
<td align="center">2013-12-12</td>
<td align="center">Z1</td>
<td align="center">Hospital A</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="even">
<td align="center">2014-08-13</td>
<td align="center">J4</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
@ -349,20 +371,20 @@
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2012-04-03</td>
<td align="center">D4</td>
<td align="center">Hospital C</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">R</td>
<td align="center">2012-04-09</td>
<td align="center">F5</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2012-10-25</td>
<td align="center">I1</td>
<td align="center">Hospital B</td>
<td align="center">2010-08-11</td>
<td align="center">N1</td>
<td align="center">Hospital A</td>
<td align="center">Klebsiella pneumoniae</td>
<td align="center">S</td>
<td align="center">S</td>
@ -370,28 +392,6 @@
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2017-04-18</td>
<td align="center">X3</td>
<td align="center">Hospital B</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">F</td>
</tr>
<tr class="even">
<td align="center">2013-03-18</td>
<td align="center">C4</td>
<td align="center">Hospital A</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
</tbody>
</table>
<p>Now, lets start the cleaning and the analysis!</p>
@ -411,8 +411,8 @@
#&gt;
#&gt; Item Count Percent Cum. Count Cum. Percent
#&gt; --- ----- ------- -------- ----------- -------------
#&gt; 1 M 10,458 52.3% 10,458 52.3%
#&gt; 2 F 9,542 47.7% 20,000 100.0%</code></pre>
#&gt; 1 M 10,436 52.2% 10,436 52.2%
#&gt; 2 F 9,564 47.8% 20,000 100.0%</code></pre>
<p>So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values <code>M</code> and <code>F</code>. From a researcher perspective: there are slightly more men. Nothing we didnt already know.</p>
<p>The data is already quite clean, but we still need to transform some variables. The <code>bacteria</code> column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The <code><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate()</a></code> function of the <code>dplyr</code> package makes this really easy:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" title="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span></a>
@ -443,10 +443,10 @@
<a class="sourceLine" id="cb14-19" title="19"><span class="co">#&gt; Kingella kingae (no changes)</span></a>
<a class="sourceLine" id="cb14-20" title="20"><span class="co">#&gt; </span></a>
<a class="sourceLine" id="cb14-21" title="21"><span class="co">#&gt; EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)</span></a>
<a class="sourceLine" id="cb14-22" title="22"><span class="co">#&gt; Table 1: Intrinsic resistance in Enterobacteriaceae (1342 changes)</span></a>
<a class="sourceLine" id="cb14-22" title="22"><span class="co">#&gt; Table 1: Intrinsic resistance in Enterobacteriaceae (1333 changes)</span></a>
<a class="sourceLine" id="cb14-23" title="23"><span class="co">#&gt; Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-24" title="24"><span class="co">#&gt; Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-25" title="25"><span class="co">#&gt; Table 4: Intrinsic resistance in Gram-positive bacteria (2761 changes)</span></a>
<a class="sourceLine" id="cb14-25" title="25"><span class="co">#&gt; Table 4: Intrinsic resistance in Gram-positive bacteria (2733 changes)</span></a>
<a class="sourceLine" id="cb14-26" title="26"><span class="co">#&gt; Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)</span></a>
<a class="sourceLine" id="cb14-27" title="27"><span class="co">#&gt; Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)</span></a>
<a class="sourceLine" id="cb14-28" title="28"><span class="co">#&gt; Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)</span></a>
@ -462,9 +462,9 @@
<a class="sourceLine" id="cb14-38" title="38"><span class="co">#&gt; Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)</span></a>
<a class="sourceLine" id="cb14-39" title="39"><span class="co">#&gt; Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)</span></a>
<a class="sourceLine" id="cb14-40" title="40"><span class="co">#&gt; </span></a>
<a class="sourceLine" id="cb14-41" title="41"><span class="co">#&gt; =&gt; EUCAST rules affected 7,471 out of 20,000 rows</span></a>
<a class="sourceLine" id="cb14-41" title="41"><span class="co">#&gt; =&gt; EUCAST rules affected 7,452 out of 20,000 rows</span></a>
<a class="sourceLine" id="cb14-42" title="42"><span class="co">#&gt; -&gt; added 0 test results</span></a>
<a class="sourceLine" id="cb14-43" title="43"><span class="co">#&gt; -&gt; changed 4,103 test results (0 to S; 0 to I; 4,103 to R)</span></a></code></pre></div>
<a class="sourceLine" id="cb14-43" title="43"><span class="co">#&gt; -&gt; changed 4,066 test results (0 to S; 0 to I; 4,066 to R)</span></a></code></pre></div>
</div>
<div id="adding-new-variables" class="section level1">
<h1 class="hasAnchor">
@ -489,8 +489,8 @@
<a class="sourceLine" id="cb16-3" title="3"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb16-4" title="4"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `date` as input for `col_date`.</span></a>
<a class="sourceLine" id="cb16-5" title="5"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb16-6" title="6"><span class="co">#&gt; =&gt; Found 5,674 first isolates (28.4% of total)</span></a></code></pre></div>
<p>So only 28.4% is suitable for resistance analysis! We can now filter on it with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<a class="sourceLine" id="cb16-6" title="6"><span class="co">#&gt; =&gt; Found 5,692 first isolates (28.5% of total)</span></a></code></pre></div>
<p>So only 28.5% is suitable for resistance analysis! We can now filter on it with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" title="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb17-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(first <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>)</a></code></pre></div>
<p>For future use, the above two syntaxes can be shortened with the <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> function:</p>
@ -516,19 +516,19 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-01-23</td>
<td align="center">A4</td>
<td align="center">2010-01-14</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-03-13</td>
<td align="center">A4</td>
<td align="center">2010-02-22</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -538,8 +538,8 @@
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-04-19</td>
<td align="center">A4</td>
<td align="center">2010-04-01</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -549,21 +549,21 @@
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-06-11</td>
<td align="center">A4</td>
<td align="center">2010-04-25</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-07-04</td>
<td align="center">A4</td>
<td align="center">2010-05-09</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
@ -571,52 +571,52 @@
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-07-05</td>
<td align="center">A4</td>
<td align="center">2010-05-29</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2011-03-21</td>
<td align="center">A4</td>
<td align="center">2010-06-27</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2011-04-02</td>
<td align="center">A4</td>
<td align="center">2010-06-27</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2011-04-05</td>
<td align="center">A4</td>
<td align="center">2011-02-01</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2011-04-13</td>
<td align="center">A4</td>
<td align="center">2011-03-20</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -637,7 +637,7 @@
<a class="sourceLine" id="cb19-7" title="7"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb19-8" title="8"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.</span></a>
<a class="sourceLine" id="cb19-9" title="9"><span class="co">#&gt; [Criterion] Inclusion based on key antibiotics, ignoring I.</span></a>
<a class="sourceLine" id="cb19-10" title="10"><span class="co">#&gt; =&gt; Found 15,801 first weighted isolates (79.0% of total)</span></a></code></pre></div>
<a class="sourceLine" id="cb19-10" title="10"><span class="co">#&gt; =&gt; Found 15,851 first weighted isolates (79.3% of total)</span></a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th align="center">isolate</th>
@ -654,32 +654,32 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-01-23</td>
<td align="center">A4</td>
<td align="center">2010-01-14</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-03-13</td>
<td align="center">A4</td>
<td align="center">2010-02-22</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-04-19</td>
<td align="center">A4</td>
<td align="center">2010-04-01</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -690,80 +690,80 @@
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-06-11</td>
<td align="center">A4</td>
<td align="center">2010-04-25</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-07-04</td>
<td align="center">A4</td>
<td align="center">2010-05-09</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-07-05</td>
<td align="center">A4</td>
<td align="center">2010-05-29</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2011-03-21</td>
<td align="center">A4</td>
<td align="center">2010-06-27</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2011-04-02</td>
<td align="center">A4</td>
<td align="center">2010-06-27</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2011-04-05</td>
<td align="center">A4</td>
<td align="center">2011-02-01</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2011-04-13</td>
<td align="center">A4</td>
<td align="center">2011-03-20</td>
<td align="center">O6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -774,11 +774,11 @@
</tr>
</tbody>
</table>
<p>Instead of 2, now 8 isolates are flagged. In total, 79% of all isolates are marked first weighted - 50.6% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>Instead of 2, now 6 isolates are flagged. In total, 79.3% of all isolates are marked first weighted - 50.8% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>As with <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code>, theres a shortcut for this new algorithm too:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" title="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb20-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/first_isolate.html">filter_first_weighted_isolate</a></span>()</a></code></pre></div>
<p>So we end up with 15,801 isolates for analysis.</p>
<p>So we end up with 15,851 isolates for analysis.</p>
<p>We can remove unneeded columns:</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" title="1">data_1st &lt;-<span class="st"> </span>data_1st <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb21-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(first, keyab))</a></code></pre></div>
@ -786,6 +786,7 @@
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/head">head</a></span>(data_1st)</a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th></th>
<th align="center">date</th>
<th align="center">patient_id</th>
<th align="center">hospital</th>
@ -802,23 +803,25 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2012-08-08</td>
<td align="center">P2</td>
<td align="center">Hospital B</td>
<td align="center">B_STRPT_PNE</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td>3</td>
<td align="center">2013-12-12</td>
<td align="center">Z1</td>
<td align="center">Hospital A</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram positive</td>
<td align="center">Streptococcus</td>
<td align="center">pneumoniae</td>
<td align="center">Staphylococcus</td>
<td align="center">aureus</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2011-03-05</td>
<td align="center">D8</td>
<td>4</td>
<td align="center">2014-08-13</td>
<td align="center">J4</td>
<td align="center">Hospital A</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
@ -832,24 +835,26 @@
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">2012-04-03</td>
<td align="center">D4</td>
<td align="center">Hospital C</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">R</td>
<td>5</td>
<td align="center">2012-04-09</td>
<td align="center">F5</td>
<td align="center">Hospital A</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">M</td>
<td align="center">Gram positive</td>
<td align="center">Staphylococcus</td>
<td align="center">aureus</td>
<td align="center">Gram negative</td>
<td align="center">Escherichia</td>
<td align="center">coli</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2012-10-25</td>
<td align="center">I1</td>
<td align="center">Hospital B</td>
<td>6</td>
<td align="center">2010-08-11</td>
<td align="center">N1</td>
<td align="center">Hospital A</td>
<td align="center">B_KLBSL_PNE</td>
<td align="center">R</td>
<td align="center">S</td>
@ -862,33 +867,35 @@
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">2017-04-18</td>
<td align="center">X3</td>
<td align="center">Hospital B</td>
<td align="center">B_STRPT_PNE</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td>7</td>
<td align="center">2010-02-25</td>
<td align="center">E9</td>
<td align="center">Hospital A</td>
<td align="center">B_KLBSL_PNE</td>
<td align="center">R</td>
<td align="center">F</td>
<td align="center">Gram positive</td>
<td align="center">Streptococcus</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
<td align="center">Gram negative</td>
<td align="center">Klebsiella</td>
<td align="center">pneumoniae</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2013-03-18</td>
<td align="center">C4</td>
<td>8</td>
<td align="center">2013-04-09</td>
<td align="center">N1</td>
<td align="center">Hospital A</td>
<td align="center">B_STRPT_PNE</td>
<td align="center">S</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">M</td>
<td align="center">Gram positive</td>
<td align="center">Streptococcus</td>
<td align="center">pneumoniae</td>
<td align="center">Staphylococcus</td>
<td align="center">aureus</td>
<td align="center">TRUE</td>
</tr>
</tbody>
@ -908,9 +915,9 @@
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb23-1" title="1"><span class="kw"><a href="../reference/freq.html">freq</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(data_1st<span class="op">$</span>genus, data_1st<span class="op">$</span>species))</a></code></pre></div>
<p>Or can be used like the <code>dplyr</code> way, which is easier readable:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb24-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(genus, species)</a></code></pre></div>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (15,801 x 13)</strong></p>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (15,851 x 13)</strong></p>
<p>Columns: 2<br>
Length: 15,801 (of which NA: 0 = 0.00%)<br>
Length: 15,851 (of which NA: 0 = 0.00%)<br>
Unique: 4</p>
<p>Shortest: 16<br>
Longest: 24</p>
@ -927,33 +934,33 @@ Longest: 24</p>
<tr class="odd">
<td align="left">1</td>
<td align="left">Escherichia coli</td>
<td align="right">7,850</td>
<td align="right">49.7%</td>
<td align="right">7,850</td>
<td align="right">49.7%</td>
<td align="right">7,853</td>
<td align="right">49.5%</td>
<td align="right">7,853</td>
<td align="right">49.5%</td>
</tr>
<tr class="even">
<td align="left">2</td>
<td align="left">Staphylococcus aureus</td>
<td align="right">3,918</td>
<td align="right">24.8%</td>
<td align="right">11,768</td>
<td align="right">74.5%</td>
<td align="right">3,943</td>
<td align="right">24.9%</td>
<td align="right">11,796</td>
<td align="right">74.4%</td>
</tr>
<tr class="odd">
<td align="left">3</td>
<td align="left">Streptococcus pneumoniae</td>
<td align="right">2,446</td>
<td align="right">15.5%</td>
<td align="right">14,214</td>
<td align="right">90.0%</td>
<td align="right">2,432</td>
<td align="right">15.3%</td>
<td align="right">14,228</td>
<td align="right">89.8%</td>
</tr>
<tr class="even">
<td align="left">4</td>
<td align="left">Klebsiella pneumoniae</td>
<td align="right">1,587</td>
<td align="right">10.0%</td>
<td align="right">15,801</td>
<td align="right">1,623</td>
<td align="right">10.2%</td>
<td align="right">15,851</td>
<td align="right">100.0%</td>
</tr>
</tbody>
@ -964,7 +971,7 @@ Longest: 24</p>
<a href="#resistance-percentages" class="anchor"></a>Resistance percentages</h2>
<p>The functions <code>portion_R</code>, <code>portion_RI</code>, <code>portion_I</code>, <code>portion_IS</code> and <code>portion_S</code> can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/portion.html">portion_IR</a></span>(amox)</a>
<a class="sourceLine" id="cb25-2" title="2"><span class="co">#&gt; [1] 0.4747801</span></a></code></pre></div>
<a class="sourceLine" id="cb25-2" title="2"><span class="co">#&gt; [1] 0.4764368</span></a></code></pre></div>
<p>Or can be used in conjuction with <code><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by()</a></code> and <code><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise()</a></code>, both from the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb26-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb26-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital) <span class="op">%&gt;%</span><span class="st"> </span></a>
@ -977,19 +984,19 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Hospital A</td>
<td align="center">0.4696939</td>
<td align="center">0.4722165</td>
</tr>
<tr class="even">
<td align="center">Hospital B</td>
<td align="center">0.4782930</td>
<td align="center">0.4788707</td>
</tr>
<tr class="odd">
<td align="center">Hospital C</td>
<td align="center">0.4683438</td>
<td align="center">0.4670535</td>
</tr>
<tr class="even">
<td align="center">Hospital D</td>
<td align="center">0.4815051</td>
<td align="center">0.4859994</td>
</tr>
</tbody>
</table>
@ -1007,23 +1014,23 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Hospital A</td>
<td align="center">0.4696939</td>
<td align="center">4867</td>
<td align="center">0.4722165</td>
<td align="center">4841</td>
</tr>
<tr class="even">
<td align="center">Hospital B</td>
<td align="center">0.4782930</td>
<td align="center">5413</td>
<td align="center">0.4788707</td>
<td align="center">5490</td>
</tr>
<tr class="odd">
<td align="center">Hospital C</td>
<td align="center">0.4683438</td>
<td align="center">2385</td>
<td align="center">0.4670535</td>
<td align="center">2413</td>
</tr>
<tr class="even">
<td align="center">Hospital D</td>
<td align="center">0.4815051</td>
<td align="center">3136</td>
<td align="center">0.4859994</td>
<td align="center">3107</td>
</tr>
</tbody>
</table>
@ -1043,27 +1050,27 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Escherichia</td>
<td align="center">0.7278981</td>
<td align="center">0.8996178</td>
<td align="center">0.9742675</td>
<td align="center">0.7324589</td>
<td align="center">0.9016936</td>
<td align="center">0.9759328</td>
</tr>
<tr class="even">
<td align="center">Klebsiella</td>
<td align="center">0.7303088</td>
<td align="center">0.9004411</td>
<td align="center">0.9716446</td>
<td align="center">0.7221195</td>
<td align="center">0.9081947</td>
<td align="center">0.9821319</td>
</tr>
<tr class="odd">
<td align="center">Staphylococcus</td>
<td align="center">0.7304747</td>
<td align="center">0.9157734</td>
<td align="center">0.9757529</td>
<td align="center">0.7420746</td>
<td align="center">0.9163074</td>
<td align="center">0.9792037</td>
</tr>
<tr class="even">
<td align="center">Streptococcus</td>
<td align="center">0.7485691</td>
<td align="center">0.7203947</td>
<td align="center">0.0000000</td>
<td align="center">0.7485691</td>
<td align="center">0.7203947</td>
</tr>
</tbody>
</table>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -218,16 +218,25 @@
<a class="sourceLine" id="cb2-9" title="9"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb2-10" title="10"><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-11" title="11"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb2-12" title="12"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb2-13" title="13"><span class="co">#&gt; as.mo("sau") 42.00 43.00 47.00 43.00 44.0 81.00 10</span></a>
<a class="sourceLine" id="cb2-14" title="14"><span class="co">#&gt; as.mo("stau") 86.00 87.00 93.00 88.00 89.0 130.00 10</span></a>
<a class="sourceLine" id="cb2-15" title="15"><span class="co">#&gt; as.mo("staaur") 43.00 43.00 45.00 43.00 43.0 64.00 10</span></a>
<a class="sourceLine" id="cb2-16" title="16"><span class="co">#&gt; as.mo("S. aureus") 23.00 23.00 27.00 23.00 24.0 60.00 10</span></a>
<a class="sourceLine" id="cb2-17" title="17"><span class="co">#&gt; as.mo("S. aureus") 23.00 23.00 29.00 24.00 24.0 73.00 10</span></a>
<a class="sourceLine" id="cb2-18" title="18"><span class="co">#&gt; as.mo("STAAUR") 43.00 43.00 43.00 43.00 44.0 46.00 10</span></a>
<a class="sourceLine" id="cb2-19" title="19"><span class="co">#&gt; as.mo("Staphylococcus aureus") 14.00 15.00 19.00 15.00 16.0 53.00 10</span></a>
<a class="sourceLine" id="cb2-20" title="20"><span class="co">#&gt; as.mo("B_STPHY_AUR") 0.34 0.42 0.47 0.49 0.5 0.58 10</span></a></code></pre></div>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 10 milliseconds means it can determine 100 input values per second. It case of 50 milliseconds, this is only 20 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of <code><a href="../reference/as.mo.html">as.mo("B_STPHY_AUR")</a></code>, the input is already a valid MO code, so it only almost takes no time at all (494 millionths of a second).</p>
<a class="sourceLine" id="cb2-12" title="12"><span class="co">#&gt; expr min lq mean median uq max</span></a>
<a class="sourceLine" id="cb2-13" title="13"><span class="co">#&gt; as.mo("sau") 100.00 100.00 110.00 100.00 100.00 160.00</span></a>
<a class="sourceLine" id="cb2-14" title="14"><span class="co">#&gt; as.mo("stau") 140.00 140.00 170.00 160.00 190.00 200.00</span></a>
<a class="sourceLine" id="cb2-15" title="15"><span class="co">#&gt; as.mo("staaur") 99.00 100.00 100.00 100.00 100.00 110.00</span></a>
<a class="sourceLine" id="cb2-16" title="16"><span class="co">#&gt; as.mo("S. aureus") 64.00 64.00 65.00 65.00 66.00 67.00</span></a>
<a class="sourceLine" id="cb2-17" title="17"><span class="co">#&gt; as.mo("S. aureus") 65.00 65.00 70.00 66.00 66.00 110.00</span></a>
<a class="sourceLine" id="cb2-18" title="18"><span class="co">#&gt; as.mo("STAAUR") 97.00 98.00 100.00 100.00 100.00 100.00</span></a>
<a class="sourceLine" id="cb2-19" title="19"><span class="co">#&gt; as.mo("Staphylococcus aureus") 35.00 35.00 36.00 36.00 37.00 38.00</span></a>
<a class="sourceLine" id="cb2-20" title="20"><span class="co">#&gt; as.mo("B_STPHY_AUR") 0.34 0.47 0.52 0.48 0.56 0.89</span></a>
<a class="sourceLine" id="cb2-21" title="21"><span class="co">#&gt; neval</span></a>
<a class="sourceLine" id="cb2-22" title="22"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-23" title="23"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-24" title="24"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-25" title="25"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-26" title="26"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-27" title="27"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-28" title="28"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb2-29" title="29"><span class="co">#&gt; 10</span></a></code></pre></div>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 10 milliseconds means it can determine 100 input values per second. It case of 50 milliseconds, this is only 20 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of <code><a href="../reference/as.mo.html">as.mo("B_STPHY_AUR")</a></code>, the input is already a valid MO code, so it only almost takes no time at all (476 millionths of a second).</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>Mycoplasma leonicaptivi</em> (<code>B_MYCPL_LEO</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" title="1">M.leonicaptivi &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">"myle"</span>),</a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"mycleo"</span>),</a>
@ -239,14 +248,14 @@
<a class="sourceLine" id="cb3-8" title="8"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb3-9" title="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(M.leonicaptivi, <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-10" title="10"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co">#&gt; expr min lq mean median uq max</span></a>
<a class="sourceLine" id="cb3-12" title="12"><span class="co">#&gt; as.mo("myle") 140.00 140.00 150.0 140.00 140.00 180.00</span></a>
<a class="sourceLine" id="cb3-13" title="13"><span class="co">#&gt; as.mo("mycleo") 470.00 480.00 500.0 510.00 520.00 560.00</span></a>
<a class="sourceLine" id="cb3-14" title="14"><span class="co">#&gt; as.mo("M. leonicaptivi") 240.00 240.00 250.0 240.00 280.00 290.00</span></a>
<a class="sourceLine" id="cb3-15" title="15"><span class="co">#&gt; as.mo("M. leonicaptivi") 240.00 240.00 250.0 240.00 280.00 280.00</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="co">#&gt; as.mo("MYCLEO") 470.00 510.00 510.0 520.00 520.00 540.00</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="co">#&gt; as.mo("Mycoplasma leonicaptivi") 150.00 150.00 170.0 180.00 190.00 200.00</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="co">#&gt; as.mo("B_MYCPL_LEO") 0.32 0.58 0.6 0.59 0.61 0.97</span></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co">#&gt; expr min lq mean median uq max</span></a>
<a class="sourceLine" id="cb3-12" title="12"><span class="co">#&gt; as.mo("myle") 210.00 220.00 240.0 230.00 260.00 310</span></a>
<a class="sourceLine" id="cb3-13" title="13"><span class="co">#&gt; as.mo("mycleo") 610.00 630.00 680.0 680.00 720.00 770</span></a>
<a class="sourceLine" id="cb3-14" title="14"><span class="co">#&gt; as.mo("M. leonicaptivi") 370.00 370.00 390.0 390.00 410.00 410</span></a>
<a class="sourceLine" id="cb3-15" title="15"><span class="co">#&gt; as.mo("M. leonicaptivi") 350.00 350.00 390.0 390.00 410.00 480</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="co">#&gt; as.mo("MYCLEO") 630.00 650.00 680.0 670.00 680.00 880</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="co">#&gt; as.mo("Mycoplasma leonicaptivi") 250.00 250.00 260.0 250.00 260.00 290</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="co">#&gt; as.mo("B_MYCPL_LEO") 0.35 0.43 5.6 0.69 0.75 50</span></a>
<a class="sourceLine" id="cb3-19" title="19"><span class="co">#&gt; neval</span></a>
<a class="sourceLine" id="cb3-20" title="20"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb3-21" title="21"><span class="co">#&gt; 10</span></a>
@ -255,7 +264,7 @@
<a class="sourceLine" id="cb3-24" title="24"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb3-25" title="25"><span class="co">#&gt; 10</span></a>
<a class="sourceLine" id="cb3-26" title="26"><span class="co">#&gt; 10</span></a></code></pre></div>
<p>That takes 6.9 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:</p>
<p>That takes 4.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:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/par">par</a></span>(<span class="dt">mar =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">16</span>, <span class="dv">4</span>, <span class="dv">2</span>)) <span class="co"># set more space for left margin text (16)</span></a>
<a class="sourceLine" id="cb4-2" title="2"></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="co"># highest value on y axis</span></a>
@ -292,8 +301,8 @@
<a class="sourceLine" id="cb6-18" title="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">3</span>)</a>
<a class="sourceLine" id="cb6-19" title="19"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-20" title="20"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-21" title="21"><span class="co">#&gt; mo_fullname(x) 445 466 497 491 536 543 10</span></a></code></pre></div>
<p>So transforming 500,000 values (!) of 95 unique values only takes 0.49 seconds (490 ms). You only lose time on your unique input values.</p>
<a class="sourceLine" id="cb6-21" title="21"><span class="co">#&gt; mo_fullname(x) 487 499 527 535 538 573 10</span></a></code></pre></div>
<p>So transforming 500,000 values (!) of 95 unique values only takes 0.54 seconds (535 ms). You only lose time on your unique input values.</p>
</div>
<div id="precalculated-results" class="section level3">
<h3 class="hasAnchor">
@ -305,11 +314,11 @@
<a class="sourceLine" id="cb7-4" title="4"> <span class="dt">times =</span> <span class="dv">10</span>)</a>
<a class="sourceLine" id="cb7-5" title="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" title="6"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-7" title="7"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-8" title="8"><span class="co">#&gt; A 38.70 39.100 40.200 40.000 40.100 45.300 10</span></a>
<a class="sourceLine" id="cb7-9" title="9"><span class="co">#&gt; B 24.50 24.600 24.800 24.700 24.700 25.500 10</span></a>
<a class="sourceLine" id="cb7-10" title="10"><span class="co">#&gt; C 0.26 0.392 0.434 0.447 0.516 0.561 10</span></a></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_fullname("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0004 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>
<a class="sourceLine" id="cb7-7" title="7"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-8" title="8"><span class="co">#&gt; A 65.500 66.100 66.200 66.300 66.500 66.700 10</span></a>
<a class="sourceLine" id="cb7-9" title="9"><span class="co">#&gt; B 61.000 61.200 61.900 61.700 62.300 64.500 10</span></a>
<a class="sourceLine" id="cb7-10" title="10"><span class="co">#&gt; C 0.329 0.335 0.461 0.527 0.551 0.556 10</span></a></code></pre></div>
<p>So going from <code><a href="../reference/mo_property.html">mo_fullname("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0005 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" title="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" title="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" title="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
@ -322,14 +331,14 @@
<a class="sourceLine" id="cb8-10" title="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" title="11"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb8-12" title="12"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb8-13" title="13"><span class="co">#&gt; A 0.297 0.329 0.400 0.416 0.453 0.459 10</span></a>
<a class="sourceLine" id="cb8-14" title="14"><span class="co">#&gt; B 0.277 0.304 0.349 0.363 0.382 0.407 10</span></a>
<a class="sourceLine" id="cb8-15" title="15"><span class="co">#&gt; C 0.281 0.430 0.436 0.440 0.471 0.493 10</span></a>
<a class="sourceLine" id="cb8-16" title="16"><span class="co">#&gt; D 0.249 0.277 0.310 0.316 0.337 0.347 10</span></a>
<a class="sourceLine" id="cb8-17" title="17"><span class="co">#&gt; E 0.214 0.252 0.300 0.306 0.338 0.403 10</span></a>
<a class="sourceLine" id="cb8-18" title="18"><span class="co">#&gt; F 0.237 0.270 0.300 0.311 0.326 0.335 10</span></a>
<a class="sourceLine" id="cb8-19" title="19"><span class="co">#&gt; G 0.245 0.282 0.297 0.298 0.314 0.348 10</span></a>
<a class="sourceLine" id="cb8-20" title="20"><span class="co">#&gt; H 0.241 0.282 0.308 0.312 0.328 0.373 10</span></a></code></pre></div>
<a class="sourceLine" id="cb8-13" title="13"><span class="co">#&gt; A 0.288 0.372 0.440 0.418 0.481 0.662 10</span></a>
<a class="sourceLine" id="cb8-14" title="14"><span class="co">#&gt; B 0.281 0.294 0.364 0.369 0.411 0.461 10</span></a>
<a class="sourceLine" id="cb8-15" title="15"><span class="co">#&gt; C 0.390 0.493 0.563 0.550 0.645 0.731 10</span></a>
<a class="sourceLine" id="cb8-16" title="16"><span class="co">#&gt; D 0.244 0.269 0.733 0.337 0.347 4.420 10</span></a>
<a class="sourceLine" id="cb8-17" title="17"><span class="co">#&gt; E 0.283 0.344 0.368 0.363 0.410 0.434 10</span></a>
<a class="sourceLine" id="cb8-18" title="18"><span class="co">#&gt; F 0.250 0.319 0.343 0.339 0.354 0.492 10</span></a>
<a class="sourceLine" id="cb8-19" title="19"><span class="co">#&gt; G 0.286 0.329 0.363 0.340 0.392 0.496 10</span></a>
<a class="sourceLine" id="cb8-20" title="20"><span class="co">#&gt; H 0.292 0.305 0.365 0.359 0.421 0.459 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">
@ -356,13 +365,13 @@
<a class="sourceLine" id="cb9-18" title="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" title="19"><span class="co">#&gt; Unit: milliseconds</span></a>
<a class="sourceLine" id="cb9-20" title="20"><span class="co">#&gt; expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb9-21" title="21"><span class="co">#&gt; en 10.85 10.89 11.10 11.03 11.23 11.83 10</span></a>
<a class="sourceLine" id="cb9-22" title="22"><span class="co">#&gt; de 19.43 19.50 19.86 19.58 20.35 20.99 10</span></a>
<a class="sourceLine" id="cb9-23" title="23"><span class="co">#&gt; nl 19.08 19.17 19.40 19.48 19.56 19.63 10</span></a>
<a class="sourceLine" id="cb9-24" title="24"><span class="co">#&gt; es 19.35 19.44 26.07 19.48 20.06 52.36 10</span></a>
<a class="sourceLine" id="cb9-25" title="25"><span class="co">#&gt; it 19.23 19.40 22.91 19.49 19.91 52.92 10</span></a>
<a class="sourceLine" id="cb9-26" title="26"><span class="co">#&gt; fr 19.10 19.22 19.40 19.45 19.54 19.68 10</span></a>
<a class="sourceLine" id="cb9-27" title="27"><span class="co">#&gt; pt 19.01 19.46 29.32 19.55 52.32 52.50 10</span></a></code></pre></div>
<a class="sourceLine" id="cb9-21" title="21"><span class="co">#&gt; en 24.41 25.27 26.34 25.41 26.92 30.60 10</span></a>
<a class="sourceLine" id="cb9-22" title="22"><span class="co">#&gt; de 35.53 35.76 36.76 35.98 37.20 41.19 10</span></a>
<a class="sourceLine" id="cb9-23" title="23"><span class="co">#&gt; nl 34.51 35.55 39.93 35.60 40.15 69.76 10</span></a>
<a class="sourceLine" id="cb9-24" title="24"><span class="co">#&gt; es 34.36 35.98 44.29 37.46 39.98 73.16 10</span></a>
<a class="sourceLine" id="cb9-25" title="25"><span class="co">#&gt; it 35.78 36.22 37.44 36.75 38.70 40.78 10</span></a>
<a class="sourceLine" id="cb9-26" title="26"><span class="co">#&gt; fr 35.45 35.71 36.09 35.79 36.15 37.93 10</span></a>
<a class="sourceLine" id="cb9-27" title="27"><span class="co">#&gt; pt 35.10 35.44 44.61 35.76 39.68 77.27 10</span></a></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -251,10 +251,15 @@
<strong>BREAKING</strong>: removed deprecated functions, parameters and references to bactid. Use <code><a href="../reference/as.mo.html">as.mo()</a></code> to identify an MO code.</li>
<li>Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The <code>microorganisms</code> data set now contains:
<ul>
<li>All ~55,000 species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses</li>
<li>All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales. The kingdom of Fungi is a very large taxon with almost 300,000 different species, of which most are not microbial. Including everything tremendously slows down our algortihms, and not all fungi fit the scope of this package. By only including the aforementioned taxonomic orders, the most relevant species are covered (like genera <em>Aspergillus</em>, <em>Candida</em>, <em>Pneumocystis</em>, <em>Saccharomyces</em> and <em>Trichophyton</em>).</li>
<li>All ~15,000 previously accepted names of species that have been taxonomically renamed</li>
<li>The responsible author(s) and year of scientific publication</li>
<li>All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses</li>
<li>
<p>All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales.</p>
The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant (sub)species are covered (like all species of <em>Aspergillus</em>, <em>Candida</em>, <em>Pneumocystis</em>, <em>Saccharomyces</em> and <em>Trichophyton</em>).</li>
<li>All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed</li>
<li><p>The responsible author(s) and year of scientific publication</p></li>
</ul>
This data is updated annually - check the included version with <code><a href="../reference/catalogue_of_life_version.html">catalogue_of_life_version()</a></code>.
<ul>
<li>Due to this change, some <code>mo</code> codes changed (e.g. <em>Streptococcus</em> changed from <code>B_STRPTC</code> to <code>B_STRPT</code>). A translation table is used internally to support older microorganism IDs, so users will not notice this difference.</li>
</ul>
</li>

View File

@ -4,7 +4,9 @@
# unzip and extract taxon.tab, then:
taxon <- data.table::fread("taxon.tab")
# result is over 3.7M rows
# result is over 3.7M rows:
library(dplyr)
library(AMR)
taxon %>% freq(kingdom)
# Item Count Percent Cum. Count Cum. Percent
# --- ---------- ---------- -------- ----------- -------------
@ -128,6 +130,7 @@ MOs <- MOs %>%
mutate(mo = ifelse(duplicated(.$mo), paste0(mo, "1"), mo)) %>%
select(mo, everything(), -abbr_genus, -abbr_species, -abbr_subspecies)
# everything distinct?
sum(duplicated(MOs$mo))

View File

@ -56,3 +56,9 @@ test_that("data sets are valid", {
})
test_that("creation of data sets is valid", {
DT <- make_DT()
expect_lt(nrow(DT[prevalence == 1]), nrow(DT[prevalence == 2]))
expect_lt(nrow(DT[prevalence == 2]), nrow(DT[prevalence == 3]))
})

View File

@ -35,6 +35,7 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL")
expect_equal(as.character(as.mo("Escherichia species")), "B_ESCHR")
expect_equal(as.character(as.mo("Escherichia")), "B_ESCHR")
expect_equal(as.character(as.mo("Esch spp.")), "B_ESCHR")
expect_equal(as.character(as.mo(" B_ESCHR_COL ")), "B_ESCHR_COL")
expect_equal(as.character(as.mo("e coli")), "B_ESCHR_COL") # not Campylobacter
expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNE")
@ -45,6 +46,7 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNE")
expect_equal(as.character(as.mo("Strepto")), "B_STRPT")
expect_equal(as.character(as.mo("Streptococcus")), "B_STRPT") # not Peptostreptoccus
expect_equal(as.character(as.mo("B_STRPTC")), "B_STRPT") # old MO code (<=v0.5.0)
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRA", "B_STRPT_GRB"))
@ -80,6 +82,10 @@ test_that("as.mo works", {
"MRSA",
"VISA"))),
rep("B_STPHY_AUR", 8))
expect_identical(
as.character(
as.mo(c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC'))),
rep("B_ESCHR_COL", 5))
# unprevalent MO
expect_identical(
as.character(
@ -116,6 +122,7 @@ test_that("as.mo works", {
expect_identical(as.character(as.mo("STCPYO", Lancefield = TRUE)), "B_STRPT_GRA") # group A
expect_identical(as.character(as.mo("S. agalactiae", Lancefield = FALSE)), "B_STRPT_AGA")
expect_identical(as.character(as.mo("S. agalactiae", Lancefield = TRUE)), "B_STRPT_GRB") # group B
expect_identical(as.character(suppressWarnings(as.mo("estreptococos grupo B"))), "B_STRPT_GRB")
expect_identical(as.character(as.mo("S. equisimilis", Lancefield = FALSE)), "B_STRPT_DYS_EQU")
expect_identical(as.character(as.mo("S. equisimilis", Lancefield = TRUE)), "B_STRPT_GRC") # group C
# Enterococci must only be influenced if Lancefield = "all"
@ -229,4 +236,13 @@ test_that("as.mo works", {
# Salmonella (City) are all actually Salmonella enterica spp (City)
expect_equal(as.character(suppressMessages(as.mo("Salmonella Goettingen"))),
"B_SLMNL_ENT")
expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL")
# no virusses
expect_warning(as.mo("Virus"))
# summary
expect_equal(length(summary(septic_patients$mo)), 6)
expect_warning(as.mo("Cutibacterium"))
})

View File

@ -75,6 +75,9 @@ test_that("mo_property works", {
expect_identical(mo_property("E. coli", property = "species"),
mo_species("E. coli"))
expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968")
expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999")
# check vector with random values
#library(dplyr)
#df_sample <- AMR::microorganisms %>% sample_n(100)