mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 18:41:58 +02:00
new class bactid
This commit is contained in:
64
tests/testthat/test-bactid.R
Normal file
64
tests/testthat/test-bactid.R
Normal file
@ -0,0 +1,64 @@
|
||||
context("bactid.R")
|
||||
|
||||
test_that("as.bactid works", {
|
||||
expect_identical(
|
||||
as.character(as.bactid(c("E. coli", "H. influenzae"))),
|
||||
c("ESCCOL", "HAEINF"))
|
||||
|
||||
expect_equal(as.character(as.bactid("Escherichia coli")), "ESCCOL")
|
||||
expect_equal(as.character(as.bactid("P. aer")), "PSEAER") # not Pasteurella aerogenes
|
||||
|
||||
expect_equal(as.character(as.bactid("Negative rods")), "GNR")
|
||||
|
||||
expect_equal(as.character(as.bactid("MRSE")), "STAEPI")
|
||||
expect_equal(as.character(as.bactid("VRE")), "ENC")
|
||||
expect_equal(as.character(as.bactid("MRPA")), "PSEAER")
|
||||
expect_equal(as.character(as.bactid("PISP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("PRSP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("VISP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("VRSP")), "STCPNE")
|
||||
|
||||
expect_identical(
|
||||
as.character(
|
||||
as.bactid(c("stau",
|
||||
"STAU",
|
||||
"staaur",
|
||||
"S. aureus",
|
||||
"S aureus",
|
||||
"Staphylococcus aureus",
|
||||
"MRSA",
|
||||
"VISA"))),
|
||||
rep("STAAUR", 8))
|
||||
|
||||
# select with one column
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus) %>%
|
||||
as.bactid() %>%
|
||||
as.character(),
|
||||
c("STC", "STC", "NEI", "STA", "STA",
|
||||
"NEI", "ENT", "ENT", "ESC", "KLE"))
|
||||
|
||||
# select with two columns
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
pull(bactid),
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus, species) %>%
|
||||
as.bactid() %>%
|
||||
as.character())
|
||||
|
||||
# unknown results
|
||||
expect_warning(as.bactid(c("INVALID", "Yeah, unknown")))
|
||||
|
||||
# print
|
||||
expect_output(print(as.bactid(c("ESCCOL", NA))))
|
||||
|
||||
# helper function
|
||||
expect_identical(as.bactid("ESCCOL"),
|
||||
guess_bactid("ESCCOL"))
|
||||
|
||||
|
||||
})
|
@ -1,27 +1,34 @@
|
||||
context("eucast.R")
|
||||
|
||||
test_that("EUCAST rules work", {
|
||||
a <- suppressWarnings(EUCAST_rules(septic_patients))
|
||||
expect_identical(colnames(septic_patients),
|
||||
colnames(suppressWarnings(EUCAST_rules(septic_patients))))
|
||||
|
||||
a <- data.frame(bactid = c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER"), # Enterobacter aerogenes
|
||||
a <- data.frame(bactid =
|
||||
c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER"), # Enterobacter aerogenes
|
||||
amox = "-", # Amoxicillin
|
||||
stringsAsFactors = FALSE)
|
||||
b <- data.frame(bactid = c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER"), # Enterobacter aerogenes
|
||||
b <- data.frame(bactid =
|
||||
as.bactid(
|
||||
c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER")), # Enterobacter aerogenes
|
||||
amox = "R", # Amoxicillin
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(EUCAST_rules(a, info = FALSE), b)
|
||||
expect_equal(suppressWarnings(interpretive_reading(a, info = TRUE)), b)
|
||||
expect_identical(EUCAST_rules(a, info = FALSE), b)
|
||||
expect_identical(suppressWarnings(interpretive_reading(a, info = TRUE)), b)
|
||||
|
||||
a <- data.frame(bactid = c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
|
||||
a <- data.frame(bactid =
|
||||
c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
|
||||
coli = "-", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
b <- data.frame(bactid = c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
|
||||
b <- data.frame(bactid =
|
||||
as.bactid(
|
||||
c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA")), # Streptococcus pyognenes (Lancefield Group A)
|
||||
coli = "R", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(EUCAST_rules(a, info = FALSE), b)
|
||||
|
@ -1,4 +1,4 @@
|
||||
context("first_isolates.R")
|
||||
context("first_isolate.R")
|
||||
|
||||
test_that("first isolates work", {
|
||||
# septic_patients contains 1959 out of 2000 first isolates
|
@ -1,49 +0,0 @@
|
||||
context("guess_bactid.R")
|
||||
|
||||
test_that("guess_bactid works", {
|
||||
expect_identical(
|
||||
guess_bactid(c("E. coli", "H. influenzae")),
|
||||
c("ESCCOL", "HAEINF"))
|
||||
|
||||
expect_equal(guess_bactid("Escherichia coli"), "ESCCOL")
|
||||
expect_equal(guess_bactid("P. aer"), "PSEAER") # not Pasteurella aerogenes
|
||||
|
||||
expect_equal(guess_bactid("Negative rods"), "GNR")
|
||||
|
||||
expect_equal(guess_bactid("MRSE"), "STAEPI")
|
||||
expect_equal(guess_bactid("VRE"), "ENC")
|
||||
expect_equal(guess_bactid("MRPA"), "PSEAER")
|
||||
expect_equal(guess_bactid("PISP"), "STCPNE")
|
||||
expect_equal(guess_bactid("PRSP"), "STCPNE")
|
||||
expect_equal(guess_bactid("VISP"), "STCPNE")
|
||||
expect_equal(guess_bactid("VRSP"), "STCPNE")
|
||||
|
||||
expect_identical(
|
||||
guess_bactid(c("stau",
|
||||
"STAU",
|
||||
"staaur",
|
||||
"S. aureus",
|
||||
"S aureus",
|
||||
"Staphylococcus aureus",
|
||||
"MRSA",
|
||||
"VISA")),
|
||||
rep("STAAUR", 8))
|
||||
|
||||
# select with one column
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus) %>%
|
||||
guess_bactid(),
|
||||
c("STC", "STC", "NEI", "STA", "STA",
|
||||
"NEI", "ENT", "ENT", "ESC", "KLE"))
|
||||
|
||||
# select with two columns
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
pull(bactid),
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus, species) %>%
|
||||
guess_bactid())
|
||||
})
|
@ -1,4 +1,4 @@
|
||||
context("joins.R")
|
||||
context("join_microorganisms.R")
|
||||
|
||||
test_that("joins work", {
|
||||
unjoined <- septic_patients
|
Reference in New Issue
Block a user