new col names for `key_antibiotics`

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-07-19 15:11:23 +02:00
parent 0d64c166f0
commit ad662d7bab
5 changed files with 90 additions and 82 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 0.2.0.9013 Version: 0.2.0.9014
Date: 2018-07-17 Date: 2018-07-19
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(
person( person(

View File

@ -24,6 +24,7 @@
#### Changed #### Changed
* Pretty printing for tibbles removed as it is not really the scope of this package * Pretty printing for tibbles removed as it is not really the scope of this package
* Improved speed of key antibiotics comparison for determining first isolates * Improved speed of key antibiotics comparison for determining first isolates
* Column names for the `key_antibiotics` function are now generic: 6 for broadspectrum ABs, 6 for Gram-positive specific and 6 for Gram-negative specific ABs
* Printing of class `mic` now shows all MIC values * Printing of class `mic` now shows all MIC values
* `%like%` now supports multiple patterns * `%like%` now supports multiple patterns
* Frequency tables are now actual `data.frame`s with altered console printing to make it look like a frequency table. Because of this, the parameter `toConsole` is not longer needed. * Frequency tables are now actual `data.frame`s with altered console printing to make it look like a frequency table. Because of this, the parameter `toConsole` is not longer needed.

View File

@ -162,7 +162,7 @@ first_isolate <- function(tbl,
} }
# remove testcodes # remove testcodes
if (!is.na(testcodes_exclude[1]) & testcodes_exclude[1] != '' & info == TRUE) { if (!is.na(testcodes_exclude[1]) & testcodes_exclude[1] != '' & info == TRUE) {
cat('Isolates from these test codes will be ignored:\n', toString(testcodes_exclude), '\n') cat('[Criteria] Excluded test codes:\n', toString(testcodes_exclude), '\n')
} }
if (is.na(col_icu)) { if (is.na(col_icu)) {
@ -181,7 +181,7 @@ first_isolate <- function(tbl,
if (!is.na(filter_specimen) & filter_specimen != '') { if (!is.na(filter_specimen) & filter_specimen != '') {
check_columns_existance(col_specimen, tbl) check_columns_existance(col_specimen, tbl)
if (info == TRUE) { if (info == TRUE) {
cat('Isolates other than of specimen group \'', filter_specimen, '\' will be ignored. ', sep = '') cat('[Criteria] Excluded other than specimen group \'', filter_specimen, '\'\n', sep = '')
} }
} else { } else {
filter_specimen <- '' filter_specimen <- ''
@ -209,8 +209,8 @@ first_isolate <- function(tbl,
if (filter_specimen == '') { if (filter_specimen == '') {
if (icu_exclude == FALSE) { if (icu_exclude == FALSE) {
if (info == TRUE) { if (info == TRUE & !is.na(col_icu)) {
cat('Isolates from ICU will *NOT* be ignored.\n') cat('[Criteria] Included isolates from ICU.\n')
} }
tbl <- tbl %>% tbl <- tbl %>%
arrange_at(c(col_patient_id, arrange_at(c(col_patient_id,
@ -221,7 +221,7 @@ first_isolate <- function(tbl,
row.end <- nrow(tbl) row.end <- nrow(tbl)
} else { } else {
if (info == TRUE) { if (info == TRUE) {
cat('Isolates from ICU will be ignored.\n') cat('[Criteria] Excluded isolates from ICU.\n')
} }
tbl <- tbl %>% tbl <- tbl %>%
arrange_at(c(col_icu, arrange_at(c(col_icu,
@ -241,8 +241,8 @@ first_isolate <- function(tbl,
} else { } else {
# sort on specimen and only analyse these row to save time # sort on specimen and only analyse these row to save time
if (icu_exclude == FALSE) { if (icu_exclude == FALSE) {
if (info == TRUE) { if (info == TRUE & !is.na(col_icu)) {
cat('Isolates from ICU will *NOT* be ignored.\n') cat('[Criteria] Included isolates from ICU.\n')
} }
tbl <- tbl %>% tbl <- tbl %>%
arrange_at(c(col_specimen, arrange_at(c(col_specimen,
@ -258,7 +258,7 @@ first_isolate <- function(tbl,
) )
} else { } else {
if (info == TRUE) { if (info == TRUE) {
cat('Isolates from ICU will be ignored.\n') cat('[Criteria] Excluded isolates from ICU.\n')
} }
tbl <- tbl %>% tbl <- tbl %>%
arrange_at(c(col_icu, arrange_at(c(col_icu,
@ -281,7 +281,7 @@ first_isolate <- function(tbl,
if (abs(row.start) == Inf | abs(row.end) == Inf) { if (abs(row.start) == Inf | abs(row.end) == Inf) {
if (info == TRUE) { if (info == TRUE) {
cat('No isolates found.\n') message('No isolates found.')
} }
# NA's where genus is unavailable # NA's where genus is unavailable
tbl <- tbl %>% tbl <- tbl %>%
@ -317,15 +317,15 @@ first_isolate <- function(tbl,
if (col_keyantibiotics != '') { if (col_keyantibiotics != '') {
if (info == TRUE) { if (info == TRUE) {
if (type == 'keyantibiotics') { if (type == 'keyantibiotics') {
cat('Key antibiotics for first weighted isolates will be compared (') cat('[Criteria] Inclusion based on key antibiotics, ')
if (ignore_I == FALSE) { if (ignore_I == FALSE) {
cat('NOT ') cat('not ')
} }
cat('ignoring I).') cat('ignoring I.\n')
} }
if (type == 'points') { if (type == 'points') {
cat(paste0('Comparing antibiotics for first weighted isolates (using points threshold of ' cat(paste0('[Criteria] Inclusion based on key antibiotics, using points threshold of '
, points_threshold, ')...\n')) , points_threshold, '.\n'))
} }
} }
type_param <- type type_param <- type
@ -350,9 +350,6 @@ first_isolate <- function(tbl,
TRUE, TRUE,
FALSE)) FALSE))
) )
if (info == TRUE) {
cat('\n')
}
} else { } else {
# suppress warnings because dplyr want us to use library(dplyr) when using filter(row_number()) # suppress warnings because dplyr want us to use library(dplyr) when using filter(row_number())
suppressWarnings( suppressWarnings(
@ -388,13 +385,13 @@ first_isolate <- function(tbl,
pull(real_first_isolate) pull(real_first_isolate)
if (info == TRUE) { if (info == TRUE) {
cat(paste0('\nFound ', message(paste0('Found ',
all_first %>% sum(na.rm = TRUE), all_first %>% sum(na.rm = TRUE),
' first ', weighted.notice, 'isolates (', ' first ', weighted.notice, 'isolates (',
(all_first %>% sum(na.rm = TRUE) / scope.size) %>% percent(), (all_first %>% sum(na.rm = TRUE) / scope.size) %>% percent(),
' of isolates in scope [where genus was not empty] and ', ' of isolates in scope [where genus was not empty] and ',
(all_first %>% sum(na.rm = TRUE) / tbl %>% nrow()) %>% percent(), (all_first %>% sum(na.rm = TRUE) / tbl %>% nrow()) %>% percent(),
' of total)\n')) ' of total)'))
} }
if (output_logical == FALSE) { if (output_logical == FALSE) {

View File

@ -22,14 +22,16 @@
#' @param tbl table with antibiotics coloms, like \code{amox} and \code{amcl}. #' @param tbl table with antibiotics coloms, like \code{amox} and \code{amcl}.
#' @param x,y characters to compare #' @param x,y characters to compare
#' @inheritParams first_isolate #' @inheritParams first_isolate
#' @param amcl,amox,cfot,cfta,cfur,cipr,coli,eryt,gent,mero,oxac,pita,rifa,teic,tetr,tobr,trsu,vanc column names of antibiotics, case-insensitive #' @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. #' @details The function \code{key_antibiotics} returns a character vector with antibiotic results.
#' #'
#' The antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr #' At default, the antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr
#' amox, amcl, cfur, pita, cipr, trsu, vanc, teic, tetr, eryt, oxac, rifa. #' \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"}.
#' #'
#' The antibiotics that are used for \strong{Gram negative bacteria} are (colum names): \cr #' At default, the antibiotics that are used for \strong{Gram negative bacteria} are (colum names): \cr
#' amox, amcl, cfur, pita, cipr, trsu, gent, tobr, coli, cfot, cfta, mero. #' \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 value.
@ -54,24 +56,24 @@
#' } #' }
key_antibiotics <- function(tbl, key_antibiotics <- function(tbl,
col_bactid = "bactid", col_bactid = "bactid",
amcl = "amcl", universal_1 = "amox",
amox = "amox", universal_2 = "amcl",
cfot = "cfot", universal_3 = "cfur",
cfta = "cfta", universal_4 = "pita",
cfur = "cfur", universal_5 = "cipr",
cipr = "cipr", universal_6 = "trsu",
coli = "coli", GramPos_1 = "vanc",
eryt = "eryt", GramPos_2 = "teic",
gent = "gent", GramPos_3 = "tetr",
mero = "mero", GramPos_4 = "eryt",
oxac = "oxac", GramPos_5 = "oxac",
pita = "pita", GramPos_6 = "rifa",
rifa = "rifa", GramNeg_1 = "gent",
teic = "teic", GramNeg_2 = "tobr",
tetr = "tetr", GramNeg_3 = "coli",
tobr = "tobr", GramNeg_4 = "cfot",
trsu = "trsu", GramNeg_5 = "cfta",
vanc = "vanc", GramNeg_6 = "mero",
info = TRUE) { info = TRUE) {
if (!col_bactid %in% colnames(tbl)) { if (!col_bactid %in% colnames(tbl)) {
@ -79,37 +81,40 @@ key_antibiotics <- function(tbl,
} }
# check columns # check columns
col.list <- c(amcl, amox, cfot, cfta, cfur, cipr, col.list <- c(universal_1, universal_2, universal_3, universal_4, universal_5, universal_6,
coli, eryt, gent, mero, oxac, pita, GramPos_1, GramPos_2, GramPos_3, GramPos_4, GramPos_5, GramPos_6,
rifa, teic, tetr, tobr, trsu, vanc) 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 = info)
amcl <- col.list[amcl] universal_1 <- col.list[universal_1]
amox <- col.list[amox] universal_2 <- col.list[universal_2]
cfot <- col.list[cfot] universal_3 <- col.list[universal_3]
cfta <- col.list[cfta] universal_4 <- col.list[universal_4]
cfur <- col.list[cfur] universal_5 <- col.list[universal_5]
cipr <- col.list[cipr] universal_6 <- col.list[universal_6]
coli <- col.list[coli] GramPos_1 <- col.list[GramPos_1]
eryt <- col.list[eryt] GramPos_2 <- col.list[GramPos_2]
gent <- col.list[gent] GramPos_3 <- col.list[GramPos_3]
mero <- col.list[mero] GramPos_4 <- col.list[GramPos_4]
oxac <- col.list[oxac] GramPos_5 <- col.list[GramPos_5]
pita <- col.list[pita] GramPos_6 <- col.list[GramPos_6]
rifa <- col.list[rifa] GramNeg_1 <- col.list[GramNeg_1]
teic <- col.list[teic] GramNeg_2 <- col.list[GramNeg_2]
tetr <- col.list[tetr] GramNeg_3 <- col.list[GramNeg_3]
tobr <- col.list[tobr] GramNeg_4 <- col.list[GramNeg_4]
trsu <- col.list[trsu] GramNeg_5 <- col.list[GramNeg_5]
vanc <- col.list[vanc] GramNeg_6 <- col.list[GramNeg_6]
gram_positive = c(amox, amcl, cfur, pita, cipr, trsu, universal <- c(universal_1, universal_2, universal_3,
# specific for G+: universal_4, universal_5, universal_6)
vanc, teic, tetr, eryt, oxac, rifa)
gram_positive = c(universal,
GramPos_1, GramPos_2, GramPos_3,
GramPos_4, GramPos_5, GramPos_6)
gram_positive <- gram_positive[!is.na(gram_positive)] gram_positive <- gram_positive[!is.na(gram_positive)]
gram_negative = c(amox, amcl, cfur, pita, cipr, trsu, gram_negative = c(universal,
# specific for G-: GramNeg_1, GramNeg_2, GramNeg_3,
gent, tobr, coli, cfot, cfta, mero) GramNeg_4, GramNeg_5, GramNeg_6)
gram_negative <- gram_negative[!is.na(gram_negative)] gram_negative <- gram_negative[!is.na(gram_negative)]
# join microorganisms # join microorganisms

View File

@ -5,12 +5,13 @@
\alias{key_antibiotics_equal} \alias{key_antibiotics_equal}
\title{Key antibiotics for first \emph{weighted} isolates} \title{Key antibiotics for first \emph{weighted} isolates}
\usage{ \usage{
key_antibiotics(tbl, col_bactid = "bactid", amcl = "amcl", amox = "amox", key_antibiotics(tbl, col_bactid = "bactid", universal_1 = "amox",
cfot = "cfot", cfta = "cfta", cfur = "cfur", cipr = "cipr", universal_2 = "amcl", universal_3 = "cfur", universal_4 = "pita",
coli = "coli", eryt = "eryt", gent = "gent", mero = "mero", universal_5 = "cipr", universal_6 = "trsu", GramPos_1 = "vanc",
oxac = "oxac", pita = "pita", rifa = "rifa", teic = "teic", GramPos_2 = "teic", GramPos_3 = "tetr", GramPos_4 = "eryt",
tetr = "tetr", tobr = "tobr", trsu = "trsu", vanc = "vanc", GramPos_5 = "oxac", GramPos_6 = "rifa", GramNeg_1 = "gent",
info = TRUE) GramNeg_2 = "tobr", GramNeg_3 = "coli", GramNeg_4 = "cfot",
GramNeg_5 = "cfta", GramNeg_6 = "mero", info = TRUE)
key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"), key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"),
ignore_I = TRUE, points_threshold = 2, info = FALSE) ignore_I = TRUE, points_threshold = 2, info = FALSE)
@ -20,7 +21,11 @@ key_antibiotics_equal(x, y, type = c("keyantibiotics", "points"),
\item{col_bactid}{column name of the unique IDs of the microorganisms (should occur in the \code{\link{microorganisms}} dataset). Get your bactid's with the function \code{\link{guess_bactid}}, that takes microorganism names as input.} \item{col_bactid}{column name of the unique IDs of the microorganisms (should occur in the \code{\link{microorganisms}} dataset). Get your bactid's with the function \code{\link{guess_bactid}}, that takes microorganism names as input.}
\item{amcl, amox, cfot, cfta, cfur, cipr, coli, eryt, gent, mero, oxac, pita, rifa, teic, tetr, tobr, trsu, vanc}{column names of antibiotics, case-insensitive} \item{universal_1, universal_2, universal_3, universal_4, universal_5, universal_6}{column names of \strong{broad-spectrum} antibiotics, case-insensitive}
\item{GramPos_1, GramPos_2, GramPos_3, GramPos_4, GramPos_5, GramPos_6}{column names of antibiotics for \strong{Gram positives}, case-insensitive}
\item{GramNeg_1, GramNeg_2, GramNeg_3, GramNeg_4, GramNeg_5, GramNeg_6}{column names of antibiotics for \strong{Gram negatives}, case-insensitive}
\item{info}{print progress} \item{info}{print progress}
@ -38,11 +43,11 @@ These function can be used to determine first isolates (see \code{\link{first_is
\details{ \details{
The function \code{key_antibiotics} returns a character vector with antibiotic results. The function \code{key_antibiotics} returns a character vector with antibiotic results.
The antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr At default, the antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr
amox, amcl, cfur, pita, cipr, trsu, vanc, teic, tetr, eryt, oxac, rifa. \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"}.
The antibiotics that are used for \strong{Gram negative bacteria} are (colum names): \cr At default, the antibiotics that are used for \strong{Gram negative bacteria} are (colum names): \cr
amox, amcl, cfur, pita, cipr, trsu, gent, tobr, coli, cfot, cfta, mero. \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 value.