diff --git a/DESCRIPTION b/DESCRIPTION index 57e2b555..e771f970 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.7.1.9082 +Version: 0.7.1.9083 Date: 2019-09-23 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 6d3ae78d..8b01871a 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9082 +# AMR 0.7.1.9083 Last updated: 23-Sep-2019 ### Breaking diff --git a/R/mo.R b/R/mo.R index 00969922..70972f10 100755 --- a/R/mo.R +++ b/R/mo.R @@ -490,8 +490,8 @@ exec_as.mo <- function(x, x_backup[grepl("^(fungus|fungi)$", x)] <- "F_FUNGUS" # will otherwise become the kingdom # remove spp and species - x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x, ignore.case = TRUE) - x <- gsub("(spp.?|ssp.?|subsp.?|subspecies|biovar|serovar|species)", "", x, ignore.case = TRUE) + x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x) + x <- gsub("(spp.?|subsp.?|subspecies|biovar|serovar|species)", "", x) x <- strip_whitespace(x, dyslexia_mode) x_backup_without_spp <- x @@ -582,7 +582,7 @@ exec_as.mo <- function(x, progress$tick()$print() - mo_hist <- get_mo_history(x, uncertainty_level, force = force_mo_history, disable = disable_mo_history) + mo_hist <- get_mo_history(x_backup[i], uncertainty_level, force = force_mo_history, disable = disable_mo_history) if (initial_search == TRUE & !any(is.na(mo_hist))) { # previously found code found <- data.frame(mo = mo_hist, @@ -638,6 +638,29 @@ exec_as.mo <- function(x, next } + # WHONET and other common LIS codes + if (any(toupper(c(x_backup[i], x_backup_without_spp[i])) %in% AMR::microorganisms.codes$code)) { + mo_found <- AMR::microorganisms.codes[which(AMR::microorganisms.codes$code %in% toupper(c(x_backup[i], x_backup_without_spp[i]))), "mo"][1L] + if (length(mo_found) > 0) { + x[i] <- microorganismsDT[mo == mo_found, ..property][[1]][1L] + if (initial_search == TRUE) { + set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) + } + next + } + } + if (!is.null(reference_df)) { + # self-defined reference + if (x_backup[i] %in% reference_df[, 1]) { + ref_mo <- reference_df[reference_df[, 1] == x_backup[i], "mo"] + if (ref_mo %in% data_to_check[, mo]) { + x[i] <- data_to_check[mo == ref_mo, ..property][[1]][1L] + next + } else { + warning("Value '", x_backup[i], "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE) + } + } + } # WHONET: xxx = no growth if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) { @@ -688,13 +711,6 @@ exec_as.mo <- function(x, x[i] <- NA_character_ next } - # x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] - # if (initial_search == TRUE) { - # failures <- c(failures, x_backup[i]) - # set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) - # } - # next - # } # translate known trivial abbreviations to genus + species ---- if (!is.na(x_trimmed[i])) { @@ -961,32 +977,7 @@ exec_as.mo <- function(x, # rest of genus only is in allow_uncertain part. } - # TRY OTHER SOURCES ---- - # WHONET and other common LIS codes - if (toupper(a.x_backup) %in% AMR::microorganisms.codes[, 1]) { - mo_found <- AMR::microorganisms.codes[toupper(a.x_backup) == AMR::microorganisms.codes[, 1], "mo"][1L] - if (length(mo_found) > 0) { - x[i] <- microorganismsDT[mo == mo_found, ..property][[1]][1L] - if (initial_search == TRUE) { - set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history) - } - return(x[i]) - } - } - if (!is.null(reference_df)) { - # self-defined reference - if (a.x_backup %in% reference_df[, 1]) { - ref_mo <- reference_df[reference_df[, 1] == a.x_backup, "mo"] - if (ref_mo %in% data_to_check[, mo]) { - x[i] <- data_to_check[mo == ref_mo, ..property][[1]][1L] - return(x[i]) - } else { - warning("Value '", a.x_backup, "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE) - } - } - } - - # allow no codes less than 4 characters long, was already checked for WHONET above + # allow no codes less than 4 characters long, was already checked for WHONET earlier if (nchar(g.x_backup_without_spp) < 4) { x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] if (initial_search == TRUE) { @@ -1565,7 +1556,6 @@ exec_as.mo <- function(x, next } - # no results found: make them UNKNOWN ---- x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] if (initial_search == TRUE) { diff --git a/R/mo_history.R b/R/mo_history.R index 5281aeb5..3a4e2b39 100644 --- a/R/mo_history.R +++ b/R/mo_history.R @@ -27,6 +27,10 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA return(base::invisible()) } + # don't save codes that are in a code data set already + mo <- mo[!x %in% microorganisms.codes$code & !x %in% microorganisms.translation$mo_old] + x <- x[!x %in% microorganisms.codes$code & !x %in% microorganisms.translation$mo_old] + if (base::interactive() | force == TRUE) { mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force) warning_new_write <- FALSE diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index 8da06281..39f18e9a 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 3340a2d0..2885927b 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083 diff --git a/docs/articles/index.html b/docs/articles/index.html index 868d380a..8bfcfe5f 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083 diff --git a/docs/authors.html b/docs/authors.html index 367c8f97..3ed28b61 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083 diff --git a/docs/index.html b/docs/index.html index e8035c6c..bbdfb2ae 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083 diff --git a/docs/news/index.html b/docs/news/index.html index 488caf83..29d25635 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083 @@ -225,9 +225,9 @@ -
+

-AMR 0.7.1.9082 Unreleased +AMR 0.7.1.9083 Unreleased

Last updated: 23-Sep-2019

@@ -1280,7 +1280,7 @@ Using as.mo(..., allow_uncertain = 3)

Contents

diff --git a/docs/reference/bug_drug_combinations.html b/docs/reference/bug_drug_combinations.html index 76b2cb7a..6e5541d7 100644 --- a/docs/reference/bug_drug_combinations.html +++ b/docs/reference/bug_drug_combinations.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083
diff --git a/docs/reference/index.html b/docs/reference/index.html index e7f81832..1842560a 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9082 + 0.7.1.9083