diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0cb9ad16..f57d3bae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,6 +64,7 @@ R: variables: WARNINGS_ARE_ERRORS: 1 script: + - export WARNINGS_ARE_ERRORS=1 # remove vignettes folder and get VignetteBuilder field out of DESCRIPTION file - rm -rf vignettes - Rscript -e 'd <- read.dcf("DESCRIPTION"); d[, colnames(d) == "VignetteBuilder"] <- NA; write.dcf(d, "DESCRIPTION")' @@ -81,6 +82,7 @@ coverage: allow_failure: true when: on_success only: + - premaster - master script: - apt-get install --yes git diff --git a/DESCRIPTION b/DESCRIPTION index 5c62f9b3..ca95dab4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.5.0.9020 -Date: 2019-02-28 +Date: 2019-03-01 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/R/mo.R b/R/mo.R index a1b38299..f3418b14 100755 --- a/R/mo.R +++ b/R/mo.R @@ -117,6 +117,7 @@ #' @seealso \code{\link{microorganisms}} for the \code{data.frame} that is being used to determine ID's. \cr #' The \code{\link{mo_property}} functions (like \code{\link{mo_genus}}, \code{\link{mo_gramstain}}) to get properties based on the returned code. #' @inheritSection AMR Read more on our website! +#' @importFrom dplyr %>% pull left_join #' @examples #' # These examples all return "B_STPHY_AUR", the ID of S. aureus: #' as.mo("stau") @@ -171,16 +172,28 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, # check onLoad() in R/zzz.R: data tables are created there. } - if (all(x %in% AMR::microorganisms$mo) + if (deparse(substitute(reference_df)) == "get_mo_source()" & isFALSE(Becker) & isFALSE(Lancefield) - & is.null(reference_df)) { + & !is.null(reference_df) + & all(x %in% reference_df[,1])) { + # has valid own reference_df + # (data.table not faster here) + colnames(reference_df)[1] <- "x" + suppressWarnings( + y <- data.frame(x = x, stringsAsFactors = FALSE) %>% + left_join(reference_df, by = "x") %>% + pull("mo") + ) + + } else if (all(x %in% AMR::microorganisms$mo) + & isFALSE(Becker) + & isFALSE(Lancefield)) { y <- x } else if (all(tolower(x) %in% microorganismsDT$fullname_lower) & isFALSE(Becker) - & isFALSE(Lancefield) - & is.null(reference_df)) { + & isFALSE(Lancefield)) { # we need special treatment for very prevalent full names, they are likely! (case insensitive) # e.g. as.mo("Staphylococcus aureus") y <- microorganismsDT[prevalence == 1][data.table(fullname_lower = tolower(x)), diff --git a/R/mo_source.R b/R/mo_source.R index 43a4fd29..4a3ae099 100644 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -52,15 +52,19 @@ #' # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. #' } #' -#' It has now created a file "~/.mo_source.rds" with the contents of our Excel file. It it an R specific format with great compression. +#' It has now created a file "~/.mo_source.rds" with the contents of our Excel file, but only the first column with foreign values and the 'mo' column will be kept. #' #' And now we can use it in our functions: #' \preformatted{ #' as.mo("lab_mo_ecoli") -#' # B_ESCHR_COL +#' [1] B_ESCHR_COL #' #' mo_genus("lab_mo_kpneumoniae") -#' # "Klebsiella" +#' [1] "Klebsiella" +#' +#' # other input values still work too +#' as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli")) +#' [1] B_ESCHR_COL B_ESCHR_COL B_ESCHR_COL #' } #' #' If we edit the Excel file to, let's say, this: @@ -78,10 +82,10 @@ #' \preformatted{ #' as.mo("lab_mo_ecoli") #' # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. -#' # B_ESCHR_COL +#' [1] B_ESCHR_COL #' #' mo_genus("lab_Staph_aureus") -#' # "Staphylococcus" +#' [1] "Staphylococcus" #' } #' #' To remove the reference completely, just use any of these: @@ -119,7 +123,9 @@ set_mo_source <- function(path) { valid <- FALSE } else if (!"mo" %in% colnames(df)) { valid <- FALSE - } else if (!all(df$mo %in% AMR::microorganisms$mo)) { + } else if (all(as.data.frame(df)[, 1] == "")) { + valid <- FALSE + } else if (!all(df$mo %in% c("", AMR::microorganisms$mo))) { valid <- FALSE } else if (NCOL(df) < 2) { valid <- FALSE @@ -163,9 +169,11 @@ set_mo_source <- function(path) { stop("File must contain a column with self-defined values and a reference column `mo` with valid values from the `microorganisms` data set.") } + # keep only first two columns, second must be mo if (colnames(df)[1] == "mo") { - # put mo to the end - df <- df %>% select(-"mo", everything(), "mo") + df <- df[, c(2, 1)] + } else { + df <- df[, c(1, 2)] } df <- as.data.frame(df, stringAsFactors = FALSE) diff --git a/appveyor.yml b/appveyor.yml index 2ee5ffa3..6d0eeea6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -55,8 +55,8 @@ on_failure: - 7z a failure.zip *.Rcheck\* - appveyor PushArtifact failure.zip -on_success: - - Rscript -e "library(covr); cc <- package_coverage(); codecov(coverage = cc, token = '50ffa0aa-fee0-4f8b-a11d-8c7edc6d32ca'); cat('Code coverage:', percent_coverage(cc))" +#on_success: +# - Rscript -e "library(covr); cc <- package_coverage(); codecov(coverage = cc, token = '50ffa0aa-fee0-4f8b-a11d-8c7edc6d32ca'); cat('Code coverage:', percent_coverage(cc))" artifacts: - path: '*.Rcheck\**\*.log' diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 31d7506c..ba2b021f 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -192,7 +192,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

28 February 2019

+

01 March 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 28 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 01 March 2019.

Introduction

@@ -217,21 +217,21 @@ -2019-02-28 +2019-03-01 abcd Escherichia coli S S -2019-02-28 +2019-03-01 abcd Escherichia coli S R -2019-02-28 +2019-03-01 efgh Escherichia coli R @@ -327,71 +327,71 @@ -2015-09-11 -C6 +2017-06-13 +Z3 Hospital D -Staphylococcus aureus +Escherichia coli R S S S -M +F -2015-05-10 -N2 -Hospital A +2013-09-13 +A1 +Hospital D Escherichia coli -I -I +R +S S S M -2012-03-06 -C2 -Hospital C -Escherichia coli -R -S -S -S -M - - -2011-11-09 -X3 +2015-06-10 +L8 Hospital B -Staphylococcus aureus -S -S -S -S -F - - -2017-02-01 -O6 -Hospital A -Staphylococcus aureus -R -S +Escherichia coli S R -F +S +S +M -2017-02-26 -X1 +2010-08-05 +A7 Hospital D Klebsiella pneumoniae +R +S +S +S +M + + +2011-08-25 +X4 +Hospital C +Staphylococcus aureus S S S S F + +2011-03-09 +B7 +Hospital D +Escherichia coli +R +S +S +S +M +

Now, let’s start the cleaning and the analysis!

@@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,244 51.2% 10,244 51.2% -#> 2 F 9,756 48.8% 20,000 100.0% +#> 1 M 10,311 51.6% 10,311 51.6% +#> 2 F 9,689 48.4% 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 (1275 changes)
+#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1364 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 (2727 changes)
+#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2659 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,427 out of 20,000 rows
+#> => EUCAST rules affected 7,366 out of 20,000 rows
 #>    -> added 0 test results
-#>    -> changed 4,002 test results (0 to S; 0 to I; 4,002 to R)
+#> -> changed 4,023 test results (0 to S; 0 to I; 4,023 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,650 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:

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

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

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

@@ -516,8 +516,8 @@ 1 -2010-04-26 -H9 +2010-01-14 +K8 B_ESCHR_COL R S @@ -527,10 +527,10 @@ 2 -2010-05-27 -H9 +2010-02-17 +K8 B_ESCHR_COL -S +R S R S @@ -538,19 +538,19 @@ 3 -2010-07-20 -H9 +2010-03-01 +K8 B_ESCHR_COL -R -I S S +R +S FALSE 4 -2010-11-25 -H9 +2010-03-11 +K8 B_ESCHR_COL S S @@ -560,54 +560,54 @@ 5 -2011-01-19 -H9 +2010-04-13 +K8 B_ESCHR_COL +R S -S -S -S +R +R FALSE 6 -2011-01-24 -H9 +2010-08-30 +K8 B_ESCHR_COL S S -S +R S FALSE 7 -2011-03-09 -H9 +2010-11-05 +K8 B_ESCHR_COL -R S -R +S +S S FALSE 8 -2011-06-07 -H9 +2010-12-21 +K8 B_ESCHR_COL S S S S -TRUE +FALSE 9 -2011-07-30 -H9 +2010-12-21 +K8 B_ESCHR_COL -S +R S S S @@ -615,14 +615,14 @@ 10 -2011-08-01 -H9 +2011-03-20 +K8 B_ESCHR_COL S S +R S -S -FALSE +TRUE @@ -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,814 first weighted isolates (79.1% of total) +#> => Found 15,738 first weighted isolates (78.7% of total) @@ -654,8 +654,8 @@ - - + + @@ -666,10 +666,10 @@ - - + + - + @@ -678,20 +678,20 @@ - - + + - - + + - - + + @@ -702,83 +702,83 @@ - - + + + - - - - + + + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - + - + - - + + + - - - + +
isolate
12010-04-26H92010-01-14K8 B_ESCHR_COL R S
22010-05-27H92010-02-17K8 B_ESCHR_COLSR S R S
32010-07-20H92010-03-01K8 B_ESCHR_COLRI S SRS FALSE TRUE
42010-11-25H92010-03-11K8 B_ESCHR_COL S S
52011-01-19H92010-04-13K8 B_ESCHR_COLR SSSSFALSERR FALSETRUE
62011-01-24H92010-08-30K8 B_ESCHR_COL S SSR S FALSEFALSETRUE
72011-03-09H92010-11-05K8 B_ESCHR_COLR SRSS S FALSE TRUE
82011-06-07H92010-12-21K8 B_ESCHR_COL S S S STRUETRUEFALSEFALSE
92011-07-30H92010-12-21K8 B_ESCHR_COLSR S S S FALSEFALSETRUE
102011-08-01H92011-03-20K8 B_ESCHR_COL S SR SSFALSEFALSETRUETRUE
-

Instead of 2, now 6 isolates are flagged. In total, 79.1% of all isolates are marked ‘first weighted’ - 50.8% 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 9 isolates are flagged. In total, 78.7% of all isolates are marked ‘first weighted’ - 50.5% 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,814 isolates for analysis.

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -804,24 +804,72 @@ 1 -2015-09-11 -C6 +2017-06-13 +Z3 Hospital D -B_STPHY_AUR +B_ESCHR_COL +R +S +S +S +F +Gram negative +Escherichia +coli +TRUE + + +3 +2015-06-10 +L8 +Hospital B +B_ESCHR_COL +S +R +S +S +M +Gram negative +Escherichia +coli +TRUE + + +6 +2011-03-09 +B7 +Hospital D +B_ESCHR_COL R S S S M +Gram negative +Escherichia +coli +TRUE + + +8 +2015-03-15 +O1 +Hospital A +B_STPHY_AUR +R +I +S +S +F Gram positive Staphylococcus aureus TRUE - -3 -2012-03-06 -C2 + +9 +2012-09-07 +K5 Hospital C B_ESCHR_COL R @@ -834,65 +882,17 @@ coli TRUE - -4 -2011-11-09 -X3 -Hospital B -B_STPHY_AUR -S -S -S -S -F -Gram positive -Staphylococcus -aureus -TRUE - -6 -2017-02-26 -X1 -Hospital D -B_KLBSL_PNE -R -S -S -S -F -Gram negative -Klebsiella -pneumoniae -TRUE - - -7 -2010-02-15 -P3 -Hospital C -B_STRPT_PNE -S -S -S -R -F -Gram positive -Streptococcus -pneumoniae -TRUE - - -8 -2012-10-20 -H4 +10 +2015-08-09 +R5 Hospital D B_STRPT_PNE S S S R -M +F Gram positive Streptococcus pneumoniae @@ -915,9 +915,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,814 x 13)

+

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

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

Shortest: 16
Longest: 24

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

1 Escherichia coli -7,918 -50.1% -7,918 -50.1% +7,875 +50.0% +7,875 +50.0% 2 Staphylococcus aureus -3,865 -24.4% -11,783 -74.5% +3,897 +24.8% +11,772 +74.8% 3 Streptococcus pneumoniae -2,458 -15.5% -14,241 -90.1% +2,400 +15.2% +14,172 +90.0% 4 Klebsiella pneumoniae -1,573 -9.9% -15,814 +1,566 +10.0% +15,738 100.0% @@ -971,7 +971,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.4762868
+#> [1] 0.4757911

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

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

Hospital A -0.4752371 +0.4800594 Hospital B -0.4825898 +0.4737983 Hospital C -0.4705631 +0.4763514 Hospital D -0.4711928 +0.4724536 @@ -1014,23 +1014,23 @@ Longest: 24

Hospital A -0.4752371 -4745 +0.4800594 +4714 Hospital B -0.4825898 -5514 +0.4737983 +5534 Hospital C -0.4705631 -2344 +0.4763514 +2368 Hospital D -0.4711928 -3211 +0.4724536 +3122 @@ -1050,27 +1050,27 @@ Longest: 24

Escherichia -0.7346552 -0.8993433 -0.9744885 +0.7283810 +0.9015873 +0.9751111 Klebsiella -0.7406230 -0.9020979 -0.9726637 +0.7311622 +0.9157088 +0.9750958 Staphylococcus -0.7322122 -0.9210867 -0.9785252 +0.7251732 +0.9230177 +0.9799846 Streptococcus -0.7135883 +0.7345833 0.0000000 -0.7135883 +0.7345833 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 f5356f1b..e2bd8a99 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 87d6b07b..dc4fe583 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 28e02068..44face47 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 6e6cfd89..0390712c 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 7479f23d..296ccfa7 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -192,7 +192,7 @@

How to apply EUCAST rules

Matthijs S. Berends

-

28 February 2019

+

01 March 2019

diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index 1f505187..7d2bafa2 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

-

28 February 2019

+

01 March 2019

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

How to work with WHONET data

Matthijs S. Berends

-

28 February 2019

+

01 March 2019

diff --git a/docs/articles/atc_property.html b/docs/articles/atc_property.html index b984a7a0..417e88ea 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

-

28 February 2019

+

01 March 2019

diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index a035fb11..151dfbe7 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -192,7 +192,7 @@

Benchmarks

Matthijs S. Berends

-

28 February 2019

+

01 March 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") 16.70 16.80 17.10 16.90 17.20 18.4 10 -#> as.mo("stau") 31.70 31.80 48.90 31.90 73.00 117.0 10 -#> as.mo("staaur") 16.70 16.80 23.10 16.90 17.90 76.0 10 -#> as.mo("STAAUR") 16.80 17.00 33.20 18.20 56.00 58.6 10 -#> as.mo("S. aureus") 24.60 24.70 29.00 24.70 25.30 65.8 10 -#> as.mo("S. aureus") 24.60 24.70 29.20 24.80 25.10 67.4 10 -#> as.mo("Staphylococcus aureus") 7.02 7.11 7.73 7.26 7.33 11.9 10
+#> expr min lq mean median uq max neval +#> as.mo("sau") 16.6 16.70 25.10 16.70 18.30 58.00 10 +#> as.mo("stau") 31.8 31.90 36.20 31.90 31.90 74.90 10 +#> as.mo("staaur") 16.7 16.80 30.70 16.90 57.80 72.20 10 +#> as.mo("STAAUR") 16.7 16.70 16.80 16.80 16.80 17.30 10 +#> as.mo("S. aureus") 24.6 24.70 33.60 24.70 25.00 70.40 10 +#> as.mo("S. aureus") 24.6 24.70 29.10 24.70 24.80 67.20 10 +#> as.mo("Staphylococcus aureus") 7.5 7.51 7.67 7.58 7.91 7.97 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"),
@@ -236,12 +236,12 @@
 print(T.islandicus, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>                         expr   min    lq  mean median  uq max neval
-#>              as.mo("theisl") 262.0 292.0 296.0  304.0 310 312    10
-#>              as.mo("THEISL") 261.0 263.0 286.0  288.0 307 311    10
-#>       as.mo("T. islandicus") 142.0 143.0 164.0  165.0 184 187    10
-#>      as.mo("T.  islandicus") 142.0 143.0 170.0  163.0 192 229    10
-#>  as.mo("Thermus islandicus")  67.7  68.1  94.3   89.4 117 132    10
-

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

+#> as.mo("theisl") 262.0 264.0 297.0 306 310 376 10 +#> as.mo("THEISL") 262.0 265.0 292.0 290 308 355 10 +#> as.mo("T. islandicus") 142.0 142.0 161.0 148 185 186 10 +#> as.mo("T. islandicus") 141.0 142.0 184.0 174 188 340 10 +#> as.mo("Thermus islandicus") 68.4 68.8 96.3 110 115 125 10 +

That takes 8 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)
 
@@ -287,8 +287,8 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>            expr min  lq mean median  uq  max neval
-#>  mo_fullname(x) 732 739  818    819 837 1040    10
-

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

+#> mo_fullname(x) 723 731 797 785 807 1010 10 +

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

@@ -300,10 +300,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> A 11.100 11.300 11.500 11.500 11.600 11.700 10 -#> B 22.200 22.500 22.800 22.900 23.000 23.500 10 -#> C 0.325 0.566 0.571 0.579 0.599 0.704 10

+#> expr min lq mean median uq max neval +#> A 11.20 11.300 12.100 11.800 12.200 15.500 10 +#> B 22.20 22.700 26.900 23.900 24.200 57.600 10 +#> C 0.53 0.552 0.652 0.591 0.781 0.803 10

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0006 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"),
@@ -317,14 +317,14 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>  expr   min    lq  mean median    uq   max neval
-#>     A 0.308 0.392 0.419  0.406 0.478 0.524    10
-#>     B 0.377 0.406 0.424  0.418 0.442 0.486    10
-#>     C 0.359 0.516 0.580  0.574 0.664 0.730    10
-#>     D 0.266 0.326 0.337  0.342 0.350 0.383    10
-#>     E 0.254 0.281 0.332  0.336 0.359 0.446    10
-#>     F 0.237 0.315 0.329  0.340 0.360 0.374    10
-#>     G 0.261 0.295 0.318  0.323 0.341 0.390    10
-#>     H 0.271 0.290 0.321  0.317 0.343 0.403    10
+#> A 0.318 0.329 0.414 0.431 0.464 0.532 10 +#> B 0.346 0.355 0.414 0.405 0.456 0.528 10 +#> C 0.347 0.357 0.507 0.489 0.608 0.778 10 +#> D 0.280 0.306 0.348 0.343 0.378 0.453 10 +#> E 0.241 0.298 0.333 0.329 0.401 0.408 10 +#> F 0.253 0.295 0.320 0.308 0.330 0.415 10 +#> G 0.271 0.279 0.309 0.284 0.363 0.379 10 +#> H 0.218 0.260 0.328 0.341 0.366 0.426 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.

@@ -351,13 +351,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> en 15.06 15.54 22.29 15.71 31.46 40.83 10 -#> de 23.57 23.91 28.72 24.04 26.24 47.77 10 -#> nl 23.46 23.87 33.14 24.71 45.69 68.77 10 -#> es 23.76 23.98 37.40 24.72 46.85 90.39 10 -#> it 23.98 24.07 30.76 24.49 25.18 67.52 10 -#> fr 24.03 24.04 27.06 24.14 26.51 47.08 10 -#> pt 23.66 24.00 30.90 24.17 25.84 65.76 10
+#> en 15.12 15.39 19.60 15.47 15.63 57.02 10 +#> de 23.37 23.62 24.02 24.01 24.09 25.10 10 +#> nl 23.44 23.94 24.05 24.02 24.14 25.02 10 +#> es 23.71 24.03 28.36 24.08 24.29 65.92 10 +#> it 23.65 23.94 24.08 24.03 24.07 25.12 10 +#> fr 23.94 23.99 32.58 24.17 25.14 66.00 10 +#> pt 23.30 23.63 28.51 24.06 24.78 68.87 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 b9b48285..009e4b61 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 c331ff99..244c9998 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -192,7 +192,7 @@

How to create frequency tables

Matthijs S. Berends

-

28 February 2019

+

01 March 2019

diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index bd11e6dd..10b51035 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

-

28 February 2019

+

01 March 2019

diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index 84fd3e73..e6cd2dd3 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

-

28 February 2019

+

01 March 2019

diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html index b9f19848..e2d9c6bf 100644 --- a/docs/reference/mo_source.html +++ b/docs/reference/mo_source.html @@ -278,12 +278,15 @@ This is the fastest way to have your organisation (or analysis) specific codes p set_mo_source("home/me/ourcodes.xlsx") # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. -

It has now created a file "~/.mo_source.rds" with the contents of our Excel file. It it an R specific format with great compression.

+

It has now created a file "~/.mo_source.rds" with the contents of our Excel file, but only the first column with foreign values and the 'mo' column will be kept.

And now we can use it in our functions:

 as.mo("lab_mo_ecoli")
-# B_ESCHR_COL
+[1] B_ESCHR_COL
     mo_genus("lab_mo_kpneumoniae")
-# "Klebsiella"
+[1] "Klebsiella"
+    # other input values still work too
+as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli"))
+[1] B_ESCHR_COL  B_ESCHR_COL  B_ESCHR_COL
 

If we edit the Excel file to, let's say, this:

   |         A          |      B      |
@@ -297,9 +300,9 @@ as.mo("lab_mo_ecoli")
     

...any new usage of an MO function in this package will update your data:

 as.mo("lab_mo_ecoli")
 # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'.
-# B_ESCHR_COL
+[1] B_ESCHR_COL
     mo_genus("lab_Staph_aureus")
-# "Staphylococcus"
+[1] "Staphylococcus"
 

To remove the reference completely, just use any of these:

 set_mo_source("")
diff --git a/man/mo_source.Rd b/man/mo_source.Rd
index e0fce598..05ca1b4d 100644
--- a/man/mo_source.Rd
+++ b/man/mo_source.Rd
@@ -45,15 +45,19 @@ set_mo_source("home/me/ourcodes.xlsx")
 # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'.
 }
 
-It has now created a file "~/.mo_source.rds" with the contents of our Excel file. It it an R specific format with great compression.
+It has now created a file "~/.mo_source.rds" with the contents of our Excel file, but only the first column with foreign values and the 'mo' column will be kept.
 
 And now we can use it in our functions:
 \preformatted{
 as.mo("lab_mo_ecoli")
-# B_ESCHR_COL
+[1] B_ESCHR_COL
 
 mo_genus("lab_mo_kpneumoniae")
-# "Klebsiella"
+[1] "Klebsiella"
+
+# other input values still work too
+as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli"))
+[1] B_ESCHR_COL  B_ESCHR_COL  B_ESCHR_COL
 }
 
 If we edit the Excel file to, let's say, this:
@@ -71,10 +75,10 @@ If we edit the Excel file to, let's say, this:
 \preformatted{
 as.mo("lab_mo_ecoli")
 # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'.
-# B_ESCHR_COL
+[1] B_ESCHR_COL
 
 mo_genus("lab_Staph_aureus")
-# "Staphylococcus"
+[1] "Staphylococcus"
 }
 
 To remove the reference completely, just use any of these: