diff --git a/DESCRIPTION b/DESCRIPTION index 252ff765..f080051c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9068 -Date: 2019-08-30 +Version: 0.7.1.9069 +Date: 2019-09-01 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 28b26bb0..94d56390 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,5 @@ -# AMR 0.7.1.9068 +# AMR 0.7.1.9069 +Last updated: 01-Sep-2019 ### Breaking * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: @@ -26,7 +27,7 @@ ### New * Function `bug_drug_combinations()` to quickly get a `data.frame` with the antimicrobial resistance of any bug-drug combination in a data set: ```r - x <- bug_drug_combinations(septic_patients) + x <- bug_drug_combinations(example_isolates) x #> ab mo S I R total #> 1 AMC B_ESCHR_COL 332 74 61 467 @@ -65,7 +66,7 @@ ```r # (run this on your own console, as this page does not support colour printing) library(dplyr) - septic_patients %>% + example_isolates %>% select(mo:AMC) %>% as_tibble() ``` diff --git a/R/mo.R b/R/mo.R index da05eed9..b68da3f6 100755 --- a/R/mo.R +++ b/R/mo.R @@ -692,7 +692,8 @@ exec_as.mo <- function(x, # - STEC (Shiga-toxin producing E. coli) # - UPEC (Uropathogenic E. coli) if (toupper(x_backup_without_spp[i]) %in% c("AIEC", "ATEC", "DAEC", "EAEC", "EHEC", "EIEC", "EPEC", "ETEC", "NMEC", "STEC", "UPEC") - | x_backup_without_spp[i] %like% "O?(26|103|104|104|111|121|145|157)") { + # also support O-antigens of E. coli: O26, O103, O104, O111, O121, O145, O157 + | x_backup_without_spp[i] %like% "O?(26|103|104|111|121|145|157)") { x[i] <- microorganismsDT[mo == 'B_ESCHR_COL', ..property][[1]][1L] if (initial_search == TRUE) { set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history) diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 09384c51..eef454d1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 4b8a57ff..f8b66330 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ @@ -185,7 +185,7 @@benchmarks.Rmd
Source: https://gitlab.com/msberends/AMR/blob/master/vignettes/benchmarks.Rmd
One of the most important features of this package is the complete microbial taxonomic database, supplied by the Catalogue of Life. We created a function as.mo()
that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.
Using the microbenchmark
package, we can review the calculation performance of this function. Its function microbenchmark()
runs different input expressions independently of each other and measures their time-to-result.
In the next test, we try to ‘coerce’ different input values for Staphylococcus aureus. The actual result is the same every time: it returns its MO code B_STPHY_AUR
(B stands for Bacteria, the taxonomic kingdom).
But the calculation time differs a lot:
-S.aureus <- microbenchmark(as.mo("sau"),
- as.mo("stau"),
- as.mo("staaur"),
- as.mo("STAAUR"),
- as.mo("S. aureus"),
- as.mo("S. aureus"),
- as.mo("Staphylococcus aureus"),
- times = 10)
-print(S.aureus, unit = "ms", signif = 2)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# as.mo("sau") 8.4 8.5 16.0 9.7 25.0 27 10
-# as.mo("stau") 31.0 31.0 33.0 31.0 33.0 49 10
-# as.mo("staaur") 8.1 8.3 13.0 8.5 23.0 24 10
-# as.mo("STAAUR") 8.2 8.5 9.1 8.9 9.4 11 10
-# as.mo("S. aureus") 22.0 22.0 23.0 23.0 23.0 24 10
-# as.mo("S. aureus") 22.0 23.0 34.0 23.0 24.0 110 10
-# as.mo("Staphylococcus aureus") 3.8 3.9 5.0 4.0 4.3 12 10
S.aureus <- microbenchmark(
+ as.mo("sau"), # WHONET code
+ as.mo("stau"),
+ as.mo("STAU"),
+ as.mo("staaur"),
+ as.mo("STAAUR"),
+ as.mo("S. aureus"),
+ as.mo("S aureus"),
+ as.mo("Staphylococcus aureus"), # official taxonomic name
+ as.mo("Staphylococcus aureus (MRSA)"), # additional text
+ as.mo("Sthafilokkockus aaureuz"), # incorrect spelling
+ as.mo("MRSA"), # Methicillin Resistant S. aureus
+ as.mo("VISA"), # Vancomycin Intermediate S. aureus
+ as.mo("VRSA"), # Vancomycin Resistant S. aureus
+ as.mo(22242419), # Catalogue of Life ID
+ times = 10)
+print(S.aureus, unit = "ms", signif = 2)
+# Unit: milliseconds
+# expr min lq mean median uq
+# as.mo("sau") 8.6 8.9 12.0 9.6 10.0
+# as.mo("stau") 33.0 33.0 39.0 34.0 50.0
+# as.mo("STAU") 33.0 33.0 40.0 35.0 49.0
+# as.mo("staaur") 9.0 9.2 11.0 9.6 9.8
+# as.mo("STAAUR") 8.8 9.2 11.0 9.6 9.9
+# as.mo("S. aureus") 23.0 25.0 29.0 26.0 27.0
+# as.mo("S aureus") 24.0 24.0 26.0 25.0 25.0
+# as.mo("Staphylococcus aureus") 4.0 4.2 4.4 4.2 4.6
+# as.mo("Staphylococcus aureus (MRSA)") 1500.0 1500.0 1600.0 1600.0 1700.0
+# as.mo("Sthafilokkockus aaureuz") 530.0 540.0 550.0 550.0 560.0
+# as.mo("MRSA") 8.2 8.7 12.0 9.1 9.5
+# as.mo("VISA") 19.0 20.0 35.0 21.0 37.0
+# as.mo("VRSA") 19.0 19.0 23.0 20.0 21.0
+# as.mo(22242419) 18.0 19.0 20.0 19.0 20.0
+# max neval
+# 25.0 10
+# 52.0 10
+# 53.0 10
+# 29.0 10
+# 28.0 10
+# 50.0 10
+# 40.0 10
+# 5.2 10
+# 1700.0 10
+# 580.0 10
+# 36.0 10
+# 110.0 10
+# 35.0 10
+# 34.0 10
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. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.
To achieve this speed, the as.mo
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 Thermus islandicus (B_THERMS_ISL
), a bug probably never found before in humans:
T.islandicus <- microbenchmark(as.mo("theisl"),
@@ -229,128 +261,116 @@
print(T.islandicus, unit = "ms", signif = 2)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# as.mo("theisl") 260 280 280 280 290 290 10
-# as.mo("THEISL") 250 260 280 280 290 300 10
-# as.mo("T. islandicus") 120 130 130 130 150 150 10
-# as.mo("T. islandicus") 120 130 140 140 140 150 10
-# as.mo("Thermus islandicus") 47 47 53 48 62 67 10
That takes 9.3 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. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.
-In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is very uncommon):
-par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
-
-boxplot(microbenchmark(as.mo("Thermus islandicus"),
- as.mo("Prevotella brevis"),
- as.mo("Escherichia coli"),
- as.mo("T. islandicus"),
- as.mo("P. brevis"),
- as.mo("E. coli"),
- times = 10),
- horizontal = TRUE, las = 1, unit = "s", log = FALSE,
- xlab = "", ylab = "Time in seconds",
- main = "Benchmarks per prevalence")
That takes 1.1 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. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.
+In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is uncommon):
+Uncommon microorganisms take a lot more time than common microorganisms. To relieve this pitfall and further improve performance, two important calculations take almost no time at all: repetitive results and already precalculated results.
Repetitive results are unique values that are present more than once. Unique values will only be calculated once by as.mo()
. We will use mo_name()
for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses as.mo()
internally.
library(dplyr)
-# take all MO codes from the example_isolates data set
-x <- example_isolates$mo %>%
- # keep only the unique ones
- unique() %>%
- # pick 50 of them at random
- sample(50) %>%
- # paste that 10,000 times
- rep(10000) %>%
- # scramble it
- sample()
-
-# got indeed 50 times 10,000 = half a million?
-length(x)
-# [1] 500000
-
-# and how many unique values do we have?
-n_distinct(x)
-# [1] 50
-
-# now let's see:
-run_it <- microbenchmark(mo_name(x),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# mo_name(x) 587 591 604 594 612 653 10
So transforming 500,000 values (!!) of 50 unique values only takes 0.59 seconds (594 ms). You only lose time on your unique input values.
+library(dplyr)
+# take all MO codes from the example_isolates data set
+x <- example_isolates$mo %>%
+ # keep only the unique ones
+ unique() %>%
+ # pick 50 of them at random
+ sample(50) %>%
+ # paste that 10,000 times
+ rep(10000) %>%
+ # scramble it
+ sample()
+
+# got indeed 50 times 10,000 = half a million?
+length(x)
+# [1] 500000
+
+# and how many unique values do we have?
+n_distinct(x)
+# [1] 50
+
+# now let's see:
+run_it <- microbenchmark(mo_name(x),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# mo_name(x) 582 614 622 620 624 677 10
So transforming 500,000 values (!!) of 50 unique values only takes 0.62 seconds (619 ms). You only lose time on your unique input values.
What about precalculated results? If the input is an already precalculated result of a helper function like mo_name()
, it almost doesn’t take any time at all (see ‘C’ below):
run_it <- microbenchmark(A = mo_name("B_STPHY_AUR"),
- B = mo_name("S. aureus"),
+run_it <- microbenchmark(A = mo_name("B_STPHY_AUR"),
+ B = mo_name("S. aureus"),
+ C = mo_name("Staphylococcus aureus"),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# A 6.520 6.600 6.790 6.800 6.930 7.080 10
+# B 22.100 22.300 25.600 23.200 23.500 42.800 10
+# C 0.705 0.772 0.816 0.806 0.854 0.977 10
+So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0008 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
+run_it <- microbenchmark(A = mo_species("aureus"),
+ B = mo_genus("Staphylococcus"),
C = mo_name("Staphylococcus aureus"),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# A 6.270 6.300 6.69 6.540 6.990 7.93 10
-# B 21.600 22.700 25.80 23.300 24.400 43.70 10
-# C 0.795 0.812 0.89 0.879 0.962 1.03 10
-So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0009 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
-run_it <- microbenchmark(A = mo_species("aureus"),
- B = mo_genus("Staphylococcus"),
- C = mo_name("Staphylococcus aureus"),
- D = mo_family("Staphylococcaceae"),
- E = mo_order("Bacillales"),
- F = mo_class("Bacilli"),
- G = mo_phylum("Firmicutes"),
- H = mo_kingdom("Bacteria"),
- times = 10)
-print(run_it, unit = "ms", signif = 3)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# A 0.452 0.459 0.473 0.464 0.475 0.518 10
-# B 0.607 0.610 0.654 0.616 0.639 0.860 10
-# C 0.661 0.686 0.724 0.729 0.763 0.796 10
-# D 0.441 0.448 0.473 0.458 0.471 0.596 10
-# E 0.412 0.439 0.464 0.449 0.458 0.593 10
-# F 0.437 0.447 0.471 0.454 0.483 0.586 10
-# G 0.437 0.446 0.478 0.454 0.477 0.580 10
-# H 0.435 0.445 0.467 0.454 0.459 0.581 10
+ D = mo_family("Staphylococcaceae"),
+ E = mo_order("Bacillales"),
+ F = mo_class("Bacilli"),
+ G = mo_phylum("Firmicutes"),
+ H = mo_kingdom("Bacteria"),
+ times = 10)
+print(run_it, unit = "ms", signif = 3)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# A 0.470 0.477 0.506 0.492 0.498 0.674 10
+# B 0.623 0.634 0.674 0.669 0.708 0.744 10
+# C 0.778 0.819 0.845 0.844 0.866 0.915 10
+# D 0.462 0.471 0.483 0.482 0.492 0.515 10
+# E 0.462 0.464 0.476 0.472 0.479 0.518 10
+# F 0.460 0.466 0.475 0.470 0.482 0.510 10
+# G 0.456 0.465 0.478 0.477 0.486 0.513 10
+# H 0.459 0.464 0.472 0.470 0.475 0.509 10
Of course, when running mo_phylum("Firmicutes")
the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes"
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.
When the system language is non-English and supported by this AMR
package, some functions will have a translated result. This almost does’t take extra time:
mo_name("CoNS", language = "en") # or just mo_name("CoNS") on an English system
-# [1] "Coagulase-negative Staphylococcus (CoNS)"
-
-mo_name("CoNS", language = "es") # or just mo_name("CoNS") on a Spanish system
-# [1] "Staphylococcus coagulasa negativo (SCN)"
-
-mo_name("CoNS", language = "nl") # or just mo_name("CoNS") on a Dutch system
-# [1] "Coagulase-negatieve Staphylococcus (CNS)"
-
-run_it <- microbenchmark(en = mo_name("CoNS", language = "en"),
- de = mo_name("CoNS", language = "de"),
- nl = mo_name("CoNS", language = "nl"),
- es = mo_name("CoNS", language = "es"),
- it = mo_name("CoNS", language = "it"),
- fr = mo_name("CoNS", language = "fr"),
- pt = mo_name("CoNS", language = "pt"),
- times = 10)
-print(run_it, unit = "ms", signif = 4)
-# Unit: milliseconds
-# expr min lq mean median uq max neval
-# en 17.56 18.00 22.17 18.14 26.18 35.39 10
-# de 18.94 19.20 19.99 19.86 20.44 21.82 10
-# nl 23.95 25.02 29.17 25.22 28.39 45.95 10
-# es 19.05 19.34 22.98 19.75 20.59 36.66 10
-# it 18.70 19.27 19.36 19.35 19.57 19.79 10
-# fr 18.54 19.07 21.03 19.24 19.37 37.92 10
-# pt 18.57 18.92 19.58 19.31 20.32 21.21 10
mo_name("CoNS", language = "en") # or just mo_name("CoNS") on an English system
+# [1] "Coagulase-negative Staphylococcus (CoNS)"
+
+mo_name("CoNS", language = "es") # or just mo_name("CoNS") on a Spanish system
+# [1] "Staphylococcus coagulasa negativo (SCN)"
+
+mo_name("CoNS", language = "nl") # or just mo_name("CoNS") on a Dutch system
+# [1] "Coagulase-negatieve Staphylococcus (CNS)"
+
+run_it <- microbenchmark(en = mo_name("CoNS", language = "en"),
+ de = mo_name("CoNS", language = "de"),
+ nl = mo_name("CoNS", language = "nl"),
+ es = mo_name("CoNS", language = "es"),
+ it = mo_name("CoNS", language = "it"),
+ fr = mo_name("CoNS", language = "fr"),
+ pt = mo_name("CoNS", language = "pt"),
+ times = 10)
+print(run_it, unit = "ms", signif = 4)
+# Unit: milliseconds
+# expr min lq mean median uq max neval
+# en 17.64 17.88 20.31 18.36 19.05 37.62 10
+# de 19.15 19.25 21.73 19.75 20.40 37.72 10
+# nl 24.34 24.48 36.33 24.88 26.21 121.60 10
+# es 18.95 19.09 19.29 19.28 19.53 19.61 10
+# it 19.02 19.10 22.80 19.24 20.42 36.65 10
+# fr 19.01 19.04 19.21 19.15 19.20 19.94 10
+# pt 18.94 19.08 22.28 19.55 20.36 38.81 10
Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.
The development of this package is part of, related to, or made possible by:
diff --git a/docs/news/index.html b/docs/news/index.html index 125fb75e..75058886 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ @@ -225,10 +225,11 @@ -Last updated: 01-Sep-2019
"testvalue"
could never be
Function bug_drug_combinations()
to quickly get a data.frame
with the antimicrobial resistance of any bug-drug combination in a data set:
x <- bug_drug_combinations(septic_patients)
+x <- bug_drug_combinations(example_isolates)
x
#> ab mo S I R total
#> 1 AMC B_ESCHR_COL 332 74 61 467
@@ -294,7 +295,7 @@ Since this is a major change, usage of the old also_single_tested
w
tibble
printing support for classes rsi
, mic
, disk
, ab
mo
. When using tibble
s containing antimicrobial columns, values S
will print in green, values I
will print in yellow and values R
will print in red. Microbial IDs (class mo
) will emphasise on the genus and species, not on the kingdom.
# (run this on your own console, as this page does not support colour printing)
library(dplyr)
-septic_patients %>%
+example_isolates %>%
select(mo:AMC) %>%
as_tibble()
@@ -1258,7 +1259,7 @@ Using as.mo(..., allow_uncertain = 3)
Contents
diff --git a/git_premaster.sh b/git_premaster.sh
index d2743490..3af88f94 100755
--- a/git_premaster.sh
+++ b/git_premaster.sh
@@ -36,12 +36,14 @@ fi
sed -i -- "s/^Version: .*/Version: ${new_version}/" DESCRIPTION
# update 1st line of NEWS.md
sed -i -- "1s/.*/# AMR ${new_version}/" NEWS.md
+# add date to 2nd line of NEWS.md
+sed -i -- "2s/.*/\Last updated: $(date '+%d-%b-%Y')\<\/small\>/" NEWS.md
rm *-- || true
echo "• First 3 lines of DESCRIPTION:"
head -3 DESCRIPTION
echo
-echo "• First line of NEWS.md:"
-head -1 NEWS.md
+echo "• First 2 lines of NEWS.md:"
+head -2 NEWS.md
echo
echo "•••••••••••••••••••••••••••••••••"
echo "• Reloading/documenting package •"
diff --git a/index.md b/index.md
index 341853c9..b408f390 100644
--- a/index.md
+++ b/index.md
@@ -19,11 +19,11 @@ We created this package for both routine analysis and academic research (as part
The development of this package is part of, related to, or made possible by:
### What can you do with this package?
diff --git a/pkgdown/extra.css b/pkgdown/extra.css
index 52765596..c40042cc 100644
--- a/pkgdown/extra.css
+++ b/pkgdown/extra.css
@@ -109,6 +109,9 @@ kbd {
li, p {
line-height: 1.5;
}
+li p {
+ margin-top: 10.5px;
+}
/* slightly smaller blockquote */
blockquote {
diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R
index 6e11087d..9f1e94e1 100755
--- a/tests/testthat/test-freq.R
+++ b/tests/testthat/test-freq.R
@@ -26,8 +26,8 @@ test_that("frequency table works", {
# mo
expect_true(is.freq(freq(example_isolates$mo)))
# for this to work, the output of mo_gramstain() is to be expected as follows:
- expect_equal(mo_gramstain("B_ESCHR_COL"), "Gram-negative")
- expect_equal(mo_gramstain("B_STPHY_AUR"), "Gram-positive")
+ expect_equal(mo_gramstain("B_ESCHR_COL", language = NULL), "Gram-negative")
+ expect_equal(mo_gramstain("B_STPHY_AUR", language = NULL), "Gram-positive")
# rsi
expect_true(is.freq(freq(example_isolates$AMX)))
diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd
index 98fc7d46..8aaf8d10 100755
--- a/vignettes/benchmarks.Rmd
+++ b/vignettes/benchmarks.Rmd
@@ -19,16 +19,44 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.width = 7.5,
- fig.height = 4.5
+ fig.height = 4.5,
+ dpi = 150
)
```
+Source: https://gitlab.com/msberends/AMR/blob/master/vignettes/benchmarks.Rmd
+
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.
Using the `microbenchmark` package, we can review the calculation performance of this function. Its function `microbenchmark()` runs different input expressions independently of each other and measures their time-to-result.
```{r, message = FALSE, echo = FALSE}
library(dplyr)
+library(ggplot2)
+ggplot.bm <- function(df, title = NULL) {
+ p <- df %>%
+ group_by(expr) %>%
+ summarise(t = median(time) / 1e+06) %>%
+ arrange(t) %>%
+ mutate(expr = factor(as.character(expr), levels = rev(as.character(expr))),
+ t_round = round(t, 1))
+ suppressWarnings(
+ print(
+ p %>%
+ ggplot(aes(x = expr, y = t)) +
+ geom_linerange(aes(ymin = 0, ymax = t), colour = "#555555") +
+ geom_text(aes(label = t_round, hjust = -0.5), size = 3) +
+ geom_point(size = 3, colour = "#555555") +
+ coord_flip() +
+ scale_y_log10(breaks = c(1, 2, 5,
+ 10, 20, 50,
+ 100, 200, 500,
+ 1000, 2000, 5000),
+ limits = c(1, max(p$t) * 2)) +
+ labs(x = "Expression", y = "Median time in milliseconds (log scale)", title = title)
+ )
+ )
+}
```
```{r, message = FALSE}
@@ -40,17 +68,28 @@ In the next test, we try to 'coerce' different input values for *Staphylococcus
But the calculation time differs a lot:
-```{r}
-S.aureus <- microbenchmark(as.mo("sau"),
- as.mo("stau"),
- as.mo("staaur"),
- as.mo("STAAUR"),
- as.mo("S. aureus"),
- as.mo("S. aureus"),
- as.mo("Staphylococcus aureus"),
- times = 10)
+```{r, warning=FALSE}
+S.aureus <- microbenchmark(
+ as.mo("sau"), # WHONET code
+ as.mo("stau"),
+ as.mo("STAU"),
+ as.mo("staaur"),
+ as.mo("STAAUR"),
+ as.mo("S. aureus"),
+ as.mo("S aureus"),
+ as.mo("Staphylococcus aureus"), # official taxonomic name
+ as.mo("Staphylococcus aureus (MRSA)"), # additional text
+ as.mo("Sthafilokkockus aaureuz"), # incorrect spelling
+ as.mo("MRSA"), # Methicillin Resistant S. aureus
+ as.mo("VISA"), # Vancomycin Intermediate S. aureus
+ as.mo("VRSA"), # Vancomycin Resistant S. aureus
+ as.mo(22242419), # Catalogue of Life ID
+ times = 10)
print(S.aureus, unit = "ms", signif = 2)
```
+```{r, echo = FALSE}
+ggplot.bm(S.aureus)
+```
In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.
@@ -68,24 +107,25 @@ print(T.islandicus, unit = "ms", signif = 2)
That takes `r round(mean(T.islandicus$time, na.rm = TRUE) / mean(S.aureus$time, na.rm = TRUE), 1)` 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. Full names (like *Thermus islandicus*) are almost fast - these are the most probable input from most data sets.
-In the figure below, we compare *Escherichia coli* (which is very common) with *Prevotella brevis* (which is moderately common) and with *Thermus islandicus* (which is very uncommon):
+In the figure below, we compare *Escherichia coli* (which is very common) with *Prevotella brevis* (which is moderately common) and with *Thermus islandicus* (which is uncommon):
-```{r}
-par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
+```{r, echo = FALSE}
+ggplot.bm(
+ microbenchmark(as.mo("Escherichia coli"),
+ as.mo("E. coli"),
+ times = 10), title = "Very common")
-boxplot(microbenchmark(as.mo("Thermus islandicus"),
- as.mo("Prevotella brevis"),
- as.mo("Escherichia coli"),
- as.mo("T. islandicus"),
- as.mo("P. brevis"),
- as.mo("E. coli"),
- times = 10),
- horizontal = TRUE, las = 1, unit = "s", log = FALSE,
- xlab = "", ylab = "Time in seconds",
- main = "Benchmarks per prevalence")
+ggplot.bm(
+ microbenchmark(as.mo("Prevotella brevis"),
+ as.mo("P. brevis"),
+ times = 10), title = "Moderately common")
+
+ggplot.bm(
+ microbenchmark(as.mo("Thermus islandicus"),
+ as.mo("T. islandicus"),
+ times = 10), title = "Uncommon")
```
-
```{r, echo = FALSE, eval = FALSE}
# In reality, the `as.mo()` functions **learns from its own output to speed up determinations for next times**. In above figure, this effect was disabled to show the difference with the boxplot below - when you would use `as.mo()` yourself: