2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
# TITLE #
|
|
|
|
# Antimicrobial Resistance (AMR) Analysis #
|
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# SOURCE #
|
|
|
|
# https://gitlab.com/msberends/AMR #
|
2018-12-16 22:45:12 +01:00
|
|
|
# #
|
|
|
|
# LICENCE #
|
2019-01-02 23:24:07 +01:00
|
|
|
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
2018-12-16 22:45:12 +01:00
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# This R package is free software; you can freely use and distribute #
|
|
|
|
# it for both personal and commercial purposes under the terms of the #
|
|
|
|
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
|
|
|
# the Free Software Foundation. #
|
|
|
|
# #
|
|
|
|
# This R package was created for academic research and was publicly #
|
|
|
|
# released in the hope that it will be useful, but it comes WITHOUT #
|
|
|
|
# ANY WARRANTY OR LIABILITY. #
|
|
|
|
# Visit our website for more info: https://msberends.gitab.io/AMR. #
|
2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
|
2018-11-16 20:50:50 +01:00
|
|
|
context("eucast_rules.R")
|
2018-03-27 17:43:42 +02:00
|
|
|
|
|
|
|
test_that("EUCAST rules work", {
|
2018-08-29 16:25:57 +02:00
|
|
|
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_error(suppressWarnings(eucast_rules(septic_patients, col_mo = "Non-existing")))
|
2018-08-29 16:25:57 +02:00
|
|
|
|
2018-07-23 14:14:03 +02:00
|
|
|
expect_identical(colnames(septic_patients),
|
2018-11-16 20:50:50 +01:00
|
|
|
colnames(suppressWarnings(eucast_rules(septic_patients))))
|
2018-05-02 14:56:25 +02:00
|
|
|
|
2019-02-27 17:39:39 +01:00
|
|
|
a <- data.frame(mo = c("Klebsiella pneumoniae",
|
|
|
|
"Pseudomonas aeruginosa",
|
|
|
|
"Enterobacter aerogenes"),
|
2018-03-27 17:43:42 +02:00
|
|
|
amox = "-", # Amoxicillin
|
|
|
|
stringsAsFactors = FALSE)
|
2019-02-27 17:39:39 +01:00
|
|
|
b <- data.frame(mo = c("Klebsiella pneumoniae",
|
|
|
|
"Pseudomonas aeruginosa",
|
|
|
|
"Enterobacter aerogenes"),
|
2018-10-17 17:32:34 +02:00
|
|
|
amox = "R", # Amoxicillin
|
2018-03-27 17:43:42 +02:00
|
|
|
stringsAsFactors = FALSE)
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_identical(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
|
|
|
expect_identical(suppressWarnings(eucast_rules(a, "mo", info = TRUE)), b)
|
2018-11-01 20:23:33 +01:00
|
|
|
expect_identical(suppressWarnings(interpretive_reading(a, "mo", info = TRUE)), b)
|
2018-04-02 16:05:09 +02:00
|
|
|
|
2019-02-27 17:39:39 +01:00
|
|
|
a <- data.frame(mo = c("Staphylococcus aureus",
|
|
|
|
"Streptococcus group A"),
|
2018-10-17 17:32:34 +02:00
|
|
|
coli = "-", # Colistin
|
2018-03-27 17:43:42 +02:00
|
|
|
stringsAsFactors = FALSE)
|
2019-02-27 17:39:39 +01:00
|
|
|
b <- data.frame(mo = c("Staphylococcus aureus",
|
|
|
|
"Streptococcus group A"),
|
2018-10-17 17:32:34 +02:00
|
|
|
coli = "R", # Colistin
|
2018-03-27 17:43:42 +02:00
|
|
|
stringsAsFactors = FALSE)
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
2018-08-29 16:25:57 +02:00
|
|
|
|
2018-11-01 20:23:33 +01:00
|
|
|
# piperacillin must be R in Enterobacteriaceae when tica is R
|
2018-08-29 16:25:57 +02:00
|
|
|
library(dplyr)
|
|
|
|
expect_equal(suppressWarnings(
|
|
|
|
septic_patients %>%
|
|
|
|
mutate(tica = as.rsi("R"),
|
2018-11-01 20:23:33 +01:00
|
|
|
pipe = as.rsi("S")) %>%
|
2018-11-16 20:50:50 +01:00
|
|
|
eucast_rules(col_mo = "mo") %>%
|
2018-08-29 16:25:57 +02:00
|
|
|
left_join_microorganisms() %>%
|
|
|
|
filter(family == "Enterobacteriaceae") %>%
|
2018-11-01 20:23:33 +01:00
|
|
|
pull(pipe) %>%
|
2018-08-29 16:25:57 +02:00
|
|
|
unique() %>%
|
|
|
|
as.character()),
|
|
|
|
"R")
|
2018-10-17 17:32:34 +02:00
|
|
|
|
2018-08-29 16:25:57 +02:00
|
|
|
# azit and clar must be equal to eryt
|
2018-10-17 17:32:34 +02:00
|
|
|
a <- suppressWarnings(
|
|
|
|
septic_patients %>%
|
|
|
|
transmute(mo,
|
|
|
|
eryt,
|
|
|
|
azit = as.rsi("R"),
|
|
|
|
clar = as.rsi("R")) %>%
|
2018-11-16 20:50:50 +01:00
|
|
|
eucast_rules(col_mo = "mo") %>%
|
2018-10-17 17:32:34 +02:00
|
|
|
pull(clar))
|
|
|
|
b <- suppressWarnings(
|
2018-08-29 16:25:57 +02:00
|
|
|
septic_patients %>%
|
2018-10-17 17:32:34 +02:00
|
|
|
select(mo, eryt) %>%
|
2018-11-16 20:50:50 +01:00
|
|
|
eucast_rules(col_mo = "mo") %>%
|
2018-10-17 17:32:34 +02:00
|
|
|
pull(eryt))
|
|
|
|
|
|
|
|
expect_identical(a[!is.na(b)],
|
|
|
|
b[!is.na(b)])
|
|
|
|
|
|
|
|
# amox is inferred by benzylpenicillin in Kingella kingae
|
|
|
|
expect_equal(
|
2019-01-03 23:56:19 +01:00
|
|
|
suppressWarnings(
|
|
|
|
as.list(eucast_rules(
|
|
|
|
data.frame(mo = as.mo("Kingella kingae"),
|
|
|
|
peni = "S",
|
|
|
|
amox = "-",
|
|
|
|
stringsAsFactors = FALSE)
|
|
|
|
, info = FALSE))$amox
|
|
|
|
),
|
2018-10-17 17:32:34 +02:00
|
|
|
"S")
|
|
|
|
|
2018-11-30 12:05:59 +01:00
|
|
|
# also test norf
|
|
|
|
expect_output(suppressWarnings(eucast_rules(septic_patients %>% mutate(norf = "S", nali = "S"))))
|
|
|
|
|
|
|
|
# check verbose output
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_output(suppressWarnings(eucast_rules(septic_patients, verbose = TRUE)))
|
2018-08-29 16:25:57 +02:00
|
|
|
|
2018-03-27 17:43:42 +02:00
|
|
|
})
|