mirror of
https://github.com/msberends/AMR.git
synced 2025-01-12 00:11:50 +01:00
fix for antibiogram()
, transform WHONET
data set to sir
This commit is contained in:
parent
dad25302f2
commit
c2cfc5ef84
@ -1,5 +1,5 @@
|
||||
Package: AMR
|
||||
Version: 1.8.2.9138
|
||||
Version: 1.8.2.9139
|
||||
Date: 2023-02-22
|
||||
Title: Antimicrobial Resistance Data Analysis
|
||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
||||
# AMR 1.8.2.9138
|
||||
# AMR 1.8.2.9139
|
||||
|
||||
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
||||
|
||||
|
2
R/ab.R
2
R/ab.R
@ -249,8 +249,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
|
||||
next
|
||||
}
|
||||
|
||||
print("here")
|
||||
|
||||
# length of input is quite long, and Levenshtein distance is only max 2
|
||||
if (nchar(x[i]) >= 10) {
|
||||
levenshtein <- as.double(utils::adist(x[i], AMR_env$AB_lookup$generalised_name))
|
||||
|
@ -31,7 +31,7 @@
|
||||
#'
|
||||
#' Generate an antibiogram, and communicate the results in plots or tables. These functions follow the logic of Klinker *et al.* and Barbieri *et al.* (see *Source*), and allow reporting in e.g. R Markdown and Quarto as well.
|
||||
#' @param x a [data.frame] containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see [as.sir()])
|
||||
#' @param antibiotics vector of column names, or (any combinations of) [antibiotic selectors][antibiotic_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be column names separated with `"+"`, such as "TZP+TOB" given that the data set contains columns "TZP" and "TOB". See *Examples*.
|
||||
#' @param antibiotics vector of any antibiotic name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antibiotic selectors][antibiotic_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be set to values separated with `"+"`, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in `x`. See *Examples*.
|
||||
#' @param mo_transform a character to transform microorganism input - must be "name", "shortname", "gramstain", or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
|
||||
#' @param ab_transform a character to transform antibiotic input - must be one of the column names of the [antibiotics] data set: `r vector_or(colnames(antibiotics), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
|
||||
#' @param syndromic_group a column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*.
|
||||
@ -165,8 +165,9 @@
|
||||
#' mo_transform = "gramstain"
|
||||
#' )
|
||||
#'
|
||||
#' # names of antibiotics do not need to resemble columns exactly:
|
||||
#' antibiogram(example_isolates,
|
||||
#' antibiotics = c("TZP", "TZP+TOB"),
|
||||
#' antibiotics = c("Cipro", "cipro + genta"),
|
||||
#' mo_transform = "gramstain",
|
||||
#' ab_transform = "name",
|
||||
#' sep = " & "
|
||||
@ -313,25 +314,16 @@ antibiogram <- function(x,
|
||||
# get antibiotics from user
|
||||
user_ab <- suppressMessages(suppressWarnings(lapply(antibiotics, as.ab, flag_multiple_results = FALSE, info = FALSE)))
|
||||
user_ab <- lapply(user_ab, function(x) unname(df_ab[match(x, names(df_ab))]))
|
||||
#
|
||||
# names(user_ab) <- antibiotics.bak
|
||||
# user_ab <- user_ab
|
||||
return(1)
|
||||
# cols <-
|
||||
# convert antibiotics to valid AB codes
|
||||
abx_ab <- suppressMessages(suppressWarnings(lapply(antibiotics, as.ab, flag_multiple_results = FALSE, info = FALSE)))
|
||||
# match them to existing column names
|
||||
abx_user <- lapply(abx_ab, function(a) unname(names(cols)[match(a, names(cols))]))
|
||||
|
||||
# remove non-existing columns
|
||||
non_existing <- unlist(antibiotics)[is.na(unlist(abx_ab))]
|
||||
if (length(non_existing) > 0) {
|
||||
warning_("The following antibiotics were not available and ignored: ", vector_and(non_existing, sort = FALSE))
|
||||
abx_user <- Map(antibiotics, abx_user, f = function(input, ab) input[!is.na(ab)])
|
||||
}
|
||||
# non_existing <- unlist(antibiotics)[is.na(unlist(abx_ab))]
|
||||
# if (length(non_existing) > 0) {
|
||||
# warning_("The following antibiotics were not available and ignored: ", vector_and(non_existing, sort = FALSE))
|
||||
# abx_user <- Map(antibiotics, abx_user, f = function(input, ab) input[!is.na(ab)])
|
||||
# }
|
||||
|
||||
# make list unique
|
||||
antibiotics <- unique(abx_user)
|
||||
print(antibiotics)
|
||||
antibiotics <- unique(user_ab)
|
||||
# go through list to set AMR in combinations
|
||||
for (i in seq_len(length(antibiotics))) {
|
||||
abx <- antibiotics[[i]]
|
||||
|
2
R/data.R
2
R/data.R
@ -197,7 +197,7 @@
|
||||
|
||||
#' Data Set with `r format(nrow(WHONET), big.mark = " ")` Isolates - WHONET Example
|
||||
#'
|
||||
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our [example_isolates] data set. All patient names are created using online surname generators and are only in place for practice purposes.
|
||||
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our [example_isolates] data set. All patient names were created using online surname generators and are only in place for practice purposes.
|
||||
#' @format A [tibble][tibble::tibble] with `r format(nrow(WHONET), big.mark = " ")` observations and `r ncol(WHONET)` variables:
|
||||
#' - `Identification number`\cr ID of the sample
|
||||
#' - `Specimen number`\cr ID of the specimen
|
||||
|
2
R/sir.R
2
R/sir.R
@ -300,7 +300,7 @@ is_sir_eligible <- function(x, threshold = 0.05) {
|
||||
#' @export
|
||||
# extra param: warn (logical, to never throw a warning)
|
||||
as.sir.default <- function(x, ...) {
|
||||
if (is.sir(x)) {
|
||||
if (inherits(x, "sir")) {
|
||||
return(x)
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,7 @@ ggplot_rsi_predict <- function(...) {
|
||||
#' @export
|
||||
is.rsi <- function(...) {
|
||||
# REMINDER: change as.sir() to remove the deprecation warning there
|
||||
deprecation_warning("is.rsi", "is.sir")
|
||||
is.sir(...)
|
||||
suppressWarnings(is.sir(...))
|
||||
}
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
|
BIN
data/WHONET.rda
BIN
data/WHONET.rda
Binary file not shown.
@ -39,7 +39,7 @@ A \link[tibble:tibble]{tibble} with 500 observations and 53 variables:
|
||||
WHONET
|
||||
}
|
||||
\description{
|
||||
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our \link{example_isolates} data set. All patient names are created using online surname generators and are only in place for practice purposes.
|
||||
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our \link{example_isolates} data set. All patient names were created using online surname generators and are only in place for practice purposes.
|
||||
}
|
||||
\details{
|
||||
Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
|
||||
|
@ -46,7 +46,7 @@ antibiogram(
|
||||
\arguments{
|
||||
\item{x}{a \link{data.frame} containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})}
|
||||
|
||||
\item{antibiotics}{vector of column names, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be column names separated with \code{"+"}, such as "TZP+TOB" given that the data set contains columns "TZP" and "TOB". See \emph{Examples}.}
|
||||
\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
|
||||
|
||||
\item{mo_transform}{a character to transform microorganism input - must be "name", "shortname", "gramstain", or one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.}
|
||||
|
||||
@ -194,8 +194,9 @@ antibiogram(example_isolates,
|
||||
mo_transform = "gramstain"
|
||||
)
|
||||
|
||||
# names of antibiotics do not need to resemble columns exactly:
|
||||
antibiogram(example_isolates,
|
||||
antibiotics = c("TZP", "TZP+TOB"),
|
||||
antibiotics = c("Cipro", "cipro + genta"),
|
||||
mo_transform = "gramstain",
|
||||
ab_transform = "name",
|
||||
sep = " & "
|
||||
|
Loading…
Reference in New Issue
Block a user