mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:46:11 +01:00
abname, logo
This commit is contained in:
parent
62304dc23f
commit
ab0503f8b8
@ -10,6 +10,7 @@ S3method(print,rsi)
|
||||
S3method(summary,mic)
|
||||
S3method(summary,rsi)
|
||||
export(EUCAST_rules)
|
||||
export(abname)
|
||||
export(anti_join_bactlist)
|
||||
export(as.mic)
|
||||
export(as.rsi)
|
||||
@ -56,6 +57,7 @@ importFrom(dplyr,progress_estimated)
|
||||
importFrom(dplyr,pull)
|
||||
importFrom(dplyr,row_number)
|
||||
importFrom(dplyr,select)
|
||||
importFrom(dplyr,slice)
|
||||
importFrom(dplyr,summarise)
|
||||
importFrom(dplyr,tibble)
|
||||
importFrom(dplyr,vars)
|
||||
|
101
R/atc.R
101
R/atc.R
@ -119,3 +119,104 @@ atc_property <- function(atc_code,
|
||||
returnvalue
|
||||
|
||||
}
|
||||
|
||||
#' Name of an antibiotic
|
||||
#'
|
||||
#' Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}.
|
||||
#' @param abcode a code or name, like \code{"amox"}, \code{"cftr"} or \code{"J01CA04"}
|
||||
#' @param from,to type to transform from and to. See \code{\link{ablist}} for its column names.
|
||||
#' @param textbetween text to put between multiple returned texts
|
||||
#' @param tolower return output as lower case with function \code{\link{tolower}}.
|
||||
#' @keywords ab antibiotics
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% filter select slice
|
||||
#' @examples
|
||||
#' abname("AMCL")
|
||||
#' # "amoxicillin and enzyme inhibitor"
|
||||
#'
|
||||
#' abname("AMCL+GENT")
|
||||
#' # "amoxicillin and enzyme inhibitor + gentamicin"
|
||||
#'
|
||||
#' abname(c("AMCL", "GENT"))
|
||||
#' # "amoxicillin and enzyme inhibitor" "gentamicin"
|
||||
#'
|
||||
#' abname("AMCL", to = "trivial")
|
||||
#' # "Amoxicilline/clavulaanzuur"
|
||||
#'
|
||||
#' abname("AMCL", to = "atc")
|
||||
#' # "J01CR02"
|
||||
#'
|
||||
#' abname("J01CR02", from = "atc", to = "umcg")
|
||||
#' # "AMCL"
|
||||
#'
|
||||
#' @source \code{\link{ablist}}
|
||||
abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) {
|
||||
|
||||
ablist <- AMR::ablist
|
||||
colnames(ablist) <- colnames(ablist) %>% tolower()
|
||||
from <- from %>% tolower()
|
||||
to <- to %>% tolower()
|
||||
|
||||
if (!from %in% colnames(ablist) |
|
||||
!to %in% colnames(ablist)) {
|
||||
stop(paste0('Invalid `from` or `to`. Choose one of ',
|
||||
colnames(ablist) %>% paste(collapse = ","), '.'), call. = FALSE)
|
||||
}
|
||||
|
||||
abcode <- as.character(abcode)
|
||||
|
||||
for (i in 1:length(abcode)) {
|
||||
drug <- abcode[i]
|
||||
if (!grepl('+', drug, fixed = TRUE) & !grepl(' en ', drug, fixed = TRUE)) {
|
||||
# bestaat maar uit 1 middel
|
||||
if (any(ablist[, from] == drug)) {
|
||||
abcode[i] <-
|
||||
ablist %>%
|
||||
filter(.[, from] == drug) %>%
|
||||
select(to) %>%
|
||||
slice(1) %>%
|
||||
as.character()
|
||||
} else {
|
||||
# niet gevonden
|
||||
warning('Code "', drug, '" not found in antibiotics list.', call. = FALSE)
|
||||
abcode[i] <- NA
|
||||
}
|
||||
} else {
|
||||
# meerdere middelen
|
||||
if (grepl('+', drug, fixed = TRUE)) {
|
||||
drug.group <-
|
||||
strsplit(drug, '+', fixed = TRUE) %>%
|
||||
unlist() %>%
|
||||
trimws('both')
|
||||
} else if (grepl(' en ', drug, fixed = TRUE)) {
|
||||
drug.group <-
|
||||
strsplit(drug, ' en ', fixed = TRUE) %>%
|
||||
unlist() %>%
|
||||
trimws('both')
|
||||
} else {
|
||||
warning('Invalid concat.')
|
||||
abcode[i] <- NA
|
||||
next
|
||||
}
|
||||
|
||||
for (j in 1:length(drug.group)) {
|
||||
drug.group[j] <-
|
||||
ablist %>%
|
||||
filter(.[, from] == drug.group[j]) %>%
|
||||
select(to) %>%
|
||||
slice(1) %>%
|
||||
as.character()
|
||||
if (j > 1 & to %in% c('official', 'trivial')) {
|
||||
drug.group[j] <- drug.group[j] %>% tolower()
|
||||
}
|
||||
}
|
||||
abcode[i] <- paste(drug.group, collapse = textbetween)
|
||||
}
|
||||
}
|
||||
|
||||
if (tolower == TRUE) {
|
||||
abcode <- abcode %>% tolower()
|
||||
}
|
||||
|
||||
abcode
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
# `AMR`
|
||||
This is an [R package](https://www.r-project.org) to simplify the analysis of Antimicrobial Resistance (AMR).
|
||||
|
||||
![logo](man/figures/logo_en.png)
|
||||
|
||||
This R package was created for academic research by PhD students of the Medical Microbiology & Infection Prevention (mmb) department of the [University of Groningen](https://www.rug.nl/) who also maintain this package, see [#authors].
|
||||
|
||||
## Why this package?
|
||||
This R package contains functions to make microbiological, epidemiological data analysis easier. It allows the use of some new S3 classes to work with MIC values and antimicrobial interpretations (i.e. values S, I and R).
|
||||
|
||||
This R package was created for academic research by PhD students of the [University of Groningen](https://www.rug.nl/).
|
||||
AMR can also be predicted for the forthcoming years with the `rsi_predict` function. For use with the `dplyr` package, the `rsi` can be used in conjunction with `summarise` to calculate the resistance percentages of different antibiotic columns of a table.
|
||||
|
||||
## How to use it?
|
||||
```r
|
||||
@ -63,7 +67,7 @@ A plot of `rsi_data`:
|
||||
plot(rsi_data)
|
||||
```
|
||||
|
||||
![plot2_ex4](man/figures/rsi_example.png)
|
||||
![example](man/figures/rsi_example.png)
|
||||
|
||||
Other epidemiological functions:
|
||||
|
||||
|
46
man/abname.Rd
Normal file
46
man/abname.Rd
Normal file
@ -0,0 +1,46 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/atc.R
|
||||
\name{abname}
|
||||
\alias{abname}
|
||||
\title{Name of an antibiotic}
|
||||
\source{
|
||||
\code{\link{ablist}}
|
||||
}
|
||||
\usage{
|
||||
abname(abcode, from = "umcg", to = "official", textbetween = " + ",
|
||||
tolower = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{abcode}{a code or name, like \code{"amox"}, \code{"cftr"} or \code{"J01CA04"}}
|
||||
|
||||
\item{from, to}{type to transform from and to. See \code{\link{ablist}} for its column names.}
|
||||
|
||||
\item{textbetween}{text to put between multiple returned texts}
|
||||
|
||||
\item{tolower}{return output as lower case with function \code{\link{tolower}}.}
|
||||
}
|
||||
\description{
|
||||
Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}.
|
||||
}
|
||||
\examples{
|
||||
abname("AMCL")
|
||||
# "amoxicillin and enzyme inhibitor"
|
||||
|
||||
abname("AMCL+GENT")
|
||||
# "amoxicillin and enzyme inhibitor + gentamicin"
|
||||
|
||||
abname(c("AMCL", "GENT"))
|
||||
# "amoxicillin and enzyme inhibitor" "gentamicin"
|
||||
|
||||
abname("AMCL", to = "trivial")
|
||||
# "Amoxicilline/clavulaanzuur"
|
||||
|
||||
abname("AMCL", to = "atc")
|
||||
# "J01CR02"
|
||||
|
||||
abname("J01CR02", from = "atc", to = "umcg")
|
||||
# "AMCL"
|
||||
|
||||
}
|
||||
\keyword{ab}
|
||||
\keyword{antibiotics}
|
BIN
man/figures/logo_en.png
Normal file
BIN
man/figures/logo_en.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
Loading…
Reference in New Issue
Block a user