mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 19:26:13 +01:00
fix for keyab, more examples
This commit is contained in:
parent
ad662d7bab
commit
9920ac8a5c
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.2.0.9014
|
||||
Date: 2018-07-19
|
||||
Version: 0.2.0.9015
|
||||
Date: 2018-07-23
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(
|
||||
|
@ -254,3 +254,4 @@ ratio <- function(x, ratio) {
|
||||
}
|
||||
base::sum(x, na.rm = TRUE) * (ratio / base::sum(ratio, na.rm = TRUE))
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
||||
#' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of \strong{broad-spectrum} antibiotics, case-insensitive
|
||||
#' @param GramPos_1,GramPos_2,GramPos_3,GramPos_4,GramPos_5,GramPos_6 column names of antibiotics for \strong{Gram positives}, case-insensitive
|
||||
#' @param GramNeg_1,GramNeg_2,GramNeg_3,GramNeg_4,GramNeg_5,GramNeg_6 column names of antibiotics for \strong{Gram negatives}, case-insensitive
|
||||
#' @details The function \code{key_antibiotics} returns a character vector with antibiotic results.
|
||||
#' @param warnings give warning about missing antibiotic columns, they will anyway be ignored
|
||||
#' @details The function \code{key_antibiotics} returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using \code{key_antibiotics_equal}, to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (\code{"."}). The \code{\link{first_isolate}} function only uses this function on the same microbial species from the same patient. Using this, an MRSA will be included after a susceptible \emph{S. aureus} (MSSA) found within the same episode (see \code{episode} parameter of \code{\link{first_isolate}}). Without key antibiotic comparison it wouldn't.
|
||||
#'
|
||||
#' At default, the antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr
|
||||
#' \code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"vanc"}, \code{"teic"}, \code{"tetr"}, \code{"eryt"}, \code{"oxac"}, \code{"rifa"}.
|
||||
@ -34,7 +35,7 @@
|
||||
#' \code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"gent"}, \code{"tobr"}, \code{"coli"}, \code{"cfot"}, \code{"cfta"}, \code{"mero"}.
|
||||
#'
|
||||
#'
|
||||
#' The function \code{key_antibiotics_equal} checks the characters returned by \code{key_antibiotics} for equality, and returns a logical value.
|
||||
#' The function \code{key_antibiotics_equal} checks the characters returned by \code{key_antibiotics} for equality, and returns a logical vector.
|
||||
#' @inheritSection first_isolate Key antibiotics
|
||||
#' @rdname key_antibiotics
|
||||
#' @export
|
||||
@ -54,6 +55,16 @@
|
||||
#' first_isolate(tbl,
|
||||
#' col_keyantibiotics = 'keyab')
|
||||
#' }
|
||||
#'
|
||||
#' # output of the `key_antibiotics` function could be like this:
|
||||
#' strainA <- "SSSRR.S.R..S"
|
||||
#' strainB <- "SSSIRSSSRSSS"
|
||||
#'
|
||||
#' key_antibiotics_equal(strainA, strainB)
|
||||
#' # TRUE, because I is ignored (as are missing values)
|
||||
#'
|
||||
#' key_antibiotics_equal(strainA, strainB, ignore_I = FALSE)
|
||||
#' # FALSE, because I is not ignored and so the 4th value differs
|
||||
key_antibiotics <- function(tbl,
|
||||
col_bactid = "bactid",
|
||||
universal_1 = "amox",
|
||||
@ -74,7 +85,7 @@ key_antibiotics <- function(tbl,
|
||||
GramNeg_4 = "cfot",
|
||||
GramNeg_5 = "cfta",
|
||||
GramNeg_6 = "mero",
|
||||
info = TRUE) {
|
||||
warnings = TRUE) {
|
||||
|
||||
if (!col_bactid %in% colnames(tbl)) {
|
||||
stop('Column ', col_bactid, ' not found.', call. = FALSE)
|
||||
@ -84,7 +95,7 @@ key_antibiotics <- function(tbl,
|
||||
col.list <- c(universal_1, universal_2, universal_3, universal_4, universal_5, universal_6,
|
||||
GramPos_1, GramPos_2, GramPos_3, GramPos_4, GramPos_5, GramPos_6,
|
||||
GramNeg_1, GramNeg_2, GramNeg_3, GramNeg_4, GramNeg_5, GramNeg_6)
|
||||
col.list <- check_available_columns(tbl = tbl, col.list = col.list, info = info)
|
||||
col.list <- check_available_columns(tbl = tbl, col.list = col.list, info = warnings)
|
||||
universal_1 <- col.list[universal_1]
|
||||
universal_2 <- col.list[universal_2]
|
||||
universal_3 <- col.list[universal_3]
|
||||
@ -173,10 +184,17 @@ key_antibiotics_equal <- function(x,
|
||||
x <- gsub('I', '.', x, ignore.case = TRUE)
|
||||
y <- gsub('I', '.', y, ignore.case = TRUE)
|
||||
}
|
||||
|
||||
for (i in 1:length(x)) {
|
||||
x_split <- strsplit(x[i], "")[[1]]
|
||||
y_split <- strsplit(y[i], "")[[1]]
|
||||
y_split[x_split == "."] <- "."
|
||||
x_split[y_split == "."] <- "."
|
||||
x_checkfor <- paste(x_split, collapse = "")
|
||||
y_checkfor <- paste(y_split, collapse = "")
|
||||
result[i] <- nchar(x[i]) == nchar(y[i]) &
|
||||
(x[i] %like% paste0("^", y[i], "$") |
|
||||
y[i] %like% paste0("^", x[i], "$"))
|
||||
(x_checkfor %like% y_checkfor |
|
||||
y_checkfor %like% x_checkfor)
|
||||
}
|
||||
return(result)
|
||||
|
||||
|
@ -41,7 +41,7 @@ key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"),
|
||||
These function can be used to determine first isolates (see \code{\link{first_isolate}}). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates will then be called first \emph{weighted} isolates.
|
||||
}
|
||||
\details{
|
||||
The function \code{key_antibiotics} returns a character vector with antibiotic results.
|
||||
The function \code{key_antibiotics} returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using \code{key_antibiotics_equal}, to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (\code{"."}). The \code{\link{first_isolate}} function only uses this function on the same microbial species from the same patient. Using this, an MRSA will be included after a susceptible \emph{S. aureus} (MSSA) found within the same episode (see \code{episode} parameter of \code{\link{first_isolate}}). Without key antibiotic comparison it wouldn't.
|
||||
|
||||
At default, the antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr
|
||||
\code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"vanc"}, \code{"teic"}, \code{"tetr"}, \code{"eryt"}, \code{"oxac"}, \code{"rifa"}.
|
||||
@ -50,7 +50,7 @@ The function \code{key_antibiotics} returns a character vector with antibiotic r
|
||||
\code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"gent"}, \code{"tobr"}, \code{"coli"}, \code{"cfot"}, \code{"cfta"}, \code{"mero"}.
|
||||
|
||||
|
||||
The function \code{key_antibiotics_equal} checks the characters returned by \code{key_antibiotics} for equality, and returns a logical value.
|
||||
The function \code{key_antibiotics_equal} checks the characters returned by \code{key_antibiotics} for equality, and returns a logical vector.
|
||||
}
|
||||
\section{Key antibiotics}{
|
||||
|
||||
@ -77,6 +77,16 @@ tbl$first_isolate_weighed <-
|
||||
first_isolate(tbl,
|
||||
col_keyantibiotics = 'keyab')
|
||||
}
|
||||
|
||||
# output of the `key_antibiotics` function could be like this:
|
||||
strainA <- "SSSRR.S.R..S"
|
||||
strainB <- "SSSIRSSSRSSS"
|
||||
|
||||
key_antibiotics_equal(strainA, strainB)
|
||||
# TRUE, because I is ignored (as are missing values)
|
||||
|
||||
key_antibiotics_equal(strainA, strainB, ignore_I = FALSE)
|
||||
# FALSE, because I is not ignored and so the 4th value differs
|
||||
}
|
||||
\seealso{
|
||||
\code{\link{first_isolate}}
|
||||
|
@ -1,13 +1,5 @@
|
||||
context("first_isolates.R")
|
||||
|
||||
test_that("keyantibiotics work", {
|
||||
expect_equal(length(key_antibiotics(septic_patients, info = FALSE)), nrow(septic_patients))
|
||||
expect_true(key_antibiotics_equal("SSS", "SSS"))
|
||||
expect_false(key_antibiotics_equal("SSS", "SRS"))
|
||||
expect_true(key_antibiotics_equal("SSS", "SIS", ignore_I = TRUE))
|
||||
expect_false(key_antibiotics_equal("SSS", "SIS", ignore_I = FALSE))
|
||||
})
|
||||
|
||||
test_that("first isolates work", {
|
||||
# septic_patients contains 1959 out of 2000 first isolates
|
||||
expect_equal(
|
||||
|
11
tests/testthat/test-key_antibiotics.R
Normal file
11
tests/testthat/test-key_antibiotics.R
Normal file
@ -0,0 +1,11 @@
|
||||
context("key_antibiotics.R")
|
||||
|
||||
test_that("keyantibiotics work", {
|
||||
expect_equal(length(key_antibiotics(septic_patients, warnings = FALSE)), nrow(septic_patients))
|
||||
expect_true(key_antibiotics_equal("SSS", "SSS"))
|
||||
expect_false(key_antibiotics_equal("SSS", "SRS"))
|
||||
expect_true(key_antibiotics_equal("SSS", "SIS", ignore_I = TRUE))
|
||||
expect_false(key_antibiotics_equal("SSS", "SIS", ignore_I = FALSE))
|
||||
expect_true(key_antibiotics_equal(".SS", "SI.", ignore_I = TRUE))
|
||||
expect_false(key_antibiotics_equal(".SS", "SI.", ignore_I = FALSE))
|
||||
})
|
Loading…
Reference in New Issue
Block a user