2018-02-21 11:52:31 +01:00
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
2019-01-02 23:24:07 +01:00
# SOURCE #
# https://gitlab.com/msberends/AMR #
2018-02-21 11:52:31 +01:00
# #
# LICENCE #
2019-01-02 23:24:07 +01:00
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
2018-02-21 11:52:31 +01:00
# #
2019-01-02 23:24:07 +01:00
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
2019-04-05 18:47:39 +02:00
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
2018-02-21 11:52:31 +01:00
# ==================================================================== #
2019-01-25 13:18:41 +01:00
#' Data set with ~500 antibiotics
2018-02-21 11:52:31 +01:00
#'
2018-09-01 21:19:46 +02:00
#' A data set containing all antibiotics with a J0 code and some other antimicrobial agents, with their DDDs. Except for trade names and abbreviations, all properties were downloaded from the WHO, see Source.
2019-01-29 00:06:50 +01:00
#' @format A \code{\link{data.frame}} with 488 observations and 17 variables:
2018-02-21 11:52:31 +01:00
#' \describe{
2019-01-29 00:06:50 +01:00
#' \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical), like \code{J01CR02}}
#' \item{\code{ears_net}}{EARS-Net code (European Antimicrobial Resistance Surveillance Network), like \code{AMC}}
2018-08-25 22:01:14 +02:00
#' \item{\code{certe}}{Certe code, like \code{amcl}}
2018-02-21 11:52:31 +01:00
#' \item{\code{umcg}}{UMCG code, like \code{AMCL}}
2018-08-28 13:51:13 +02:00
#' \item{\code{abbr}}{Abbreviation as used by many countries, used internally by \code{\link{as.atc}}}
#' \item{\code{official}}{Official name by the WHO, like \code{"Amoxicillin and beta-lactamase inhibitor"}}
2018-02-21 11:52:31 +01:00
#' \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}}
2018-02-26 15:53:09 +01:00
#' \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}}
2018-08-29 12:27:37 +02:00
#' \item{\code{trade_name}}{Trade name as used by many countries (a total of 294), used internally by \code{\link{as.atc}}}
2018-03-19 12:43:22 +01:00
#' \item{\code{oral_ddd}}{Defined Daily Dose (DDD), oral treatment}
2018-02-21 11:52:31 +01:00
#' \item{\code{oral_units}}{Units of \code{ddd_units}}
2018-03-19 12:43:22 +01:00
#' \item{\code{iv_ddd}}{Defined Daily Dose (DDD), parenteral treatment}
2018-02-21 11:52:31 +01:00
#' \item{\code{iv_units}}{Units of \code{iv_ddd}}
2018-03-19 12:43:22 +01:00
#' \item{\code{atc_group1}}{ATC group, like \code{"Macrolides, lincosamides and streptogramins"}}
#' \item{\code{atc_group2}}{Subgroup of \code{atc_group1}, like \code{"Macrolides"}}
#' \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
#' \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
2018-02-21 11:52:31 +01:00
#' }
2019-01-29 20:20:09 +01:00
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
2019-01-25 13:18:41 +01:00
#'
2019-01-29 00:06:50 +01:00
#' Table antibiotic coding EARSS (from WHONET 5.3): \url{http://www.madsonline.dk/Tutorials/landskoder_antibiotika_WM.pdf}
#'
2019-01-25 13:18:41 +01:00
#' EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes Tables. Version 3.1, 2016: \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
#'
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
2019-01-29 20:20:09 +01:00
#' @inheritSection WHOCC WHOCC
2019-01-02 23:24:07 +01:00
#' @inheritSection AMR Read more on our website!
2018-03-23 14:46:02 +01:00
#' @seealso \code{\link{microorganisms}}
2018-08-25 22:01:14 +02:00
# use this later to further fill AMR::antibiotics
# drug <- "Ciprofloxacin"
# url <- xml2::read_html(paste0("https://www.ncbi.nlm.nih.gov/pccompound?term=", drug)) %>%
# html_nodes(".rslt") %>%
# .[[1]] %>%
# html_nodes(".title a") %>%
# html_attr("href") %>%
# gsub("/compound/", "/rest/pug_view/data/compound/", ., fixed = TRUE) %>%
# paste0("/XML/?response_type=display")
# synonyms <- url %>%
# read_xml() %>%
# xml_contents() %>% .[[6]] %>%
# xml_contents() %>% .[[8]] %>%
# xml_contents() %>% .[[3]] %>%
# xml_contents() %>% .[[3]] %>%
# xml_contents() %>%
# paste() %>%
# .[. %like% "StringValueList"] %>%
# gsub("[</]+StringValueList[>]", "", .)
2018-08-29 12:27:37 +02:00
2018-03-19 12:43:22 +01:00
# last two columns created with:
# antibiotics %>%
2018-04-02 11:11:21 +02:00
# mutate(useful_gramnegative =
2018-03-19 12:43:22 +01:00
# if_else(
# atc_group1 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' |
# atc_group2 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' |
# official %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)',
# FALSE,
# NA
# ),
# useful_grampositive =
# if_else(
# atc_group1 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' |
# atc_group2 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' |
# official %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)',
# FALSE,
# NA
# )
# )
2018-08-29 12:27:37 +02:00
#
# ADD NEW TRADE NAMES FROM OTHER DATAFRAME
# antibiotics_add_to_property <- function(ab_df, atc, property, value) {
# if (length(atc) > 1L) {
# stop("only one atc at a time")
# }
# if (!property %in% c("abbr", "trade_name")) {
# stop("only possible for abbr and trade_name")
# }
#
# value <- gsub(ab_df[which(ab_df$atc == atc),] %>% pull("official"), "", value, fixed = TRUE)
# value <- gsub("||", "|", value, fixed = TRUE)
# value <- gsub("[äáàâ]", "a", value)
# value <- gsub("[ëéèê]", "e", value)
# value <- gsub("[ïíìî]", "i", value)
# value <- gsub("[öóòô]", "o", value)
# value <- gsub("[üúùû]", "u", value)
# if (!atc %in% ab_df$atc) {
# message("SKIPPING - UNKNOWN ATC: ", atc)
# }
# if (is.na(value)) {
# message("SKIPPING - VALUE MISSES: ", atc)
# }
# if (atc %in% ab_df$atc & !is.na(value)) {
# current <- ab_df[which(ab_df$atc == atc),] %>% pull(property)
# if (!is.na(current)) {
# value <- paste(current, value, sep = "|")
# }
# value <- strsplit(value, "|", fixed = TRUE) %>% unlist() %>% unique() %>% paste(collapse = "|")
# value <- gsub("||", "|", value, fixed = TRUE)
# # print(value)
# ab_df[which(ab_df$atc == atc), property] <- value
# message("Added ", value, " to ", ab_official(atc), " (", atc, ", ", ab_certe(atc), ")")
# }
# ab_df
# }
#
2018-03-19 12:43:22 +01:00
" antibiotics"
2018-02-21 11:52:31 +01:00
2019-03-18 14:29:41 +01:00
#' Data set with ~65,000 microorganisms
2018-02-21 11:52:31 +01:00
#'
2019-02-18 02:33:37 +01:00
#' A data set containing the microbial taxonomy of six kingdoms from the Catalogue of Life. MO codes can be looked up using \code{\link{as.mo}}.
2019-02-20 00:04:48 +01:00
#' @inheritSection catalogue_of_life Catalogue of Life
2019-03-18 14:29:41 +01:00
#' @format A \code{\link{data.frame}} with 65,629 observations and 16 variables:
2018-02-21 11:52:31 +01:00
#' \describe{
2019-02-20 00:04:48 +01:00
#' \item{\code{mo}}{ID of microorganism as used by this package}
2019-02-18 02:33:37 +01:00
#' \item{\code{col_id}}{Catalogue of Life ID}
2018-09-24 23:33:29 +02:00
#' \item{\code{fullname}}{Full name, like \code{"Echerichia coli"}}
2019-02-20 00:04:48 +01:00
#' \item{\code{kingdom}}{Taxonomic kingdom of the microorganism}
#' \item{\code{phylum}}{Taxonomic phylum of the microorganism}
#' \item{\code{class}}{Taxonomic class of the microorganism}
#' \item{\code{order}}{Taxonomic order of the microorganism}
#' \item{\code{family}}{Taxonomic family of the microorganism}
#' \item{\code{genus}}{Taxonomic genus of the microorganism}
#' \item{\code{species}}{Taxonomic species of the microorganism}
#' \item{\code{subspecies}}{Taxonomic subspecies of the microorganism}
#' \item{\code{rank}}{Taxonomic rank of the microorganism, like \code{"species"} or \code{"genus"}}
#' \item{\code{ref}}{Author(s) and year of concerning scientific publication}
#' \item{\code{species_id}}{ID of the species as used by the Catalogue of Life}
2019-03-18 14:29:41 +01:00
#' \item{\code{source}}{Either \code{"CoL"}, \code{"DSMZ"} (see source) or "manually added"}
2019-03-02 22:47:04 +01:00
#' \item{\code{prevalence}}{Prevalence of the microorganism, see \code{?as.mo}}
2018-02-21 11:52:31 +01:00
#' }
2019-02-08 16:06:54 +01:00
#' @details Manually added were:
#' \itemize{
2019-02-18 02:33:37 +01:00
#' \item{9 species of \emph{Streptococcus} (beta haemolytic groups A, B, C, D, F, G, H, K and unspecified)}
#' \item{2 species of \emph{Staphylococcus} (coagulase-negative [CoNS] and coagulase-positive [CoPS])}
2019-03-18 14:29:41 +01:00
#' \item{3 other undefined (unknown, unknown Gram negatives and unknown Gram positives)}
#' \item{8,830 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) that are not in the Catalogue of Life}
2019-02-08 16:06:54 +01:00
#' }
2019-03-18 14:29:41 +01:00
#' @section About the records from DSMZ (see source):
#' Names of prokaryotes are defined as being validly published by the International Code of Nomenclature of Bacteria. Validly published are all names which are included in the Approved Lists of Bacterial Names and the names subsequently published in the International Journal of Systematic Bacteriology (IJSB) and, from January 2000, in the International Journal of Systematic and Evolutionary Microbiology (IJSEM) as original articles or in the validation lists.
#'
#' From: \url{https://www.dsmz.de/support/bacterial-nomenclature-up-to-date-downloads/readme.html}
#' @source Catalogue of Life: Annual Checklist (public online taxonomic database), \url{www.catalogueoflife.org} (check included annual version with \code{\link{catalogue_of_life_version}()}).
#'
#' Leibniz Institute DSMZ-German Collection of Microorganisms and Cell Cultures, Germany, Prokaryotic Nomenclature Up-to-Date, \url{http://www.dsmz.de/bacterial-diversity/prokaryotic-nomenclature-up-to-date} (check included version with \code{\link{catalogue_of_life_version}()}).
2019-01-02 23:24:07 +01:00
#' @inheritSection AMR Read more on our website!
2019-02-20 00:04:48 +01:00
#' @seealso \code{\link{as.mo}}, \code{\link{mo_property}}, \code{\link{microorganisms.codes}}
2018-03-23 14:46:02 +01:00
" microorganisms"
2018-02-21 11:52:31 +01:00
2019-02-20 00:04:48 +01:00
catalogue_of_life <- list (
2019-02-22 22:12:10 +01:00
year = 2018 ,
2019-03-18 14:29:41 +01:00
version = " Catalogue of Life: {year} Annual Checklist" ,
url_CoL = " http://www.catalogueoflife.org/annual-checklist/{year}/" ,
url_DSMZ = " https://www.dsmz.de/microorganisms/pnu/bacterial_nomenclature_info_mm.php" ,
yearmonth_DSMZ = " February 2019"
2019-02-20 00:04:48 +01:00
)
2019-01-25 13:18:41 +01:00
#' Data set with previously accepted taxonomic names
2018-09-24 23:33:29 +02:00
#'
2019-02-20 00:04:48 +01:00
#' A data set containing old (previously valid or accepted) taxonomic names according to the Catalogue of Life. This data set is used internally by \code{\link{as.mo}}.
#' @inheritSection catalogue_of_life Catalogue of Life
2019-04-05 18:47:39 +02:00
#' @format A \code{\link{data.frame}} with 21,342 observations and 4 variables:
2018-09-24 23:33:29 +02:00
#' \describe{
2019-04-05 18:47:39 +02:00
#' \item{\code{col_id}}{Catalogue of Life ID that was originally given}
#' \item{\code{col_id_new}}{New Catalogue of Life ID that responds to an entry in the \code{\link{microorganisms}} data set}
#' \item{\code{fullname}}{Old full taxonomic name of the microorganism}
2019-02-20 00:04:48 +01:00
#' \item{\code{ref}}{Author(s) and year of concerning scientific publication}
2018-09-24 23:33:29 +02:00
#' }
2019-04-05 18:47:39 +02:00
#' @source Catalogue of Life: Annual Checklist (public online taxonomic database), \url{www.catalogueoflife.org} (check included annual version with \code{\link{catalogue_of_life_version}()}).
2019-01-02 23:24:07 +01:00
#' @inheritSection AMR Read more on our website!
2018-09-24 23:33:29 +02:00
#' @seealso \code{\link{as.mo}} \code{\link{mo_property}} \code{\link{microorganisms}}
" microorganisms.old"
2019-01-21 15:53:01 +01:00
#' Translation table for microorganism codes
2018-02-21 11:52:31 +01:00
#'
2019-02-08 16:06:54 +01:00
#' A data set containing commonly used codes for microorganisms, from laboratory systems and WHONET. Define your own with \code{\link{set_mo_source}}.
2019-03-12 12:19:27 +01:00
#' @format A \code{\link{data.frame}} with 5,171 observations and 2 variables:
2018-02-21 11:52:31 +01:00
#' \describe{
2019-01-21 15:53:01 +01:00
#' \item{\code{certe}}{Commonly used code of a microorganism}
2019-02-08 16:06:54 +01:00
#' \item{\code{mo}}{ID of the microorganism in the \code{\link{microorganisms}} data set}
2018-02-21 11:52:31 +01:00
#' }
2019-02-20 00:04:48 +01:00
#' @inheritSection catalogue_of_life Catalogue of Life
2019-01-02 23:24:07 +01:00
#' @inheritSection AMR Read more on our website!
2018-09-24 23:33:29 +02:00
#' @seealso \code{\link{as.mo}} \code{\link{microorganisms}}
2019-01-21 15:53:01 +01:00
" microorganisms.codes"
2018-02-27 20:01:02 +01:00
2019-01-25 13:18:41 +01:00
#' Data set with 2,000 blood culture isolates from septic patients
2018-02-27 20:01:02 +01:00
#'
2019-01-02 23:24:07 +01:00
#' An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
2018-10-17 17:32:34 +02:00
#' @format A \code{\link{data.frame}} with 2,000 observations and 49 variables:
2018-02-27 20:01:02 +01:00
#' \describe{
#' \item{\code{date}}{date of receipt at the laboratory}
2018-08-12 22:34:03 +02:00
#' \item{\code{hospital_id}}{ID of the hospital, from A to D}
2018-02-27 20:01:02 +01:00
#' \item{\code{ward_icu}}{logical to determine if ward is an intensive care unit}
#' \item{\code{ward_clinical}}{logical to determine if ward is a regular clinical ward}
#' \item{\code{ward_outpatient}}{logical to determine if ward is an outpatient clinic}
#' \item{\code{age}}{age of the patient}
2018-12-14 07:48:12 +01:00
#' \item{\code{gender}}{gender of the patient}
2018-02-27 20:01:02 +01:00
#' \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information}
2018-12-14 07:48:12 +01:00
#' \item{\code{mo}}{ID of microorganism created with \code{\link{as.mo}}, see also \code{\link{microorganisms}}}
2018-07-25 14:17:04 +02:00
#' \item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{abname}}}
2018-02-27 20:01:02 +01:00
#' }
2019-01-02 23:24:07 +01:00
#' @inheritSection AMR Read more on our website!
2018-03-19 12:43:22 +01:00
" septic_patients"
2018-10-31 12:10:49 +01:00
2019-01-29 20:20:09 +01:00
#' Data set with 500 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 data itself was based on our \code{\link{septic_patients}} data set.
#' @format A \code{\link{data.frame}} with 500 observations and 53 variables:
#' \describe{
#' \item{\code{Identification number}}{ID of the sample}
#' \item{\code{Specimen number}}{ID of the specimen}
2019-02-04 12:24:07 +01:00
#' \item{\code{Organism}}{Name of the microorganism. Before analysis, you should transform this to a valid microbial class, using \code{\link{as.mo}}.}
2019-01-29 20:20:09 +01:00
#' \item{\code{Country}}{Country of origin}
#' \item{\code{Laboratory}}{Name of laboratory}
#' \item{\code{Last name}}{Last name of patient}
#' \item{\code{First name}}{Initial of patient}
#' \item{\code{Sex}}{Gender of patient}
#' \item{\code{Age}}{Age of patient}
#' \item{\code{Age category}}{Age group, can also be looked up using \code{\link{age_groups}}}
#' \item{\code{Date of admission}}{Date of hospital admission}
#' \item{\code{Specimen date}}{Date when specimen was received at laboratory}
#' \item{\code{Specimen type}}{Specimen type or group}
#' \item{\code{Specimen type (Numeric)}}{Translation of \code{"Specimen type"}}
#' \item{\code{Reason}}{Reason of request with Differential Diagnosis}
#' \item{\code{Isolate number}}{ID of isolate}
#' \item{\code{Organism type}}{Type of microorganism, can also be looked up using \code{\link{mo_type}}}
#' \item{\code{Serotype}}{Serotype of microorganism}
#' \item{\code{Beta-lactamase}}{Microorganism produces beta-lactamase?}
#' \item{\code{ESBL}}{Microorganism produces extended spectrum beta-lactamase?}
#' \item{\code{Carbapenemase}}{Microorganism produces carbapenemase?}
#' \item{\code{MRSA screening test}}{Microorganism is possible MRSA?}
#' \item{\code{Inducible clindamycin resistance}}{Clindamycin can be induced?}
#' \item{\code{Comment}}{Other comments}
#' \item{\code{Date of data entry}}{Date this data was entered in WHONET}
2019-02-04 12:24:07 +01:00
#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link{as.rsi}}.}
2019-01-29 20:20:09 +01:00
#' }
#' @inheritSection AMR Read more on our website!
" WHONET"
2019-04-05 18:47:39 +02:00
# transforms data set to data.frame with only ASCII values, to comply with CRAN policies
dataset_UTF8_to_ASCII <- function ( df ) {
trans <- function ( vect ) {
iconv ( vect , from = " UTF-8" , to = " ASCII//TRANSLIT" )
}
df <- as.data.frame ( df , stringsAsFactors = FALSE )
for ( i in 1 : NCOL ( df ) ) {
col <- df [ , i ]
if ( is.factor ( col ) ) {
levels ( col ) <- trans ( levels ( col ) )
} else if ( is.character ( col ) ) {
col <- trans ( col )
} else {
col
}
df [ , i ] <- col
}
df
}