diff --git a/DESCRIPTION b/DESCRIPTION index a899b173..45f7ab3e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9078 -Date: 2019-09-20 +Version: 0.7.1.9079 +Date: 2019-09-22 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index d5ce2e45..5b8024ed 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9078 -Last updated: 20-Sep-2019 +# AMR 0.7.1.9079 +Last updated: 22-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`: diff --git a/R/freq.R b/R/freq.R index 64f740fc..40a0032f 100755 --- a/R/freq.R +++ b/R/freq.R @@ -29,6 +29,7 @@ clean::freq #' @export #' @noRd freq.mo <- function(x, ...) { + x <- as.mo(x) # to get the newest mo codes x_noNA <- x[!is.na(x)] grams <- mo_gramstain(x_noNA, language = NULL) freq.default(x = x, ..., diff --git a/R/globals.R b/R/globals.R index 3ccba949..6e78b141 100755 --- a/R/globals.R +++ b/R/globals.R @@ -46,6 +46,7 @@ globalVariables(c(".", "key_ab_lag", "key_ab_other", "kingdom", + "kingdom_index", "lang", "Last name", "lookup", diff --git a/R/mo.R b/R/mo.R index 222caa16..0348665e 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1721,7 +1721,7 @@ exec_as.mo <- function(x, print(mo_renamed()) } - if (old_mo_warning == TRUE) { + if (old_mo_warning == TRUE & property != "mo") { warning("The input contained old microorganism IDs from previous versions of this package. Please use as.mo() on these old codes.\nSUPPORT FOR THIS WILL BE DROPPED IN A FUTURE VERSION.", call. = FALSE) } diff --git a/R/mo_history.R b/R/mo_history.R index ce38e719..5281aeb5 100644 --- a/R/mo_history.R +++ b/R/mo_history.R @@ -29,6 +29,7 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA if (base::interactive() | force == TRUE) { mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force) + warning_new_write <- FALSE df <- data.frame(x, mo, stringsAsFactors = FALSE) %>% distinct(x, .keep_all = TRUE) %>% filter(!is.na(x) & !is.na(mo)) @@ -55,8 +56,9 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA # if (tryCatch(nrow(getOption("mo_remembered_results")), error = function(e) 1001) > 1000) { # return(base::invisible()) # } - if (is.null(mo_hist) & interactive()) { + if (is.null(mo_hist) & interactive() & warning_new_write == FALSE) { message(blue(paste0("NOTE: results are saved to ", mo_history_file(), "."))) + warning_new_write <- TRUE } tryCatch(write.csv(rbind(mo_hist, data.frame( diff --git a/cran-comments.md b/cran-comments.md index ed725dd0..f976f622 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,5 @@ # Version 0.8.0 * A NOTE for having a data directory over 3 MB. This is needed to offer users reference data for the complete taxonomy of microorganisms - one of the most important features of this pacakge. Has been this way since version 0.3.0. -* This package writes lines to `[user library]/AMR/mo_history/mo_history.csv` when using the `as.mo()` function, in the exact same way (and borrowed from) the `extrafont` package on CRAN (version 0.17) writes to the package folder. Users are notified about this and staged install still works. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. See the source code of `set_mo_history()` and `clear_mo_history()`. + +* This package writes lines to `[user library]/AMR/mo_history/mo_history.csv` when using the `as.mo()` function, in the exact same way (and borrowed from) the `extrafont` package on CRAN (version 0.17) writes to their user library package folder. Users are notified about this with a `message()` and staged install on R >= 3.6.0 still works. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. See the source code of `set_mo_history()` and `clear_mo_history()`. diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 5a5d8f45..32d087e6 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 01ea8fe7..46756e10 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.1.9076 + 0.7.1.9079 @@ -185,7 +185,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

20 September 2019

+

22 September 2019

@@ -194,7 +194,7 @@ -

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 20 September 2019.

+

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 22 September 2019.

Introduction

@@ -210,21 +210,21 @@ -2019-09-20 +2019-09-22 abcd Escherichia coli S S -2019-09-20 +2019-09-22 abcd Escherichia coli S R -2019-09-20 +2019-09-22 efgh Escherichia coli R @@ -319,9 +319,20 @@ -2011-05-18 -O8 +2014-05-20 +X4 Hospital B +Escherichia coli +R +S +S +S +F + + +2011-12-18 +O9 +Hospital A Staphylococcus aureus S S @@ -329,55 +340,44 @@ S F - -2011-03-28 -Q8 -Hospital B + +2015-10-10 +G10 +Hospital A Streptococcus pneumoniae R I S S +M + + +2016-06-01 +N7 +Hospital C +Escherichia coli +S +S +S +S F -2015-12-27 -W2 -Hospital A +2013-04-04 +O5 +Hospital B Klebsiella pneumoniae S -R -R -S -F - - -2014-05-30 -X6 -Hospital B -Escherichia coli -S -I -S -S -F - - -2015-07-30 -Q3 -Hospital D -Escherichia coli -S S S S F -2016-11-03 -O8 -Hospital D -Staphylococcus aureus +2016-05-23 +X1 +Hospital A +Escherichia coli S S S @@ -405,8 +405,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,330 51.6% 10,330 51.6% -# 2 F 9,670 48.4% 20,000 100.0% +# 1 M 10,388 51.9% 10,388 51.9% +# 2 F 9,612 48.1% 20,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M and F. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.

The data is already quite clean, but we still need to transform some variables. The bacteria 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 mutate() function of the dplyr package makes this really easy:

data <- data %>%
@@ -436,14 +436,14 @@
 # Pasteurella multocida (no changes)
 # Staphylococcus (no changes)
 # Streptococcus groups A, B, C, G (no changes)
-# Streptococcus pneumoniae (1,405 values changed)
+# Streptococcus pneumoniae (1,479 values changed)
 # Viridans group streptococci (no changes)
 # 
 # EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,290 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,275 values changed)
 # Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
 # Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,639 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,756 values changed)
 # Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
 # Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
 # Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
@@ -451,24 +451,24 @@
 # Table 13: Interpretive rules for quinolones (no changes)
 # 
 # Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,299 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (101 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,209 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (121 values changed)
 # Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
 # Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
 # Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
 # Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
 # 
 # --------------------------------------------------------------------------
-# EUCAST rules affected 6,427 out of 20,000 rows, making a total of 7,734 edits
+# EUCAST rules affected 6,481 out of 20,000 rows, making a total of 7,840 edits
 # => added 0 test results
 # 
-# => changed 7,734 test results
-#    - 99 test results changed from S to I
-#    - 4,591 test results changed from S to R
-#    - 1,111 test results changed from I to S
-#    - 289 test results changed from I to R
-#    - 1,622 test results changed from R to S
-#    - 22 test results changed from R to I
+# => changed 7,840 test results
+#    - 112 test results changed from S to I
+#    - 4,739 test results changed from S to R
+#    - 1,038 test results changed from I to S
+#    - 333 test results changed from I to R
+#    - 1,595 test results changed from R to S
+#    - 23 test results changed from R to I
 # --------------------------------------------------------------------------
 # 
 # Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
@@ -496,8 +496,8 @@ # NOTE: Using column `bacteria` as input for `col_mo`. # NOTE: Using column `date` as input for `col_date`. # NOTE: Using column `patient_id` as input for `col_patient_id`. -# => Found 5,635 first isolates (28.2% of total)
-

So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+# => Found 5,658 first isolates (28.3% of total) +

So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

data_1st <- data %>% 
   filter(first == TRUE)

For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

@@ -507,7 +507,7 @@

First weighted isolates

-

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient O6, sorted on date:

+

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient D8, sorted on date:

@@ -523,21 +523,21 @@ - - + + - - + + - - + + - + @@ -545,8 +545,8 @@ - - + + @@ -556,8 +556,8 @@ - - + + @@ -567,52 +567,52 @@ - - + + + - - + - - + + - + - - + + - + - - + + - - + + - - + + @@ -622,18 +622,18 @@ - - + + - +
isolate
12010-01-29O62010-02-17D8 B_ESCHR_COLIRR S SSR TRUE
22010-04-29O62010-03-19D8 B_ESCHR_COLIRS S S S
32010-08-31O62010-05-22D8 B_ESCHR_COLI S S
42010-09-18O62010-05-27D8 B_ESCHR_COLI S S
52011-03-23O62010-09-23D8 B_ESCHR_COLI S SR SSTRUEFALSE
62011-03-24O62010-10-27D8 B_ESCHR_COLI S SSR S FALSE
72011-07-19O62010-11-04D8 B_ESCHR_COLI S SSR S FALSE
82011-08-04O62010-12-12D8 B_ESCHR_COLI RRRSS S FALSE
92011-08-15O62010-12-17D8 B_ESCHR_COLI S S
102011-08-22O62010-12-29D8 B_ESCHR_COLI S SSR S FALSE
-

Only 2 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

+

Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

If a column exists with a name like ‘key(…)ab’ the first_isolate() function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:

data <- data %>% 
   mutate(keyab = key_antibiotics(.)) %>% 
@@ -644,7 +644,7 @@
 # NOTE: Using column `patient_id` as input for `col_patient_id`.
 # NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
 # [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 15,041 first weighted isolates (75.2% of total)
+# => Found 15,076 first weighted isolates (75.4% of total)
@@ -661,22 +661,22 @@ - - + + - - + + - - + + - + @@ -685,20 +685,20 @@ - - + + - + - - + + @@ -709,56 +709,56 @@ - - + + + - - + - - + + - + - - + + - + - - + + - - + + - - + + @@ -769,23 +769,23 @@ - - + + - + - +
isolate
12010-01-29O62010-02-17D8 B_ESCHR_COLIRR S SSR TRUE TRUE
22010-04-29O62010-03-19D8 B_ESCHR_COLIRS S S S
32010-08-31O62010-05-22D8 B_ESCHR_COLI S S S S FALSETRUEFALSE
42010-09-18O62010-05-27D8 B_ESCHR_COLI S S
52011-03-23O62010-09-23D8 B_ESCHR_COLI S SR SSTRUEFALSE TRUE
62011-03-24O62010-10-27D8 B_ESCHR_COLI S SSR S FALSE FALSE
72011-07-19O62010-11-04D8 B_ESCHR_COLI S SSR S FALSE FALSE
82011-08-04O62010-12-12D8 B_ESCHR_COLI RRRSS S FALSE TRUE
92011-08-15O62010-12-17D8 B_ESCHR_COLI S S
102011-08-22O62010-12-29D8 B_ESCHR_COLI S SSR S FALSEFALSETRUE
-

Instead of 2, now 6 isolates are flagged. In total, 75.2% of all isolates are marked ‘first weighted’ - 47% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

+

Instead of 1, now 6 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 47.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

As with filter_first_isolate(), there’s a shortcut for this new algorithm too:

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 15,041 isolates for analysis.

+

So we end up with 15,076 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -810,10 +810,10 @@ -1 -2011-05-18 -O8 -Hospital B +2 +2011-12-18 +O9 +Hospital A B_STPHY_AURS S S @@ -826,30 +826,14 @@ TRUE -2 -2011-03-28 -Q8 +5 +2013-04-04 +O5 Hospital B -B_STRPT_PNMN -R -R -S -R -F -Gram-positive -Streptococcus -pneumoniae -TRUE - - -3 -2015-12-27 -W2 -Hospital A B_KLBSL_PNMN R -R -R +S +S S F Gram-negative @@ -857,11 +841,27 @@ pneumoniae TRUE + +6 +2016-05-23 +X1 +Hospital A +B_ESCHR_COLI +S +S +S +S +F +Gram-negative +Escherichia +coli +TRUE + -5 -2015-07-30 -Q3 -Hospital D +8 +2013-07-08 +O3 +Hospital B B_ESCHR_COLI S S @@ -874,29 +874,29 @@ TRUE -6 -2016-11-03 -O8 -Hospital D -B_STPHY_AURS +9 +2014-01-06 +N2 +Hospital B +B_STRPT_PNMN +R +R S -S -S -S -F +R +M Gram-positive -Staphylococcus -aureus +Streptococcus +pneumoniae TRUE -7 -2013-04-03 -F8 -Hospital A +10 +2015-10-02 +H5 +Hospital B B_ESCHR_COLI -S -S +R +R S S M @@ -924,7 +924,7 @@
data_1st %>% freq(genus, species)

Frequency table

Class: character
-Length: 15,041 (of which NA: 0 = 0.00%)
+Length: 15,076 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -941,33 +941,33 @@ Longest: 24

1 Escherichia coli -7,491 -49.8% -7,491 -49.8% +7,447 +49.4% +7,447 +49.4% 2 Staphylococcus aureus -3,732 +3,738 24.8% -11,223 -74.6% +11,185 +74.2% 3 Streptococcus pneumoniae -2,223 -14.8% -13,446 -89.4% +2,305 +15.3% +13,490 +89.5% 4 Klebsiella pneumoniae -1,595 -10.6% -15,041 +1,586 +10.5% +15,076 100.0% @@ -978,7 +978,7 @@ Longest: 24

Resistance percentages

The functions portion_S(), portion_SI(), portion_I(), portion_IR() and portion_R() can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()) and susceptibility as the portion of S and I (portion_SI()). These functions can be used on their own:

data_1st %>% portion_R(AMX)
-# [1] 0.4677216
+# [1] 0.4692889

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
@@ -991,19 +991,19 @@ Longest: 24

Hospital A -0.4646398 +0.4708452 Hospital B -0.4578497 +0.4723226 Hospital C -0.4776586 +0.4660508 Hospital D -0.4822200 +0.4640650 @@ -1021,23 +1021,23 @@ Longest: 24

Hospital A -0.4646398 -4539 +0.4708452 +4579 Hospital B -0.4578497 -5255 +0.4723226 +5257 Hospital C -0.4776586 -2238 +0.4660508 +2165 Hospital D -0.4822200 -3009 +0.4640650 +3075 @@ -1057,27 +1057,27 @@ Longest: 24

Escherichia -0.9236417 -0.8994794 -0.9942598 +0.9246677 +0.8941856 +0.9924802 Klebsiella -0.8206897 -0.9028213 -0.9868339 +0.8234552 +0.8972257 +0.9892812 Staphylococcus -0.9228296 -0.9265809 -0.9951768 +0.9210808 +0.9266988 +0.9925094 Streptococcus -0.6171840 +0.6121475 0.0000000 -0.6171840 +0.6121475 diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index 09da251a..bedac351 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 65fd4d62..6b80b7f0 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 09af4838..051e2127 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 075b01d1..870f727c 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 32ea701b..5bbd3863 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.1.9077 + 0.7.1.9079
@@ -185,7 +185,7 @@

Benchmarks

Matthijs S. Berends

-

20 September 2019

+

22 September 2019

@@ -219,36 +219,36 @@ times = 10) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq -# as.mo("sau") 8.6 8.8 9.0 9.0 9.2 -# as.mo("stau") 31.0 31.0 32.0 32.0 33.0 -# as.mo("STAU") 31.0 32.0 39.0 33.0 38.0 -# as.mo("staaur") 8.6 9.1 17.0 9.7 31.0 -# as.mo("STAAUR") 8.7 9.0 14.0 9.3 9.6 -# as.mo("S. aureus") 23.0 23.0 45.0 24.0 25.0 -# as.mo("S aureus") 23.0 23.0 29.0 24.0 26.0 -# as.mo("Staphylococcus aureus") 28.0 28.0 32.0 29.0 30.0 -# as.mo("Staphylococcus aureus (MRSA)") 530.0 560.0 580.0 570.0 580.0 -# as.mo("Sthafilokkockus aaureuz") 270.0 300.0 310.0 310.0 320.0 -# as.mo("MRSA") 8.6 9.0 9.3 9.2 9.3 -# as.mo("VISA") 19.0 20.0 27.0 20.0 43.0 -# as.mo("VRSA") 19.0 20.0 26.0 21.0 23.0 -# as.mo(22242419) 18.0 18.0 24.0 19.0 22.0 -# max neval -# 9.5 10 -# 38.0 10 -# 61.0 10 -# 38.0 10 -# 35.0 10 -# 210.0 10 -# 56.0 10 -# 57.0 10 -# 660.0 10 -# 380.0 10 -# 10.0 10 -# 46.0 10 -# 48.0 10 -# 42.0 10
+# expr min lq mean median uq max +# as.mo("sau") 8.5 8.6 11 8.7 9.1 34 +# as.mo("stau") 31.0 31.0 39 31.0 56.0 58 +# as.mo("STAU") 31.0 34.0 39 34.0 35.0 60 +# as.mo("staaur") 8.5 8.7 15 8.9 9.6 67 +# as.mo("STAAUR") 8.6 8.7 14 9.0 9.9 36 +# as.mo("S. aureus") 23.0 23.0 40 25.0 26.0 180 +# as.mo("S aureus") 23.0 24.0 30 26.0 30.0 51 +# as.mo("Staphylococcus aureus") 28.0 28.0 31 29.0 29.0 51 +# as.mo("Staphylococcus aureus (MRSA)") 570.0 600.0 620 620.0 640.0 710 +# as.mo("Sthafilokkockus aaureuz") 280.0 310.0 320 320.0 330.0 340 +# as.mo("MRSA") 8.4 8.6 11 8.8 9.5 35 +# as.mo("VISA") 19.0 19.0 21 20.0 22.0 24 +# as.mo("VRSA") 19.0 19.0 27 23.0 41.0 46 +# as.mo(22242419) 18.0 18.0 22 21.0 22.0 43 +# neval +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 10 +# 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 Methanosarcina semesiae (B_MTHNSR_SEMS), a bug probably never found before in humans:

@@ -260,19 +260,19 @@ times = 10) print(M.semesiae, unit = "ms", signif = 4) # Unit: milliseconds -# expr min lq mean median uq -# as.mo("metsem") 1201.00 1327.00 1331.00 1340.00 1359.00 -# as.mo("METSEM") 1255.00 1298.00 1333.00 1340.00 1363.00 -# as.mo("M. semesiae") 1927.00 1943.00 1985.00 1995.00 2014.00 -# as.mo("M. semesiae") 1914.00 1953.00 1979.00 1977.00 1987.00 -# as.mo("Methanosarcina semesiae") 27.84 30.71 31.59 31.12 31.44 +# expr min lq mean median uq +# as.mo("metsem") 1310.00 1340.0 1361.00 1358 1387.00 +# as.mo("METSEM") 1304.00 1320.0 1350.00 1341 1382.00 +# as.mo("M. semesiae") 1839.00 1968.0 1990.00 2006 2032.00 +# as.mo("M. semesiae") 1947.00 1978.0 2014.00 2019 2046.00 +# as.mo("Methanosarcina semesiae") 30.49 31.2 35.04 32 32.81 # max neval -# 1371.00 10 -# 1398.00 10 -# 2040.00 10 -# 2058.00 10 -# 39.75 10 -

That takes 15.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. Full names (like Methanosarcina semesiae) are almost fast - these are the most probable input from most data sets.

+# 1401.00 10 +# 1411.00 10 +# 2049.00 10 +# 2088.00 10 +# 63.03 10 +

That takes 15.2 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 Methanosarcina semesiae) 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 Methanosarcina semesiae (which is uncommon):

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:

@@ -309,8 +309,8 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# mo_name(x) 610 637 653 652 668 718 10 -

So transforming 500,000 values (!!) of 50 unique values only takes 0.65 seconds (652 ms). You only lose time on your unique input values.

+# mo_name(x) 598 639 656 657 671 735 10 +

So transforming 500,000 values (!!) of 50 unique values only takes 0.66 seconds (657 ms). You only lose time on your unique input values.

@@ -322,10 +322,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) # Unit: milliseconds -# expr min lq mean median uq max neval -# A 6.280 6.560 9.940 6.720 6.860 39.30 10 -# B 22.500 22.900 24.300 23.000 24.900 30.90 10 -# C 0.805 0.829 0.871 0.847 0.869 1.09 10

+# expr min lq mean median uq max neval +# A 6.150 6.340 9.110 6.370 6.400 33.700 10 +# B 22.000 22.200 22.900 22.300 22.400 28.300 10 +# C 0.691 0.784 0.783 0.795 0.802 0.814 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"),
@@ -339,14 +339,14 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #  expr   min    lq  mean median    uq   max neval
-#     A 0.456 0.457 0.472  0.465 0.493 0.498    10
-#     B 0.629 0.640 0.713  0.668 0.752 0.956    10
-#     C 0.798 0.811 0.840  0.832 0.840 0.965    10
-#     D 0.428 0.453 0.473  0.464 0.503 0.518    10
-#     E 0.446 0.477 0.513  0.495 0.525 0.648    10
-#     F 0.466 0.473 0.496  0.484 0.521 0.545    10
-#     G 0.457 0.461 0.477  0.468 0.486 0.545    10
-#     H 0.456 0.467 0.478  0.477 0.482 0.512    10
+# A 0.462 0.471 0.480 0.482 0.491 0.498 10 +# B 0.609 0.627 0.645 0.638 0.657 0.714 10 +# C 0.651 0.731 0.771 0.772 0.806 0.887 10 +# D 0.431 0.457 0.488 0.468 0.485 0.675 10 +# E 0.450 0.452 0.466 0.465 0.473 0.500 10 +# F 0.461 0.466 0.481 0.474 0.495 0.514 10 +# G 0.449 0.453 0.465 0.464 0.471 0.495 10 +# H 0.455 0.458 0.481 0.465 0.485 0.594 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.

@@ -373,13 +373,13 @@ print(run_it, unit = "ms", signif = 4) # Unit: milliseconds # expr min lq mean median uq max neval -# en 18.04 18.47 18.79 18.54 19.25 19.70 10 -# de 19.36 19.88 22.78 20.17 20.39 47.73 10 -# nl 24.57 25.38 28.46 25.63 26.12 54.82 10 -# es 19.50 19.89 25.49 20.51 25.79 44.96 10 -# it 19.52 19.82 20.44 20.11 20.80 23.09 10 -# fr 19.50 19.79 20.42 19.86 20.53 23.35 10 -# pt 19.25 19.55 22.50 19.59 20.04 47.50 10
+# en 17.93 18.18 19.34 18.76 19.02 26.27 10 +# de 19.44 19.63 22.03 19.80 20.23 41.83 10 +# nl 24.54 24.78 27.37 25.23 25.55 47.06 10 +# es 19.51 19.94 20.27 20.20 20.55 21.16 10 +# it 19.40 19.67 24.91 19.99 20.90 46.83 10 +# fr 19.24 19.45 22.53 19.80 20.17 47.71 10 +# pt 19.18 19.33 19.87 19.72 20.62 20.75 10

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

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png index 6d9e642b..b5d4e836 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index 62be83e0..86a14d05 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png index 92b0e416..73afb918 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index deda88cf..2eb61aec 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079 diff --git a/docs/authors.html b/docs/authors.html index 237e888f..7c2b5617 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079 diff --git a/docs/index.html b/docs/index.html index 8a42b888..72e64c5a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079 diff --git a/docs/news/index.html b/docs/news/index.html index 4dcb1e4a..fddc477d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079 @@ -225,11 +225,11 @@ -
+

-AMR 0.7.1.9078 Unreleased +AMR 0.7.1.9079 Unreleased

-

Last updated: 20-Sep-2019

+

Last updated: 22-Sep-2019

Breaking

@@ -1267,7 +1267,7 @@ Using as.mo(..., allow_uncertain = 3)

Contents

diff --git a/docs/reference/index.html b/docs/reference/index.html index 715ce24a..8a606c57 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9078 + 0.7.1.9079
diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html index 6b99d88c..320b68dd 100644 --- a/docs/reference/microorganisms.html +++ b/docs/reference/microorganisms.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9076 + 0.7.1.9079
diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index f5f1a7c1..efe269bb 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9077 + 0.7.1.9079 diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd index 9cb03535..f48f3ead 100755 --- a/vignettes/benchmarks.Rmd +++ b/vignettes/benchmarks.Rmd @@ -149,8 +149,8 @@ boxplot(microbenchmark( 'as.mo("P. brevis")' = as.mo("P. brevis", force_mo_history = TRUE), 'as.mo("E. coli")' = as.mo("E. coli", force_mo_history = TRUE), times = 10), - horizontal = TRUE, las = 1, unit = "s", log = FALSE, - xlab = "", ylab = "Time in seconds", + horizontal = TRUE, las = 1, unit = "s", log = TRUE, + xlab = "", ylab = "Time in seconds (log)", main = "Benchmarks per prevalence") ```