mirror of
https://github.com/msberends/AMR.git
synced 2025-02-22 23:50:04 +01:00
(v2.1.1.9148) scale fix, antibiogram fix
This commit is contained in:
parent
d94efb0f5e
commit
9d636983ac
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 2.1.1.9147
|
||||
Date: 2025-02-14
|
||||
Version: 2.1.1.9148
|
||||
Date: 2025-02-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
|
||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
||||
# AMR 2.1.1.9147
|
||||
# AMR 2.1.1.9148
|
||||
|
||||
*(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).)*
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
Metadata-Version: 2.2
|
||||
Name: AMR
|
||||
Version: 2.1.1.9147
|
||||
Version: 2.1.1.9148
|
||||
Summary: A Python wrapper for the AMR R package
|
||||
Home-page: https://github.com/msberends/AMR
|
||||
Author: Matthijs Berends
|
||||
|
Binary file not shown.
BIN
PythonPackage/AMR/dist/amr-2.1.1.9147.tar.gz
vendored
BIN
PythonPackage/AMR/dist/amr-2.1.1.9147.tar.gz
vendored
Binary file not shown.
BIN
PythonPackage/AMR/dist/amr-2.1.1.9148.tar.gz
vendored
Normal file
BIN
PythonPackage/AMR/dist/amr-2.1.1.9148.tar.gz
vendored
Normal file
Binary file not shown.
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='AMR',
|
||||
version='2.1.1.9147',
|
||||
version='2.1.1.9148',
|
||||
packages=find_packages(),
|
||||
install_requires=[
|
||||
'rpy2',
|
||||
|
@ -179,12 +179,16 @@ globalVariables(c(
|
||||
"microorganisms.codes",
|
||||
"mo",
|
||||
"n",
|
||||
"n_susceptible",
|
||||
"n_tested",
|
||||
"n_total",
|
||||
"name",
|
||||
"new",
|
||||
"numerator",
|
||||
"observations",
|
||||
"old",
|
||||
"old_name",
|
||||
"p_susceptible",
|
||||
"pattern",
|
||||
"R",
|
||||
"rank_index",
|
||||
|
@ -441,7 +441,7 @@ antibiogram.default <- function(x,
|
||||
x <- ascertain_sir_classes(x, "x")
|
||||
meet_criteria(wisca, allow_class = "logical", has_length = 1)
|
||||
if (isTRUE(wisca)) {
|
||||
if (!missing(mo_transform)) {
|
||||
if (!is.null(mo_transform)) {
|
||||
warning_("WISCA must be based on the species level as WISCA parameters are based on this. For that reason, `mo_transform` will be ignored.")
|
||||
}
|
||||
mo_transform <- function(x) suppressMessages(suppressWarnings(paste(mo_genus(x, keep_synonyms = TRUE, language = NULL), mo_species(x, keep_synonyms = TRUE, language = NULL))))
|
||||
@ -469,7 +469,7 @@ antibiogram.default <- function(x,
|
||||
|
||||
# try to find columns based on type
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo", info = interactive())
|
||||
col_mo <- search_type_in_df(x = x, type = "mo", info = info)
|
||||
stop_if(is.null(col_mo), "`col_mo` must be set")
|
||||
}
|
||||
# transform MOs
|
||||
@ -594,7 +594,7 @@ antibiogram.default <- function(x,
|
||||
}
|
||||
if (all(out$n_tested < minimum, na.rm = TRUE) && wisca == FALSE) {
|
||||
warning_("All combinations had less than `minimum = ", minimum, "` results, returning an empty antibiogram")
|
||||
return(as_original_data_class(data.frame(), class(out), extra_class = "antibiogram"))
|
||||
return(as_original_data_class(data.frame(), class(x), extra_class = "antibiogram"))
|
||||
} else if (any(out$n_tested < minimum, na.rm = TRUE)) {
|
||||
out <- out %pm>%
|
||||
# also for WISCA, refrain from anything below 15 isolates:
|
||||
@ -612,7 +612,7 @@ antibiogram.default <- function(x,
|
||||
}
|
||||
|
||||
if (NROW(out) == 0) {
|
||||
return(as_original_data_class(data.frame(), class(out), extra_class = "antibiogram"))
|
||||
return(as_original_data_class(data.frame(), class(x), extra_class = "antibiogram"))
|
||||
}
|
||||
|
||||
out$p_susceptible <- out$n_susceptible / out$n_tested
|
||||
@ -927,7 +927,6 @@ antibiogram.default <- function(x,
|
||||
rownames(out) <- NULL
|
||||
rownames(wisca_parameters) <- NULL
|
||||
rownames(long_numeric) <- NULL
|
||||
|
||||
structure(out,
|
||||
has_syndromic_group = has_syndromic_group,
|
||||
combine_SI = combine_SI,
|
||||
@ -943,7 +942,7 @@ antibiogram.default <- function(x,
|
||||
#' @export
|
||||
antibiogram.grouped_df <- function(x,
|
||||
antibiotics = where(is.sir),
|
||||
mo_transform = function (...) "no_mo",
|
||||
mo_transform = NULL,
|
||||
ab_transform = "name",
|
||||
syndromic_group = NULL,
|
||||
add_total_n = FALSE,
|
||||
@ -960,6 +959,7 @@ antibiogram.grouped_df <- function(x,
|
||||
conf_interval = 0.95,
|
||||
interval_side = "two-tailed",
|
||||
info = interactive()) {
|
||||
stop_ifnot(is.null(mo_transform), "`mo_transform` must not be set if creating an antibiogram using a grouped tibble. The groups will become the variables over which the antimicrobials are calculated, which could include the pathogen information (though not necessary). Nonetheless, this makes `mo_transform` redundant.", call = FALSE)
|
||||
stop_ifnot(is.null(syndromic_group), "`syndromic_group` must not be set if creating an antibiogram using a grouped tibble. The groups will become the variables over which the antimicrobials are calculated, making `syndromic_groups` redundant.", call = FALSE)
|
||||
groups <- attributes(x)$groups
|
||||
n_groups <- NROW(groups)
|
||||
@ -969,16 +969,19 @@ antibiogram.grouped_df <- function(x,
|
||||
title = paste("Calculating AMR for", n_groups, "groups"))
|
||||
on.exit(close(progress))
|
||||
|
||||
out <- NULL
|
||||
wisca_parameters <- NULL
|
||||
long_numeric <- NULL
|
||||
|
||||
for (i in seq_len(n_groups)) {
|
||||
if (i > 1) progress$tick()
|
||||
progress$tick()
|
||||
rows <- unlist(groups[i, ]$.rows)
|
||||
if (length(rows) == 0) {
|
||||
next
|
||||
}
|
||||
|
||||
new_out <- antibiogram(as.data.frame(x)[rows, , drop = FALSE],
|
||||
antibiotics = antibiotics,
|
||||
mo_transform = function(x) "no_mo",
|
||||
mo_transform = NULL,
|
||||
ab_transform = ab_transform,
|
||||
syndromic_group = NULL,
|
||||
add_total_n = add_total_n,
|
||||
@ -994,17 +997,15 @@ antibiogram.grouped_df <- function(x,
|
||||
simulations = simulations,
|
||||
conf_interval = conf_interval,
|
||||
interval_side = interval_side,
|
||||
info = i == 1 && info == TRUE)
|
||||
info = FALSE)
|
||||
new_wisca_parameters <- attributes(new_out)$wisca_parameters
|
||||
new_long_numeric <- attributes(new_out)$long_numeric
|
||||
|
||||
if (i == 1) progress$tick()
|
||||
|
||||
if (NROW(new_out) == 0) {
|
||||
next
|
||||
}
|
||||
|
||||
# remove first column 'Pathogen' (in whatever language)
|
||||
# remove first column 'Pathogen' (in whatever language), except WISCA since that never has Pathogen column
|
||||
if (isFALSE(wisca)) {
|
||||
new_out <- new_out[, -1, drop = FALSE]
|
||||
new_long_numeric <- new_long_numeric[, -1, drop = FALSE]
|
||||
@ -1037,17 +1038,17 @@ antibiogram.grouped_df <- function(x,
|
||||
long_numeric <- rbind_AMR(long_numeric, new_long_numeric)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
close(progress)
|
||||
|
||||
out <- structure(as_original_data_class(out, class(x), extra_class = "antibiogram"),
|
||||
has_syndromic_group = FALSE,
|
||||
combine_SI = isTRUE(combine_SI),
|
||||
wisca = isTRUE(wisca),
|
||||
conf_interval = conf_interval,
|
||||
formatting_type = formatting_type,
|
||||
wisca_parameters = as_original_data_class(wisca_parameters, class(x)),
|
||||
long_numeric = as_original_data_class(long_numeric, class(x)))
|
||||
structure(as_original_data_class(out, class(x), extra_class = "antibiogram"),
|
||||
has_syndromic_group = FALSE,
|
||||
combine_SI = isTRUE(combine_SI),
|
||||
wisca = isTRUE(wisca),
|
||||
conf_interval = conf_interval,
|
||||
formatting_type = formatting_type,
|
||||
wisca_parameters = as_original_data_class(wisca_parameters, class(x)),
|
||||
long_numeric = as_original_data_class(long_numeric, class(x)))
|
||||
}
|
||||
|
||||
#' @export
|
||||
@ -1072,6 +1073,7 @@ wisca <- function(x,
|
||||
antibiogram(x = x,
|
||||
antibiotics = antibiotics,
|
||||
ab_transform = ab_transform,
|
||||
mo_transform = NULL,
|
||||
syndromic_group = syndromic_group,
|
||||
add_total_n = add_total_n,
|
||||
only_all_tested = only_all_tested,
|
||||
|
34
R/plotting.R
34
R/plotting.R
@ -227,10 +227,16 @@
|
||||
#' }
|
||||
NULL
|
||||
|
||||
create_scale_mic <- function(aest, keep_operators, mic_range, ...) {
|
||||
create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
ggplot_fn <- getExportedValue(paste0("scale_", aest, "_continuous"),
|
||||
ns = asNamespace("ggplot2"))
|
||||
args <- list(...)
|
||||
breaks_set <- args$breaks
|
||||
if (!is.null(args$limits)) {
|
||||
stop_ifnot(is.null(mic_range),
|
||||
"In `scale_", aest, "_mic()`, `limits` cannot be combined with `mic_range`, as they working identically. Use `mic_range` OR `limits`.", call = FALSE)
|
||||
mic_range <- args$limits
|
||||
}
|
||||
# do not take these arguments into account, as they will be overwritten and seem to allow weird behaviour
|
||||
args[c("aesthetics", "trans", "transform", "transform_df", "breaks", "labels", "limits")] <- NULL
|
||||
scale <- do.call(ggplot_fn, args)
|
||||
@ -252,8 +258,30 @@ create_scale_mic <- function(aest, keep_operators, mic_range, ...) {
|
||||
df[[aest]] <- self$`.values_log`
|
||||
df
|
||||
}
|
||||
scale$breaks <- function(..., self) log2(as.mic(self$`.values_levels`))
|
||||
scale$labels <- function(..., self) self$`.values_levels`
|
||||
scale$breaks <- function(..., self) {
|
||||
if (!is.null(breaks_set)) {
|
||||
if (is.function(breaks_set)) {
|
||||
breaks_set(...)
|
||||
} else {
|
||||
log2(as.mic(breaks_set))
|
||||
}
|
||||
} else {
|
||||
log2(as.mic(self$`.values_levels`))
|
||||
}
|
||||
}
|
||||
scale$labels <- function(..., self) {
|
||||
if (is.null(breaks_set)) {
|
||||
self$`.values_levels`
|
||||
} else {
|
||||
breaks <- tryCatch(scale$breaks(), error = function(e) NULL)
|
||||
if (!is.null(breaks)) {
|
||||
# for when breaks are set by the user
|
||||
2 ^ breaks
|
||||
} else {
|
||||
self$`.values_levels`
|
||||
}
|
||||
}
|
||||
}
|
||||
scale$limits <- function(x, ..., self) {
|
||||
rng <- range(log2(as.mic(self$`.values_levels`)))
|
||||
# add 0.5 extra space
|
||||
|
@ -1,6 +1,6 @@
|
||||
This knowledge base contains all context you must know about the AMR package for R. You are a GPT trained to be an assistant for the AMR package in R. You are an incredible R specialist, especially trained in this package and in the tidyverse.
|
||||
|
||||
First and foremost, you are trained on version 2.1.1.9147. Remember this whenever someone asks which AMR package version you’re at.
|
||||
First and foremost, you are trained on version 2.1.1.9148. Remember this whenever someone asks which AMR package version you’re at.
|
||||
|
||||
Below are the contents of the file, the file, and all the files (documentation) in the package. Every file content is split using 100 hypens.
|
||||
----------------------------------------------------------------------------------------------------
|
@ -104,7 +104,7 @@ ab8 <- suppressWarnings(antibiogram(example_isolates,
|
||||
wisca = TRUE))
|
||||
|
||||
expect_inherits(ab8, "antibiogram")
|
||||
expect_equal(colnames(ab8), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
|
||||
expect_equal(colnames(ab8), c("Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
|
||||
|
||||
# grouped tibbles
|
||||
|
||||
@ -128,7 +128,7 @@ expect_silent(plot(ab5))
|
||||
expect_silent(plot(ab6))
|
||||
expect_silent(plot(ab7))
|
||||
expect_silent(plot(ab8))
|
||||
expect_error(plot(ab9))
|
||||
expect_silent(plot(ab9))
|
||||
|
||||
if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot2::autoplot(ab1), "gg")
|
||||
@ -139,5 +139,5 @@ if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot2::autoplot(ab6), "gg")
|
||||
expect_inherits(ggplot2::autoplot(ab7), "gg")
|
||||
expect_inherits(ggplot2::autoplot(ab8), "gg")
|
||||
expect_error(ggplot2::autoplot(ab9))
|
||||
expect_inherits(ggplot2::autoplot(ab9), "gg")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user