adding mo fixes

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-01-14 19:50:25 +01:00
parent ca79068604
commit b94bc6c67b
12 changed files with 69 additions and 44 deletions

View File

@ -1,5 +1,5 @@
Package: AMR
Version: 1.8.2.9092
Version: 1.8.2.9093
Date: 2023-01-14
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)

View File

@ -1,4 +1,4 @@
# AMR 1.8.2.9092
# AMR 1.8.2.9093
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*

View File

@ -1372,6 +1372,13 @@ percentage <- function(x, digits = NULL, ...) {
)
}
add_intrinsic_resistance_to_AMR_env <- function() {
# for mo_is_intrinsic_resistant() - saves a lot of time when executed on this vector
if (is.null(AMR_env$intrinsic_resistant)) {
AMR_env$intrinsic_resistant <- paste(AMR::intrinsic_resistant$mo, AMR::intrinsic_resistant$ab)
}
}
trimws2 <- function(..., whitespace = "[\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u200C\u200D\u2028\u2029\u202F\u205F\u2060\u3000\uFEFF]") {
# this is even faster than trimws() itself which sets " \t\n\r".
trimws(..., whitespace = whitespace)

View File

@ -27,9 +27,9 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#' Add Custom Antimicrobials to This Package
#' Add Custom Antimicrobials
#'
#' With [add_custom_antimicrobials()] you can add your own custom antimicrobial drug codes to the `AMR` package.
#' With [add_custom_antimicrobials()] you can add your own custom antimicrobial drug names and codes.
#' @param x a [data.frame] resembling the [antibiotics] data set, at least containing columns "ab" and "name"
#' @details **Important:** Due to how \R works, the [add_custom_antimicrobials()] function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
#'
@ -65,13 +65,13 @@
#' ```
#'
#' Use [clear_custom_antimicrobials()] to clear the previously added antimicrobials.
#' @seealso [add_custom_microorganisms()] to add custom microorganisms to this package.
#' @seealso [add_custom_microorganisms()] to add custom microorganisms.
#' @rdname add_custom_antimicrobials
#' @export
#' @examples
#' \donttest{
#'
#' # returns NA and throws a warning (which is now suppressed):
#' # returns NA and throws a warning (which is suppressed here):
#' suppressWarnings(
#' as.ab("testab")
#' )

View File

@ -27,9 +27,9 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#' Add Custom Microorganisms to This Package
#' Add Custom Microorganisms
#'
#' With [add_custom_microorganisms()] you can add your own custom microorganisms to the `AMR` package, such the non-taxonomic outcome of laboratory analysis.
#' With [add_custom_microorganisms()] you can add your own custom microorganisms, such the non-taxonomic outcome of laboratory analysis.
#' @param x a [data.frame] resembling the [microorganisms] data set, at least containing column "genus" (case-insensitive)
#' @details This function will fill in missing taxonomy for you, if specific taxonomic columns are missing, see *Examples*.
#'
@ -66,7 +66,7 @@
#' ```
#'
#' Use [clear_custom_microorganisms()] to clear the previously added antimicrobials.
#' @seealso [add_custom_antimicrobials()] to add custom antimicrobials to this package.
#' @seealso [add_custom_antimicrobials()] to add custom antimicrobials.
#' @rdname add_custom_microorganisms
#' @export
#' @examples
@ -102,15 +102,23 @@
#'
#' # the function tries to be forgiving:
#' add_custom_microorganisms(
#' data.frame(GENUS = "ESCHERICHIA / KLEBSIELLA",
#' SPECIES = "SPECIES"))
#' data.frame(GENUS = "ESCHERICHIA / KLEBSIELLA SLASHLINE",
#' SPECIES = "SPECIES")
#' )
#' mo_name("ESCHERICHIA / KLEBSIELLA")
#' mo_rank("ESCHERICHIA / KLEBSIELLA")
#' # taxonomy still works, although a slashline genus was given as input:
#' mo_family("Escherichia/Klebsiella")
#'
#' # for groups and complexes, set them as species or subspecies:
#' add_custom_microorganisms(
#' data.frame(genus = "Citrobacter", species = "freundii complex"))
#' mo_name("C. freundii complex")
#' mo_gramstain("C. freundii complex")
#' data.frame(genus = "Citrobacter",
#' species = c("freundii", "braakii complex"),
#' subspecies = c("complex", ""))
#' )
#' mo_name(c("C. freundii complex", "C. braakii complex"))
#' mo_species(c("C. freundii complex", "C. braakii complex"))
#' mo_gramstain(c("C. freundii complex", "C. braakii complex"))
#' }
add_custom_microorganisms <- function(x) {
meet_criteria(x, allow_class = "data.frame")
@ -135,12 +143,13 @@ add_custom_microorganisms <- function(x) {
x[, col] <- as.character(x[, col, drop = TRUE])
}
col_ <- x[, col, drop = TRUE]
col_ <- tolower(trimws2(col_))
col_ <- tolower(col_)
col_ <- gsub("slashline", "", col_, fixed = TRUE)
col_ <- trimws2(col_)
col_[col_ %like% "(sub)?species"] <- ""
col_ <- gsub(" *([/-]) *", "\\1", col_, perl = TRUE)
# groups are in our taxonomic table with a capital G, and complexes might be added by the user
# groups are in our taxonomic table with a capital G
col_ <- gsub(" group( |$)", " Group\\1", col_, perl = TRUE)
col_ <- gsub(" complex( |$)", " Complex\\1", col_, perl = TRUE)
col_[is.na(col_)] <- ""
if (col == "genus") {
@ -151,6 +160,10 @@ add_custom_microorganisms <- function(x) {
}
x[, col] <- col_
}
# if subspecies is a group or complex, add it to the species and empty the subspecies
x$species[which(x$subspecies %in% c("group", "Group", "complex"))] <- paste(x$species[which(x$subspecies %in% c("group", "Group", "complex"))],
x$subspecies[which(x$subspecies %in% c("group", "Group", "complex"))])
x$subspecies[which(x$subspecies %in% c("group", "Group", "complex"))] <- ""
if ("rank" %in% colnames(x)) {
stop_ifnot(all(x$rank %in% AMR_env$MO_lookup$rank),

3
R/mo.R
View File

@ -236,9 +236,8 @@ as.mo <- function(x,
x[trimws2(x) %like% translate_into_language("no .*growth", language = language)] <- NA_character_
x[trimws2(x) %like% paste0("^(", translate_into_language("no|not", language = language), ") ")] <- NA_character_
# groups are in our taxonomic table with a capital G, and complexes might be added by the user
# groups are in our taxonomic table with a capital G
x <- gsub(" group( |$)", " Group\\1", x, perl = TRUE)
x <- gsub(" complex( |$)", " Complex\\1", x, perl = TRUE)
# run over all unique leftovers
x_unique <- unique(x[is.na(out) & !is.na(x)])

View File

@ -239,10 +239,3 @@ create_MO_lookup <- function() {
MO_lookup$subspecies_first <- tolower(substr(MO_lookup$subspecies, 1, 1)) # tolower for Salmonella serovars
MO_lookup
}
add_intrinsic_resistance_to_AMR_env <- function() {
# for mo_is_intrinsic_resistant() - saves a lot of time when executed on this vector
if (is.null(AMR_env$intrinsic_resistant)) {
AMR_env$intrinsic_resistant <- paste(AMR::intrinsic_resistant$mo, AMR::intrinsic_resistant$ab)
}
}

View File

@ -95,6 +95,7 @@ expect_equal(mo_synonyms("Escherichia coli"), NULL)
expect_true(length(mo_synonyms("Candida albicans")) > 1)
expect_inherits(mo_synonyms(c("Candida albicans", "Escherichia coli")), "list")
expect_equal(names(mo_info("Escherichia coli")), c(
"identifier",
"kingdom", "phylum", "class", "order",
"family", "genus", "species", "subspecies",
"status", "synonyms", "gramstain", "url", "ref",

View File

@ -3,7 +3,7 @@
\name{add_custom_antimicrobials}
\alias{add_custom_antimicrobials}
\alias{clear_custom_antimicrobials}
\title{Add Custom Antimicrobials to This Package}
\title{Add Custom Antimicrobials}
\usage{
add_custom_antimicrobials(x)
@ -13,7 +13,7 @@ clear_custom_antimicrobials()
\item{x}{a \link{data.frame} resembling the \link{antibiotics} data set, at least containing columns "ab" and "name"}
}
\description{
With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you can add your own custom antimicrobial drug codes to the \code{AMR} package.
With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you can add your own custom antimicrobial drug names and codes.
}
\details{
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
@ -52,7 +52,7 @@ Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to
\examples{
\donttest{
# returns NA and throws a warning (which is now suppressed):
# returns NA and throws a warning (which is suppressed here):
suppressWarnings(
as.ab("testab")
)
@ -101,5 +101,5 @@ x[, betalactams()]
}
}
\seealso{
\code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} to add custom microorganisms to this package.
\code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} to add custom microorganisms.
}

View File

@ -3,7 +3,7 @@
\name{add_custom_microorganisms}
\alias{add_custom_microorganisms}
\alias{clear_custom_microorganisms}
\title{Add Custom Microorganisms to This Package}
\title{Add Custom Microorganisms}
\usage{
add_custom_microorganisms(x)
@ -13,7 +13,7 @@ clear_custom_microorganisms()
\item{x}{a \link{data.frame} resembling the \link{microorganisms} data set, at least containing column "genus" (case-insensitive)}
}
\description{
With \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} you can add your own custom microorganisms to the \code{AMR} package, such the non-taxonomic outcome of laboratory analysis.
With \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} you can add your own custom microorganisms, such the non-taxonomic outcome of laboratory analysis.
}
\details{
This function will fill in missing taxonomy for you, if specific taxonomic columns are missing, see \emph{Examples}.
@ -83,17 +83,25 @@ mo_info("Enterobacter asburiae/cloacae")
# the function tries to be forgiving:
add_custom_microorganisms(
data.frame(GENUS = "ESCHERICHIA / KLEBSIELLA",
SPECIES = "SPECIES"))
data.frame(GENUS = "ESCHERICHIA / KLEBSIELLA SLASHLINE",
SPECIES = "SPECIES")
)
mo_name("ESCHERICHIA / KLEBSIELLA")
mo_rank("ESCHERICHIA / KLEBSIELLA")
# taxonomy still works, although a slashline genus was given as input:
mo_family("Escherichia/Klebsiella")
# for groups and complexes, set them as species or subspecies:
add_custom_microorganisms(
data.frame(genus = "Citrobacter", species = "freundii complex"))
mo_name("C. freundii complex")
mo_gramstain("C. freundii complex")
data.frame(genus = "Citrobacter",
species = c("freundii", "braakii complex"),
subspecies = c("complex", ""))
)
mo_name(c("C. freundii complex", "C. braakii complex"))
mo_species(c("C. freundii complex", "C. braakii complex"))
mo_gramstain(c("C. freundii complex", "C. braakii complex"))
}
}
\seealso{
\code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} to add custom antimicrobials to this package.
\code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} to add custom antimicrobials.
}

View File

@ -78,6 +78,11 @@ pre .co, .co {
color: #999999 !important;
font-style: italic !important;
}
pre code .r-out,
pre code .r-msg {
/* output of functions */
color: #555555 !important;
}
code a[href],
a[href] code,
pre a[href],

View File

@ -33,15 +33,14 @@ $(document).ready(function() {
// Replace 'Developers' with 'Maintainers' on the main page, and "Contributors" on the Authors page
$(".developers h2").text("Maintainers");
$(".citation h2:first").text("All contributors");
$(".citation h2:second").text("How to Cite");
$(".citation h2:nth(0)").text("All contributors");
$(".citation h2:nth(1)").text("How to Cite");
// remove \donttest and \dontrun texts in Examples
if ($("#ref-examples ~ div pre").length > 0) {
const regex1 = /# \\dont(test|run)\{(\n|<br>)*/ig;
const regex2 = /(\n|<br>)*# \}/ig;
$("#ref-examples ~ div pre").html($("#ref-examples ~ div pre").html().replaceAll(regex1, ""));
$("#ref-examples ~ div pre").html($("#ref-examples ~ div pre").html().replaceAll(regex2, ""));
$("#ref-examples ~ div pre").html($("#ref-examples ~ div pre").html().replaceAll("# \\donttest{", ""));
$("#ref-examples ~ div pre").html($("#ref-examples ~ div pre").html().replaceAll("# \\dontrun{", ""));
$("#ref-examples ~ div pre").html($("#ref-examples ~ div pre").html().replaceAll("# }", ""));
}
// remove leading newline in code examples on changelog