2018-08-31 13:36:19 +02:00
|
|
|
context("mo.R")
|
|
|
|
|
|
|
|
test_that("as.mo works", {
|
2018-09-09 12:11:44 +02:00
|
|
|
|
|
|
|
library(dplyr)
|
2018-09-16 16:43:29 +02:00
|
|
|
MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
|
2018-09-09 12:11:44 +02:00
|
|
|
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo)))
|
|
|
|
|
2018-08-31 13:36:19 +02:00
|
|
|
expect_identical(
|
|
|
|
as.character(as.mo(c("E. coli", "H. influenzae"))),
|
2018-09-24 23:33:29 +02:00
|
|
|
c("B_ESCHR_COL", "B_HMPHL_INF"))
|
2018-08-31 13:36:19 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL")
|
|
|
|
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL")
|
|
|
|
expect_equal(as.character(as.mo("Escherichia species")), "B_ESCHR")
|
|
|
|
expect_equal(as.character(as.mo("Escherichia")), "B_ESCHR")
|
|
|
|
expect_equal(as.character(as.mo(" B_ESCHR_COL ")), "B_ESCHR_COL")
|
2018-09-27 23:23:48 +02:00
|
|
|
expect_equal(as.character(as.mo("e coli")), "B_ESCHR_COL") # not Campylobacter
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNE")
|
|
|
|
expect_equal(as.character(as.mo("Klebsiella")), "B_KLBSL")
|
|
|
|
expect_equal(as.character(as.mo("K. pneu rhino")), "B_KLBSL_PNE_RHI") # K. pneumoniae subspp. rhinoscleromatis
|
|
|
|
expect_equal(as.character(as.mo("Bartonella")), "B_BRTNL")
|
|
|
|
expect_equal(as.character(as.mo("C. difficile")), "B_CTRDM_DIF")
|
|
|
|
expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNE")
|
|
|
|
# expect_equal(as.character(as.mo("L. non pneumophila")), "LEGNON")
|
|
|
|
# expect_equal(as.character(as.mo("S. beta-haemolytic")), "STCHAE")
|
|
|
|
expect_equal(as.character(as.mo("Strepto")), "B_STRPTC")
|
|
|
|
expect_equal(as.character(as.mo("Streptococcus")), "B_STRPTC") # not Peptostreptoccus
|
2018-09-14 11:54:01 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPTC_GRA", "B_STRPTC_GRB"))
|
2018-09-14 11:54:01 +02:00
|
|
|
|
2018-08-31 13:36:19 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("S. pyo")), "B_STRPTC_PYO") # not Actinomyces pyogenes
|
2018-09-05 10:51:46 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("P. aer")), "B_PDMNS_AER") # not Pasteurella aerogenes
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# GLIMS
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRA")
|
2018-08-31 13:36:19 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPI")
|
|
|
|
expect_equal(as.character(as.mo("VRE")), "B_ENTRC")
|
|
|
|
expect_equal(as.character(as.mo("MRPA")), "B_PDMNS_AER")
|
|
|
|
expect_equal(as.character(as.mo("PISP")), "B_STRPTC_PNE")
|
|
|
|
expect_equal(as.character(as.mo("PRSP")), "B_STRPTC_PNE")
|
|
|
|
expect_equal(as.character(as.mo("VISP")), "B_STRPTC_PNE")
|
|
|
|
expect_equal(as.character(as.mo("VRSP")), "B_STRPTC_PNE")
|
2018-08-31 13:36:19 +02:00
|
|
|
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(as.character(as.mo("CNS")), "B_STPHY_CNS")
|
|
|
|
expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CNS")
|
|
|
|
expect_equal(as.character(as.mo("CPS")), "B_STPHY_CPS")
|
|
|
|
expect_equal(as.character(as.mo("CoPS")), "B_STPHY_CPS")
|
2018-09-04 11:33:30 +02:00
|
|
|
|
2018-08-31 13:36:19 +02:00
|
|
|
expect_identical(
|
|
|
|
as.character(
|
|
|
|
as.mo(c("stau",
|
2018-09-04 11:33:30 +02:00
|
|
|
"STAU",
|
|
|
|
"staaur",
|
|
|
|
"S. aureus",
|
|
|
|
"S aureus",
|
|
|
|
"Staphylococcus aureus",
|
|
|
|
"MRSA",
|
|
|
|
"VISA"))),
|
2018-09-24 23:33:29 +02:00
|
|
|
rep("B_STPHY_AUR", 8))
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# check for Becker classification
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_identical(as.character(guess_mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPI")
|
|
|
|
expect_identical(as.character(guess_mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CNS")
|
|
|
|
expect_identical(as.character(guess_mo("STAEPI", Becker = TRUE)), "B_STPHY_CNS")
|
|
|
|
expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "B_STRPTC_INT") # Strep (!) intermedius
|
|
|
|
expect_identical(as.character(guess_mo("Sta intermedius",Becker = FALSE)), "B_STPHY_INT")
|
|
|
|
expect_identical(as.character(guess_mo("Sta intermedius",Becker = TRUE)), "B_STPHY_CPS")
|
|
|
|
expect_identical(as.character(guess_mo("STAINT", Becker = TRUE)), "B_STPHY_CPS")
|
2018-08-31 13:36:19 +02:00
|
|
|
# aureus must only be influenced if Becker = "all"
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_identical(as.character(guess_mo("STAAUR", Becker = FALSE)), "B_STPHY_AUR")
|
|
|
|
expect_identical(as.character(guess_mo("STAAUR", Becker = TRUE)), "B_STPHY_AUR")
|
|
|
|
expect_identical(as.character(guess_mo("STAAUR", Becker = "all")), "B_STPHY_CPS")
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# check for Lancefield classification
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = FALSE)), "B_STRPTC_PYO")
|
|
|
|
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = TRUE)), "B_STRPTC_GRA")
|
|
|
|
expect_identical(as.character(guess_mo("STCPYO", Lancefield = TRUE)), "B_STRPTC_GRA") # group A
|
|
|
|
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = FALSE)), "B_STRPTC_AGA")
|
|
|
|
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = TRUE)), "B_STRPTC_GRB") # group B
|
|
|
|
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = FALSE)), "B_STRPTC_DYS_EQU")
|
|
|
|
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = TRUE)), "B_STRPTC_GRC") # group C
|
2018-09-04 11:33:30 +02:00
|
|
|
# Enterococci must only be influenced if Lancefield = "all"
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_identical(as.character(guess_mo("E. faecium", Lancefield = FALSE)), "B_ENTRC_IUM")
|
|
|
|
expect_identical(as.character(guess_mo("E. faecium", Lancefield = TRUE)), "B_ENTRC_IUM")
|
|
|
|
expect_identical(as.character(guess_mo("E. faecium", Lancefield = "all")), "B_STRPTC_GRD") # group D
|
|
|
|
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = FALSE)), "B_STRPTC_ANG")
|
|
|
|
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = TRUE)), "B_STRPTC_GRF") # group F
|
|
|
|
expect_identical(as.character(guess_mo("S. sanguinis", Lancefield = FALSE)), "B_STRPTC_SAN")
|
|
|
|
expect_identical(as.character(guess_mo("S. sanguinis", Lancefield = TRUE)), "B_STRPTC_GRH") # group H
|
|
|
|
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = FALSE)), "B_STRPTC_SAL")
|
|
|
|
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = TRUE)), "B_STRPTC_GRK") # group K
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
library(dplyr)
|
|
|
|
|
|
|
|
# select with one column
|
|
|
|
expect_identical(
|
|
|
|
septic_patients[1:10,] %>%
|
|
|
|
left_join_microorganisms() %>%
|
|
|
|
select(genus) %>%
|
|
|
|
as.mo() %>%
|
|
|
|
as.character(),
|
2018-09-24 23:33:29 +02:00
|
|
|
c("B_ESCHR", "B_ESCHR", "B_STPHY", "B_STPHY", "B_STPHY",
|
|
|
|
"B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY"))
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# select with two columns
|
|
|
|
expect_identical(
|
|
|
|
septic_patients[1:10,] %>%
|
|
|
|
pull(mo),
|
|
|
|
septic_patients[1:10,] %>%
|
|
|
|
left_join_microorganisms() %>%
|
|
|
|
select(genus, species) %>%
|
|
|
|
as.mo() %>%
|
|
|
|
as.character())
|
|
|
|
|
|
|
|
# unknown results
|
|
|
|
expect_warning(as.mo(c("INVALID", "Yeah, unknown")))
|
|
|
|
|
|
|
|
# too many columns
|
|
|
|
expect_error(septic_patients %>% select(1:3) %>% as.mo())
|
|
|
|
|
|
|
|
# print
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_output(print(as.mo(c("B_ESCHR_COL", NA))))
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# helper function
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_identical(as.mo("B_ESCHR_COL"),
|
|
|
|
guess_mo("B_ESCHR_COL"))
|
2018-08-31 13:36:19 +02:00
|
|
|
|
|
|
|
# test pull
|
|
|
|
expect_equal(nrow(septic_patients %>% mutate(mo = as.mo(mo))),
|
|
|
|
2000)
|
|
|
|
|
|
|
|
# test data.frame
|
2018-09-24 23:33:29 +02:00
|
|
|
expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COL"))),
|
2018-08-31 13:36:19 +02:00
|
|
|
1)
|
|
|
|
|
|
|
|
# check empty values
|
|
|
|
expect_equal(as.character(suppressWarnings(as.mo(""))),
|
|
|
|
NA_character_)
|
|
|
|
|
2018-10-01 11:39:43 +02:00
|
|
|
# check less prevalent MOs
|
|
|
|
expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APO_DEL")
|
|
|
|
expect_equal(as.character(as.mo("G apo deli")), "B_GMPHS_APO_DEL")
|
|
|
|
expect_equal(as.character(as.mo("Gomphosphaeria aponina")), "B_GMPHS_APO")
|
|
|
|
expect_equal(as.character(as.mo("Gomphosphaeria species")), "B_GMPHS")
|
|
|
|
expect_equal(as.character(as.mo("Gomphosphaeria")), "B_GMPHS")
|
|
|
|
expect_equal(as.character(as.mo(" B_GMPHS_APO ")), "B_GMPHS_APO")
|
|
|
|
expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APO")
|
|
|
|
|
|
|
|
# check old names
|
|
|
|
expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLA")
|
|
|
|
|
|
|
|
# check uncertain names
|
|
|
|
expect_equal(suppressWarnings(as.character(as.mo("esco extra_text", allow_uncertain = FALSE))), NA_character_)
|
|
|
|
expect_equal(suppressWarnings(as.character(as.mo("esco extra_text", allow_uncertain = TRUE))), "B_ESCHR_COL")
|
|
|
|
expect_warning(as.mo("esco extra_text", allow_uncertain = TRUE))
|
|
|
|
|
2018-10-01 14:44:40 +02:00
|
|
|
# predefined reference_df
|
|
|
|
expect_equal(as.character(as.mo("TestingOwnID",
|
|
|
|
reference_df = data.frame(a = "TestingOwnID", b = "B_ESCHR_COL"))),
|
|
|
|
"B_ESCHR_COL")
|
|
|
|
expect_equal(as.character(as.mo(c("TestingOwnID", "E. coli"),
|
|
|
|
reference_df = data.frame(a = "TestingOwnID", b = "B_ESCHR_COL"))),
|
|
|
|
c("B_ESCHR_COL", "B_ESCHR_COL"))
|
2018-10-09 15:41:44 +02:00
|
|
|
expect_warning(as.mo("TestingOwnID", reference_df = NULL))
|
|
|
|
expect_error(as.mo("E. coli", reference_df = data.frame(a = "TestingOwnID")))
|
|
|
|
|
|
|
|
# combination of existing mo and certe
|
|
|
|
expect_identical(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL"))),
|
|
|
|
c("B_ESCHR_COL", "B_ESCHR_COL"))
|
|
|
|
|
|
|
|
# TSN of prevalent and non prevalent ones
|
|
|
|
expect_equal(mo_TSN(c("Gomphosphaeria aponina delicatula", "Escherichia coli")),
|
|
|
|
c(717, 285))
|
2018-10-01 14:44:40 +02:00
|
|
|
|
2018-08-31 13:36:19 +02:00
|
|
|
})
|