diff --git a/DESCRIPTION b/DESCRIPTION
index f340b27f..c575e498 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,5 +1,5 @@
Package: AMR
-Version: 1.3.0.9030
+Version: 1.3.0.9031
Date: 2020-09-26
Title: Antimicrobial Resistance Analysis
Authors@R: c(
diff --git a/NEWS.md b/NEWS.md
index ad4bf8e5..146e7098 100755
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,4 @@
-# AMR 1.3.0.9030
+# AMR 1.3.0.9031
## Last updated: 26 September 2020
Note: some changes in this version were suggested by anonymous reviewers from the journal we submitted our manuscipt to. We are those reviewers very grateful for going through our code so thoroughly!
diff --git a/R/mo.R b/R/mo.R
index ddc5e5a5..03487c8a 100755
--- a/R/mo.R
+++ b/R/mo.R
@@ -301,7 +301,7 @@ exec_as.mo <- function(x,
initial = initial_search,
uncertainty = actual_uncertainty,
input_actual = actual_input) {
-
+
if (!is.null(input_actual)) {
input <- input_actual
} else {
@@ -318,7 +318,7 @@ exec_as.mo <- function(x,
if (NROW(res_df) > 1 & uncertainty != -1) {
# sort the findings on matching score
scores <- mo_matching_score(x = input,
- fullname = res_df[, "fullname", drop = TRUE])
+ n = res_df[, "fullname", drop = TRUE])
res_df <- res_df[order(scores, decreasing = TRUE), , drop = FALSE]
}
res <- as.character(res_df[, column, drop = TRUE])
@@ -442,7 +442,7 @@ exec_as.mo <- function(x,
# we need special treatment for very prevalent full names, they are likely!
# e.g. as.mo("Staphylococcus aureus")
x <- MO_lookup[match(tolower(x), MO_lookup$fullname_lower), property, drop = TRUE]
-
+
} else if (all(x %in% reference_data_to_use$fullname)) {
# we need special treatment for very prevalent full names, they are likely!
# e.g. as.mo("Staphylococcus aureus")
@@ -1544,7 +1544,7 @@ exec_as.mo <- function(x,
# this will save the uncertain items as attribute, so they can be bound to `uncertainties` in the uncertain_fn() function
x <- structure(x, uncertainties = uncertainties)
}
-
+
if (old_mo_warning == TRUE & property != "mo") {
warning("The input contained old microorganism IDs from previous versions of this package.\nPlease use `as.mo()` on these old IDs to transform them to the new format.\nSUPPORT FOR THIS WILL BE DROPPED IN A FUTURE VERSION.", call. = FALSE)
@@ -1639,7 +1639,7 @@ freq.mo <- function(x, ...) {
")"),
`No. of genera` = pm_n_distinct(mo_genus(x_noNA, language = NULL)),
`No. of species` = pm_n_distinct(paste(mo_genus(x_noNA, language = NULL),
- mo_species(x_noNA, language = NULL)))))
+ mo_species(x_noNA, language = NULL)))))
}
#' @method print mo
@@ -1773,7 +1773,7 @@ print.mo_uncertainties <- function(x, ...) {
if (x[i, ]$candidates != "") {
candidates <- unlist(strsplit(x[i, ]$candidates, ", ", fixed = TRUE))
scores <- mo_matching_score(x = x[i, ]$input,
- fullname = candidates)
+ n = candidates)
# sort on descending scores
candidates <- candidates[order(1 - scores)]
n_candidates <- length(candidates)
@@ -1799,8 +1799,8 @@ print.mo_uncertainties <- function(x, ...) {
ifelse(!is.na(x[i, ]$renamed_to), paste(", renamed to", font_italic(x[i, ]$renamed_to)), ""),
" (", x[i, ]$mo,
", matching score = ", trimws(percentage(mo_matching_score(x = x[i, ]$input,
- fullname = x[i, ]$fullname),
- digits = 1)),
+ n = x[i, ]$fullname),
+ digits = 1)),
") "),
uncertainty_interpretation,
candidates),
diff --git a/R/mo_matching_score.R b/R/mo_matching_score.R
index 9c92a645..38d3bf23 100755
--- a/R/mo_matching_score.R
+++ b/R/mo_matching_score.R
@@ -24,20 +24,21 @@
#' This helper function is used by [as.mo()] to determine the most probable match of taxonomic records, based on user input.
#' @param x Any user input value(s)
#' @param n A full taxonomic name, that exists in [`microorganisms$fullname`][microorganisms]
-#' @param uncertainty The level of uncertainty set in [as.mo()], see `allow_uncertain` in that function (here, it defaults to 1, but is automatically determined in [as.mo()] based on the number of transformations needed to get to a result)
#' @section Matching score for microorganisms:
-#' With ambiguous user input in [as.mo()] and all the [`mo_*`][mo_property()] functions, the returned results are chosen based on their matching score using [mo_matching_score()]. This matching score \eqn{m} is calculated as:
+#' With ambiguous user input in [as.mo()] and all the [`mo_*`][mo_property()] functions, the returned results are chosen based on their matching score using [mo_matching_score()]. This matching score \eqn{m}, ranging from 0 to 100%, is calculated as:
#'
-#' \deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \times \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} p k}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p * k )}
+#' \deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}
#'
#' where:
#'
#' * \eqn{x} is the user input;
-#' * \eqn{n} is a taxonomic name (genus, species and subspecies);
-#' * \eqn{l_{n}}{l_n} is the length of the taxonomic name;
-#' * \eqn{\operatorname{lev}}{lev} is the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) function;
-#' * \eqn{p} is the human pathogenic prevalence, categorised into group \eqn{1}, \eqn{2} and \eqn{3} (see *Details* in `?as.mo`), meaning that \eqn{p = \{1, 2 , 3\}}{p = {1, 2, 3}};
-#' * \eqn{k} is the kingdom index, set as follows: Bacteria = \eqn{1}, Fungi = \eqn{2}, Protozoa = \eqn{3}, Archaea = \eqn{4}, and all others = \eqn{5}, meaning that \eqn{k = \{1, 2 , 3, 4, 5\}}{k = {1, 2, 3, 4, 5}}.
+#' * \eqn{n} is a taxonomic name (genus, species and subspecies) as found in [`microorganisms$fullname`][microorganisms];
+#' * \eqn{l_{n}}{l_n} is the length of \eqn{n};
+#' * \eqn{\operatorname{lev}}{lev} is the [Levenshtein distance function](https://en.wikipedia.org/wiki/Levenshtein_distance);
+#' * \eqn{p_{n}}{p_n} is the human pathogenic prevalence of \eqn{n}, categorised into group \eqn{1}, \eqn{2} and \eqn{3} (see *Details* in `?as.mo`), meaning that \eqn{p = \{1, 2 , 3\}}{p = {1, 2, 3}};
+#' * \eqn{k_{n}}{k_n} is the kingdom index of \eqn{n}, set as follows: Bacteria = \eqn{1}, Fungi = \eqn{2}, Protozoa = \eqn{3}, Archaea = \eqn{4}, and all others = \eqn{5}, meaning that \eqn{k = \{1, 2 , 3, 4, 5\}}{k = {1, 2, 3, 4, 5}}.
+#'
+#' This means that the user input `x = "E. coli"` gets for *Escherichia coli* a matching score of `r percentage(mo_matching_score("E. coli", "Escherichia coli"), 1)` and for *Entamoeba coli* a matching score of `r percentage(mo_matching_score("E. coli", "Entamoeba coli"), 1)`.
#'
#' All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
#' @export
diff --git a/docs/404.html b/docs/404.html
index 027deb6b..a7621ac0 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -81,7 +81,7 @@
NEWS.md
-
as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\) is calculated as:
-$$m_{(x, n)} = \frac{l_{n} - 0.5 \times \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} p k}$$
+With ambiguous user input in as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\), ranging from 0 to 100%, is calculated as:
$$m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}$$
where:
\(x\) is the user input;
\(n\) is a taxonomic name (genus, species and subspecies);
\(l_{n}\) is the length of the taxonomic name;
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p\) is the human pathogenic prevalence, categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k\) is the kingdom index, set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
\(n\) is a taxonomic name (genus, species and subspecies) as found in microorganisms$fullname
;
\(l_{n}\) is the length of \(n\);
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p_{n}\) is the human pathogenic prevalence of \(n\), categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k_{n}\) is the kingdom index of \(n\), set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
This means that the user input x = "E. coli"
gets for Escherichia coli a matching score of 68.8% and for Entamoeba coli a matching score of 7.9%.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
A full taxonomic name, that exists in microorganisms$fullname
The level of uncertainty set in as.mo()
, see allow_uncertain
in that function (here, it defaults to 1, but is automatically determined in as.mo()
based on the number of transformations needed to get to a result)
With ambiguous user input in as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\) is calculated as:
$$m_{(x, n)} = \frac{l_{n} - 0.5 \times \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} p k}$$
+With ambiguous user input in as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\), ranging from 0 to 100%, is calculated as:
$$m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}$$
where:
\(x\) is the user input;
\(n\) is a taxonomic name (genus, species and subspecies);
\(l_{n}\) is the length of the taxonomic name;
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p\) is the human pathogenic prevalence, categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k\) is the kingdom index, set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
\(n\) is a taxonomic name (genus, species and subspecies) as found in microorganisms$fullname
;
\(l_{n}\) is the length of \(n\);
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p_{n}\) is the human pathogenic prevalence of \(n\), categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k_{n}\) is the kingdom index of \(n\), set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
This means that the user input x = "E. coli"
gets for Escherichia coli a matching score of 68.8% and for Entamoeba coli a matching score of 7.9%.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\) is calculated as:
-$$m_{(x, n)} = \frac{l_{n} - 0.5 \times \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} p k}$$
+With ambiguous user input in as.mo()
and all the mo_*
functions, the returned results are chosen based on their matching score using mo_matching_score()
. This matching score \(m\), ranging from 0 to 100%, is calculated as:
$$m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \operatorname{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}$$
where:
\(x\) is the user input;
\(n\) is a taxonomic name (genus, species and subspecies);
\(l_{n}\) is the length of the taxonomic name;
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p\) is the human pathogenic prevalence, categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k\) is the kingdom index, set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
\(n\) is a taxonomic name (genus, species and subspecies) as found in microorganisms$fullname
;
\(l_{n}\) is the length of \(n\);
\(\operatorname{lev}\) is the Levenshtein distance function;
\(p_{n}\) is the human pathogenic prevalence of \(n\), categorised into group \(1\), \(2\) and \(3\) (see Details in ?as.mo
), meaning that \(p = \{1, 2 , 3\}\);
\(k_{n}\) is the kingdom index of \(n\), set as follows: Bacteria = \(1\), Fungi = \(2\), Protozoa = \(3\), Archaea = \(4\), and all others = \(5\), meaning that \(k = \{1, 2 , 3, 4, 5\}\).
This means that the user input x = "E. coli"
gets for Escherichia coli a matching score of 68.8% and for Entamoeba coli a matching score of 7.9%.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.