diff --git a/R/catalogue_of_life.R b/R/catalogue_of_life.R index 25c41ba5..30e9f626 100755 --- a/R/catalogue_of_life.R +++ b/R/catalogue_of_life.R @@ -30,7 +30,7 @@ #' \itemize{ #' \item{All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria, Protozoa and Viruses} #' \item{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 \emph{Aspergillus}, \emph{Candida}, \emph{Pneumocystis}, \emph{Saccharomyces} and \emph{Trichophyton}).} -#' \item{All ~15,000 previously accepted names of (sub)species that have been taxonomically renamed} +#' \item{All ~15,000 previously accepted names of inckuded (sub)species that have been taxonomically renamed} #' \item{The complete taxonomic tree of all included (sub)species: from kingdom to subspecies} #' \item{The responsible author(s) and year of scientific publication} #' } diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index f50800a3..c8d17ea9 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -218,26 +218,26 @@ times = 10) print(S.aureus, unit = "ms") #> Unit: milliseconds -#> expr min lq mean median -#> as.mo("sau") 42.58139 42.645368 43.3006677 42.970095 -#> as.mo("stau") 76.60094 77.168264 83.7686909 77.316642 -#> as.mo("staaur") 42.86607 42.947083 43.5035571 43.497293 -#> as.mo("S. aureus") 18.39354 18.432582 22.4304233 18.495928 -#> as.mo("S. aureus") 18.46513 18.559903 18.6640991 18.579110 -#> as.mo("STAAUR") 42.71975 42.788612 44.3280682 43.069864 -#> as.mo("Staphylococcus aureus") 11.56285 11.591419 15.9457298 11.667161 -#> as.mo("B_STPHY_AUR") 0.40487 0.450128 0.5036822 0.481417 +#> expr min lq mean median +#> as.mo("sau") 42.680497 42.766053 43.5046242 43.2246305 +#> as.mo("stau") 76.627901 76.760320 82.2084011 77.2020310 +#> as.mo("staaur") 42.751945 42.828281 46.8816599 43.0017665 +#> as.mo("S. aureus") 18.328588 18.370632 22.3298018 18.4252830 +#> as.mo("S. aureus") 18.258048 18.385997 18.7710600 18.5449555 +#> as.mo("STAAUR") 42.734554 42.854751 43.6593017 43.6353320 +#> as.mo("Staphylococcus aureus") 11.466961 11.572841 16.5287637 11.6172940 +#> as.mo("B_STPHY_AUR") 0.284603 0.302692 0.4095492 0.4190475 #> uq max neval -#> 43.448543 45.058105 10 -#> 78.335591 127.180349 10 -#> 43.817095 44.999509 10 -#> 19.007097 56.501460 10 -#> 18.651814 19.373275 10 -#> 43.741388 54.703256 10 -#> 12.323077 50.121808 10 -#> 0.519271 0.766578 10 -

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 as.mo("B_STPHY_AUR"), the input is already a valid MO code, so it only almost takes no time at all (404 millionths of seconds).

-

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 far less faster. See this example for the ID of Mycoplasma leonicaptivi (B_MYCPL_LEO), a bug probably never found before in humans:

+#> 44.091919 45.191431 10 +#> 78.670409 123.715942 10 +#> 43.089558 81.640969 10 +#> 18.546004 57.384741 10 +#> 19.235128 19.693775 10 +#> 44.189907 45.381609 10 +#> 12.175081 59.815567 10 +#> 0.482254 0.500343 10 +

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 as.mo("B_STPHY_AUR"), the input is already a valid MO code, so it only almost takes no time at all (284 millionths of seconds).

+

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 Mycoplasma leonicaptivi (B_MYCPL_LEO), a bug probably never found before in humans:

M.leonicaptivi <- microbenchmark(as.mo("myle"),
                                  as.mo("mycleo"),
                                  as.mo("M. leonicaptivi"),
@@ -248,22 +248,22 @@
                                  times = 10)
 print(M.leonicaptivi, unit = "ms")
 #> Unit: milliseconds
-#>                              expr       min         lq       mean
-#>                     as.mo("myle") 112.28656 112.372601 112.751678
-#>                   as.mo("mycleo") 382.46812 382.757612 383.432440
-#>          as.mo("M. leonicaptivi") 202.68674 203.654949 210.461303
-#>         as.mo("M.  leonicaptivi") 202.89759 203.440956 203.816387
-#>                   as.mo("MYCLEO") 382.27864 383.090895 401.904482
-#>  as.mo("Mycoplasma leonicaptivi") 102.99676 103.191196 109.196394
-#>              as.mo("B_MYCPL_LEO")   0.32155   0.564807   4.320068
-#>      median        uq       max neval
-#>  112.540884 112.76874 113.76321    10
-#>  383.232219 384.05897 385.28587    10
-#>  204.255445 205.80976 242.53035    10
-#>  203.613673 203.82802 206.15038    10
-#>  386.478757 421.87837 437.26978    10
-#>  103.596136 104.65940 142.25748    10
-#>    0.593652   0.62522  37.96384    10
+#> expr min lq mean +#> as.mo("myle") 112.493914 112.698409 113.5834588 +#> as.mo("mycleo") 382.813554 382.992838 389.0918181 +#> as.mo("M. leonicaptivi") 202.903596 203.855253 211.7932317 +#> as.mo("M. leonicaptivi") 203.761037 204.178479 212.5451427 +#> as.mo("MYCLEO") 382.602355 383.481517 393.2696052 +#> as.mo("Mycoplasma leonicaptivi") 103.701176 103.991018 109.5707840 +#> as.mo("B_MYCPL_LEO") 0.312051 0.564876 0.5870787 +#> median uq max neval +#> 113.363438 114.20691 115.907686 10 +#> 384.139806 388.34114 421.458483 10 +#> 204.186195 205.16631 243.204461 10 +#> 204.715173 207.97372 244.462163 10 +#> 383.918409 386.97938 434.456156 10 +#> 104.428888 104.87207 153.125617 10 +#> 0.567914 0.63779 0.859048 10

That takes 6 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:

par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
 
@@ -273,9 +273,8 @@
 boxplot(S.aureus, horizontal = TRUE, las = 1, unit = "ms", log = FALSE, xlab = "", ylim = c(0, max_y_axis),
         main = expression(paste("Benchmark of ", italic("Staphylococcus aureus"))))

-

-boxplot(M.leonicaptivi, horizontal = TRUE, las = 1, unit = "ms", log = FALSE, xlab = "", ylim = c(0, max_y_axis),
-        main = expression(paste("Benchmark of ", italic("Mycoplasma leonicaptivi"))))
+
boxplot(M.leonicaptivi, horizontal = TRUE, las = 1, unit = "ms", log = FALSE, xlab = "", ylim = c(0, max_y_axis),
+        main = expression(paste("Benchmark of ", italic("Mycoplasma leonicaptivi"))))

To relieve this pitfall and further improve performance, two important calculations take almost no time at all: repetitive results and already precalculated results.

@@ -283,35 +282,27 @@ Repetitive results

Repetitive results mean that unique values are present more than once. Unique values will only be calculated once by as.mo(). We will use mo_fullname() for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) which uses as.mo() internally.

library(dplyr)
-#> 
-#> Attaching package: 'dplyr'
-#> The following objects are masked from 'package:stats':
-#> 
-#>     filter, lag
-#> The following objects are masked from 'package:base':
-#> 
-#>     intersect, setdiff, setequal, union
-# take 500,000 random MO codes from the septic_patients data set
-x = septic_patients %>%
-  sample_n(500000, replace = TRUE) %>%
-  pull(mo)
-  
-# got the right length?
-length(x)
-#> [1] 500000
-
-# and how many unique values do we have?
-n_distinct(x)
-#> [1] 95
-
-# now let's see:
-run_it <- microbenchmark(X = mo_fullname(x),
-                         times = 10)
-print(run_it, unit = "ms")
-#> Unit: milliseconds
-#>  expr      min       lq     mean   median       uq     max neval
-#>     X 435.7086 442.1682 465.5949 468.8453 477.1915 505.961    10
-

So transforming 500,000 values (!) of 95 unique values only takes 0.47 seconds (468 ms). You only lose time on your unique input values.

+# take 500,000 random MO codes from the septic_patients data set +x = septic_patients %>% + sample_n(500000, replace = TRUE) %>% + pull(mo) + +# got the right length? +length(x) +#> [1] 500000 + +# and how many unique values do we have? +n_distinct(x) +#> [1] 95 + +# now let's see: +run_it <- microbenchmark(X = mo_fullname(x), + times = 10) +print(run_it, unit = "ms") +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> X 413.2556 431.8327 448.3355 445.8654 465.2447 480.5499 10
+

So transforming 500,000 values (!) of 95 unique values only takes 0.45 seconds (445 ms). You only lose time on your unique input values.

@@ -323,10 +314,10 @@ times = 10) print(run_it, unit = "ms") #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> A 38.887977 38.920313 39.3674024 39.076862 39.258415 42.166327 10 -#> B 19.589084 19.631059 19.8682396 19.781567 19.955611 20.751941 10 -#> C 0.255829 0.382732 0.4199913 0.400156 0.499156 0.564807 10

+#> expr min lq mean median uq max neval +#> A 39.603291 39.713640 39.950479 39.8150500 40.172707 40.664181 10 +#> B 19.570436 19.623515 19.964292 19.9376620 20.228830 20.609744 10 +#> C 0.251429 0.333144 0.389883 0.3866775 0.499087 0.510401 10

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0004 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:

microbenchmark(A = mo_species("aureus"),
                B = mo_genus("Staphylococcus"),
@@ -340,20 +331,20 @@
                unit = "ms")
 #> Unit: milliseconds
 #>  expr      min       lq      mean    median       uq      max neval
-#>     A 0.250242 0.292496 0.3891774 0.4266960 0.456902 0.520388    10
-#>     B 0.259461 0.311702 0.3428727 0.3412800 0.374141 0.443912    10
-#>     C 0.290960 0.313169 0.4334429 0.4097595 0.520389 0.725373    10
-#>     D 0.271823 0.282789 0.3187217 0.3192800 0.352909 0.375398    10
-#>     E 0.245353 0.270985 0.3081197 0.2960235 0.330839 0.429036    10
-#>     F 0.246122 0.266585 0.2991101 0.3089435 0.332794 0.351582    10
-#>     G 0.271893 0.272452 0.3085039 0.2850580 0.368204 0.385525    10
-#>     H 0.252686 0.259251 0.3161791 0.2985025 0.334820 0.422680    10
+#> A 0.298084 0.370509 0.4040816 0.4065820 0.449569 0.475480 10 +#> B 0.293753 0.306115 0.3352809 0.3212705 0.370160 0.386154 10 +#> C 0.307652 0.353328 0.4106327 0.3943595 0.467239 0.548255 10 +#> D 0.244376 0.262954 0.2987189 0.3027975 0.338102 0.353747 10 +#> E 0.249614 0.255550 0.2985027 0.2772710 0.351931 0.397049 10 +#> F 0.259531 0.282439 0.3248814 0.3193850 0.345575 0.415906 10 +#> G 0.249055 0.266516 0.3293723 0.3020295 0.344528 0.616350 10 +#> H 0.242141 0.288515 0.3122614 0.3152295 0.339779 0.355773 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.

Results in other languages

-

When the system language is non-English and supported by this AMR package, some functions take a little while longer:

+

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_fullname("CoNS", language = "en") # or just mo_fullname("CoNS") on an English system
 #> [1] "Coagulase Negative Staphylococcus (CoNS)"
 
@@ -371,13 +362,13 @@
                unit = "ms")
 #> Unit: milliseconds
 #>  expr      min       lq     mean   median       uq      max neval
-#>    en 10.67105 11.03136 11.06332 11.07271 11.15310 11.45006    10
-#>    de 19.13393 19.50080 26.13799 19.61419 20.23400 52.66501    10
-#>    nl 19.05410 19.53789 22.94707 19.59205 20.12616 52.47399    10
-#>    es 19.31635 19.55221 26.22342 19.58633 20.01875 52.97636    10
-#>    it 19.21725 19.47105 19.63980 19.58053 19.68162 20.58914    10
-#>    fr 19.07854 19.45450 19.67303 19.56153 19.64517 20.45651    10
-#>    pt 19.00668 19.28388 19.53493 19.57857 19.66423 20.55317    10
+#> en 10.74026 11.10686 11.09997 11.11563 11.20366 11.34076 10 +#> de 19.15977 19.59293 19.76980 19.71204 19.78338 20.54633 10 +#> nl 19.42929 19.54013 19.75978 19.67233 19.77263 20.58935 10 +#> es 19.31042 19.66821 19.65120 19.69552 19.73421 19.75538 10 +#> it 19.26362 19.34003 22.93301 19.62998 19.67213 52.79729 10 +#> fr 19.33011 19.54739 26.16391 19.64726 19.87145 52.40164 10 +#> pt 19.22800 19.50164 26.41786 19.66766 20.96244 53.16479 10

Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png index 331cac82..5d6d8993 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-2.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-2.png index c1225095..d979007f 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-2.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-2.png differ diff --git a/docs/index.html b/docs/index.html index 2b9faf0d..aa2572ee 100644 --- a/docs/index.html +++ b/docs/index.html @@ -197,11 +197,12 @@

(TLDR - to find out how to conduct AMR analysis, please continue reading here to get started.


AMR is a free and open-source R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods. It supports any data format, including WHONET/EARS-Net data.

-

After installing this package, R knows almost all ~20,000 microorganisms and ~500 antibiotics by name and code, and knows all about valid RSI and MIC values.

+

After installing this package, R knows almost all ~60,000 microorganisms and ~500 antibiotics by name and code, and knows all about valid RSI and MIC values.

Used to SPSS? Read our tutorial on how to import data from SPSS, SAS or Stata and learn in which ways R outclasses any of these statistical packages.

We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and is free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. Read the full license here.

This package can be used for: