diff --git a/DESCRIPTION b/DESCRIPTION index 5b13cd75..4c3603da 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.5.0.9018 -Date: 2019-02-22 +Date: 2019-02-23 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/R/mo.R b/R/mo.R index ecf598ae..2c23109f 100755 --- a/R/mo.R +++ b/R/mo.R @@ -84,7 +84,6 @@ #' \itemize{ #' \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRB}) needs review.} #' \item{\code{"S. aureus - please mind: MRSA"}. The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result \emph{Staphylococcus aureus} (\code{B_STPHY_AUR}) needs review.} -#' \item{\code{"D. spartina"}. This is the abbreviation of an old taxonomic name: \emph{Didymosphaeria spartinae} (the last "e" was missing from the input). This fungus was renamed to \emph{Leptosphaeria obiones}, so a warning will be thrown that this result (\code{F_LPTSP_OBI}) needs review.} #' \item{\code{"Fluoroquinolone-resistant Neisseria gonorrhoeae"}. The first word will be stripped, after which the function will try to find a match. A warning will be thrown that the result \emph{Neisseria gonorrhoeae} (\code{B_NESSR_GON}) needs review.} #' } #' @@ -156,6 +155,7 @@ #' mutate(mo = as.mo(paste(genus, species))) #' } as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, reference_df = get_mo_source()) { + # will be checked for mo class in validation mo <- mo_validate(x = x, property = "mo", Becker = Becker, Lancefield = Lancefield, allow_uncertain = allow_uncertain, reference_df = reference_df) @@ -170,7 +170,7 @@ is.mo <- function(x) { #' @importFrom dplyr %>% pull left_join n_distinct progress_estimated filter #' @importFrom data.table data.table as.data.table setkey -#' @importFrom crayon magenta red silver italic has_color +#' @importFrom crayon magenta red blue silver italic has_color exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, reference_df = get_mo_source(), property = "mo", clear_options = TRUE) { @@ -210,12 +210,12 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, uncertainties <- character(0) failures <- character(0) x_input <- x + x <- trimws(x, which = "both") # only check the uniques, which is way faster x <- unique(x) # remove empty values (to later fill them in again with NAs) x <- x[!is.na(x) & !is.null(x) & !identical(x, "")] - # conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life) if (any(x %like% "^[BFP]_[A-Z]{3,7}")) { leftpart <- gsub("^([BFP]_[A-Z]{3,7}).*", "\\1", x) @@ -271,7 +271,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } else if (!all(x %in% microorganismsDT[[property]])) { - x_backup <- trimws(x, which = "both") + x_backup <- x # trimws(x, which = "both") # remove spp and species x <- trimws(gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x_backup, ignore.case = TRUE), which = "both") @@ -323,6 +323,13 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, progress$tick()$print() + found <- microorganismsDT[mo == toupper(x_backup[i]), ..property][[1]] + # is a valid MO code + if (length(found) > 0) { + x[i] <- found[1L] + next + } + if (tolower(x_trimmed[i]) %in% c("", "xxx", "other", "none", "unknown")) { # empty and nonsense values, ignore without warning ("xxx" is WHONET code for 'no growth') x[i] <- NA_character_ @@ -510,11 +517,11 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, return(found[1L]) } - found <- data_to_check[mo == toupper(a.x_backup), ..property][[1]] - # is a valid mo - if (length(found) > 0) { - return(found[1L]) - } + # found <- data_to_check[mo == toupper(a.x_backup), ..property][[1]] + # # is a valid mo + # if (length(found) > 0) { + # return(found[1L]) + # } found <- data_to_check[tolower(fullname) == tolower(c.x_trimmed_without_group), ..property][[1]] if (length(found) > 0) { return(found[1L]) @@ -872,7 +879,7 @@ TEMPORARY_TAXONOMY <- function(x) { x } -#' @importFrom crayon blue italic +#' @importFrom crayon italic was_renamed <- function(name_old, name_new, ref_old = "", ref_new = "", mo = "") { if (!is.na(ref_old)) { ref_old <- paste0(" (", ref_old, ")") diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index f9e3bbcb..d95f132e 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -192,7 +192,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

@@ -201,7 +201,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 RMarkdown. However, the methodology remains unchanged. This page was generated on 22 February 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 RMarkdown. However, the methodology remains unchanged. This page was generated on 23 February 2019.

Introduction

@@ -217,21 +217,21 @@ -2019-02-22 +2019-02-23 abcd Escherichia coli S S -2019-02-22 +2019-02-23 abcd Escherichia coli S R -2019-02-22 +2019-02-23 efgh Escherichia coli R @@ -327,70 +327,70 @@ -2014-11-25 -O2 -Hospital D -Escherichia coli -R -S -R -S -F - - -2016-11-18 -I10 +2011-09-14 +N3 Hospital B Escherichia coli -R S -R +S +S S M - -2014-08-15 -G9 -Hospital D -Staphylococcus aureus + +2011-01-09 +I3 +Hospital A +Escherichia coli R S S S M - -2017-07-26 -S2 -Hospital B -Staphylococcus aureus + +2015-06-02 +E8 +Hospital A +Streptococcus pneumoniae +R S R S +M + + +2011-02-06 +S1 +Hospital D +Escherichia coli +S +S +S S F -2017-01-25 -H5 +2010-01-27 +N7 Hospital C Escherichia coli R +I +R S -S -S -M +F -2017-03-12 -B9 -Hospital C +2017-08-11 +U3 +Hospital B Escherichia coli S S S S -M +F @@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,377 51.9% 10,377 51.9% -#> 2 F 9,623 48.1% 20,000 100.0% +#> 1 M 10,364 51.8% 10,364 51.8% +#> 2 F 9,636 48.2% 20,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M and F. From a researcher 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 %>%
@@ -443,10 +443,10 @@
 #> Kingella kingae (no changes)
 #> 
 #> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1284 changes)
+#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1334 changes)
 #> Table 2:  Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
 #> Table 3:  Intrinsic resistance in other Gram-negative bacteria (no changes)
-#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2790 changes)
+#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2731 changes)
 #> Table 8:  Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
 #> Table 9:  Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
 #> Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)
@@ -462,9 +462,9 @@
 #> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
 #> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
 #> 
-#> => EUCAST rules affected 7,321 out of 20,000 rows
+#> => EUCAST rules affected 7,419 out of 20,000 rows
 #>    -> added 0 test results
-#>    -> changed 4,074 test results (0 to S; 0 to I; 4,074 to R)
+#> -> changed 4,065 test results (0 to S; 0 to I; 4,065 to R)

@@ -489,8 +489,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,680 first isolates (28.4% of total)

-

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

+#> => Found 5,667 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:

@@ -516,10 +516,10 @@ 1 -2010-01-10 -X9 +2010-02-08 +H1 B_ESCHR_COL -R +S S S S @@ -527,43 +527,43 @@ 2 -2010-04-18 -X9 +2010-04-06 +H1 B_ESCHR_COL R -I +S S S FALSE 3 -2010-07-02 -X9 +2010-04-25 +H1 B_ESCHR_COL +S R S -S -S +R FALSE 4 -2010-09-21 -X9 +2010-10-05 +H1 B_ESCHR_COL -R +I +S S R -S FALSE 5 -2010-09-22 -X9 +2010-11-09 +H1 B_ESCHR_COL -R +S S S S @@ -571,59 +571,59 @@ 6 -2010-10-06 -X9 +2010-11-23 +H1 B_ESCHR_COL +R S -S -S +R S FALSE 7 -2010-10-14 -X9 +2010-12-26 +H1 B_ESCHR_COL R -S +I S S FALSE 8 -2011-01-09 -X9 +2011-01-01 +H1 B_ESCHR_COL S -I S -R +S +S FALSE 9 -2011-03-31 -X9 +2011-01-21 +H1 B_ESCHR_COL R +I +S +S +FALSE + + +10 +2011-02-28 +H1 +B_ESCHR_COL +S S S S TRUE - -10 -2011-03-31 -X9 -B_ESCHR_COL -S -S -R -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.

@@ -637,7 +637,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,854 first weighted isolates (79.3% of total) +#> => Found 15,851 first weighted isolates (79.3% of total) @@ -654,10 +654,10 @@ - - + + - + @@ -666,47 +666,47 @@ - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -714,23 +714,23 @@ - - + + + - - + - - + + - + @@ -738,47 +738,47 @@ - - + + - - + + - - + + + - - - - - - - - - - - - - + + + + + + + + + + + +
isolate
12010-01-10X92010-02-08H1 B_ESCHR_COLRS S S S
22010-04-18X9B_ESCHR_COLRISSFALSEFALSE
32010-07-02X92010-04-06H1 B_ESCHR_COL R S S S FALSEFALSE
42010-09-21X9B_ESCHR_COLRSRSFALSE TRUE
52010-09-22X932010-04-25H1 B_ESCHR_COLS R SRFALSETRUE
42010-10-05H1B_ESCHR_COLISSRFALSETRUE
52010-11-09H1B_ESCHR_COLSS S S FALSE
62010-10-06X92010-11-23H1 B_ESCHR_COLR SSSR S FALSE TRUE
72010-10-14X92010-12-26H1 B_ESCHR_COL RSI S S FALSE
82011-01-09X92011-01-01H1 B_ESCHR_COL SI SRSS FALSE TRUE
92011-03-31X92011-01-21H1 B_ESCHR_COL RI S SSTRUETRUE
102011-03-31X9B_ESCHR_COLSSRS FALSE TRUE
102011-02-28H1B_ESCHR_COLSSSSTRUETRUE
-

Instead of 2, now 8 isolates are flagged. In total, 79.3% of all isolates are marked ‘first weighted’ - 50.9% 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 2, now 10 isolates are flagged. In total, 79.3% of all isolates are marked ‘first weighted’ - 50.9% 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,854 isolates for analysis.

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -786,7 +786,6 @@
head(data_1st)
- @@ -803,14 +802,13 @@ - - - + + - - + + @@ -819,10 +817,9 @@ - - - - + + + @@ -835,67 +832,63 @@ - - - - - - - - + + + + + + + - - - + + + - - - - - - + + + + + - - - + + + - - - - + + + + + + - - - - + - - - + + - + - - - - - + + + + + @@ -915,9 +908,9 @@
freq(paste(data_1st$genus, data_1st$species))

Or can be used like the dplyr way, which is easier readable:

data_1st %>% freq(genus, species)
-

Frequency table of genus and species from a data.frame (15,854 x 13)

+

Frequency table of genus and species from a data.frame (15,851 x 13)

Columns: 2
-Length: 15,854 (of which NA: 0 = 0.00%)
+Length: 15,851 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -934,33 +927,33 @@ Longest: 24

- - - - + + + + - - - - + + + + - - - - + + + + - - - + + + @@ -971,7 +964,7 @@ Longest: 24

Resistance percentages

The functions portion_R, portion_RI, portion_I, portion_IS and portion_S can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:

data_1st %>% portion_IR(amox)
-#> [1] 0.4726883
+#> [1] 0.4828087

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

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

- + - + - + - +
date patient_id hospital
22016-11-18I102011-09-14N3 Hospital B B_ESCHR_COLR SRSS S M Gram negativeTRUE
52017-01-25H5Hospital C2011-01-09I3Hospital A B_ESCHR_COL R STRUE
62017-03-12B9Hospital CB_ESCHR_COLSSS2015-06-02E8Hospital AB_STRPT_PNER SRR MGram negativeEscherichiacoliGram positiveStreptococcuspneumoniae TRUE
72015-08-12Y4Hospital BB_STPHY_AURR2011-02-06S1Hospital DB_ESCHR_COLS S S S FGram positiveStaphylococcusaureusGram negativeEscherichiacoli TRUE
92016-01-24L10Hospital A2010-01-27N7Hospital C B_ESCHR_COLRIR SSSSMF Gram negative Escherichia coli TRUE
122013-09-11H62017-08-11U3 Hospital BB_STPHY_AURB_ESCHR_COL S SR SMGram positiveStaphylococcusaureusSFGram negativeEscherichiacoli TRUE
1 Escherichia coli7,91849.9%7,91849.9%7,80049.2%7,80049.2%
2 Staphylococcus aureus3,93024.8%11,84874.7%4,00825.3%11,80874.5%
3 Streptococcus pneumoniae2,49815.8%14,34690.5%2,44515.4%14,25389.9%
4 Klebsiella pneumoniae1,5089.5%15,8541,59810.1%15,851 100.0%
Hospital A0.47373950.4877378
Hospital B0.47637090.4750000
Hospital C0.47392570.4869240
Hospital D0.46368540.4860406
@@ -1014,23 +1007,23 @@ Longest: 24

Hospital A -0.4737395 -4760 +0.4877378 +4730 Hospital B -0.4763709 -5544 +0.4750000 +5560 Hospital C -0.4739257 -2397 +0.4869240 +2409 Hospital D -0.4636854 -3153 +0.4860406 +3152 @@ -1050,27 +1043,27 @@ Longest: 24

Escherichia -0.7350341 -0.9051528 -0.9761303 +0.7452564 +0.9002564 +0.9765385 Klebsiella -0.7274536 -0.9177719 -0.9781167 +0.7509387 +0.9030038 +0.9724656 Staphylococcus -0.7432570 -0.9216285 -0.9788804 +0.7262974 +0.9224052 +0.9790419 Streptococcus -0.7273819 +0.7325153 0.0000000 -0.7273819 +0.7325153 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 8765e873..84012686 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 139f69f6..f1fcfbaf 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 25e89498..1d936084 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 cb7bf92f..188517e5 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/EUCAST.html b/docs/articles/EUCAST.html index 082df783..dbdfb913 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -192,7 +192,7 @@

How to apply EUCAST rules

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index 0742e808..a9e944e4 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -192,7 +192,7 @@

How to use the G-test

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index e6aea648..dea88275 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -192,7 +192,7 @@

How to work with WHONET data

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/atc_property.html b/docs/articles/atc_property.html index 54772c9d..83d221a5 100644 --- a/docs/articles/atc_property.html +++ b/docs/articles/atc_property.html @@ -192,7 +192,7 @@

How to get properties of an antibiotic

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 7557f953..19c332af 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -192,7 +192,7 @@

Benchmarks

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

@@ -217,14 +217,14 @@ times = 10) print(S.aureus, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> as.mo("sau") 42.9 43.2 43.9 44.0 44.2 45.1 10 -#> as.mo("stau") 86.8 87.0 88.9 87.3 88.2 101.0 10 -#> as.mo("staaur") 42.6 43.6 51.5 43.8 44.5 82.8 10 -#> as.mo("S. aureus") 23.2 23.3 31.0 23.5 23.6 61.8 10 -#> as.mo("S. aureus") 23.1 23.3 26.4 23.7 24.4 51.2 10 -#> as.mo("STAAUR") 42.8 43.4 44.5 44.3 44.5 47.8 10 -#> as.mo("Staphylococcus aureus") 14.3 14.5 20.4 14.8 16.0 64.6 10
+#> expr min lq mean median uq max neval +#> as.mo("sau") 10.4 10.5 10.7 10.6 10.7 11.2 10 +#> as.mo("stau") 84.4 84.7 95.6 85.2 101.0 136.0 10 +#> as.mo("staaur") 10.5 10.6 10.8 10.6 11.1 11.2 10 +#> as.mo("S. aureus") 21.3 21.4 31.4 21.9 41.6 60.3 10 +#> as.mo("S. aureus") 21.3 21.4 21.8 21.4 21.5 24.9 10 +#> as.mo("STAAUR") 10.5 10.6 23.5 10.6 43.8 65.0 10 +#> as.mo("Staphylococcus aureus") 16.1 16.2 20.7 16.4 17.5 57.7 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.

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"),
@@ -237,13 +237,13 @@
 print(M.leonicaptivi, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>                              expr min  lq mean median  uq max neval
-#>                     as.mo("myle") 141 142  162    142 142 299    10
-#>                   as.mo("mycleo") 479 481  520    525 530 634    10
-#>          as.mo("M. leonicaptivi") 241 242  273    263 281 382    10
-#>         as.mo("M.  leonicaptivi") 239 241  268    282 283 299    10
-#>                   as.mo("MYCLEO") 487 520  525    524 528 601    10
-#>  as.mo("Mycoplasma leonicaptivi") 152 156  183    174 200 261    10
-

That takes 7.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.

+#> as.mo("myle") 131 132 132 132 133 133 10 +#> as.mo("mycleo") 439 445 471 481 488 505 10 +#> as.mo("M. leonicaptivi") 202 205 234 243 247 262 10 +#> as.mo("M. leonicaptivi") 202 202 221 212 242 249 10 +#> as.mo("MYCLEO") 441 449 469 480 486 493 10 +#> as.mo("Mycoplasma leonicaptivi") 143 143 165 165 185 190 10 +

That takes 9.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.

In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Mycoplasma leonicaptivi (which is very uncommon):

par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
 
@@ -283,8 +283,8 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>            expr min  lq mean median  uq max neval
-#>  mo_fullname(x) 400 405  463    441 533 558    10
-

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

+#> mo_fullname(x) 618 653 729 695 813 846 10 +

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

@@ -296,10 +296,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> A 39.000 39.80 40.000 40.100 40.300 41.100 10 -#> B 24.400 24.70 25.000 24.900 25.200 25.600 10 -#> C 0.294 0.39 0.422 0.401 0.505 0.535 10

+#> expr min lq mean median uq max neval +#> A 6.460 6.560 6.660 6.650 6.720 6.950 10 +#> B 22.300 22.400 22.700 22.700 22.900 23.000 10 +#> C 0.254 0.263 0.378 0.396 0.413 0.563 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:

run_it <- microbenchmark(A = mo_species("aureus"),
                          B = mo_genus("Staphylococcus"),
@@ -313,14 +313,14 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>  expr   min    lq  mean median    uq   max neval
-#>     A 0.298 0.327 0.398  0.400 0.452 0.535    10
-#>     B 0.251 0.287 0.339  0.344 0.377 0.436    10
-#>     C 0.293 0.403 0.451  0.487 0.500 0.537    10
-#>     D 0.250 0.262 0.300  0.277 0.336 0.395    10
-#>     E 0.249 0.261 0.306  0.313 0.344 0.384    10
-#>     F 0.273 0.283 0.325  0.326 0.338 0.420    10
-#>     G 0.238 0.293 0.312  0.325 0.342 0.356    10
-#>     H 0.250 0.262 0.304  0.316 0.337 0.358    10
+#> A 0.303 0.338 0.414 0.431 0.453 0.550 10 +#> B 0.244 0.282 0.339 0.363 0.372 0.395 10 +#> C 0.302 0.404 0.437 0.430 0.490 0.527 10 +#> D 0.257 0.279 0.315 0.310 0.344 0.378 10 +#> E 0.219 0.270 0.306 0.298 0.355 0.377 10 +#> F 0.248 0.296 0.312 0.317 0.334 0.349 10 +#> G 0.228 0.248 0.287 0.278 0.336 0.367 10 +#> H 0.250 0.255 0.312 0.312 0.352 0.398 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.

@@ -347,13 +347,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> en 10.78 11.11 11.15 11.14 11.30 11.41 10 -#> de 19.60 19.65 23.24 19.76 20.61 52.47 10 -#> nl 19.14 19.71 19.75 19.72 19.87 20.22 10 -#> es 19.64 19.73 28.36 20.60 25.91 64.67 10 -#> it 19.33 19.49 23.13 19.68 19.97 52.72 10 -#> fr 19.43 19.54 20.08 19.72 20.60 21.46 10 -#> pt 19.34 19.66 23.15 19.80 20.48 52.40 10
+#> en 12.45 12.60 15.94 12.66 12.69 45.75 10 +#> de 20.73 20.87 24.50 21.13 21.29 54.54 10 +#> nl 21.02 21.14 24.63 21.22 21.44 54.44 10 +#> es 20.56 21.15 21.46 21.21 22.02 22.39 10 +#> it 20.54 20.80 21.08 20.93 21.19 22.15 10 +#> fr 20.86 21.11 24.55 21.21 21.45 54.12 10 +#> pt 20.74 20.93 28.96 21.17 21.60 66.52 10

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

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 49660c8e..daad2819 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/freq.html b/docs/articles/freq.html index 0e5b2b51..3d5d055a 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -192,7 +192,7 @@

How to create frequency tables

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index 3e17c75c..22ba4aa4 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -192,7 +192,7 @@

How to get properties of a microorganism

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index a67a62ae..2ef2ffe9 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -192,7 +192,7 @@

How to predict antimicrobial resistance

Matthijs S. Berends

-

22 February 2019

+

23 February 2019

diff --git a/docs/reference/as.mo.html b/docs/reference/as.mo.html index eb6a5aab..be279295 100644 --- a/docs/reference/as.mo.html +++ b/docs/reference/as.mo.html @@ -323,7 +323,6 @@ When using allow_uncertain = TRUE (which is the default setting), i

Examples:

Use mo_failures() to get a vector with all values that could not be coerced to a valid value.

diff --git a/man/as.mo.Rd b/man/as.mo.Rd index 0f7bce55..dcf74582 100644 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -91,7 +91,6 @@ Examples: \itemize{ \item{\code{"Streptococcus group B (known as S. agalactiae)"}. The text between brackets will be removed and a warning will be thrown that the result \emph{Streptococcus group B} (\code{B_STRPT_GRB}) needs review.} \item{\code{"S. aureus - please mind: MRSA"}. The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result \emph{Staphylococcus aureus} (\code{B_STPHY_AUR}) needs review.} - \item{\code{"D. spartina"}. This is the abbreviation of an old taxonomic name: \emph{Didymosphaeria spartinae} (the last "e" was missing from the input). This fungus was renamed to \emph{Leptosphaeria obiones}, so a warning will be thrown that this result (\code{F_LPTSP_OBI}) needs review.} \item{\code{"Fluoroquinolone-resistant Neisseria gonorrhoeae"}. The first word will be stripped, after which the function will try to find a match. A warning will be thrown that the result \emph{Neisseria gonorrhoeae} (\code{B_NESSR_GON}) needs review.} }