1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 09:51:48 +02:00

(v0.7.1.9069) documentation update

This commit is contained in:
2019-09-01 13:16:57 +02:00
parent 88ee1b7268
commit c7be72f0ce
20 changed files with 251 additions and 180 deletions

View File

@ -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
)
```
<small>Source: https://gitlab.com/msberends/AMR/blob/master/vignettes/benchmarks.Rmd</small>
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: