mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 08:46:12 +01:00
styler dep
This commit is contained in:
parent
a0ee86536a
commit
a98d0d75ea
2
.github/prehooks/pre-commit
vendored
2
.github/prehooks/pre-commit
vendored
@ -33,7 +33,7 @@ echo "Running pre-commit hook..."
|
|||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
if command -v Rscript > /dev/null; then
|
if command -v Rscript > /dev/null; then
|
||||||
if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"', '"'styler'"') %in% rownames(installed.packages())))')" = "TRUE" ]; then
|
if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"') %in% rownames(installed.packages())))')" = "TRUE" ]; then
|
||||||
Rscript -e "source('data-raw/_pre_commit_hook.R')"
|
Rscript -e "source('data-raw/_pre_commit_hook.R')"
|
||||||
currentpkg=`Rscript -e "cat(pkgload::pkg_name())"`
|
currentpkg=`Rscript -e "cat(pkgload::pkg_name())"`
|
||||||
echo "-> Adding all files in 'data-raw' to this commit"
|
echo "-> Adding all files in 'data-raw' to this commit"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 1.8.2.9077
|
Version: 1.8.2.9078
|
||||||
Date: 2023-01-05
|
Date: 2023-01-05
|
||||||
Title: Antimicrobial Resistance Data Analysis
|
Title: Antimicrobial Resistance Data Analysis
|
||||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
|||||||
# 1.8.2.9077
|
# AMR 1.8.2.9078
|
||||||
|
|
||||||
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
||||||
|
|
||||||
|
BIN
R/sysdata.rda
BIN
R/sysdata.rda
Binary file not shown.
@ -486,14 +486,16 @@ suppressMessages(devtools::document(quiet = TRUE))
|
|||||||
|
|
||||||
|
|
||||||
# Style pkg ---------------------------------------------------------------
|
# Style pkg ---------------------------------------------------------------
|
||||||
# if (interactive()) {
|
if (!"styler" %in% rownames(utils::installed.packages())) {
|
||||||
# # only when sourcing this file ourselves
|
message("Package 'styler' not installed!")
|
||||||
# usethis::ui_info("Styling package")
|
} else if (interactive()) {
|
||||||
# styler::style_pkg(
|
# # only when sourcing this file ourselves
|
||||||
# style = styler::tidyverse_style,
|
# usethis::ui_info("Styling package")
|
||||||
# filetype = c("R", "Rmd")
|
# styler::style_pkg(
|
||||||
# )
|
# style = styler::tidyverse_style,
|
||||||
# }
|
# filetype = c("R", "Rmd")
|
||||||
|
# )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Finished ----------------------------------------------------------------
|
# Finished ----------------------------------------------------------------
|
||||||
|
@ -62,7 +62,7 @@ set_ab_names(
|
|||||||
|
|
||||||
\item{tolower}{a \link{logical} to indicate whether the first \link{character} of every output should be transformed to a lower case \link{character}. This will lead to e.g. "polymyxin B" and not "polymyxin b".}
|
\item{tolower}{a \link{logical} to indicate whether the first \link{character} of every output should be transformed to a lower case \link{character}. This will lead to e.g. "polymyxin B" and not "polymyxin b".}
|
||||||
|
|
||||||
\item{...}{in case of \code{\link[=set_ab_names]{set_ab_names()}} and \code{data} is a \link{data.frame}: variables to select (supports tidy selection such as \code{column1:column4}), otherwise other arguments passed on to \code{\link[=as.ab]{as.ab()}}}
|
\item{...}{in case of \code{\link[=set_ab_names]{set_ab_names()}} and \code{data} is a \link{data.frame}: columns to select (supports tidy selection such as \code{column1:column4}), otherwise other arguments passed on to \code{\link[=as.ab]{as.ab()}}}
|
||||||
|
|
||||||
\item{only_first}{a \link{logical} to indicate whether only the first ATC code must be returned, with giving preference to J0-codes (i.e., the antimicrobial drug group)}
|
\item{only_first}{a \link{logical} to indicate whether only the first ATC code must be returned, with giving preference to J0-codes (i.e., the antimicrobial drug group)}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ eucast_rules(df, rules = "custom", custom_rules = x, info = FALSE)
|
|||||||
|
|
||||||
\subsection{Using taxonomic properties in rules}{
|
\subsection{Using taxonomic properties in rules}{
|
||||||
|
|
||||||
There is one exception in variables used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence" and "snomed". Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}:
|
There is one exception in columns used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence" and "snomed". Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}:
|
||||||
|
|
||||||
\if{html}{\out{<div class="sourceCode r">}}\preformatted{y <- custom_eucast_rules(TZP == "S" & genus == "Klebsiella" ~ aminopenicillins == "S",
|
\if{html}{\out{<div class="sourceCode r">}}\preformatted{y <- custom_eucast_rules(TZP == "S" & genus == "Klebsiella" ~ aminopenicillins == "S",
|
||||||
TZP == "R" & genus == "Klebsiella" ~ aminopenicillins == "R")
|
TZP == "R" & genus == "Klebsiella" ~ aminopenicillins == "R")
|
||||||
|
@ -16,7 +16,7 @@ mean_amr_distance(x, ...)
|
|||||||
amr_distance_from_row(amr_distance, row)
|
amr_distance_from_row(amr_distance, row)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{x}{a vector of class \link[=as.rsi]{rsi}, \link[=as.rsi]{rsi} or \link[=as.rsi]{rsi}, or a \link{data.frame} containing columns of any of these classes}
|
\item{x}{a vector of class \link[=as.rsi]{rsi}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes}
|
||||||
|
|
||||||
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}}
|
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}}
|
||||||
|
|
||||||
@ -30,13 +30,13 @@ amr_distance_from_row(amr_distance, row)
|
|||||||
Calculates a normalised mean for antimicrobial resistance between multiple observations, to help to identify similar isolates without comparing antibiograms by hand.
|
Calculates a normalised mean for antimicrobial resistance between multiple observations, to help to identify similar isolates without comparing antibiograms by hand.
|
||||||
}
|
}
|
||||||
\details{
|
\details{
|
||||||
The mean AMR distance is a normalised numeric value to compare AMR test results and can help to identify similar isolates, without comparing antibiograms by hand. For common numeric data this distance is equal to \href{https://en.wikipedia.org/wiki/Standard_score}{Z scores} (the number of standard deviations from the mean).
|
The mean AMR distance is effectively \href{https://en.wikipedia.org/wiki/Standard_score}{the Z-score}; a normalised numeric value to compare AMR test results which can help to identify similar isolates, without comparing antibiograms by hand.
|
||||||
|
|
||||||
MIC values (see \code{\link[=as.mic]{as.mic()}}) are transformed with \code{\link[=log2]{log2()}} first; their distance is calculated as \code{(log2(x) - mean(log2(x))) / sd(log2(x))}.
|
MIC values (see \code{\link[=as.mic]{as.mic()}}) are transformed with \code{\link[=log2]{log2()}} first; their distance is thus calculated as \code{(log2(x) - mean(log2(x))) / sd(log2(x))}.
|
||||||
|
|
||||||
R/SI values (see \code{\link[=as.rsi]{as.rsi()}}) are transformed using \code{"S"} = 1, \code{"I"} = 2, and \code{"R"} = 3. If \code{combine_SI} is \code{TRUE} (default), the \code{"I"} will be considered to be 1.
|
R/SI values (see \code{\link[=as.rsi]{as.rsi()}}) are transformed using \code{"S"} = 1, \code{"I"} = 2, and \code{"R"} = 3. If \code{combine_SI} is \code{TRUE} (default), the \code{"I"} will be considered to be 1.
|
||||||
|
|
||||||
For data sets, the mean AMR distance will be calculated per variable, after which the mean of all columns will returned per row (using \code{\link[=rowMeans]{rowMeans()}}), see \emph{Examples}.
|
For data sets, the mean AMR distance will be calculated per column, after which the mean per row will be returned, see \emph{Examples}.
|
||||||
|
|
||||||
Use \code{\link[=amr_distance_from_row]{amr_distance_from_row()}} to subtract distances from the distance of one row, see \emph{Examples}.
|
Use \code{\link[=amr_distance_from_row]{amr_distance_from_row()}} to subtract distances from the distance of one row, see \emph{Examples}.
|
||||||
}
|
}
|
||||||
@ -46,14 +46,24 @@ Isolates with distances less than 0.01 difference from each other should be cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
\examples{
|
\examples{
|
||||||
x <- random_mic(10)
|
rsi <- random_rsi(10)
|
||||||
x
|
rsi
|
||||||
mean_amr_distance(x)
|
mean_amr_distance(rsi)
|
||||||
|
|
||||||
|
mic <- random_mic(10)
|
||||||
|
mic
|
||||||
|
mean_amr_distance(mic)
|
||||||
|
# equal to the Z-score of their log2:
|
||||||
|
(log2(mic) - mean(log2(mic))) / sd(log2(mic))
|
||||||
|
|
||||||
|
disk <- random_disk(10)
|
||||||
|
disk
|
||||||
|
mean_amr_distance(disk)
|
||||||
|
|
||||||
y <- data.frame(
|
y <- data.frame(
|
||||||
id = LETTERS[1:10],
|
id = LETTERS[1:10],
|
||||||
amox = random_mic(10, ab = "amox", mo = "Escherichia coli"),
|
amox = random_rsi(10, ab = "amox", mo = "Escherichia coli"),
|
||||||
cipr = random_mic(10, ab = "cipr", mo = "Escherichia coli"),
|
cipr = random_disk(10, ab = "cipr", mo = "Escherichia coli"),
|
||||||
gent = random_mic(10, ab = "gent", mo = "Escherichia coli"),
|
gent = random_mic(10, ab = "gent", mo = "Escherichia coli"),
|
||||||
tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli")
|
tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli")
|
||||||
)
|
)
|
||||||
@ -65,7 +75,7 @@ y[order(y$amr_distance), ]
|
|||||||
if (require("dplyr")) {
|
if (require("dplyr")) {
|
||||||
y \%>\%
|
y \%>\%
|
||||||
mutate(
|
mutate(
|
||||||
amr_distance = mean_amr_distance(., where(is.mic)),
|
amr_distance = mean_amr_distance(y),
|
||||||
check_id_C = amr_distance_from_row(amr_distance, id == "C")
|
check_id_C = amr_distance_from_row(amr_distance, id == "C")
|
||||||
) \%>\%
|
) \%>\%
|
||||||
arrange(check_id_C)
|
arrange(check_id_C)
|
||||||
@ -76,7 +86,7 @@ if (require("dplyr")) {
|
|||||||
filter(mo_genus() == "Enterococcus" & mo_species() != "") \%>\%
|
filter(mo_genus() == "Enterococcus" & mo_species() != "") \%>\%
|
||||||
select(mo, TCY, carbapenems()) \%>\%
|
select(mo, TCY, carbapenems()) \%>\%
|
||||||
group_by(mo) \%>\%
|
group_by(mo) \%>\%
|
||||||
mutate(d = mean_amr_distance(., where(is.rsi))) \%>\%
|
mutate(dist = mean_amr_distance(.)) \%>\%
|
||||||
arrange(mo, d)
|
arrange(mo, dist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user