diff --git a/DESCRIPTION b/DESCRIPTION index b547216b..83c33c5e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.0.9012 -Date: 2019-06-18 +Version: 0.7.0.9013 +Date: 2019-06-22 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 7143a761..fbc28680 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.0.9012 +# AMR 0.7.0.9013 #### New * Function `rsi_df()` to transform a `data.frame` to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions `count_df()` and `portion_df()` to immediately show resistance percentages and number of available isolates: @@ -12,7 +12,7 @@ # 3 Ciprofloxacin SI 0.8381831 1181 # 4 Ciprofloxacin R 0.1618169 228 ``` -* Support for all scientifically published pathotypes of *E. coli* to date. Supported are: +* Support for all scientifically published pathotypes of *E. coli* to date (that we could find). Supported are: * AIEC (Adherent-Invasive *E. coli*) * ATEC (Atypical Entero-pathogenic *E. coli*) @@ -51,9 +51,10 @@ * Fixed a EUCAST rule for Staphylococci, where amikacin resistance would not be inferred from tobramycin * Removed `latest_annual_release` from the `catalogue_of_life_version()` function * Removed antibiotic code `PVM1` from the `antibiotics` data set as this was a duplicate of `PME` -* Fixed bug where not all old taxonomic named would not be printed when using a vector as input for `as.mo()` +* Fixed bug where not all old taxonomic names would be printed, when using a vector as input for `as.mo()` * Manually added *Trichomonas vaginalis* from the kingdom of Protozoa, which is missing from the Catalogue of Life * Small improvements to `plot()` and `barplot()` for MIC and RSI classes +* Allow Catalogue of Life IDs to be coerced by `as.mo()` #### Other * Fixed a note thrown by CRAN tests diff --git a/R/mo.R b/R/mo.R index 2aaaf9ca..d521638b 100755 --- a/R/mo.R +++ b/R/mo.R @@ -148,9 +148,10 @@ #' as.mo("Staphylococcus aureus") #' as.mo("Staphylococcus aureus (MRSA)") #' as.mo("Sthafilokkockus aaureuz") # handles incorrect spelling -#' as.mo("MRSA") # Methicillin Resistant S. aureus -#' as.mo("VISA") # Vancomycin Intermediate S. aureus -#' as.mo("VRSA") # Vancomycin Resistant S. aureus +#' as.mo("MRSA") # Methicillin Resistant S. aureus +#' as.mo("VISA") # Vancomycin Intermediate S. aureus +#' as.mo("VRSA") # Vancomycin Resistant S. aureus +#' as.mo(22242419) # Catalogue of Life ID #' #' # Dyslexia is no problem - these all work: #' as.mo("Ureaplasma urealyticum") @@ -232,11 +233,11 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, & isFALSE(Lancefield)) { y <- x - # } else if (!any(is.na(mo_hist)) - # & isFALSE(Becker) - # & isFALSE(Lancefield)) { - # # check previously found results - # y <- mo_hist + # } else if (!any(is.na(mo_hist)) + # & isFALSE(Becker) + # & isFALSE(Lancefield)) { + # # check previously found results + # y <- mo_hist } else if (all(tolower(x) %in% microorganismsDT$fullname_lower) & isFALSE(Becker) @@ -564,6 +565,17 @@ exec_as.mo <- function(x, next } + found <- microorganismsDT[col_id == x_backup[i], ..property][[1]] + # is a valid Catalogue of Life ID + if (NROW(found) > 0) { + x[i] <- found[1L] + if (initial_search == TRUE) { + set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history) + } + next + } + + # WHONET: xxx = no growth if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) { x[i] <- NA_character_ @@ -642,6 +654,18 @@ exec_as.mo <- function(x, } next } + # support for: + # - AIEC (Adherent-Invasive E. coli) + # - ATEC (Atypical Entero-pathogenic E. coli) + # - DAEC (Diffusely Adhering E. coli) + # - EAEC (Entero-Aggresive E. coli) + # - EHEC (Entero-Haemorrhagic E. coli) + # - EIEC (Entero-Invasive E. coli) + # - EPEC (Entero-Pathogenic E. coli) + # - ETEC (Entero-Toxigenic E. coli) + # - NMEC (Neonatal Meningitis‐causing E. coli) + # - STEC (Shiga-toxin producing E. coli) + # - UPEC (Uropathogenic E. coli) if (toupper(x_backup_without_spp[i]) %in% c("AIEC", "ATEC", "DAEC", "EAEC", "EHEC", "EIEC", "EPEC", "ETEC", "NMEC", "STEC", "UPEC") | x_backup_without_spp[i] %like% "O?(26|103|104|104|111|121|145|157)") { x[i] <- microorganismsDT[mo == 'B_ESCHR_COL', ..property][[1]][1L] @@ -770,7 +794,7 @@ exec_as.mo <- function(x, } } - # FIRST TRY FULLNAMES AND CODES + # FIRST TRY FULLNAMES AND CODES ---- # if only genus is available, return only genus if (all(!c(x[i], x_trimmed[i]) %like% " ")) { found <- microorganismsDT[fullname_lower %in% tolower(c(x_species[i], x_trimmed_species[i])), ..property][[1]] @@ -1465,6 +1489,9 @@ unregex <- function(x) { } get_mo_code <- function(x, property) { + # don't use right now + return(NULL) + if (property == "mo") { unique(x) } else { diff --git a/R/mo_property.R b/R/mo_property.R index e02bdae8..f9a06003 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -279,7 +279,7 @@ mo_ref <- function(x, ...) { #' @export mo_authors <- function(x, ...) { x <- mo_validate(x = x, property = "ref", ...) - # remove last 4 digits and presumably the comma and space that preceeds them + # remove last 4 digits and presumably the comma and space that preceed them x[!is.na(x)] <- gsub(",? ?[0-9]{4}", "", x[!is.na(x)]) suppressWarnings(x) } @@ -303,35 +303,52 @@ mo_rank <- function(x, ...) { #' @export mo_taxonomy <- function(x, language = get_locale(), ...) { x <- AMR::as.mo(x, ...) - base::list(kingdom = mo_kingdom(x, language = language), - phylum = mo_phylum(x, language = language), - class = mo_class(x, language = language), - order = mo_order(x, language = language), - family = mo_family(x, language = language), - genus = mo_genus(x, language = language), - species = mo_species(x, language = language), - subspecies = mo_subspecies(x, language = language)) + base::list(kingdom = AMR::mo_kingdom(x, language = language), + phylum = AMR::mo_phylum(x, language = language), + class = AMR::mo_class(x, language = language), + order = AMR::mo_order(x, language = language), + family = AMR::mo_family(x, language = language), + genus = AMR::mo_genus(x, language = language), + species = AMR::mo_species(x, language = language), + subspecies = AMR::mo_subspecies(x, language = language)) } #' @rdname mo_property #' @export mo_synonyms <- function(x, ...) { - x <- AMR::as.mo(x, ...) - col_id <- AMR::microorganisms[which(AMR::microorganisms$mo == x), "col_id"] - if (is.na(col_id) | !col_id %in% AMR::microorganisms.old$col_id_new) { - return(NULL) + x <- as.mo(x, ...) + IDs <- AMR::mo_property(x = x, property = "col_id", language = NULL) + syns <- lapply(IDs, function(col_id) { + res <- sort(AMR::microorganisms.old[which(AMR::microorganisms.old$col_id_new == col_id), "fullname"]) + if (length(res) == 0) { + NULL + } else { + res + } + }) + if (length(syns) > 1) { + names(syns) <- mo_fullname(x) + syns + } else { + unlist(syns) } - sort(AMR::microorganisms.old[which(AMR::microorganisms.old$col_id_new == col_id), "fullname"]) } #' @rdname mo_property #' @export mo_info <- function(x, language = get_locale(), ...) { x <- AMR::as.mo(x, ...) - c(mo_taxonomy(x, language = language), - list(synonyms = mo_synonyms(x), - url = unname(mo_url(x, open = FALSE)), - ref = mo_ref(x))) + info <- lapply(x, function(y) + c(mo_taxonomy(y, language = language), + list(synonyms = mo_synonyms(y), + url = unname(mo_url(y, open = FALSE)), + ref = mo_ref(y)))) + if (length(info) > 1) { + names(info) <- mo_fullname(x) + info + } else { + info[[1L]] + } } #' @rdname mo_property @@ -350,7 +367,7 @@ mo_url <- function(x, open = FALSE, ...) { NA_character_)) u <- df$url - names(u) <- mo_fullname(mo) + names(u) <- AMR::mo_fullname(mo) if (open == TRUE) { if (length(u) > 1) { warning("only the first URL will be opened, as `browseURL()` only suports one string.") @@ -400,12 +417,15 @@ mo_validate <- function(x, property, ...) { if (!all(x %in% pull(AMR::microorganisms, property)) | Becker %in% c(TRUE, "all") | Lancefield %in% c(TRUE, "all")) { - exec_as.mo(x, property = property, ...) - } else { - if (property == "mo") { - return(structure(x, class = "mo")) - } else { - return(x) - } + x <- exec_as.mo(x, property = property, ...) } + + if (property == "mo") { + return(structure(x, class = "mo")) + } else if (property == "col_id") { + return(as.integer(x)) + } else { + return(x) + } + } diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index 4e187753..db8b7217 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -525,15 +525,19 @@ MOs <- MOs %>% MOs <- MOs %>% arrange(fullname) MOs.old <- MOs.old %>% arrange(fullname) -# save it +# transform MOs <- as.data.frame(MOs, stringsAsFactors = FALSE) MOs.old <- as.data.frame(MOs.old, stringsAsFactors = FALSE) class(MOs$mo) <- "mo" +MOs$col_id <- as.integer(MOs$col_id) +MOs.old$col_id <- as.integer(MOs.old$col_id) +MOs.old$col_id_new <- as.integer(MOs.old$col_id_new) +# save saveRDS(MOs, "microorganisms.rds") saveRDS(MOs.old, "microorganisms.old.rds") -# on the server: +# on the server, do: usethis::use_data(microorganisms, overwrite = TRUE, version = 2) usethis::use_data(microorganisms.old, overwrite = TRUE, version = 2) rm(microorganisms) diff --git a/data/microorganisms.old.rda b/data/microorganisms.old.rda index a62408fd..5d42f9d3 100644 Binary files a/data/microorganisms.old.rda and b/data/microorganisms.old.rda differ diff --git a/data/microorganisms.rda b/data/microorganisms.rda index c27938fa..830db938 100755 Binary files a/data/microorganisms.rda and b/data/microorganisms.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 0f0f5d87..dc6eb7cc 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 9543f9ee..9ec1ab02 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ @@ -192,7 +192,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 18 June 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 June 2019.
Now, let’s start the cleaning and the analysis!
@@ -411,8 +411,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,332 51.7% 10,332 51.7% -# 2 F 9,668 48.3% 20,000 100.0% +# 1 M 10,382 51.9% 10,382 51.9% +# 2 F 9,618 48.1% 20,000 100.0%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 %>%
@@ -442,14 +442,14 @@
# Pasteurella multocida (no new changes)
# Staphylococcus (no new changes)
# Streptococcus groups A, B, C, G (no new changes)
-# Streptococcus pneumoniae (1,428 new changes)
+# Streptococcus pneumoniae (1,472 new changes)
# Viridans group streptococci (no new changes)
#
# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,339 new changes)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,278 new changes)
# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no new changes)
# Table 03: Intrinsic resistance in other Gram-negative bacteria (no new changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,671 new changes)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,802 new changes)
# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no new changes)
# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no new changes)
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no new changes)
@@ -457,24 +457,24 @@
# Table 13: Interpretive rules for quinolones (no new changes)
#
# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,233 new changes)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (92 new changes)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,239 new changes)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (112 new changes)
# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no new changes)
# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no new changes)
# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no new changes)
# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no new changes)
#
# --------------------------------------------------------------------------
-# EUCAST rules affected 6,456 out of 20,000 rows, making a total of 7,763 edits
+# EUCAST rules affected 6,529 out of 20,000 rows, making a total of 7,903 edits
# => added 0 test results
#
-# => changed 7,763 test results
-# - 95 test results changed from S to I
-# - 4,674 test results changed from S to R
-# - 1,070 test results changed from I to S
-# - 305 test results changed from I to R
-# - 1,596 test results changed from R to S
-# - 23 test results changed from R to I
+# => changed 7,903 test results
+# - 117 test results changed from S to I
+# - 4,760 test results changed from S to R
+# - 1,044 test results changed from I to S
+# - 324 test results changed from I to R
+# - 1,642 test results changed from R to S
+# - 16 test results changed from R to I
# --------------------------------------------------------------------------
#
# Use verbose = TRUE to get a data.frame with all specified edits instead.
So only 28.4% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
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 W10, 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 L1, sorted on date:
isolate | @@ -529,8 +529,8 @@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-10 | -W10 | +2010-06-13 | +L1 | B_ESCHR_COL | S | S | @@ -540,8 +540,8 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | -2010-04-21 | -W10 | +2010-08-25 | +L1 | B_ESCHR_COL | S | S | @@ -551,30 +551,30 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | -2010-05-14 | -W10 | +2010-09-09 | +L1 | B_ESCHR_COL | -S | -S | +R | S | R | +S | FALSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | -2010-05-21 | -W10 | +2010-09-14 | +L1 | B_ESCHR_COL | +R | +I | S | -S | -S | -S | +R | FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | -2010-06-09 | -W10 | +2010-10-01 | +L1 | B_ESCHR_COL | R | S | @@ -584,30 +584,30 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | -2010-06-19 | -W10 | +2010-11-15 | +L1 | B_ESCHR_COL | S | S | -R | +S | S | FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | -2010-07-07 | -W10 | +2010-12-31 | +L1 | B_ESCHR_COL | -S | -S | R | +I | +S | S | FALSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | -2010-07-10 | -W10 | +2011-01-14 | +L1 | B_ESCHR_COL | R | S | @@ -617,8 +617,8 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | -2010-08-12 | -W10 | +2011-01-31 | +L1 | B_ESCHR_COL | S | S | @@ -628,10 +628,10 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | -2010-10-15 | -W10 | +2011-03-23 | +L1 | B_ESCHR_COL | -S | +R | S | S | S | @@ -650,7 +650,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,099 first weighted isolates (75.5% of total) +# => Found 15,191 first weighted isolates (76.0% of total)
isolate | @@ -667,8 +667,8 @@||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-01-10 | -W10 | +2010-06-13 | +L1 | B_ESCHR_COL | S | S | @@ -679,8 +679,8 @@|||||||
2 | -2010-04-21 | -W10 | +2010-08-25 | +L1 | B_ESCHR_COL | S | S | @@ -691,32 +691,32 @@|||||||
3 | -2010-05-14 | -W10 | +2010-09-09 | +L1 | B_ESCHR_COL | -S | -S | +R | S | R | +S | FALSE | TRUE | |
4 | -2010-05-21 | -W10 | +2010-09-14 | +L1 | B_ESCHR_COL | +R | +I | S | -S | -S | -S | +R | FALSE | TRUE |
5 | -2010-06-09 | -W10 | +2010-10-01 | +L1 | B_ESCHR_COL | R | S | @@ -727,44 +727,44 @@|||||||
6 | -2010-06-19 | -W10 | +2010-11-15 | +L1 | B_ESCHR_COL | S | S | -R | +S | S | FALSE | TRUE | ||
7 | -2010-07-07 | -W10 | +2010-12-31 | +L1 | B_ESCHR_COL | -S | -S | R | +I | +S | S | FALSE | -FALSE | +TRUE |
8 | -2010-07-10 | -W10 | +2011-01-14 | +L1 | B_ESCHR_COL | R | S | S | S | FALSE | -TRUE | +FALSE | ||
9 | -2010-08-12 | -W10 | +2011-01-31 | +L1 | B_ESCHR_COL | S | S | @@ -775,23 +775,23 @@|||||||
10 | -2010-10-15 | -W10 | +2011-03-23 | +L1 | B_ESCHR_COL | -S | +R | S | S | S | FALSE | -FALSE | +TRUE |
Instead of 1, now 7 isolates are flagged. In total, 75.5% 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.
+Instead of 1, now 8 isolates are flagged. In total, 76% of all isolates are marked ‘first weighted’ - 47.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,099 isolates for analysis.
+So we end up with 15,191 isolates for analysis.
We can remove unneeded columns:
@@ -816,31 +816,31 @@Or can be used like the dplyr
way, which is easier readable:
Frequency table of genus
and species
from data_1st
(15,099 x 13)
Frequency table of genus
and species
from data_1st
(15,191 x 13)
Columns: 2
-Length: 15,099 (of which NA: 0 = 0.00%)
+Length: 15,191 (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) %>%
@@ -997,19 +997,19 @@ Longest: 24
Hospital A
-0.4754386
+0.4769129
Hospital B
-0.4673058
+0.4643125
Hospital C
-0.4625054
+0.4723793
Hospital D
-0.4617169
+0.4731788
EUCAST.Rmd
MDR.Rmd
The data set looks like this now:
head(my_TB_data)
# rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1 R S R R I R
-# 2 I S S I S R
-# 3 S R S R I R
-# 4 R R R R R R
-# 5 S S S S R S
-# 6 S I S R R I
+# 1 S S R S R I
+# 2 S S R S R S
+# 3 R R S S S S
+# 4 S I S I S S
+# 5 S S I I R R
+# 6 R R R R R R
# kanamycin
-# 1 S
-# 2 S
+# 1 R
+# 2 I
# 3 R
# 4 I
-# 5 S
-# 6 S
We can now add the interpretation of MDR-TB to our data set:
my_TB_data$mdr <- mdr_tb(my_TB_data)
# NOTE: No column found as input for `col_mo`, assuming all records contain Mycobacterium tuberculosis.
@@ -284,40 +277,40 @@ Unique: 5
1
Mono-resistance
-3,283
+3,284
65.7%
-3,283
+3,284
65.7%
2
Negative
-650
-13.0%
-3,933
-78.7%
+675
+13.5%
+3,959
+79.2%
3
Multidrug resistance
-593
-11.9%
-4,526
-90.5%
+570
+11.4%
+4,529
+90.6%
4
Poly-resistance
-259
-5.2%
-4,785
-95.7%
+263
+5.3%
+4,792
+95.8%
5
Extensive drug resistance
-215
-4.3%
+208
+4.2%
5,000
100.0%
diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html
index 05da7bf4..a169c1cb 100644
--- a/docs/articles/SPSS.html
+++ b/docs/articles/SPSS.html
@@ -40,7 +40,7 @@
SPSS.Rmd
WHONET.Rmd
ab_property.Rmd
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 Thermus islandicus (B_THERMS_ISL
), a bug probably never found before in humans:
T.islandicus <- microbenchmark(as.mo("theisl"),
@@ -243,12 +236,12 @@
print(T.islandicus, unit = "ms", signif = 2)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# as.mo("theisl") 370 370 390 370 420 420 10
-# as.mo("THEISL") 370 420 420 420 420 440 10
-# as.mo("T. islandicus") 190 190 200 190 230 250 10
-# as.mo("T. islandicus") 190 190 210 210 230 240 10
-# as.mo("Thermus islandicus") 73 73 83 74 74 120 10
That takes 8.6 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") 400 400 430 430 450 450 10 +# as.mo("THEISL") 390 400 420 420 450 460 10 +# as.mo("T. islandicus") 210 210 260 240 270 430 10 +# as.mo("T. islandicus") 210 210 250 260 260 270 10 +# as.mo("Thermus islandicus") 74 75 94 76 120 120 10 +That takes 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 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)
@@ -294,8 +287,8 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# mo_fullname(x) 1220 1320 1410 1390 1540 1570 10
So transforming 500,000 values (!!) of 50 unique values only takes 1.39 seconds (1393 ms). You only lose time on your unique input values.
+# mo_fullname(x) 1090 1130 1190 1170 1230 1320 10 +So transforming 500,000 values (!!) of 50 unique values only takes 1.17 seconds (1167 ms). You only lose time on your unique input values.
So going from mo_fullname("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.002 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:
So going from mo_fullname("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0018 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"),
C = mo_fullname("Staphylococcus aureus"),
@@ -324,14 +317,14 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# A 0.555 0.585 0.666 0.619 0.777 0.788 10
-# B 0.574 0.653 0.771 0.740 0.857 1.080 10
-# C 1.630 1.790 1.950 1.930 2.120 2.280 10
-# D 0.571 0.671 0.726 0.702 0.725 1.090 10
-# E 0.528 0.569 0.704 0.762 0.807 0.833 10
-# F 0.511 0.556 0.618 0.580 0.694 0.752 10
-# G 0.481 0.538 0.649 0.674 0.736 0.791 10
-# H 0.213 0.282 0.336 0.298 0.348 0.636 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 df4a0b10..bf33e9bf 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 94217729..ca20393e 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ @@ -125,13 +125,6 @@ Create frequency tablesfreq.Rmd
mo_property
functions (like Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal ggplot2
functions.
Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal ggplot2
functions.
At default, the names of antibiotics will be shown on the plots using ab_name
. This can be set with the translate_ab
parameter. See count_df
.
The functions
geom_rsi
will take any variable from the data that has an rsi
class (created with as.rsi
) using fun
(count_df
at default, can also be portion_df
) and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.
facet_rsi
creates 2d plots (at default based on S/I/R) using facet_wrap
.
facet_rsi
creates 2d plots (at default based on S/I/R) using facet_wrap
.
scale_y_percent
transforms the y axis to a 0 to 100% range using scale_continuous
.
scale_rsi_colours
sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using scale_brewer
.
theme_rsi
is a ggplot theme
with minimal distraction.
labels_rsi_count
print datalabels on the bars with percentage and amount of isolates using geom_text
theme_rsi
is a ggplot theme
with minimal distraction.
labels_rsi_count
print datalabels on the bars with percentage and amount of isolates using geom_text
ggplot_rsi
is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (%>%
). See Examples.