diff --git a/DESCRIPTION b/DESCRIPTION index a899b173..45f7ab3e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9078 -Date: 2019-09-20 +Version: 0.7.1.9079 +Date: 2019-09-22 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index d5ce2e45..5b8024ed 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9078 -Last updated: 20-Sep-2019 +# AMR 0.7.1.9079 +Last updated: 22-Sep-2019 ### Breaking * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: diff --git a/R/freq.R b/R/freq.R index 64f740fc..40a0032f 100755 --- a/R/freq.R +++ b/R/freq.R @@ -29,6 +29,7 @@ clean::freq #' @export #' @noRd freq.mo <- function(x, ...) { + x <- as.mo(x) # to get the newest mo codes x_noNA <- x[!is.na(x)] grams <- mo_gramstain(x_noNA, language = NULL) freq.default(x = x, ..., diff --git a/R/globals.R b/R/globals.R index 3ccba949..6e78b141 100755 --- a/R/globals.R +++ b/R/globals.R @@ -46,6 +46,7 @@ globalVariables(c(".", "key_ab_lag", "key_ab_other", "kingdom", + "kingdom_index", "lang", "Last name", "lookup", diff --git a/R/mo.R b/R/mo.R index 222caa16..0348665e 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1721,7 +1721,7 @@ exec_as.mo <- function(x, print(mo_renamed()) } - if (old_mo_warning == TRUE) { + if (old_mo_warning == TRUE & property != "mo") { warning("The input contained old microorganism IDs from previous versions of this package. Please use as.mo() on these old codes.\nSUPPORT FOR THIS WILL BE DROPPED IN A FUTURE VERSION.", call. = FALSE) } diff --git a/R/mo_history.R b/R/mo_history.R index ce38e719..5281aeb5 100644 --- a/R/mo_history.R +++ b/R/mo_history.R @@ -29,6 +29,7 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA if (base::interactive() | force == TRUE) { mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force) + warning_new_write <- FALSE df <- data.frame(x, mo, stringsAsFactors = FALSE) %>% distinct(x, .keep_all = TRUE) %>% filter(!is.na(x) & !is.na(mo)) @@ -55,8 +56,9 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA # if (tryCatch(nrow(getOption("mo_remembered_results")), error = function(e) 1001) > 1000) { # return(base::invisible()) # } - if (is.null(mo_hist) & interactive()) { + if (is.null(mo_hist) & interactive() & warning_new_write == FALSE) { message(blue(paste0("NOTE: results are saved to ", mo_history_file(), "."))) + warning_new_write <- TRUE } tryCatch(write.csv(rbind(mo_hist, data.frame( diff --git a/cran-comments.md b/cran-comments.md index ed725dd0..f976f622 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,5 @@ # Version 0.8.0 * A NOTE for having a data directory over 3 MB. This is needed to offer users reference data for the complete taxonomy of microorganisms - one of the most important features of this pacakge. Has been this way since version 0.3.0. -* This package writes lines to `[user library]/AMR/mo_history/mo_history.csv` when using the `as.mo()` function, in the exact same way (and borrowed from) the `extrafont` package on CRAN (version 0.17) writes to the package folder. Users are notified about this and staged install still works. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. See the source code of `set_mo_history()` and `clear_mo_history()`. + +* This package writes lines to `[user library]/AMR/mo_history/mo_history.csv` when using the `as.mo()` function, in the exact same way (and borrowed from) the `extrafont` package on CRAN (version 0.17) writes to their user library package folder. Users are notified about this with a `message()` and staged install on R >= 3.6.0 still works. The CSV file is never newly created or deleted by this package, it only changes this file to improve speed and reliability of the `as.mo()` function. See the source code of `set_mo_history()` and `clear_mo_history()`. diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 5a5d8f45..32d087e6 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 01ea8fe7..46756e10 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ @@ -185,7 +185,7 @@AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 20 September 2019.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 22 September 2019.
So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M
and F
. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.
The data is already quite clean, but we still need to transform some variables. The bacteria
column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate()
function of the dplyr
package makes this really easy:
data <- data %>%
@@ -436,14 +436,14 @@
# Pasteurella multocida (no changes)
# Staphylococcus (no changes)
# Streptococcus groups A, B, C, G (no changes)
-# Streptococcus pneumoniae (1,405 values changed)
+# Streptococcus pneumoniae (1,479 values changed)
# Viridans group streptococci (no changes)
#
# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,290 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,275 values changed)
# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
# Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,639 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,756 values changed)
# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
@@ -451,24 +451,24 @@
# Table 13: Interpretive rules for quinolones (no changes)
#
# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,299 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (101 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,209 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (121 values changed)
# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
#
# --------------------------------------------------------------------------
-# EUCAST rules affected 6,427 out of 20,000 rows, making a total of 7,734 edits
+# EUCAST rules affected 6,481 out of 20,000 rows, making a total of 7,840 edits
# => added 0 test results
#
-# => changed 7,734 test results
-# - 99 test results changed from S to I
-# - 4,591 test results changed from S to R
-# - 1,111 test results changed from I to S
-# - 289 test results changed from I to R
-# - 1,622 test results changed from R to S
-# - 22 test results changed from R to I
+# => changed 7,840 test results
+# - 112 test results changed from S to I
+# - 4,739 test results changed from S to R
+# - 1,038 test results changed from I to S
+# - 333 test results changed from I to R
+# - 1,595 test results changed from R to S
+# - 23 test results changed from R to I
# --------------------------------------------------------------------------
#
# Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
So only 28.3% 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:
We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient O6, sorted on date:
+We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient D8, sorted on date:
isolate | @@ -523,21 +523,21 @@||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-29 | -O6 | +2010-02-17 | +D8 | B_ESCHR_COLI | -R | -R | S | S | +S | +R | TRUE |
2 | -2010-04-29 | -O6 | +2010-03-19 | +D8 | B_ESCHR_COLI | -R | +S | S | S | S | @@ -545,8 +545,8 @@||
3 | -2010-08-31 | -O6 | +2010-05-22 | +D8 | B_ESCHR_COLI | S | S | @@ -556,8 +556,8 @@|||||
4 | -2010-09-18 | -O6 | +2010-05-27 | +D8 | B_ESCHR_COLI | S | S | @@ -567,52 +567,52 @@|||||
5 | -2011-03-23 | -O6 | +2010-09-23 | +D8 | B_ESCHR_COLI | S | S | +R | S | -S | -TRUE | +FALSE |
6 | -2011-03-24 | -O6 | +2010-10-27 | +D8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | |
7 | -2011-07-19 | -O6 | +2010-11-04 | +D8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | |
8 | -2011-08-04 | -O6 | +2010-12-12 | +D8 | B_ESCHR_COLI | R | -R | -R | +S | +S | S | FALSE |
9 | -2011-08-15 | -O6 | +2010-12-17 | +D8 | B_ESCHR_COLI | S | S | @@ -622,18 +622,18 @@|||||
10 | -2011-08-22 | -O6 | +2010-12-29 | +D8 | B_ESCHR_COLI | S | 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.
Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics()
function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.
If a column exists with a name like ‘key(…)ab’ the first_isolate()
function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:
data <- data %>%
mutate(keyab = key_antibiotics(.)) %>%
@@ -644,7 +644,7 @@
# NOTE: Using column `patient_id` as input for `col_patient_id`.
# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
# [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 15,041 first weighted isolates (75.2% of total)
isolate | @@ -661,22 +661,22 @@|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-29 | -O6 | +2010-02-17 | +D8 | B_ESCHR_COLI | -R | -R | S | S | +S | +R | TRUE | TRUE |
2 | -2010-04-29 | -O6 | +2010-03-19 | +D8 | B_ESCHR_COLI | -R | +S | S | S | S | @@ -685,20 +685,20 @@|||
3 | -2010-08-31 | -O6 | +2010-05-22 | +D8 | B_ESCHR_COLI | S | S | S | S | FALSE | -TRUE | +FALSE | |
4 | -2010-09-18 | -O6 | +2010-05-27 | +D8 | B_ESCHR_COLI | S | S | @@ -709,56 +709,56 @@||||||
5 | -2011-03-23 | -O6 | +2010-09-23 | +D8 | B_ESCHR_COLI | S | S | +R | S | -S | -TRUE | +FALSE | TRUE |
6 | -2011-03-24 | -O6 | +2010-10-27 | +D8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | FALSE | |
7 | -2011-07-19 | -O6 | +2010-11-04 | +D8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | FALSE | |
8 | -2011-08-04 | -O6 | +2010-12-12 | +D8 | B_ESCHR_COLI | R | -R | -R | +S | +S | S | FALSE | TRUE |
9 | -2011-08-15 | -O6 | +2010-12-17 | +D8 | B_ESCHR_COLI | S | S | @@ -769,23 +769,23 @@||||||
10 | -2011-08-22 | -O6 | +2010-12-29 | +D8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | -FALSE | +TRUE |
Instead of 2, now 6 isolates are flagged. In total, 75.2% of all isolates are marked ‘first weighted’ - 47% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
+Instead of 1, now 6 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 47.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
As with filter_first_isolate()
, there’s a shortcut for this new algorithm too:
So we end up with 15,041 isolates for analysis.
+So we end up with 15,076 isolates for analysis.
We can remove unneeded columns:
@@ -810,10 +810,10 @@Frequency table
Class: character
-Length: 15,041 (of which NA: 0 = 0.00%)
+Length: 15,076 (of which NA: 0 = 0.00%)
Unique: 4
Shortest: 16
Longest: 24
The functions portion_S()
, portion_SI()
, portion_I()
, portion_IR()
and portion_R()
can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()
) and susceptibility as the portion of S and I (portion_SI()
). These functions can be used on their own:
Or can be used in conjuction with group_by()
and summarise()
, both from the dplyr
package:
data_1st %>%
group_by(hospital) %>%
@@ -991,19 +991,19 @@ Longest: 24
Hospital A
-0.4646398
+0.4708452
Hospital B
-0.4578497
+0.4723226
Hospital C
-0.4776586
+0.4660508
Hospital D
-0.4822200
+0.4640650
@@ -1021,23 +1021,23 @@ Longest: 24
Hospital A
-0.4646398
-4539
+0.4708452
+4579
Hospital B
-0.4578497
-5255
+0.4723226
+5257
Hospital C
-0.4776586
-2238
+0.4660508
+2165
Hospital D
-0.4822200
-3009
+0.4640650
+3075
@@ -1057,27 +1057,27 @@ Longest: 24
Escherichia
-0.9236417
-0.8994794
-0.9942598
+0.9246677
+0.8941856
+0.9924802
Klebsiella
-0.8206897
-0.9028213
-0.9868339
+0.8234552
+0.8972257
+0.9892812
Staphylococcus
-0.9228296
-0.9265809
-0.9951768
+0.9210808
+0.9266988
+0.9925094
Streptococcus
-0.6171840
+0.6121475
0.0000000
-0.6171840
+0.6121475
diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png
index 09da251a..bedac351 100644
Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ
diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png
index 65fd4d62..6b80b7f0 100644
Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ
diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png
index 09af4838..051e2127 100644
Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ
diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png
index 075b01d1..870f727c 100644
Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html
index 32ea701b..5bbd3863 100644
--- a/docs/articles/benchmarks.html
+++ b/docs/articles/benchmarks.html
@@ -40,7 +40,7 @@
benchmarks.Rmd
In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.
To achieve this speed, the as.mo
function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Methanosarcina semesiae (B_MTHNSR_SEMS
), a bug probably never found before in humans:
That takes 15.7 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Methanosarcina semesiae) are almost fast - these are the most probable input from most data sets.
+# 1401.00 10 +# 1411.00 10 +# 2049.00 10 +# 2088.00 10 +# 63.03 10 +That takes 15.2 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Methanosarcina semesiae) are almost fast - these are the most probable input from most data sets.
In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Methanosarcina semesiae (which is uncommon):
In reality, the as.mo()
functions learns from its own output to speed up determinations for next times. In above figure, this effect was disabled to show the difference with the boxplot below - when you would use as.mo()
yourself:
So transforming 500,000 values (!!) of 50 unique values only takes 0.65 seconds (652 ms). You only lose time on your unique input values.
+# mo_name(x) 598 639 656 657 671 735 10 +So transforming 500,000 values (!!) of 50 unique values only takes 0.66 seconds (657 ms). You only lose time on your unique input values.
So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0008 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
run_it <- microbenchmark(A = mo_species("aureus"),
B = mo_genus("Staphylococcus"),
@@ -339,14 +339,14 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# A 0.456 0.457 0.472 0.465 0.493 0.498 10
-# B 0.629 0.640 0.713 0.668 0.752 0.956 10
-# C 0.798 0.811 0.840 0.832 0.840 0.965 10
-# D 0.428 0.453 0.473 0.464 0.503 0.518 10
-# E 0.446 0.477 0.513 0.495 0.525 0.648 10
-# F 0.466 0.473 0.496 0.484 0.521 0.545 10
-# G 0.457 0.461 0.477 0.468 0.486 0.545 10
-# H 0.456 0.467 0.478 0.477 0.482 0.512 10
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-11-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png index 6d9e642b..b5d4e836 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index 62be83e0..86a14d05 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png index 92b0e416..73afb918 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index deda88cf..2eb61aec 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 237e888f..7c2b5617 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ diff --git a/docs/index.html b/docs/index.html index 8a42b888..72e64c5a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ diff --git a/docs/news/index.html b/docs/news/index.html index 4dcb1e4a..fddc477d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ @@ -225,11 +225,11 @@ -Last updated: 20-Sep-2019
+Last updated: 22-Sep-2019
as.mo(..., allow_uncertain = 3)
Contents