diff --git a/R/mo.R b/R/mo.R index 3d44c66c..09be7250 100755 --- a/R/mo.R +++ b/R/mo.R @@ -219,7 +219,6 @@ 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) @@ -267,9 +266,12 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, 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! + # we need special treatment for very 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(x %in% microorganismsDT[prevalence == 2, "fullname"][[1]])) { + # same for common full names, they are also likely + x <- microorganismsDT[prevalence == 2][data.table(fullname = x), on = "fullname", ..property][[1]] } else if (all(toupper(x) %in% microorganisms.codes[, "code"])) { # commonly used MO codes diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index b0b78828..7515f28e 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -327,52 +327,52 @@
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,50 +423,48 @@
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")
-#> [1] "is any"
-#> [1] "is any"
+#>
+#> Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
#>
-#> 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)
+#> 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 (1291 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 (2705 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,376 out of 20,000 rows
+#> -> added 0 test results
+#> -> changed 3,996 test results (0 to S; 0 to I; 3,996 to R)
data <- data %>%
mutate(gramstain = mo_gramstain(bacteria),
genus = mo_genus(bacteria),
- species = mo_species(bacteria))
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
For future use, the above two syntaxes can be shortened with the filter_first_isolate()
function:
isolate | @@ -662,11 +654,11 @@|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-04-19 | -S8 | +2010-01-24 | +A4 | B_ESCHR_COL | -S | -S | +R | +R | S | S | TRUE | @@ -674,46 +666,46 @@|||
2 | -2010-08-08 | -S8 | +2010-03-30 | +A4 | B_ESCHR_COL | -S | I | S | +R | S | FALSE | -FALSE | +TRUE | ||
3 | -2010-10-31 | -S8 | +2010-07-21 | +A4 | B_ESCHR_COL | -R | -I | -R | +S | +S | +S | S | FALSE | TRUE | |
4 | -2010-11-11 | -S8 | +2010-09-23 | +A4 | B_ESCHR_COL | S | -I | -R | -R | +S | +S | +S | +FALSE | FALSE | -TRUE |
5 | -2011-04-04 | -S8 | +2010-10-05 | +A4 | B_ESCHR_COL | -S | +R | S | S | S | @@ -722,47 +714,47 @@|||||
6 | -2011-05-22 | -S8 | +2010-10-26 | +A4 | B_ESCHR_COL | -S | -S | -S | -S | -TRUE | -TRUE | -||||
7 | -2011-08-15 | -S8 | -B_ESCHR_COL | -I | R | S | S | +S | FALSE | +FALSE | +|||||
7 | +2011-02-03 | +A4 | +B_ESCHR_COL | +S | +S | +S | +S | +TRUE | TRUE | ||||||
8 | -2011-08-20 | -S8 | +2011-02-16 | +A4 | B_ESCHR_COL | -S | -S | +R | S | R | +S | FALSE | TRUE | ||
9 | -2011-08-25 | -S8 | +2011-04-19 | +A4 | B_ESCHR_COL | S | -S | +R | S | S | FALSE | @@ -770,23 +762,23 @@||||
10 | -2011-12-16 | -S8 | +2011-05-17 | +A4 | B_ESCHR_COL | -S | -S | R | +R | +S | S | FALSE | TRUE |
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.
+Instead of 2, now 8 isolates are flagged. In total, 79.7% of all isolates are marked ‘first weighted’ - 51.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:
So we end up with 15,865 isolates for analysis.
+So we end up with 15,939 isolates for analysis.
We can remove unneeded columns:
@@ -812,28 +804,28 @@Time for the analysis!
@@ -923,9 +915,9 @@Or can be used like the dplyr
way, which is easier readable:
Frequency table of genus
and species
from a data.frame
(15,865 x 13)
Frequency table of genus
and species
from a data.frame
(15,939 x 13)
Columns: 2
-Length: 15,865 (of which NA: 0 = 0.00%)
+Length: 15,939 (of which NA: 0 = 0.00%)
Unique: 4
Shortest: 16
Longest: 24
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:
Or can be used in conjuction with group_by()
and summarise()
, both from the dplyr
package:
data_1st %>%
group_by(hospital) %>%
@@ -992,19 +984,19 @@ Longest: 24
Hospital A
-0.4644901
+0.4616191
Hospital B
-0.4754156
+0.4714054
Hospital C
-0.4927721
+0.4865089
Hospital D
-0.4793125
+0.4703324
@@ -1022,23 +1014,23 @@ Longest: 24
Hospital A
-0.4644901
-4717
+0.4616191
+4768
Hospital B
-0.4754156
-5654
+0.4714054
+5543
Hospital C
-0.4927721
-2352
+0.4865089
+2409
Hospital D
-0.4793125
-3142
+0.4703324
+3219
@@ -1058,27 +1050,27 @@ Longest: 24
Escherichia
-0.7249656
-0.8993624
-0.9729966
+0.7251397
+0.9020484
+0.9738051
Klebsiella
-0.7336418
-0.9035030
-0.9801718
+0.7305965
+0.8941629
+0.9737011
Staphylococcus
-0.7261538
-0.9179487
-0.9789744
+0.7174472
+0.9217705
+0.9804426
Streptococcus
-0.7382797
+0.7437474
0.0000000
-0.7382797
+0.7437474
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 1fd60fa7..b6f8a3eb 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 984c4d91..bc660051 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 9b07fca2..847dd9de 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 82246e78..6847eec7 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 a8905be0..dea88275 100644
--- a/docs/articles/WHONET.html
+++ b/docs/articles/WHONET.html
@@ -231,7 +231,6 @@
No errors or warnings, so all values are transformed succesfully. Let’s check it though, with a couple of frequency tables:
-[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 8f718c6f..9564482c 100644
--- a/docs/articles/benchmarks.html
+++ b/docs/articles/benchmarks.html
@@ -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") 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"),
@@ -237,13 +237,13 @@
print(M.leonicaptivi, unit = "ms", signif = 3)
#> Unit: milliseconds
#> expr min lq mean median uq max neval
-#> 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.
+#> as.mo("myle") 136 137 141 137 138 176 10 +#> as.mo("mycleo") 447 464 484 487 490 551 10 +#> as.mo("M. leonicaptivi") 206 208 225 210 248 252 10 +#> as.mo("M. leonicaptivi") 207 208 230 229 251 255 10 +#> as.mo("MYCLEO") 444 446 462 446 486 487 10 +#> as.mo("Mycoplasma leonicaptivi") 147 148 170 173 187 192 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.
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,21 +280,11 @@
# now let's see:
run_it <- microbenchmark(mo_fullname(x),
times = 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
-#> 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.
+print(run_it, unit = "ms", signif = 3) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> mo_fullname(x) 615 647 698 649 801 851 10 +So transforming 500,000 values (!) of 95 unique values only takes 0.65 seconds (649 ms). You only lose time on your unique input values.
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"),
@@ -333,14 +313,14 @@
print(run_it, unit = "ms", signif = 3)
#> Unit: milliseconds
#> expr min lq mean median uq max neval
-#> 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.
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 cd0b6c3f..9a89bdc9 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 15e5cc33..2ef2ffe9 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -305,9 +305,7 @@ filter(mo_gramstain(mo) == "Gram positive") %>% resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE) %>% ggplot_rsi_predict() -#> [1] "is any" -#> [1] "is any" -#> NOTE: Using column `date` as input for `col_date`. +#> 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.
This seems more likely, doesn’t it?
The model itself is also available from the object, as an attribute
: