diff --git a/R/mo.R b/R/mo.R index 8305c2a8..0ad16c9e 100755 --- a/R/mo.R +++ b/R/mo.R @@ -267,6 +267,8 @@ as.mo <- function(x, x_out <- trimws2(gsub(" +", " ", x_out, perl = TRUE)) x_search_cleaned <- x_out x_out <- tolower(x_out) + # when x_search_cleaned are only capitals (such as in codes), make them lowercase to increase matching score + x_search_cleaned[x_search_cleaned == toupper(x_search_cleaned)] <- x_out[x_search_cleaned == toupper(x_search_cleaned)] # first check if cleaning led to an exact result, case-insensitive if (x_out %in% AMR_env$MO_lookup$fullname_lower) { @@ -334,7 +336,7 @@ as.mo <- function(x, # correct back for kingdom minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$kingdom_index[match(mo_to_search, AMR_env$MO_lookup$fullname)] minimum_matching_score_current <- pmax(minimum_matching_score_current, m) - if (all(m <= 0.55, na.rm = TRUE)) { + if (length(m) > 1 && all(m <= 0.55, na.rm = TRUE)) { # if the highest score is 0.5, we have nothing serious - 0.5 is the lowest for pathogenic group 1 # make everything NA so the results will get removed below m[seq_len(length(m))] <- NA_real_ diff --git a/inst/tinytest/test-data.R b/inst/tinytest/test-data.R index 1cd2db65..51ccd5a3 100644 --- a/inst/tinytest/test-data.R +++ b/inst/tinytest/test-data.R @@ -47,10 +47,10 @@ expect_false(any(is.na(microorganisms.codes$mo))) expect_true(all(dosage$ab %in% antibiotics$ab)) expect_true(all(dosage$name %in% antibiotics$name)) # check valid disks/MICs -expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_S", drop = TRUE])))) -expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_R", drop = TRUE])))) -expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_S", drop = TRUE])))) -expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_R", drop = TRUE])))) +expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_S", drop = TRUE])))) +expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_R", drop = TRUE])))) +expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_S", drop = TRUE])))) +expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_R", drop = TRUE])))) # antibiotic names must always be coercible to their original AB code expect_identical(as.ab(antibiotics$name), antibiotics$ab) diff --git a/inst/tinytest/test-mo.R b/inst/tinytest/test-mo.R index 95b80a38..926bd92d 100644 --- a/inst/tinytest/test-mo.R +++ b/inst/tinytest/test-mo.R @@ -28,7 +28,7 @@ # ==================================================================== # MOs <- subset(microorganisms, !is.na(mo) & nchar(mo) > 3) -expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo))) +expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo, keep_synonyms = TRUE))) expect_identical( as.character(as.mo(c("E. coli", "H. influenzae"), keep_synonyms = FALSE)),