diff --git a/DESCRIPTION b/DESCRIPTION index e771f970..5a9dbb7f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.7.1.9083 +Version: 0.7.1.9084 Date: 2019-09-23 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 8b01871a..f9656a39 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9083 +# AMR 0.7.1.9084 Last updated: 23-Sep-2019 ### Breaking diff --git a/R/globals.R b/R/globals.R index 6e78b141..9485920a 100755 --- a/R/globals.R +++ b/R/globals.R @@ -53,6 +53,7 @@ globalVariables(c(".", "mdr", "median", "microorganisms", + "microorganisms.codes", "missing_names", "mo", "mono_count", diff --git a/R/mo.R b/R/mo.R index 70972f10..b074ca28 100755 --- a/R/mo.R +++ b/R/mo.R @@ -652,9 +652,9 @@ exec_as.mo <- function(x, 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] + ref_mo <- reference_df[reference_df[, 1] == x_backup[i], "mo"][[1L]] + if (ref_mo %in% microorganismsDT[, mo]) { + x[i] <- microorganismsDT[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) @@ -769,8 +769,7 @@ exec_as.mo <- function(x, } next } - if (toupper(x_backup_without_spp[i]) == 'CRS' - | toupper(x_backup_without_spp[i]) == 'CRSM') { + if (toupper(x_backup_without_spp[i]) == 'CRSM') { # co-trim resistant S. maltophilia x[i] <- microorganismsDT[mo == 'B_STNTR_MLTP', ..property][[1]][1L] if (initial_search == TRUE) { diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 2885927b..405096e1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9083 + 0.7.1.9084 diff --git a/docs/articles/index.html b/docs/articles/index.html index 8bfcfe5f..a143102a 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9083 + 0.7.1.9084 diff --git a/docs/authors.html b/docs/authors.html index 3ed28b61..7704f960 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9083 + 0.7.1.9084 diff --git a/docs/index.html b/docs/index.html index bbdfb2ae..1e7517da 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9083 + 0.7.1.9084 diff --git a/docs/news/index.html b/docs/news/index.html index 29d25635..334d9c7c 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9083 + 0.7.1.9084 @@ -225,9 +225,9 @@ -
+

-AMR 0.7.1.9083 Unreleased +AMR 0.7.1.9084 Unreleased

Last updated: 23-Sep-2019

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

Contents

diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index 3becb18c..8e646623 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -24,15 +24,15 @@ context("mo.R") test_that("as.mo works", { clear_mo_history(force = TRUE) - + library(dplyr) MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3) expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo))) - + expect_identical( as.character(as.mo(c("E. coli", "H. influenzae"))), c("B_ESCHR_COLI", "B_HMPHL_INFL")) - + expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") expect_equal(as.character(as.mo(22242416)), "B_ESCHR_COLI") @@ -53,14 +53,14 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRPB") expect_equal(as.character(suppressWarnings(as.mo("B_STRPTC"))), "B_STRPT") # old MO code (<=v0.5.0) expect_equal(as.character(suppressWarnings(as.mo("B_STRPT_PNE"))), "B_STRPT_PNMN") # old MO code (<=v0.8.0) - + expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRPA", "B_STRPT_GRPB")) - + expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYGN") # not Actinomyces pyogenes - + # GLIMS expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRGL") - + expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPDR") expect_equal(as.character(as.mo("VRE")), "B_ENTRC") expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_ARGN") @@ -68,7 +68,7 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNMN") expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNMN") expect_equal(as.character(as.mo("VRSP")), "B_STRPT_PNMN") - + expect_equal(as.character(as.mo("CNS")), "B_STPHY_CONS") expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CONS") expect_equal(as.character(as.mo("CPS")), "B_STPHY_COPS") @@ -76,9 +76,9 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("VGS")), "B_STRPT_VIRI") expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MILL") - + expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAMN", "B_GRAMP")) - + # prevalent MO expect_identical( suppressWarnings(as.character( @@ -104,15 +104,15 @@ test_that("as.mo works", { "B nodosa", "Burkholderia nodosa"))), rep("B_BRKHL_NODS", 4)) - + # empty values expect_identical(as.character(as.mo(c("", NA, NaN))), rep(NA_character_, 3)) # too few characters expect_warning(as.mo("ab")) - - expect_equal(suppressWarnings(as.character(as.mo(c("Qq species", "", "CRS", "K. pneu rhino", "esco")))), + + expect_equal(suppressWarnings(as.character(as.mo(c("Qq species", "", "CRSM", "K. pneu rhino", "esco")))), c("UNKNOWN", NA_character_, "B_STNTR_MLTP", "B_KLBSL_PNMN_RHNS", "B_ESCHR_COLI")) - + # check for Becker classification expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR") expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS") @@ -125,7 +125,7 @@ test_that("as.mo works", { expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AURS") expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AURS") expect_identical(as.character(as.mo("STAAUR", Becker = "all")), "B_STPHY_COPS") - + # check for Lancefield classification expect_identical(as.character(as.mo("S. pyogenes", Lancefield = FALSE)), "B_STRPT_PYGN") expect_identical(as.character(as.mo("S. pyogenes", Lancefield = TRUE)), "B_STRPT_GRPA") @@ -145,9 +145,9 @@ test_that("as.mo works", { expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRPT_GRPH") # group H expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR") expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K - + library(dplyr) - + # select with one column expect_identical( example_isolates[1:10,] %>% @@ -157,7 +157,7 @@ test_that("as.mo works", { as.character(), c("B_ESCHR", "B_ESCHR", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY")) - + # select with two columns expect_identical( example_isolates[1:10,] %>% @@ -166,28 +166,28 @@ test_that("as.mo works", { left_join_microorganisms() %>% select(genus, species) %>% as.mo()) - + # unknown results expect_warning(as.mo(c("INVALID", "Yeah, unknown"))) - + # too many columns expect_error(example_isolates %>% select(1:3) %>% as.mo()) - + # print expect_output(print(as.mo(c("B_ESCHR_COLI", NA)))) - + # test pull expect_equal(nrow(example_isolates %>% mutate(mo = as.mo(mo))), 2000) - + # test data.frame expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COLI"))), 1) - + # check empty values expect_equal(as.character(suppressWarnings(as.mo(""))), NA_character_) - + # check less prevalent MOs expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APNN_DLCT") expect_equal(as.character(as.mo("Gomphosphaeria apo del")), "B_GMPHS_APNN_DLCT") @@ -197,11 +197,11 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("Gomphosphaeria")), "B_GMPHS") expect_equal(as.character(as.mo(" B_GMPHS_APNN ")), "B_GMPHS_APNN") expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APNN") - + # check old names expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLTT") print(mo_renamed()) - + # check uncertain names expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = FALSE))), "UNKNOWN") @@ -209,7 +209,7 @@ test_that("as.mo works", { expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY") expect_equal(suppressWarnings(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AURS") - + # predefined reference_df expect_equal(as.character(as.mo("TestingOwnID", reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COLI"))), @@ -219,21 +219,16 @@ test_that("as.mo works", { c("B_ESCHR_COLI", "B_ESCHR_COLI")) expect_warning(as.mo("TestingOwnID", reference_df = NULL)) expect_error(as.mo("E. coli", reference_df = data.frame(mycol = "TestingOwnID"))) - + # combination of existing mo and other code - expect_identical(suppressWarnings(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL")))), + expect_identical(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL"))), c("B_ESCHR_COLI", "B_ESCHR_COLI")) - - # expect_equal(mo_fullname(c("E. spp.", - # "E. spp", - # "E. species")), - # rep("Escherichia species", 3)) - + # from different sources expect_equal(as.character(as.mo( c("PRTMIR", "bclcer", "B_ESCHR_COLI"))), c("B_PROTS_MRBL", "B_BCLLS_CERS", "B_ESCHR_COLI")) - + # hard to find expect_equal(as.character(suppressWarnings(as.mo( c("Microbacterium paraoxidans", @@ -241,43 +236,43 @@ test_that("as.mo works", { "Raoultella (here some text) terrigena")))), c("B_MCRBC_PRXY", "B_STRPT_SUIS", "B_RLTLL_TRRG")) expect_output(print(mo_uncertainties())) - + # Salmonella (City) are all actually Salmonella enterica spp (City) expect_equal(as.character(suppressWarnings(as.mo("Salmonella Goettingen"))), "B_SLMNL_ENTR") expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL") - + # no virusses expect_equal(as.character(as.mo("Virus")), NA_character_) - + # summary expect_equal(length(summary(example_isolates$mo)), 6) - + # WHONET codes and NA/NaN expect_equal(as.character(as.mo(c("xxx", "na", "nan"), debug = TRUE)), rep(NA_character_, 3)) expect_equal(as.character(as.mo("con")), "UNKNOWN") expect_equal(as.character(as.mo("xxx")), NA_character_) expect_equal(as.character(as.mo(c("xxx", "con", "eco"))), c(NA_character_, "UNKNOWN", "B_ESCHR_COLI")) - expect_equal(as.character(as.mo(c("other", "none", "unknown"))), + expect_equal(as.character(as.mo(c("other", "none", "unknown"))), rep("UNKNOWN", 3)) - + expect_null(mo_failures()) expect_true(example_isolates %>% pull(mo) %>% is.mo()) - + # expect_equal(get_mo_code("test", "mo"), "test") # expect_equal(length(get_mo_code("Escherichia", "genus")), # nrow(AMR::microorganisms[base::which(AMR::microorganisms[, "genus"] %in% "Escherichia"),])) - + expect_error(translate_allow_uncertain(5)) - + # very old MO codes (<= v0.5.0) expect_equal(suppressWarnings(as.character(as.mo("F_CCCCS_NEO"))), "F_CRYPT_NFRM") expect_equal(suppressWarnings(as.character(as.mo("F_CANDD_GLB"))), "F_CANDD_GLBR") # debug mode expect_output(print(suppressMessages(suppressWarnings(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3))))) - + # ..coccus expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))), c("B_NESSR_MNNG", "B_NESSR_GNRR", "B_STRPT_PNMN")) diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 777f922a..4682b157 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -90,7 +90,9 @@ test_that("mo_property works", { expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968") expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999") - + # old codes must throw a warning in mo_* family + expect_warning(mo_name(c("B_ESCHR_COL", "B_STPHY_AUR"))) + # outcome of mo_fullname must always return the fullname from the data set library(dplyr) x <- microorganisms %>%