diff --git a/DESCRIPTION b/DESCRIPTION index 59479626d..1c29de0fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 2.1.1.9274 -Date: 2025-05-12 +Version: 2.1.1.9275 +Date: 2025-05-13 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index fc62d2e51..45050954f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9274 +# AMR 2.1.1.9275 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://amr-for-r.org/#get-this-package).)* @@ -149,6 +149,7 @@ This package now supports not only tools for AMR data analysis in clinical setti * MDRO determination (using `mdro()`) * Implemented the new Dutch national MDRO guideline (SRI-richtlijn BRMO, Nov 2024) * Added arguments `esbl`, `carbapenemase`, `mecA`, `mecC`, `vanA`, `vanB` to denote column names or logical values indicating presence of these genes (or production of their proteins) + * The Verbose Mode (`verbose = TRUE`) now includes the guideline name * Added console colours support of `sir` class for Positron ### Other diff --git a/R/mdro.R b/R/mdro.R index 02ad893ec..51f2a35b4 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -141,6 +141,8 @@ #' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()]. #' @inheritSection as.sir Interpretation of SIR #' @return +#' - If `verbose` is set to `TRUE`:\cr +#' A [data.frame] containing columns `row_number`, `microorganism`, `MDRO`, `reason`, `all_nonsusceptible_columns`, `guideline` #' - CMI 2012 paper - function [mdr_cmi2012()] or [mdro()]:\cr #' Ordered [factor] with levels `Negative` < `Multi-drug-resistant (MDR)` < `Extensively drug-resistant (XDR)` < `Pandrug-resistant (PDR)` #' - TB guideline - function [mdr_tb()] or [`mdro(..., guideline = "TB")`][mdro()]:\cr @@ -148,7 +150,7 @@ #' - German guideline - function [mrgn()] or [`mdro(..., guideline = "MRGN")`][mdro()]:\cr #' Ordered [factor] with levels `Negative` < `3MRGN` < `4MRGN` #' - Everything else, except for custom guidelines:\cr -#' Ordered [factor] with levels `Negative` < `Positive, unconfirmed` < `Positive`. The value `"Positive, unconfirmed"` means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests +#' Ordered [factor] with levels `Negative` < `Positive, unconfirmed` < `Positive`. The value `"Positive, unconfirmed"` means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. genotypic) tests #' @rdname mdro #' @aliases MDR XDR PDR BRMO 3MRGN 4MRGN #' @export @@ -349,17 +351,26 @@ mdro <- function(x = NULL, )))) } } + if (isTRUE(verbose)) { + x$reason[is.na(x$reason)] <- "not covered by guideline" + x$microorganism <- NA_character_ + x$guideline <- "Custom guideline" return(x[, c( "row_number", + "microorganism", "MDRO", "reason", - "all_nonsusceptible_columns" - )]) + "all_nonsusceptible_columns", + "guideline" + ), + drop = FALSE + ]) } else { return(x$MDRO) } - } + } # end of custom MDRO guideline + guideline <- tolower(gsub("[^a-zA-Z0-9.]+", "", guideline)) if (is.null(guideline)) { # default to the paper by Magiorakos et al. (2012) @@ -772,10 +783,10 @@ mdro <- function(x = NULL, function(y) y %in% search_result ) paste( - sort(c( + unique(sort(c( unlist(strsplit(x[row, "all_nonsusceptible_columns", drop = TRUE], ", ", fixed = TRUE)), names(cols_nonsus)[cols_nonsus] - )), + ))), collapse = ", " ) } @@ -849,7 +860,7 @@ mdro <- function(x = NULL, rows, function(row, group_vct = lst_vector) { cols_nonsus <- vapply(FUN.VALUE = logical(1), x[row, group_vct, drop = FALSE], function(y) y %in% search_result) - paste(sort(names(cols_nonsus)[cols_nonsus]), collapse = ", ") + paste(unique(sort(names(cols_nonsus)[cols_nonsus])), collapse = ", ") } ) } @@ -1943,12 +1954,14 @@ mdro <- function(x = NULL, # format data set colnames(x)[colnames(x) == col_mo] <- "microorganism" x$microorganism <- mo_name(x$microorganism, language = NULL) + x$guideline <- paste0(guideline$author, " - ", guideline$name, ", ", guideline$version, ")") x[, c( "row_number", "microorganism", "MDRO", "reason", - "all_nonsusceptible_columns" + "all_nonsusceptible_columns", + "guideline" ), drop = FALSE ] @@ -2119,7 +2132,7 @@ run_custom_mdro_guideline <- function(df, guideline, info) { all_nonsusceptible_columns <- vapply( FUN.VALUE = character(1), all_nonsusceptible_columns, - function(x) paste0(rownames(all_nonsusceptible_columns)[which(x)], collapse = " ") + function(x) paste0(rownames(all_nonsusceptible_columns)[which(x)], collapse = ", ") ) all_nonsusceptible_columns[is.na(out)] <- NA_character_ diff --git a/man/mdro.Rd b/man/mdro.Rd index 1a99e5bce..f6d1783e7 100644 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -72,6 +72,8 @@ eucast_exceptional_phenotypes(x = NULL, only_sir_columns = FALSE, } \value{ \itemize{ +\item If \code{verbose} is set to \code{TRUE}:\cr +A \link{data.frame} containing columns \code{row_number}, \code{microorganism}, \code{MDRO}, \code{reason}, \code{all_nonsusceptible_columns}, \code{guideline} \item CMI 2012 paper - function \code{\link[=mdr_cmi2012]{mdr_cmi2012()}} or \code{\link[=mdro]{mdro()}}:\cr Ordered \link{factor} with levels \code{Negative} < \code{Multi-drug-resistant (MDR)} < \verb{Extensively drug-resistant (XDR)} < \code{Pandrug-resistant (PDR)} \item TB guideline - function \code{\link[=mdr_tb]{mdr_tb()}} or \code{\link[=mdro]{mdro(..., guideline = "TB")}}:\cr @@ -79,7 +81,7 @@ Ordered \link{factor} with levels \code{Negative} < \code{Mono-resistant} < \cod \item German guideline - function \code{\link[=mrgn]{mrgn()}} or \code{\link[=mdro]{mdro(..., guideline = "MRGN")}}:\cr Ordered \link{factor} with levels \code{Negative} < \verb{3MRGN} < \verb{4MRGN} \item Everything else, except for custom guidelines:\cr -Ordered \link{factor} with levels \code{Negative} < \verb{Positive, unconfirmed} < \code{Positive}. The value \code{"Positive, unconfirmed"} means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests +Ordered \link{factor} with levels \code{Negative} < \verb{Positive, unconfirmed} < \code{Positive}. The value \code{"Positive, unconfirmed"} means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. genotypic) tests } } \description{ diff --git a/tests/testthat/test-mdro.R b/tests/testthat/test-mdro.R index 4ac851564..751d8ac0b 100755 --- a/tests/testthat/test-mdro.R +++ b/tests/testthat/test-mdro.R @@ -284,7 +284,7 @@ test_that("test-mdro.R", { expect_equal( colnames(suppressWarnings(mdro(example_isolates[1:10, ], verbose = TRUE, info = FALSE))), - c("row_number", "microorganism", "MDRO", "reason", "all_nonsusceptible_columns") + c("row_number", "microorganism", "MDRO", "reason", "all_nonsusceptible_columns", "guideline") ) # print groups