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. #
|
2019-04-05 18:47:39 +02:00
|
|
|
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
2018-04-18 12:24:54 +02:00
|
|
|
|
2018-12-16 22:45:12 +01:00
|
|
|
context("mdro.R")
|
2018-04-18 12:24:54 +02:00
|
|
|
|
2018-11-16 20:50:50 +01:00
|
|
|
test_that("mdro works", {
|
2018-04-18 12:24:54 +02:00
|
|
|
library(dplyr)
|
|
|
|
|
2019-05-23 16:58:59 +02:00
|
|
|
expect_error(suppressWarnings(mdro(septic_patients, country = "invalid", col_mo = "mo", info = TRUE)))
|
|
|
|
expect_error(suppressWarnings(mdro(septic_patients, country = "fr", info = TRUE)))
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_error(suppressWarnings(mdro(septic_patients, country = c("de", "nl"), info = TRUE)))
|
|
|
|
expect_error(suppressWarnings(mdro(septic_patients, col_mo = "invalid", info = TRUE)))
|
2018-09-14 11:54:01 +02:00
|
|
|
|
2018-11-16 20:50:50 +01:00
|
|
|
outcome <- suppressWarnings(mdro(septic_patients))
|
|
|
|
outcome <- suppressWarnings(eucast_exceptional_phenotypes(septic_patients, info = TRUE))
|
2018-04-25 15:33:58 +02:00
|
|
|
# check class
|
|
|
|
expect_equal(outcome %>% class(), c('ordered', 'factor'))
|
|
|
|
|
2018-11-16 20:50:50 +01:00
|
|
|
outcome <- suppressWarnings(mdro(septic_patients, "nl", info = TRUE))
|
2018-04-18 12:24:54 +02:00
|
|
|
# check class
|
|
|
|
expect_equal(outcome %>% class(), c('ordered', 'factor'))
|
|
|
|
|
|
|
|
# septic_patients should have these finding using Dutch guidelines
|
2018-07-25 14:17:04 +02:00
|
|
|
expect_equal(outcome %>% freq() %>% pull(count),
|
2019-05-20 19:12:41 +02:00
|
|
|
c(1969, 25, 6)) # 1969 neg, 25 unconfirmed, 6 pos
|
2018-04-18 12:24:54 +02:00
|
|
|
|
2019-01-03 23:56:19 +01:00
|
|
|
expect_equal(
|
|
|
|
suppressWarnings(
|
|
|
|
brmo(septic_patients, info = FALSE)),
|
|
|
|
suppressWarnings(
|
2019-05-23 16:58:59 +02:00
|
|
|
mdro(septic_patients, country = "nl", info = FALSE)
|
2019-01-03 23:56:19 +01:00
|
|
|
)
|
|
|
|
)
|
2018-04-18 12:24:54 +02:00
|
|
|
|
2018-08-24 11:08:20 +02:00
|
|
|
# still working on German guidelines
|
2018-11-16 20:50:50 +01:00
|
|
|
expect_error(suppressWarnings(mrgn(septic_patients, info = TRUE)))
|
2018-08-24 11:08:20 +02:00
|
|
|
|
2019-04-09 14:59:17 +02:00
|
|
|
# test Dutch P. aeruginosa MDRO
|
|
|
|
expect_equal(suppressWarnings(
|
|
|
|
as.character(mdro(data.frame(mo = as.mo("P. aeruginosa"),
|
|
|
|
cfta = "S",
|
|
|
|
cipr = "S",
|
|
|
|
mero = "S",
|
|
|
|
imip = "S",
|
|
|
|
gent = "S",
|
|
|
|
tobr = "S",
|
|
|
|
pita = "S"),
|
|
|
|
country = "nl",
|
|
|
|
col_mo = "mo",
|
|
|
|
info = FALSE))
|
|
|
|
), "Negative")
|
|
|
|
expect_equal(suppressWarnings(
|
|
|
|
as.character(mdro(data.frame(mo = as.mo("P. aeruginosa"),
|
|
|
|
cefta = "R",
|
|
|
|
cipr = "R",
|
|
|
|
mero = "R",
|
|
|
|
imip = "R",
|
|
|
|
gent = "R",
|
|
|
|
tobr = "R",
|
|
|
|
pita = "R"),
|
|
|
|
country = "nl",
|
|
|
|
col_mo = "mo",
|
|
|
|
info = FALSE))
|
|
|
|
), "Positive")
|
|
|
|
|
2019-05-23 16:58:59 +02:00
|
|
|
# MDR TB
|
|
|
|
expect_equal(
|
|
|
|
suppressWarnings(
|
|
|
|
# select only rifampicine, mo will be determined automatically (as M. tuberculosis),
|
|
|
|
# number of mono-resistant strains should be equal to number of rifampicine-resistant strains
|
|
|
|
septic_patients %>% select(RIF) %>% mdr_tb() %>% freq() %>% pull(count) %>% .[2]
|
|
|
|
),
|
|
|
|
count_R(septic_patients$RIF))
|
|
|
|
|
|
|
|
sample_rsi <- function() {
|
|
|
|
sample(c("S", "I", "R"),
|
|
|
|
size = 5000,
|
|
|
|
prob = c(0.5, 0.1, 0.4),
|
|
|
|
replace = TRUE)
|
|
|
|
}
|
|
|
|
expect_gt(
|
|
|
|
suppressWarnings(
|
|
|
|
data.frame(rifampicin = sample_rsi(),
|
|
|
|
inh = sample_rsi(),
|
|
|
|
gatifloxacin = sample_rsi(),
|
|
|
|
eth = sample_rsi(),
|
|
|
|
pza = sample_rsi(),
|
|
|
|
MFX = sample_rsi(),
|
|
|
|
KAN = sample_rsi()) %>%
|
|
|
|
mdr_tb() %>%
|
|
|
|
n_distinct()),
|
|
|
|
2)
|
|
|
|
|
2018-04-18 12:24:54 +02:00
|
|
|
})
|