diff --git a/R/mo.R b/R/mo.R index 2c23109f..3d44c66c 100755 --- a/R/mo.R +++ b/R/mo.R @@ -210,6 +210,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, uncertainties <- character(0) failures <- character(0) x_input <- x + # already strip leading and trailing spaces x <- trimws(x, which = "both") # only check the uniques, which is way faster x <- unique(x) @@ -218,6 +219,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # 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}")) { + print("is any") leftpart <- gsub("^([BFP]_[A-Z]{3,7}).*", "\\1", x) if (any(leftpart %in% names(mo_codes_v0.5.0))) { rightpart <- gsub("^[BFP]_[A-Z]{3,7}(.*)", "\\1", x) @@ -241,8 +243,8 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, ) } + # all empty if (all(identical(trimws(x_input), "") | is.na(x_input))) { - # all empty if (property == "mo") { return(structure(rep(NA_character_, length(x_input)), class = "mo")) } else { @@ -264,6 +266,11 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # existing mo codes when not looking for property "mo", like mo_genus("B_ESCHR_COL") x <- microorganismsDT[data.table(mo = x), on = "mo", ..property][[1]] + } else if (all(x %in% microorganismsDT[prevalence == 1, "fullname"][[1]])) { + # we need special treatment for prevalent full names, they are likely! + # e.g. as.mo("Staphylococcus aureus") + x <- microorganismsDT[prevalence == 1][data.table(fullname = x), on = "fullname", ..property][[1]] + } else if (all(toupper(x) %in% microorganisms.codes[, "code"])) { # commonly used MO codes y <- as.data.table(microorganisms.codes)[data.table(code = toupper(x)), on = "code", ] @@ -271,7 +278,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } else if (!all(x %in% microorganismsDT[[property]])) { - x_backup <- x # trimws(x, which = "both") + x_backup <- x # remove spp and species x <- trimws(gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x_backup, ignore.case = TRUE), which = "both") @@ -517,11 +524,6 @@ 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[tolower(fullname) == tolower(c.x_trimmed_without_group), ..property][[1]] if (length(found) > 0) { return(found[1L]) diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index d95f132e..b0b78828 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -327,70 +327,70 @@ -2011-09-14 -N3 -Hospital B -Escherichia coli -S -S -S -S -M - - -2011-01-09 -I3 +2017-09-14 +X8 Hospital A Escherichia coli -R -S -S -S -M - - -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 + +2011-10-29 +H5 +Hospital D +Streptococcus pneumoniae +S +S +S +S +M + -2010-01-27 -N7 +2013-02-03 +D7 +Hospital D +Streptococcus pneumoniae +S +S +S +S +M + + +2013-01-14 +U1 Hospital C Escherichia coli +S +S +S +R +F + + +2010-02-23 +O7 +Hospital A +Staphylococcus aureus +R +S +S +S +F + + +2010-09-26 +E6 +Hospital D +Klebsiella pneumoniae R I R S -F - - -2017-08-11 -U3 -Hospital B -Escherichia coli -S -S -S -S -F +M @@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,364 51.8% 10,364 51.8% -#> 2 F 9,636 48.2% 20,000 100.0% +#> 1 M 10,391 52.0% 10,391 52.0% +#> 2 F 9,609 48.0% 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 %>%
@@ -423,48 +423,50 @@
 

Finally, we will apply EUCAST rules on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the eucast_rules() function can also apply additional rules, like forcing ampicillin = R when amoxicillin/clavulanic acid = R.

Because the amoxicillin (column amox) and amoxicillin/clavulanic acid (column amcl) in our data were generated randomly, some rows will undoubtedly contain amox = S and amcl = R, which is technically impossible. The eucast_rules() fixes this:

data <- eucast_rules(data, col_mo = "bacteria")
-#> 
-#> Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
+#> [1] "is any"
+#> [1] "is any"
 #> 
-#> EUCAST Clinical Breakpoints (v9.0, 2019)
-#> Enterobacteriales (Order) (no changes)
-#> Staphylococcus (no changes)
-#> Enterococcus (no changes)
-#> Streptococcus groups A, B, C, G (no changes)
-#> Streptococcus pneumoniae (no changes)
-#> Viridans group streptococci (no changes)
-#> Haemophilus influenzae (no changes)
-#> Moraxella catarrhalis (no changes)
-#> Anaerobic Gram positives (no changes)
-#> Anaerobic Gram negatives (no changes)
-#> Pasteurella multocida (no changes)
-#> Campylobacter jejuni and C. coli (no changes)
-#> Aerococcus sanguinicola and A. urinae (no changes)
-#> Kingella kingae (no changes)
-#> 
-#> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-#> 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 (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)
-#> Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
-#> Table 12: Interpretive rules for aminoglycosides (no changes)
-#> Table 13: Interpretive rules for quinolones (no changes)
-#> 
-#> Other rules
-#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes)
-#> Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
-#> Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
-#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes)
-#> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
-#> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
-#> 
-#> => EUCAST rules affected 7,419 out of 20,000 rows
-#>    -> added 0 test results
-#>    -> changed 4,065 test results (0 to S; 0 to I; 4,065 to R)
+#> Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST) +#> +#> EUCAST Clinical Breakpoints (v9.0, 2019) +#> Enterobacteriales (Order) (no changes) +#> Staphylococcus (no changes) +#> Enterococcus (no changes) +#> Streptococcus groups A, B, C, G (no changes) +#> Streptococcus pneumoniae (no changes) +#> Viridans group streptococci (no changes) +#> Haemophilus influenzae (no changes) +#> Moraxella catarrhalis (no changes) +#> Anaerobic Gram positives (no changes) +#> Anaerobic Gram negatives (no changes) +#> Pasteurella multocida (no changes) +#> Campylobacter jejuni and C. coli (no changes) +#> Aerococcus sanguinicola and A. urinae (no changes) +#> Kingella kingae (no changes) +#> +#> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) +#> Table 1: Intrinsic resistance in Enterobacteriaceae (1230 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 (2700 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) +#> Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes) +#> Table 12: Interpretive rules for aminoglycosides (no changes) +#> Table 13: Interpretive rules for quinolones (no changes) +#> +#> Other rules +#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes) +#> Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) +#> Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) +#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) +#> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) +#> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) +#> +#> => EUCAST rules affected 7,267 out of 20,000 rows +#> -> added 0 test results +#> -> changed 3,930 test results (0 to S; 0 to I; 3,930 to R)

@@ -473,7 +475,11 @@ + species = mo_species(bacteria)) +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any"

First isolates

@@ -489,7 +495,7 @@ #> 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,667 first isolates (28.3% of total)
+#> => Found 5,663 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)
@@ -516,8 +522,8 @@ 1 -2010-02-08 -H1 +2010-04-19 +S8 B_ESCHR_COL S S @@ -527,41 +533,41 @@ 2 -2010-04-06 -H1 +2010-08-08 +S8 B_ESCHR_COL -R S +I S S FALSE 3 -2010-04-25 -H1 +2010-10-31 +S8 B_ESCHR_COL -S +R +I R S -R FALSE 4 -2010-10-05 -H1 +2010-11-11 +S8 B_ESCHR_COL +S I -S -S +R R FALSE 5 -2010-11-09 -H1 +2011-04-04 +S8 B_ESCHR_COL S S @@ -571,52 +577,8 @@ 6 -2010-11-23 -H1 -B_ESCHR_COL -R -S -R -S -FALSE - - -7 -2010-12-26 -H1 -B_ESCHR_COL -R -I -S -S -FALSE - - -8 -2011-01-01 -H1 -B_ESCHR_COL -S -S -S -S -FALSE - - -9 -2011-01-21 -H1 -B_ESCHR_COL -R -I -S -S -FALSE - - -10 -2011-02-28 -H1 +2011-05-22 +S8 B_ESCHR_COL S S @@ -624,6 +586,50 @@ S TRUE + +7 +2011-08-15 +S8 +B_ESCHR_COL +I +R +S +S +FALSE + + +8 +2011-08-20 +S8 +B_ESCHR_COL +S +S +S +R +FALSE + + +9 +2011-08-25 +S8 +B_ESCHR_COL +S +S +S +S +FALSE + + +10 +2011-12-16 +S8 +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.

@@ -632,12 +638,14 @@ mutate(keyab = key_antibiotics(.)) %>% mutate(first_weighted = first_isolate(.)) #> NOTE: Using column `bacteria` as input for `col_mo`. -#> 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`. -#> 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,851 first weighted isolates (79.3% of total) +#> [1] "is any" +#> [1] "is any" +#> 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`. +#> 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,865 first weighted isolates (79.3% of total) @@ -654,8 +662,8 @@ - - + + @@ -666,44 +674,44 @@ - - + + - + - + - - + + - + + - - - + + + - - + - - + + @@ -714,23 +722,23 @@ - - + + - - - + + + - - + + - + @@ -738,23 +746,23 @@ - - + + - + - - + + - - + + @@ -762,23 +770,23 @@ - - + + + - - +
isolate
12010-02-08H12010-04-19S8 B_ESCHR_COL S S
22010-04-06H12010-08-08S8 B_ESCHR_COLR SI S S FALSETRUEFALSE
32010-04-25H12010-10-31S8 B_ESCHR_COLSRI R SR FALSE TRUE
42010-10-05H12010-11-11S8 B_ESCHR_COLS ISSR R FALSE TRUE
52010-11-09H12011-04-04S8 B_ESCHR_COL S S
62010-11-23H12011-05-22S8 B_ESCHR_COLR SR SFALSESSTRUE TRUE
72010-12-26H12011-08-15S8 B_ESCHR_COLR IR S S FALSE
82011-01-01H12011-08-20S8 B_ESCHR_COL S S SSR FALSE TRUE
92011-01-21H12011-08-25S8 B_ESCHR_COLRISS S S FALSE
102011-02-28H12011-12-16S8 B_ESCHR_COL S SR SSTRUEFALSE TRUE
-

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.

+

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

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -786,6 +794,7 @@
head(data_1st)
+ @@ -802,43 +811,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - + + @@ -847,29 +827,31 @@ - - + + + - + - - - - - + + + + + - - + + + - - - + + + @@ -877,18 +859,51 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + @@ -908,9 +923,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,851 x 13)

+

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

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

Shortest: 16
Longest: 24

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

- - - - + + + + - - - - + + + + - - - - + + + + - - - + + + @@ -964,7 +979,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.4828087
+#> [1] 0.4755121

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

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

- + - + - + - +
date patient_id hospital
2011-09-14N3Hospital BB_ESCHR_COLSSSSMGram negativeEscherichiacoliTRUE
2011-01-09I3Hospital AB_ESCHR_COLRSSSMGram negativeEscherichiacoliTRUE
2015-06-02E8Hospital A22011-10-29H5Hospital D B_STRPT_PNER SRSS R M Gram positiveTRUE
2011-02-06S132013-02-03D7 Hospital DB_ESCHR_COLB_STRPT_PNE S S SSFGram negativeEscherichiacoliRMGram positiveStreptococcuspneumoniae TRUE
2010-01-27N742013-01-14U1 Hospital C B_ESCHR_COLRIR SSSR F Gram negative EscherichiaTRUE
2017-08-11U3Hospital BB_ESCHR_COLS52010-02-23O7Hospital AB_STPHY_AURR S S S FGram positiveStaphylococcusaureusTRUE
62010-09-26E6Hospital DB_KLBSL_PNERIRSM Gram negativeEscherichiacoliKlebsiellapneumoniaeTRUE
82017-06-19J3Hospital BB_STPHY_AURSSSSMGram positiveStaphylococcusaureus TRUE
1 Escherichia coli7,80049.2%7,80049.2%7,99950.4%7,99950.4%
2 Staphylococcus aureus4,00825.3%11,80874.5%3,90024.6%11,89975.0%
3 Streptococcus pneumoniae2,44515.4%14,25389.9%2,45315.5%14,35290.5%
4 Klebsiella pneumoniae1,59810.1%15,8511,5139.5%15,865 100.0%
Hospital A0.48773780.4644901
Hospital B0.47500000.4754156
Hospital C0.48692400.4927721
Hospital D0.48604060.4793125
@@ -1007,23 +1022,23 @@ Longest: 24

Hospital A -0.4877378 -4730 +0.4644901 +4717 Hospital B -0.4750000 -5560 +0.4754156 +5654 Hospital C -0.4869240 -2409 +0.4927721 +2352 Hospital D -0.4860406 -3152 +0.4793125 +3142 @@ -1043,27 +1058,27 @@ Longest: 24

Escherichia -0.7452564 -0.9002564 -0.9765385 +0.7249656 +0.8993624 +0.9729966 Klebsiella -0.7509387 -0.9030038 -0.9724656 +0.7336418 +0.9035030 +0.9801718 Staphylococcus -0.7262974 -0.9224052 -0.9790419 +0.7261538 +0.9179487 +0.9789744 Streptococcus -0.7325153 +0.7382797 0.0000000 -0.7325153 +0.7382797 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 84012686..1fd60fa7 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 f1fcfbaf..984c4d91 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 1d936084..9b07fca2 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 188517e5..82246e78 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/WHONET.html b/docs/articles/WHONET.html index dea88275..a8905be0 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -231,6 +231,7 @@

No errors or warnings, so all values are transformed succesfully. Let’s check it though, with a couple of frequency tables:

# our newly created `mo` variable
 data %>% freq(mo, nmax = 10)
+

[1] “is any” [1] “is any” [1] “is any”

Frequency table of mo from a data.frame (500 x 54)

Class: mo (character)
Length: 500 (of which NA: 0 = 0.00%)
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 19c332af..8f718c6f 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -217,15 +217,15 @@ times = 10) print(S.aureus, unit = "ms", signif = 3) #> Unit: milliseconds -#> 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.

+#> expr min lq mean median uq max neval +#> as.mo("sau") 12.7 12.7 22.7 13.2 13.5 71.1 10 +#> as.mo("stau") 87.6 87.8 90.2 87.9 90.6 104.0 10 +#> as.mo("staaur") 12.6 12.6 12.8 12.7 12.8 13.6 10 +#> as.mo("S. aureus") 24.0 24.2 32.0 24.5 25.4 63.2 10 +#> as.mo("S. aureus") 24.1 24.1 29.3 24.2 24.6 74.0 10 +#> as.mo("STAAUR") 12.6 12.7 16.6 12.7 12.8 51.5 10 +#> as.mo("Staphylococcus aureus") 13.5 13.5 17.9 13.6 14.5 54.5 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 second input is the only one that has to be looked up thoroughly. All the others are known codes (the first is a WHONET code) or common laboratory codes, or common full organism names like the last one.

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"),
@@ -237,13 +237,13 @@
 print(M.leonicaptivi, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>                              expr min  lq mean median  uq max neval
-#>                     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.

+#> as.mo("myle") 134 135 144 135 138 184 10 +#> as.mo("mycleo") 445 458 479 487 493 500 10 +#> as.mo("M. leonicaptivi") 204 207 224 214 245 248 10 +#> as.mo("M. leonicaptivi") 205 206 223 208 246 250 10 +#> as.mo("MYCLEO") 446 448 480 486 492 529 10 +#> as.mo("Mycoplasma leonicaptivi") 146 149 170 169 191 193 10 +

That takes 9.1 times as much time on average! A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance.

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)
 
@@ -280,11 +280,21 @@
 # now let's see:
 run_it <- microbenchmark(mo_fullname(x),
                          times = 10)
-print(run_it, unit = "ms", signif = 3)
-#> Unit: milliseconds
-#>            expr min  lq mean median  uq max neval
-#>  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.

+#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +print(run_it, unit = "ms", signif = 3) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> mo_fullname(x) 623 641 708 648 822 864 10 +

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

@@ -294,12 +304,22 @@ B = mo_fullname("S. aureus"), C = mo_fullname("Staphylococcus aureus"), times = 10) -print(run_it, unit = "ms", signif = 3) -#> Unit: milliseconds -#> 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

+#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +#> [1] "is any" +print(run_it, unit = "ms", signif = 3) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> A 6.500 6.590 6.710 6.680 6.870 6.900 10 +#> B 24.900 25.000 25.300 25.300 25.500 25.800 10 +#> C 0.259 0.383 0.387 0.395 0.411 0.564 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 +333,14 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>  expr   min    lq  mean median    uq   max neval
-#>     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
+#> A 0.304 0.337 0.393 0.396 0.440 0.513 10 +#> B 0.297 0.304 0.348 0.349 0.380 0.409 10 +#> C 0.312 0.361 0.428 0.427 0.513 0.527 10 +#> D 0.242 0.254 0.302 0.298 0.328 0.414 10 +#> E 0.243 0.296 0.325 0.328 0.348 0.431 10 +#> F 0.237 0.257 0.302 0.322 0.329 0.343 10 +#> G 0.242 0.260 0.306 0.325 0.341 0.345 10 +#> H 0.244 0.283 0.322 0.335 0.360 0.375 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 +367,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> 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
+#> en 14.72 14.90 15.64 15.22 15.27 20.60 10 +#> de 23.41 23.59 27.01 23.69 23.77 57.27 10 +#> nl 23.40 23.58 23.80 23.72 23.83 24.46 10 +#> es 23.18 24.35 37.51 24.80 57.35 58.29 10 +#> it 23.26 23.47 27.11 23.68 24.14 57.07 10 +#> fr 23.37 23.65 27.05 23.76 23.80 57.26 10 +#> pt 23.34 23.47 24.02 23.70 23.86 26.79 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 daad2819..cd0b6c3f 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/resistance_predict.html b/docs/articles/resistance_predict.html index 2ef2ffe9..15e5cc33 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -305,7 +305,9 @@ filter(mo_gramstain(mo) == "Gram positive") %>% resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE) %>% ggplot_rsi_predict() -#> NOTE: Using column `date` as input for `col_date`. +#> [1] "is any" +#> [1] "is any" +#> NOTE: Using column `date` as input for `col_date`.

Vancomycin resistance could be 100% in ten years, but might also stay around 0%.

You can define the model with the model parameter. The default model is a generalised linear regression model using a binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance.

@@ -350,7 +352,9 @@ filter(mo_gramstain(mo) == "Gram positive") %>% resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE, model = "linear") %>% ggplot_rsi_predict() -#> NOTE: Using column `date` as input for `col_date`. +#> [1] "is any" +#> [1] "is any" +#> NOTE: Using column `date` as input for `col_date`.

This seems more likely, doesn’t it?

The model itself is also available from the object, as an attribute:

diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd index 7fea7540..46b94f6a 100755 --- a/vignettes/benchmarks.Rmd +++ b/vignettes/benchmarks.Rmd @@ -52,7 +52,7 @@ S.aureus <- microbenchmark(as.mo("sau"), print(S.aureus, unit = "ms", signif = 3) ``` -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 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 second input is the only one that has to be looked up thoroughly. All the others are known codes (the first is a WHONET code) or common laboratory codes, or common full organism names like the last one. 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: