1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 19:01:51 +02:00

(v1.5.0.9031) math processing of MICs

This commit is contained in:
2021-03-05 15:36:39 +01:00
parent 0d29bde693
commit 91dd755cac
36 changed files with 310 additions and 52 deletions

View File

@ -29,7 +29,7 @@
#' @details
#' `AMR` is a free, open-source and independent \R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting.
#'
#' After installing this package, \R knows ~70,000 distinct microbial species and all ~550 antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-NET, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data.
#' After installing this package, \R knows `r format_included_data_number(microorganisms)` distinct microbial species and all `r format_included_data_number(rbind(antibiotics[, "atc", drop = FALSE], antivirals[, "atc", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-NET, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data.
#'
#' This package is fully independent of any other \R package and works on Windows, macOS and Linux with all versions of \R since R-3.0.0 (April 2013). It was designed to work in any setting, including those with very limited resources. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the University of Groningen, in collaboration with non-profit organisations Certe Medical Diagnostics and Advice and University Medical Center Groningen. This \R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation.
#'

View File

@ -44,7 +44,7 @@ format_included_data_number <- function(data) {
#' This package contains the complete taxonomic tree of almost all microorganisms from the authoritative and comprehensive Catalogue of Life.
#' @section Catalogue of Life:
#' \if{html}{\figure{logo_col.png}{options: height=40px style=margin-bottom:5px} \cr}
#' This package contains the complete taxonomic tree of almost all microorganisms (~70,000 species) from the authoritative and comprehensive Catalogue of Life (CoL, <http://www.catalogueoflife.org>). The CoL is the most comprehensive and authoritative global index of species currently available. Nonetheless, we supplemented the CoL data with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN, [lpsn.dsmz.de](https://lpsn.dsmz.de)). This supplementation is needed until the [CoL+ project](https://github.com/CatalogueOfLife/general) is finished, which we await.
#' This package contains the complete taxonomic tree of almost all microorganisms (`r format_included_data_number(microorganisms)` species) from the authoritative and comprehensive Catalogue of Life (CoL, <http://www.catalogueoflife.org>). The CoL is the most comprehensive and authoritative global index of species currently available. Nonetheless, we supplemented the CoL data with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN, [lpsn.dsmz.de](https://lpsn.dsmz.de)). This supplementation is needed until the [CoL+ project](https://github.com/CatalogueOfLife/general) is finished, which we await.
#'
#' [Click here][catalogue_of_life] for more information about the included taxa. Check which versions of the CoL and LPSN were included in this package with [catalogue_of_life_version()].
#' @section Included Taxa:

221
R/mic.R
View File

@ -42,6 +42,11 @@
#'
#' # this can also coerce combined MIC/RSI values:
#' as.mic("<=0.002; S") # will return <=0.002
#'
#' # mathematical processing treats MICs as numeric values
#' fivenum(mic_data)
#' quantile(mic_data)
#' all(mic_data < 512)
#'
#' # interpret MIC values
#' as.rsi(x = as.mic(2),
@ -276,6 +281,222 @@ unique.mic <- function(x, incomparables = FALSE, ...) {
y
}
#' @method range mic
#' @export
#' @noRd
range.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
out <- c(as.character(rng[1]), as.character(rng[length(rng)]))
as.double(as.mic(out))
}
#' @method min mic
#' @export
#' @noRd
min.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
as.double(as.mic(as.character(rng[1])))
}
#' @method max mic
#' @export
#' @noRd
max.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
as.double(as.mic(as.character(rng[length(rng)])))
}
#' @method sum mic
#' @export
#' @noRd
sum.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
sum(as.double(rng))
}
#' @method all mic
#' @export
#' @noRd
all.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
all(as.double(rng))
}
#' @method any mic
#' @export
#' @noRd
any.mic <- function(..., na.rm = FALSE) {
rng <- sort(c(...))
if (na.rm == TRUE) {
rng <- rng[!is.na(rng)]
}
any(as.double(rng))
}
#' @method mean mic
#' @export
#' @noRd
mean.mic <- function(x, na.rm = FALSE, ...) {
mean(as.double(x), na.rm = na.rm, ...)
}
#' @method median mic
#' @export
#' @noRd
median.mic <- function(x, na.rm = FALSE, ...) {
median(as.double(x), na.rm = na.rm, ...)
}
#' @method quantile mic
#' @export
#' @noRd
quantile.mic <- function(x, probs = seq(0, 1, 0.25), na.rm = FALSE,
names = TRUE, type = 7, ...) {
quantile(as.double(x), props = props, na.rm = na.rm, names = names, type = type, ...)
}
#' @method floor mic
#' @export
#' @noRd
floor.mic <- function(x) {
floor(as.double(x))
}
#' @method ceiling mic
#' @export
#' @noRd
ceiling.mic <- function(x) {
ceiling(as.double(x))
}
#' @method + mic
#' @export
#' @noRd
`+.mic` <- function(e1, e2) {
as.double(e1) + as.double(e2)
}
#' @method - mic
#' @export
#' @noRd
`-.mic` <- function(e1, e2) {
as.double(e1) - as.double(e2)
}
#' @method * mic
#' @export
#' @noRd
`*.mic` <- function(e1, e2) {
as.double(e1) * as.double(e2)
}
#' @method / mic
#' @export
#' @noRd
`/.mic` <- function(e1, e2) {
as.double(e1) / as.double(e2)
}
#' @method ^ mic
#' @export
#' @noRd
`^.mic` <- function(e1, e2) {
as.double(e1) ^ as.double(e2)
}
#' @method %% mic
#' @export
#' @noRd
`%%.mic` <- function(e1, e2) {
as.double(e1) %% as.double(e2)
}
#' @method %/% mic
#' @export
#' @noRd
`%/%.mic` <- function(e1, e2) {
as.double(e1) %/% as.double(e2)
}
#' @method == mic
#' @export
#' @noRd
`==.mic` <- function(e1, e2) {
as.double(e1) == as.double(e2)
}
#' @method != mic
#' @export
#' @noRd
`!=.mic` <- function(e1, e2) {
as.double(e1) != as.double(e2)
}
#' @method < mic
#' @export
#' @noRd
`<.mic` <- function(e1, e2) {
as.double(e1) < as.double(e2)
}
#' @method <= mic
#' @export
#' @noRd
`<=.mic` <- function(e1, e2) {
as.double(e1) <= as.double(e2)
}
#' @method >= mic
#' @export
#' @noRd
`>=.mic` <- function(e1, e2) {
as.double(e1) >= as.double(e2)
}
#' @method > mic
#' @export
#' @noRd
`>.mic` <- function(e1, e2) {
as.double(e1) > as.double(e2)
}
#' @method sort mic
#' @export
#' @noRd
sort.mic <- function(x, decreasing = FALSE, ...) {
if (decreasing == TRUE) {
ord <- order(-as.double(x))
} else {
ord <- order(as.double(x))
}
x[ord]
}
#' @method hist mic
#' @export
#' @noRd
hist.mic <- function(x, ...) {
warning_("Use `plot()` or `ggplot()` for plotting MIC values", call = FALSE)
hist(as.double(x), ...)
}
# will be exported using s3_register() in R/zzz.R
get_skimmers.mic <- function(column) {
skimr::sfl(

4
R/mo.R
View File

@ -1474,8 +1474,8 @@ exec_as.mo <- function(x,
if (length(uncertainties$input) > 1) {
plural <- c("s", "them", "were")
}
msg <- paste0("Translation to ", nr2char(length(uncertainties$input)), " microorganism", plural[1],
" was guessed with uncertainty. Use `mo_uncertainties()` to review ", plural[2], ".")
msg <- paste0("Translation is uncertain of ", nr2char(length(uncertainties$input)), " microorganism", plural[1],
". Use `mo_uncertainties()` to review ", plural[2], ".")
message_(msg)
}
x[already_known] <- x_known

View File

@ -261,7 +261,6 @@ ggplot.mic <- function(data,
ggplot2::labs(title = title, x = xlab, y = ylab, subtitle = cols_sub$sub)
}
#' @method plot disk
#' @export
#' @importFrom graphics barplot axis mtext legend

View File

@ -51,9 +51,9 @@
#' random_mic(100, "Klebsiella pneumoniae", "meropenem") # range 0.0625-16
#' random_mic(100, "Streptococcus pneumoniae", "meropenem") # range 0.0625-4
#'
#' random_disk(100, "Klebsiella pneumoniae") # range 11-50
#' random_disk(100, "Klebsiella pneumoniae", "ampicillin") # range 6-14
#' random_disk(100, "Streptococcus pneumoniae", "ampicillin") # range 16-22
#' random_disk(100, "Klebsiella pneumoniae") # range 8-50
#' random_disk(100, "Klebsiella pneumoniae", "ampicillin") # range 11-17
#' random_disk(100, "Streptococcus pneumoniae", "ampicillin") # range 12-27
#' }
random_mic <- function(size, mo = NULL, ab = NULL, ...) {
random_exec("MIC", size = size, mo = mo, ab = ab)