Skip to content

Commit

Permalink
(v2.1.1.9123) add EFF code to antibiotics data set
Browse files Browse the repository at this point in the history
  • Loading branch information
msberends committed Jan 15, 2025
1 parent 2e31ec1 commit 08ddbaa
Show file tree
Hide file tree
Showing 32 changed files with 522 additions and 461 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: AMR
Version: 2.1.1.9122
Date: 2024-12-20
Version: 2.1.1.9123
Date: 2025-01-15
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export(not_intrinsic_resistant)
export(oxazolidinones)
export(pca)
export(penicillins)
export(phenicols)
export(polymyxins)
export(proportion_I)
export(proportion_IR)
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AMR 2.1.1.9122
# AMR 2.1.1.9123

*(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)*

Expand Down Expand Up @@ -47,8 +47,9 @@ This package now supports not only tools for AMR data analysis in clinical setti
* `antibiotics` data set
* Added "clindamycin inducible screening" as `CLI1`. Since clindamycin is a lincosamide, the antibiotic selector `lincosamides()` now contains the argument `only_treatable = TRUE` (similar to other antibiotic selectors that contain non-treatable drugs)
* Added Amorolfine (`AMO`, D01AE16), which is now also part of the `antifungals()` selector
* Added Efflux (`EFF`), to allow mapping to AMRFinderPlus
* Antibiotic selectors
* Added selectors `nitrofurans()` and `rifamycins()`
* Added selectors `nitrofurans()`, `phenicols()`, and `rifamycins()`
* When using antibiotic selectors (such as `aminoglycosides()`) that exclude non-treatable drugs (such as gentamicin-high), the function now always returns a warning that these can be included using `only_treatable = FALSE`
* All selectors can now be run as a separate command to retrieve a vector of all possible antimicrobials that the selector can select
* MICs
Expand Down
15 changes: 13 additions & 2 deletions PythonPackage/AMR/AMR.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Metadata-Version: 2.2
Name: AMR
Version: 2.1.1.9122
Version: 2.1.1.9123
Summary: A Python wrapper for the AMR R package
Home-page: https://github.com/msberends/AMR
Author: Matthijs Berends
Expand All @@ -14,6 +14,17 @@ Description-Content-Type: text/markdown
Requires-Dist: rpy2
Requires-Dist: numpy
Requires-Dist: pandas
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

---
title: "AMR for Python"
Expand Down
1 change: 1 addition & 0 deletions PythonPackage/AMR/AMR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from .functions import nitrofurans
from .functions import oxazolidinones
from .functions import penicillins
from .functions import phenicols
from .functions import polymyxins
from .functions import quinolones
from .functions import rifamycins
Expand Down
3 changes: 3 additions & 0 deletions PythonPackage/AMR/AMR/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def oxazolidinones(only_sir_columns = False, *args, **kwargs):
def penicillins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.penicillins(only_sir_columns = False, *args, **kwargs))
def phenicols(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.phenicols(only_sir_columns = False, *args, **kwargs))
def polymyxins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.polymyxins(only_sir_columns = False, *args, **kwargs))
Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed PythonPackage/AMR/dist/amr-2.1.1.9122.tar.gz
Binary file not shown.
Binary file added PythonPackage/AMR/dist/amr-2.1.1.9123.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion PythonPackage/AMR/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='AMR',
version='2.1.1.9122',
version='2.1.1.9123',
packages=find_packages(),
install_requires=[
'rpy2',
Expand Down
27 changes: 27 additions & 0 deletions R/ab.R
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,30 @@ get_translate_ab <- function(translate_ab) {
translate_ab
}
}

create_AB_AV_lookup <- function(df) {
new_df <- df
new_df$generalised_name <- generalise_antibiotic_name(new_df$name)
new_df$generalised_synonyms <- lapply(new_df$synonyms, generalise_antibiotic_name)
if ("abbreviations" %in% colnames(df)) {
new_df$generalised_abbreviations <- lapply(new_df$abbreviations, generalise_antibiotic_name)
}
new_df$generalised_loinc <- lapply(new_df$loinc, generalise_antibiotic_name)
new_df$generalised_all <- unname(lapply(
as.list(as.data.frame(
t(new_df[,
c(
colnames(new_df)[colnames(new_df) %in% c("ab", "av", "atc", "cid", "name")],
colnames(new_df)[colnames(new_df) %like% "generalised"]
),
drop = FALSE
]),
stringsAsFactors = FALSE
)),
function(x) {
x <- generalise_antibiotic_name(unname(unlist(x)))
x[x != ""]
}
))
new_df[, colnames(new_df)[colnames(new_df) %like% "^generalised"]]
}
20 changes: 13 additions & 7 deletions R/ab_selectors.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' `r paste0(" * ", na.omit(sapply(DEFINED_AB_GROUPS, function(ab) ifelse(tolower(gsub("^AB_", "", ab)) %in% ls(envir = asNamespace("AMR")), paste0("[", tolower(gsub("^AB_", "", ab)), "()] can select: \\cr ", vector_and(paste0(ab_name(eval(parse(text = ab), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), " (", eval(parse(text = ab), envir = asNamespace("AMR")), ")"), quotes = FALSE, sort = TRUE)), character(0)), USE.NAMES = FALSE)), "\n", collapse = "")`
#' @rdname antibiotic_class_selectors
#' @name antibiotic_class_selectors
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"ab_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobial that the function would be able to select or filter.
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"ab_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobials that the function would be able to select or filter.
#' @export
#' @inheritSection AMR Reference Data Publicly Available
#' @examples
Expand Down Expand Up @@ -418,6 +418,13 @@ penicillins <- function(only_sir_columns = FALSE, ...) {
ab_select_exec("penicillins", only_sir_columns = only_sir_columns)
}

#' @rdname antibiotic_class_selectors
#' @export
phenicols <- function(only_sir_columns = FALSE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("phenicols", only_sir_columns = only_sir_columns)
}

#' @rdname antibiotic_class_selectors
#' @export
polymyxins <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
Expand Down Expand Up @@ -675,17 +682,16 @@ ab_select_exec <- function(function_name,
}

if (is.null(vars_df)) {
# no data found, no antimicrobials, so no input. Can happen if users run e.g. `aminoglycosides()` as a separate command.
# no data found, no antimicrobials, so no input. Happens if users run e.g. `aminoglycosides()` as a separate command.
examples <- paste0(
", e.g.:\n",
" ", AMR_env$bullet_icon, " your_data %>% select(", function_name, "())\n",
" ", AMR_env$bullet_icon, " your_data %>% select(column_a, column_b, ", function_name, "())\n",
" ", AMR_env$bullet_icon, " your_data %>% filter(any(", function_name, "() == \"R\"))\n",
" ", AMR_env$bullet_icon, " your_data[, ", function_name, "()]\n",
" ", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]"
)
message_("The function `" , function_name, "()` should be used inside a `dplyr` verb or `data.frame` call",
examples, "\n\nNow returning a vector of all possible antimicrobials that `" , function_name, "()` can select.")
" ", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]")
message_("The function `" , function_name, "()` should be used inside a `dplyr` verb or `data.frame` call, e.g.:\n",
examples,
"\n\nNow returning a vector of all possible antimicrobials that `" , function_name, "()` can select.")
return(sort(abx))
}

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
8 changes: 6 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,14 @@ AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE)
if (pkg_is_available("tibble")) {
try(loadNamespace("tibble"), silent = TRUE)
}

# reference data - they have additional data to improve algorithm speed
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
if (NROW(AB_LOOKUP) != NROW(AMR::antibiotics)) {
# antibiotics data set was updated - run create_AB_AV_lookup() again
AB_LOOKUP <- create_AB_AV_lookup(AMR::antibiotics)
}
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
}

Expand Down
46 changes: 12 additions & 34 deletions data-raw/_pre_commit_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ create_species_cons_cops <- function(type = c("CoNS", "CoPS")) {
# - Becker et al. 2019, PMID 30872103
# - Becker et al. 2020, PMID 32056452
# this function returns class <mo>
MO_staph <- AMR::microorganisms
MO_staph <- microorganisms

Check warning on line 104 in data-raw/_pre_commit_checks.R

View workflow job for this annotation

GitHub Actions / lintr

file=data-raw/_pre_commit_checks.R,line=104,col=15,[object_usage_linter] no visible binding for global variable 'microorganisms'
MO_staph <- MO_staph[which(MO_staph$genus == "Staphylococcus"), , drop = FALSE]
if (type == "CoNS") {
MO_staph[
Expand Down Expand Up @@ -152,12 +152,12 @@ create_species_cons_cops <- function(type = c("CoNS", "CoPS")) {
}
pre_commit_lst$MO_CONS <- create_species_cons_cops("CoNS")
pre_commit_lst$MO_COPS <- create_species_cons_cops("CoPS")
pre_commit_lst$MO_STREP_ABCG <- AMR::microorganisms$mo[which(AMR::microorganisms$genus == "Streptococcus" &
tolower(AMR::microorganisms$species) %in% c(
pre_commit_lst$MO_STREP_ABCG <- microorganisms$mo[which(microorganisms$genus == "Streptococcus" &
tolower(microorganisms$species) %in% c(
"pyogenes", "agalactiae", "dysgalactiae", "equi", "canis",
"group a", "group b", "group c", "group g"
))]
pre_commit_lst$MO_LANCEFIELD <- AMR::microorganisms$mo[which(AMR::microorganisms$mo %like% "^(B_STRPT_PYGN(_|$)|B_STRPT_AGLC(_|$)|B_STRPT_(DYSG|EQUI)(_|$)|B_STRPT_ANGN(_|$)|B_STRPT_(DYSG|CANS)(_|$)|B_STRPT_SNGN(_|$)|B_STRPT_SLVR(_|$))")]
pre_commit_lst$MO_LANCEFIELD <- microorganisms$mo[which(microorganisms$mo %like% "^(B_STRPT_PYGN(_|$)|B_STRPT_AGLC(_|$)|B_STRPT_(DYSG|EQUI)(_|$)|B_STRPT_ANGN(_|$)|B_STRPT_(DYSG|CANS)(_|$)|B_STRPT_SNGN(_|$)|B_STRPT_SLVR(_|$))")]
pre_commit_lst$MO_WHO_PRIORITY_GENERA <- c(
# World Health Organization's (WHO) Priority Pathogen List (some are from the group Enterobacteriaceae)
"Acinetobacter",
Expand Down Expand Up @@ -419,6 +419,9 @@ pre_commit_lst$AB_OXAZOLIDINONES <- antibiotics %>%
pre_commit_lst$AB_PENICILLINS <- antibiotics %>%
filter(group %like% "penicillin") %>%
pull(ab)
pre_commit_lst$AB_PHENICOLS <- antibiotics %>%
filter(group %like% "phenicol" | atc_group1 %like% "phenicol" | atc_group2 %like% "phenicol") %>%
pull(ab)
pre_commit_lst$AB_POLYMYXINS <- antibiotics %>%
filter(group %like% "polymyxin") %>%
pull(ab)
Expand All @@ -445,34 +448,9 @@ pre_commit_lst$AB_BETALACTAMS_WITH_INHIBITOR <- antibiotics %>%
pull(ab)
# this will be used for documentation:
pre_commit_lst$DEFINED_AB_GROUPS <- sort(names(pre_commit_lst)[names(pre_commit_lst) %like% "^AB_" & names(pre_commit_lst) != "AB_LOOKUP"])
create_AB_AV_lookup <- function(df) {
new_df <- df
new_df$generalised_name <- generalise_antibiotic_name(new_df$name)
new_df$generalised_synonyms <- lapply(new_df$synonyms, generalise_antibiotic_name)
if ("abbreviations" %in% colnames(df)) {
new_df$generalised_abbreviations <- lapply(new_df$abbreviations, generalise_antibiotic_name)
}
new_df$generalised_loinc <- lapply(new_df$loinc, generalise_antibiotic_name)
new_df$generalised_all <- unname(lapply(
as.list(as.data.frame(
t(new_df[,
c(
colnames(new_df)[colnames(new_df) %in% c("ab", "av", "atc", "cid", "name")],
colnames(new_df)[colnames(new_df) %like% "generalised"]
),
drop = FALSE
]),
stringsAsFactors = FALSE
)),
function(x) {
x <- generalise_antibiotic_name(unname(unlist(x)))
x[x != ""]
}
))
new_df[, colnames(new_df)[colnames(new_df) %like% "^generalised"]]
}
pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(AMR::antibiotics)
pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(AMR::antivirals)

pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(antibiotics)
pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(antivirals)

# Export to package as internal data ----
# usethis::use_data() must receive unquoted object names, which is not flexible at all.
Expand Down Expand Up @@ -521,8 +499,8 @@ changed_md5 <- function(object) {

# give official names to ABs and MOs
clin_break <- clinical_breakpoints %>%
mutate(mo_name = mo_name(mo, language = NULL, keep_synonyms = TRUE, info = FALSE), .after = mo) %>%
mutate(ab_name = ab_name(ab, language = NULL), .after = ab)
mutate(mo_name = microorganisms$fullname[match(mo, microorganisms$mo)], .after = mo) %>%
mutate(ab_name = antibiotics$name[match(ab, antibiotics$ab)], .after = ab)
if (changed_md5(clin_break)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}"))
write_md5(clin_break)
Expand Down
2 changes: 1 addition & 1 deletion data-raw/ab.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6f6b49606c2c51f8344fbb9e186a3ad3
33a6626c9ac1ca6c5c13ad96588d11e5
Binary file modified data-raw/antibiotics.dta
Binary file not shown.
Binary file modified data-raw/antibiotics.feather
Binary file not shown.
Binary file modified data-raw/antibiotics.parquet
Binary file not shown.
Binary file modified data-raw/antibiotics.rds
Binary file not shown.
Binary file modified data-raw/antibiotics.sav
Binary file not shown.
Loading

0 comments on commit 08ddbaa

Please sign in to comment.