1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-10 10:21:56 +02:00

- For functions first_isolate, EUCAST_rules the antibiotic column names are case-insensitive

- Functions `first_isolate`, `EUCAST_rules` and `rsi_predict` supports tidyverse-like evaluation of parameters (no need to quote columns them anymore)
- Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS
- Renamed dataset `bactlist` to `microorganisms`
This commit is contained in:
2018-03-23 14:46:02 +01:00
parent e1e19af625
commit 53464ff1c8
29 changed files with 693 additions and 373 deletions

View File

@ -9,11 +9,11 @@ EUCAST Expert Rules Version 2.0: \cr
Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr
\url{https://doi.org/10.1111/j.1469-0691.2011.03703.x} \cr
\cr
EUCAST Expert Rules Version 3.1: \cr
\url{http://www.eucast.org/expert_rules_and_intrinsic_resistance}
EUCAST Expert Rules Version 3.1 (Intrinsic Resistance and Exceptional Phenotypes Tables): \cr
\url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
}
\usage{
EUCAST_rules(tbl, col_bactcode = "bactid", info = TRUE, amcl = "amcl",
EUCAST_rules(tbl, col_bactid = "bactid", info = TRUE, amcl = "amcl",
amik = "amik", amox = "amox", ampi = "ampi", azit = "azit",
aztr = "aztr", cefa = "cefa", cfra = "cfra", cfep = "cfep",
cfot = "cfot", cfox = "cfox", cfta = "cfta", cftr = "cftr",
@ -35,7 +35,7 @@ interpretive_reading(...)
\arguments{
\item{tbl}{table with antibiotic columns, like e.g. \code{amox} and \code{amcl}}
\item{col_bactcode}{column name of the bacteria ID in \code{tbl} - values of this column should be present in \code{bactlist$bactid}, see \code{\link{bactlist}}}
\item{col_bactid}{column name of the bacteria ID in \code{tbl} - values of this column should be present in \code{microorganisms$bactid}, see \code{\link{microorganisms}}}
\item{info}{print progress}

View File

@ -7,13 +7,13 @@
\code{\link{antibiotics}}
}
\usage{
abname(abcode, from = "umcg", to = "official", textbetween = " + ",
tolower = FALSE)
abname(abcode, from = c("guess", "atc", "molis", "umcg"), to = "official",
textbetween = " + ", tolower = FALSE)
}
\arguments{
\item{abcode}{a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"}}
\item{from, to}{type to transform from and to. See \code{\link{antibiotics}} for its column names.}
\item{from, to}{type to transform from and to. See \code{\link{antibiotics}} for its column names. WIth \code{from = "guess"} the from will be guessed from \code{"atc"}, \code{"molis"} and \code{"umcg"}.}
\item{textbetween}{text to put between multiple returned texts}

View File

@ -33,6 +33,6 @@ antibiotics
A dataset containing all antibiotics with a J0 code, with their DDD's. Properties were downloaded from the WHO, see Source.
}
\seealso{
\code{\link{bactlist}}
\code{\link{microorganisms}}
}
\keyword{datasets}

50
man/clipboard.Rd Normal file
View File

@ -0,0 +1,50 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/clipboard.R
\name{clipboard}
\alias{clipboard}
\alias{clipboard_import}
\alias{clipboard_export}
\title{Import/export from clipboard}
\usage{
clipboard_import(sep = "\\t", header = TRUE, dec = ".", na = c("", "NA",
"NULL"), startrow = 1, as_vector = TRUE)
clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE)
}
\arguments{
\item{sep}{the field separator character. Values on each line of the
file are separated by this character. If \code{sep = ""} (the
default for \code{read.table}) the separator is \sQuote{white space},
that is one or more spaces, tabs, newlines or carriage returns.}
\item{header}{a logical value indicating whether the file contains the
names of the variables as its first line. If missing, the value is
determined from the file format: \code{header} is set to \code{TRUE}
if and only if the first row contains one fewer field than the
number of columns.}
\item{dec}{the character used in the file for decimal points.}
\item{na}{the string to use for missing values in the data.}
\item{startrow}{\emph{n}th row to start importing from. For \code{clipboard_import}, when \code{header = TRUE} the import will start on row \code{startrow} \emph{below} the header.}
\item{as_vector}{a logical value indicating whether data consisting of only one column should be imported as vector using \code{\link[dplyr]{pull}}. This will strip off the header.}
\item{x}{the object to be written, preferably a matrix or data frame.
If not, it is attempted to coerce \code{x} to a data frame.}
}
\value{
data.frame
}
\description{
These are helper functions around \code{\link{read.table}} and \code{\link{write.table}} to import from and export to clipboard. The data will be read and written as tab-separated by default, which makes it possible to copy and paste from other software like Excel and SPSS without further transformation.
}
\details{
For \code{clipboard_export}, the reserved clipboard size for exporting will be set automatically to 125\% of the object size of \code{x}. This way, it is possible to export data with thousands of rows as the only limit will be your systems RAM.
}
\keyword{clipboard}
\keyword{clipboard_export}
\keyword{clipboard_import}
\keyword{export}
\keyword{import}

View File

@ -4,12 +4,12 @@
\alias{first_isolate}
\title{Determine first (weighted) isolates}
\usage{
first_isolate(tbl, col_date, col_patient_id, col_genus, col_species,
first_isolate(tbl, col_date, col_patient_id, col_bactid = NA,
col_testcode = NA, col_specimen = NA, col_icu = NA,
col_keyantibiotics = NA, episode_days = 365, testcodes_exclude = "",
icu_exclude = FALSE, filter_specimen = NA, output_logical = TRUE,
type = "keyantibiotics", ignore_I = TRUE, points_threshold = 2,
info = TRUE)
info = TRUE, col_genus = NA, col_species = NA)
}
\arguments{
\item{tbl}{a \code{data.frame} containing isolates.}
@ -18,9 +18,7 @@ first_isolate(tbl, col_date, col_patient_id, col_genus, col_species,
\item{col_patient_id}{column name of the unique IDs of the patients, supports tidyverse-like quotation}
\item{col_genus}{column name of the genus of the microorganisms, supports tidyverse-like quotation}
\item{col_species}{column name of the species of the microorganisms, supports tidyverse-like quotation}
\item{col_bactid}{column name of the unique IDs of the microorganisms (should occur in the \code{\link{microorganisms}} dataset), supports tidyverse-like quotation}
\item{col_testcode}{column name of the test codes. Use \code{col_testcode = NA} to \strong{not} exclude certain test codes (like test codes for screening). In that case \code{testcodes_exclude} will be ignored. Supports tidyverse-like quotation.}
@ -47,6 +45,10 @@ first_isolate(tbl, col_date, col_patient_id, col_genus, col_species,
\item{points_threshold}{points until the comparison of key antibiotics will lead to inclusion of an isolate when \code{type = "points"}, see Details}
\item{info}{print progress}
\item{col_genus}{(deprecated, use \code{col_bactid} instead) column name of the genus of the microorganisms, supports tidyverse-like quotation}
\item{col_species}{(deprecated, use \code{col_bactid} instead) column name of the species of the microorganisms, supports tidyverse-like quotation}
}
\value{
A vector to add to table, see Examples.
@ -71,7 +73,7 @@ my_patients <- septic_patients
library(dplyr)
my_patients$first_isolate <- my_patients \%>\%
left_join_bactlist() \%>\%
left_join_microorganisms() \%>\%
first_isolate(col_date = date,
col_patient_id = patient_id,
col_genus = genus,

View File

@ -27,5 +27,5 @@ guess_bactid("MRSA") # Methicillin-resistant S. aureus
guess_bactid("VISA") # Vancomycin Intermediate S. aureus
}
\seealso{
\code{\link{bactlist}} for the dataframe that is being used to determine ID's.
\code{\link{microorganisms}} for the dataframe that is being used to determine ID's.
}

View File

@ -2,47 +2,47 @@
% Please edit documentation in R/join.R
\name{join}
\alias{join}
\alias{inner_join_bactlist}
\alias{inner_join_microorganisms}
\alias{inner_join}
\alias{left_join_bactlist}
\alias{right_join_bactlist}
\alias{full_join_bactlist}
\alias{semi_join_bactlist}
\alias{anti_join_bactlist}
\title{Join a table with \code{bactlist}}
\alias{left_join_microorganisms}
\alias{right_join_microorganisms}
\alias{full_join_microorganisms}
\alias{semi_join_microorganisms}
\alias{anti_join_microorganisms}
\title{Join a table with \code{microorganisms}}
\usage{
inner_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...)
inner_join_microorganisms(x, by = "bactid", suffix = c("2", ""), ...)
left_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...)
left_join_microorganisms(x, by = "bactid", suffix = c("2", ""), ...)
right_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...)
right_join_microorganisms(x, by = "bactid", suffix = c("2", ""), ...)
full_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...)
full_join_microorganisms(x, by = "bactid", suffix = c("2", ""), ...)
semi_join_bactlist(x, by = "bactid", ...)
semi_join_microorganisms(x, by = "bactid", ...)
anti_join_bactlist(x, by = "bactid", ...)
anti_join_microorganisms(x, by = "bactid", ...)
}
\arguments{
\item{x}{existing table to join, also supports character vectors}
\item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})}
\item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{microorganisms$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{microorganisms}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})}
\item{suffix}{if there are non-joined duplicate variables in \code{x} and \code{y}, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.}
\item{...}{other parameters to pass on to \code{dplyr::\link[dplyr]{join}}.}
}
\description{
Join the list of microorganisms \code{\link{bactlist}} easily to an existing table.
Join the dataset \code{\link{microorganisms}} easily to an existing table or character vector.
}
\details{
As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
}
\examples{
left_join_bactlist("STAAUR")
left_join_microorganisms("STAAUR")
library(dplyr)
septic_patients \%>\% left_join_bactlist()
septic_patients \%>\% left_join_microorganisms()
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),
@ -51,6 +51,6 @@ df <- data.frame(date = seq(from = as.Date("2018-01-01"),
"ESCCOL", "ESCCOL", "ESCCOL"),
stringsAsFactors = FALSE)
colnames(df)
df2 <- left_join_bactlist(df, "bacteria_id")
df2 <- left_join_microorganisms(df, "bacteria_id")
colnames(df2)
}

View File

@ -4,7 +4,7 @@
\alias{key_antibiotics}
\title{Key antibiotics based on bacteria ID}
\usage{
key_antibiotics(tbl, col_bactcode = "bactid", info = TRUE, amcl = "amcl",
key_antibiotics(tbl, col_bactid = "bactid", info = TRUE, amcl = "amcl",
amox = "amox", cfot = "cfot", cfta = "cfta", cftr = "cftr",
cfur = "cfur", cipr = "cipr", clar = "clar", clin = "clin",
clox = "clox", doxy = "doxy", gent = "gent", line = "line",
@ -14,7 +14,7 @@ key_antibiotics(tbl, col_bactcode = "bactid", info = TRUE, amcl = "amcl",
\arguments{
\item{tbl}{table with antibiotics coloms, like \code{amox} and \code{amcl}.}
\item{col_bactcode}{column of bacteria IDs in \code{tbl}; these should occur in \code{bactlist$bactid}, see \code{\link{bactlist}}}
\item{col_bactid}{column of bacteria IDs in \code{tbl}; these should occur in \code{microorganisms$bactid}, see \code{\link{microorganisms}}}
\item{info}{print warnings}

View File

@ -1,8 +1,8 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{bactlist}
\alias{bactlist}
\name{microorganisms}
\alias{microorganisms}
\title{Dataset with ~2500 microorganisms}
\format{A data.frame with 2507 observations and 12 variables:
\describe{
@ -23,12 +23,12 @@
MOLIS (LIS of Certe) - \url{https://www.certe.nl}
}
\usage{
bactlist
microorganisms
}
\description{
A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}.
A dataset containing 2500 microorganisms. MO codes of the UMCG can be looked up using \code{\link{microorganisms.umcg}}.
}
\seealso{
\code{\link{guess_bactid}} \code{\link{antibiotics}} \code{\link{bactlist.umcg}}
\code{\link{guess_bactid}} \code{\link{antibiotics}} \code{\link{microorganisms.umcg}}
}
\keyword{datasets}

View File

@ -1,24 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{bactlist.umcg}
\alias{bactlist.umcg}
\name{microorganisms.umcg}
\alias{microorganisms.umcg}
\title{Translation table for UMCG with ~1100 microorganisms}
\format{A data.frame with 1090 observations and 2 variables:
\describe{
\item{\code{mocode}}{Code of microorganism according to UMCG MMB}
\item{\code{bactid}}{Code of microorganism in \code{\link{bactlist}}}
\item{\code{bactid}}{Code of microorganism in \code{\link{microorganisms}}}
}}
\source{
MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl}
}
\usage{
bactlist.umcg
microorganisms.umcg
}
\description{
A dataset containing all bacteria codes of UMCG MMB. These codes can be joined to data with an ID from \code{\link{bactlist}$bactid} (using \code{\link{left_join_bactlist}}). GLIMS codes can also be translated to valid \code{bactid}'s with \code{\link{guess_bactid}}.
A dataset containing all bacteria codes of UMCG MMB. These codes can be joined to data with an ID from \code{\link{microorganisms}$bactid} (using \code{\link{left_join_microorganisms}}). GLIMS codes can also be translated to valid \code{bactid}'s with \code{\link{guess_bactid}}.
}
\seealso{
\code{\link{guess_bactid}} \code{\link{bactlist}}
\code{\link{guess_bactid}} \code{\link{microorganisms}}
}
\keyword{datasets}

View File

@ -4,10 +4,10 @@
\alias{mo_property}
\title{Poperties of a microorganism}
\usage{
mo_property(bactcode, property = "fullname")
mo_property(bactid, property = "fullname")
}
\arguments{
\item{bactcode}{ID of a microorganisme, like \code{"STAAUR} and \code{"ESCCOL}}
\item{bactid}{ID of a microorganisme, like \code{"STAAUR} and \code{"ESCCOL}}
\item{property}{One of the values \code{bactid}, \code{bactsys}, \code{family}, \code{genus}, \code{species}, \code{subspecies}, \code{fullname}, \code{type}, \code{gramstain}, \code{aerobic}}
}
@ -15,5 +15,5 @@ mo_property(bactcode, property = "fullname")
Poperties of a microorganism
}
\seealso{
\code{\link{bactlist}}
\code{\link{microorganisms}}
}

View File

@ -4,13 +4,13 @@
\alias{rsi_df}
\title{Resistance of isolates in data.frame}
\usage{
rsi_df(tbl, antibiotics, interpretation = "IR", minimum = 30,
percent = FALSE, info = TRUE, warning = TRUE)
rsi_df(tbl, ab, interpretation = "IR", minimum = 30, percent = FALSE,
info = TRUE, warning = TRUE)
}
\arguments{
\item{tbl}{\code{data.frame} containing columns with antibiotic interpretations.}
\item{antibiotics}{character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{antibiotics = c("amox", "amcl")}}
\item{ab}{character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{ab = c("amox", "amcl")}}
\item{interpretation}{antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.}
@ -42,7 +42,7 @@ library(dplyr)
my_table \%>\%
filter(first_isolate == TRUE,
genus == "Helicobacter") \%>\%
rsi_df(antibiotics = c("amox", "metr"))
rsi_df(ab = c("amox", "metr"))
}
}
\seealso{

View File

@ -53,7 +53,7 @@ tbl \%>\%
library(dplyr)
septic_patients \%>\%
# get bacteria properties like genus and species
left_join_bactlist("bactid") \%>\%
left_join_microorganisms("bactid") \%>\%
# calculate first isolates
mutate(first_isolate =
first_isolate(.,

View File

@ -14,8 +14,8 @@
\item{\code{age}}{age of the patient}
\item{\code{sex}}{sex of the patient}
\item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information}
\item{\code{bactid}}{ID of microorganism, see \code{\link{bactlist}}}
\item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}), these column names occur in \code{\link{antibiotics}} and can be translated with \code{\link{abname}}}
\item{\code{bactid}}{ID of microorganism, see \code{\link{microorganisms}}}
\item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} and can be translated with \code{\link{abname}}}
}}
\source{
MOLIS (LIS of Certe) - \url{https://www.certe.nl}
@ -24,6 +24,46 @@ MOLIS (LIS of Certe) - \url{https://www.certe.nl}
septic_patients
}
\description{
An anonymised dataset containing 2000 microbial blood culture isolates with their antibiogram of septic patients found in 5 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis e.g. with \code{\link{rsi}} or \code{\link{rsi_predict}}, or it can be used to practice other statistics.
An anonymised dataset containing 2000 microbial blood culture isolates with their antibiogram of septic patients found in 5 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis. For examples, press F1.
}
\examples{
# ----------- #
# PREPARATION #
# ----------- #
# Save this example dataset to an object, so we can edit it:
my_data <- septic_patients
# load the dplyr package to make data science A LOT easier
library(dplyr)
# Add first isolates to our dataset:
my_data <- my_data \%>\%
mutate(first_isolates = first_isolate(my_data, date, patient_id, bactid))
# -------- #
# ANALYSIS #
# -------- #
# 1. Get the amoxicillin resistance percentages
# of E. coli, divided by hospital:
my_data \%>\%
filter(bactid == "ESCCOL",
first_isolates == TRUE) \%>\%
group_by(hospital_id) \%>\%
summarise(n = n(),
amoxicillin_resistance = rsi(amox))
# 2. Get the amoxicillin/clavulanic acid resistance
# percentages of E. coli, trend over the years:
my_data \%>\%
filter(bactid == guess_bactid("E. coli"),
first_isolates == TRUE) \%>\%
group_by(year = format(date, "\%Y")) \%>\%
summarise(n = n(),
amoxclav_resistance = rsi(amcl, minimum = 20))
}
\keyword{datasets}