mirror of
https://github.com/msberends/AMR.git
synced 2025-07-18 01:23:16 +02:00
(v2.1.1.9126) implemented WISCA! Also added top_n_microorganisms()
and fixed Python wrapper
This commit is contained in:
@ -99,17 +99,22 @@ expect_equal(colnames(ab7), c("Syndroomgroep", "Pathogeen (N min-max)", "Amikaci
|
||||
# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
|
||||
|
||||
# the data set could contain a filter for e.g. respiratory specimens
|
||||
ab8 <- antibiogram(example_isolates,
|
||||
antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
|
||||
mo_transform = "gramstain",
|
||||
minimum = 10, # this should be >= 30, but now just as example
|
||||
syndromic_group = ifelse(example_isolates$age >= 65 &
|
||||
example_isolates$gender == "M",
|
||||
"WISCA Group 1", "WISCA Group 2"),
|
||||
ab_transform = NULL)
|
||||
ab8 <- suppressWarnings(antibiogram(example_isolates,
|
||||
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
|
||||
wisca = TRUE))
|
||||
|
||||
expect_inherits(ab8, "antibiogram")
|
||||
expect_equal(colnames(ab8), c("Syndromic Group", "Pathogen", "AMC", "AMC + CIP", "TZP", "TZP + TOB"))
|
||||
expect_equal(colnames(ab8), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
|
||||
|
||||
# grouped tibbles
|
||||
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
ab9 <- example_isolates %>%
|
||||
group_by(ward, gender) %>%
|
||||
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
|
||||
expect_equal(colnames(ab9), c("ward", "gender", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
|
||||
}
|
||||
|
||||
|
||||
# Generate plots with ggplot2 or base R --------------------------------
|
||||
|
||||
@ -123,6 +128,9 @@ expect_silent(plot(ab5))
|
||||
expect_silent(plot(ab6))
|
||||
expect_silent(plot(ab7))
|
||||
expect_silent(plot(ab8))
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
expect_silent(plot(ab9))
|
||||
}
|
||||
|
||||
if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot2::autoplot(ab1), "gg")
|
||||
@ -133,4 +141,7 @@ if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot2::autoplot(ab6), "gg")
|
||||
expect_inherits(ggplot2::autoplot(ab7), "gg")
|
||||
expect_inherits(ggplot2::autoplot(ab8), "gg")
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
expect_inherits(ggplot2::autoplot(ab9), "gg")
|
||||
}
|
||||
}
|
||||
|
43
inst/tinytest/test-top_n_microorganisms.R
Normal file
43
inst/tinytest/test-top_n_microorganisms.R
Normal file
@ -0,0 +1,43 @@
|
||||
# ==================================================================== #
|
||||
# TITLE: #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
||||
# #
|
||||
# SOURCE CODE: #
|
||||
# https://github.com/msberends/AMR #
|
||||
# #
|
||||
# PLEASE CITE THIS SOFTWARE AS: #
|
||||
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
|
||||
# Journal of Statistical Software, 104(3), 1-31. #
|
||||
# https://doi.org/10.18637/jss.v104.i03 #
|
||||
# #
|
||||
# Developed at the University of Groningen and the University Medical #
|
||||
# Center Groningen in The Netherlands, in collaboration with many #
|
||||
# colleagues from around the world, see our website. #
|
||||
# #
|
||||
# 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. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# #
|
||||
# Visit our website for the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
out1 <- top_n_microorganisms(example_isolates, n = 3)
|
||||
out2 <- top_n_microorganisms(example_isolates, n = 5, property = "genus")
|
||||
out3 <- top_n_microorganisms(example_isolates, n = 5, property = "genus", n_for_each = 3)
|
||||
|
||||
expect_equal(NROW(out1), 1015, tolerance = 0.5)
|
||||
expect_equal(NROW(out2), 1742, tolerance = 0.5)
|
||||
expect_equal(NROW(out3), 1497, tolerance = 0.5)
|
||||
|
||||
expect_equal(length(table(out1$mo)), 3, tolerance = 0.5)
|
||||
expect_equal(length(table(out2$mo)), 39, tolerance = 0.5)
|
||||
expect_equal(length(table(out3$mo)), 13, tolerance = 0.5)
|
||||
|
||||
expect_equal(length(unique(mo_genus(out2$mo))), 5, tolerance = 0.5)
|
||||
expect_equal(length(unique(mo_genus(out3$mo))), 5, tolerance = 0.5)
|
Reference in New Issue
Block a user