mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 04:20:53 +01:00
(v3.0.1.9097) Never remove released taxa; link orthographic variants; registry line in NEWS
- taxonomy build: released taxa (since v2.0.0) that are missing are restored from their last release with their old code and last known status, and are exempt from later removals (decision by Matthijs S. Berends) - exceptions are retired on purpose in data-raw/microorganisms_files/mo_code_retirements.csv with a reason: other organisms with the same genus name (e.g. the Graphium butterflies, wrongly in the Fungi until v3.0.1) and taxa whose genus is now only known in another domain; as.mo() translates these codes to NA with that reason - synonyms without a current name are linked to an accepted name in the same genus that only differs by a Latin gender ending (e.g. Candida glabratus -> Nakaseomyces glabratus) - placeholders such as "(unknown class)" never become records; codes of manually added records are matched by domain and name - integrity rule released_taxon_missing; known defects of the data on main updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d683b9e7c6
commit
83a4853936
12 files changed
+5326
-23
No files matched your search
@@ -61,6 +61,14 @@ read_mo_renames <- function(root = mo_repository_root()) {
|
||||
# only approved renames count
|
||||
renames[renames$approved_by != "" & renames$approved_date != "", , drop = FALSE]
|
||||
}
|
||||
# MO codes that are retired on purpose, because their taxon was another organism (see the README)
|
||||
read_mo_retirements <- function(root = mo_repository_root()) {
|
||||
file <- file.path(root, "data-raw", "microorganisms_files", "mo_code_retirements.csv")
|
||||
if (is.null(root) || !file.exists(file)) {
|
||||
return(NULL)
|
||||
}
|
||||
utils::read.csv(file, colClasses = "character", na.strings = character(0))
|
||||
}
|
||||
mo_repository_root <- function() {
|
||||
# works from the root of the repository and from tests/testthat
|
||||
for (path in c(".", "../..", "..")) {
|
||||
@@ -78,7 +86,7 @@ mo_name_without_suffix <- function(x) {
|
||||
|
||||
# Returns a named list with one character vector per rule, each describing the records that break the rule.
|
||||
# All vectors must be empty.
|
||||
mo_integrity_issues <- function(df, registry = NULL, renames = NULL) {
|
||||
mo_integrity_issues <- function(df, registry = NULL, renames = NULL, retirements = NULL) {
|
||||
df <- as.data.frame(df, stringsAsFactors = FALSE)
|
||||
df$mo <- as.character(df$mo)
|
||||
describe <- function(rows) {
|
||||
@@ -161,6 +169,17 @@ mo_integrity_issues <- function(df, registry = NULL, renames = NULL) {
|
||||
issues$registered_code_with_other_taxon <- describe(
|
||||
!is.na(registered_name) & mo_name_without_suffix(registered_name) != mo_name_without_suffix(df$fullname)
|
||||
)
|
||||
# a released taxon is never removed, unless its code was retired on purpose
|
||||
expected <- registry$fullname
|
||||
if (!is.null(renames) && nrow(renames) > 0) {
|
||||
renamed <- match(registry$mo, renames$mo)
|
||||
expected[!is.na(renamed)] <- renames$new_name[renamed[!is.na(renamed)]]
|
||||
}
|
||||
missing <- !mo_name_without_suffix(expected) %in% mo_name_without_suffix(df$fullname)
|
||||
if (!is.null(retirements)) {
|
||||
missing <- missing & !registry$mo %in% retirements$mo
|
||||
}
|
||||
issues$released_taxon_missing <- if (any(missing)) paste0(registry$mo[missing], " (", expected[missing], ")") else character(0)
|
||||
}
|
||||
|
||||
issues
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -97,7 +97,7 @@ sentinel_defects <- function() {
|
||||
|
||||
test_that("microorganisms: integrity rules", {
|
||||
skip_on_cran()
|
||||
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames())
|
||||
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames(), retirements = read_mo_retirements())
|
||||
for (rule in names(issues)) {
|
||||
defects <- new_defects(rule, issues[[rule]])
|
||||
expect_true(length(defects) == 0,
|
||||
@@ -111,7 +111,7 @@ test_that("microorganisms: known defects are no longer than needed", {
|
||||
# a known defect that is solved must be removed from the list, so that it cannot come back unnoticed
|
||||
kd <- known_defects()
|
||||
skip_if(nrow(kd) == 0)
|
||||
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames())
|
||||
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames(), retirements = read_mo_retirements())
|
||||
current <- c(
|
||||
unlist(lapply(names(issues), function(rule) paste(rule, issues[[rule]], sep = "|"))),
|
||||
paste("sentinel", sentinel_defects(), sep = "|")
|
||||
@@ -145,6 +145,12 @@ test_that("MO codes: every code of every release since v2.0.0 still means the sa
|
||||
expected_name[!is.na(renamed)] <- renames$new_name[renamed[!is.na(renamed)]]
|
||||
# deliberate in as.mo() since v2.0.0: the kingdom/domain Fungi returns the code for an unknown fungus
|
||||
expected_name[registry$mo == "F_[KNG]_FUNGI"] <- "(unknown fungus)"
|
||||
# codes retired on purpose (their taxon was another organism) must lead to NA
|
||||
retirements <- read_mo_retirements()
|
||||
retired_on_purpose <- registry$mo %in% retirements$mo
|
||||
expect_true(all(is.na(suppressWarnings(as.mo(registry$mo[retired_on_purpose], info = FALSE)))))
|
||||
registry <- registry[!retired_on_purpose, , drop = FALSE]
|
||||
expected_name <- expected_name[!retired_on_purpose]
|
||||
result <- suppressWarnings(as.mo(registry$mo, keep_synonyms = TRUE, info = FALSE))
|
||||
result_name <- microorganisms$fullname[match(result, microorganisms$mo)]
|
||||
wrong <- !is.na(result) & mo_name_without_suffix(result_name) != mo_name_without_suffix(expected_name)
|
||||
@@ -154,8 +160,8 @@ test_that("MO codes: every code of every release since v2.0.0 still means the sa
|
||||
)
|
||||
|
||||
# the internal lookup table must be up to date with the registry
|
||||
retired <- registry$mo[!registry$mo %in% microorganisms$mo]
|
||||
expect_setequal(AMR:::MO_RETIRED_CODES$old_mo, retired)
|
||||
full_registry <- read_mo_registry()
|
||||
expect_setequal(AMR:::MO_RETIRED_CODES$old_mo, full_registry$mo[!full_registry$mo %in% microorganisms$mo])
|
||||
})
|
||||
|
||||
test_that("MO codes: codes of earlier releases are translated, never guessed", {
|
||||
|
||||
Reference in new issue
Block a user