1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 04:06:12 +01:00

(v0.7.1.9083) LIS code improvement

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-09-23 17:32:05 +02:00
parent a8c6b8f9c4
commit 8ce252fbc5
13 changed files with 44 additions and 50 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 0.7.1.9082 Version: 0.7.1.9083
Date: 2019-09-23 Date: 2019-09-23
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(

View File

@ -1,4 +1,4 @@
# AMR 0.7.1.9082 # AMR 0.7.1.9083
<small>Last updated: 23-Sep-2019</small> <small>Last updated: 23-Sep-2019</small>
### Breaking ### Breaking

64
R/mo.R
View File

@ -490,8 +490,8 @@ exec_as.mo <- function(x,
x_backup[grepl("^(fungus|fungi)$", x)] <- "F_FUNGUS" # will otherwise become the kingdom x_backup[grepl("^(fungus|fungi)$", x)] <- "F_FUNGUS" # will otherwise become the kingdom
# remove spp and species # remove spp and species
x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x, ignore.case = TRUE) x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x)
x <- gsub("(spp.?|ssp.?|subsp.?|subspecies|biovar|serovar|species)", "", x, ignore.case = TRUE) x <- gsub("(spp.?|subsp.?|subspecies|biovar|serovar|species)", "", x)
x <- strip_whitespace(x, dyslexia_mode) x <- strip_whitespace(x, dyslexia_mode)
x_backup_without_spp <- x x_backup_without_spp <- x
@ -582,7 +582,7 @@ exec_as.mo <- function(x,
progress$tick()$print() progress$tick()$print()
mo_hist <- get_mo_history(x, uncertainty_level, force = force_mo_history, disable = disable_mo_history) mo_hist <- get_mo_history(x_backup[i], uncertainty_level, force = force_mo_history, disable = disable_mo_history)
if (initial_search == TRUE & !any(is.na(mo_hist))) { if (initial_search == TRUE & !any(is.na(mo_hist))) {
# previously found code # previously found code
found <- data.frame(mo = mo_hist, found <- data.frame(mo = mo_hist,
@ -638,6 +638,29 @@ exec_as.mo <- function(x,
next next
} }
# WHONET and other common LIS codes
if (any(toupper(c(x_backup[i], x_backup_without_spp[i])) %in% AMR::microorganisms.codes$code)) {
mo_found <- AMR::microorganisms.codes[which(AMR::microorganisms.codes$code %in% toupper(c(x_backup[i], x_backup_without_spp[i]))), "mo"][1L]
if (length(mo_found) > 0) {
x[i] <- microorganismsDT[mo == mo_found, ..property][[1]][1L]
if (initial_search == TRUE) {
set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history)
}
next
}
}
if (!is.null(reference_df)) {
# self-defined reference
if (x_backup[i] %in% reference_df[, 1]) {
ref_mo <- reference_df[reference_df[, 1] == x_backup[i], "mo"]
if (ref_mo %in% data_to_check[, mo]) {
x[i] <- data_to_check[mo == ref_mo, ..property][[1]][1L]
next
} else {
warning("Value '", x_backup[i], "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE)
}
}
}
# WHONET: xxx = no growth # WHONET: xxx = no growth
if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) { if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) {
@ -688,13 +711,6 @@ exec_as.mo <- function(x,
x[i] <- NA_character_ x[i] <- NA_character_
next next
} }
# x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
# if (initial_search == TRUE) {
# failures <- c(failures, x_backup[i])
# set_mo_history(x_backup[i], get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history)
# }
# next
# }
# translate known trivial abbreviations to genus + species ---- # translate known trivial abbreviations to genus + species ----
if (!is.na(x_trimmed[i])) { if (!is.na(x_trimmed[i])) {
@ -961,32 +977,7 @@ exec_as.mo <- function(x,
# rest of genus only is in allow_uncertain part. # rest of genus only is in allow_uncertain part.
} }
# TRY OTHER SOURCES ---- # allow no codes less than 4 characters long, was already checked for WHONET earlier
# WHONET and other common LIS codes
if (toupper(a.x_backup) %in% AMR::microorganisms.codes[, 1]) {
mo_found <- AMR::microorganisms.codes[toupper(a.x_backup) == AMR::microorganisms.codes[, 1], "mo"][1L]
if (length(mo_found) > 0) {
x[i] <- microorganismsDT[mo == mo_found, ..property][[1]][1L]
if (initial_search == TRUE) {
set_mo_history(a.x_backup, get_mo_code(x[i], property), 0, force = force_mo_history, disable = disable_mo_history)
}
return(x[i])
}
}
if (!is.null(reference_df)) {
# self-defined reference
if (a.x_backup %in% reference_df[, 1]) {
ref_mo <- reference_df[reference_df[, 1] == a.x_backup, "mo"]
if (ref_mo %in% data_to_check[, mo]) {
x[i] <- data_to_check[mo == ref_mo, ..property][[1]][1L]
return(x[i])
} else {
warning("Value '", a.x_backup, "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE)
}
}
}
# allow no codes less than 4 characters long, was already checked for WHONET above
if (nchar(g.x_backup_without_spp) < 4) { if (nchar(g.x_backup_without_spp) < 4) {
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
if (initial_search == TRUE) { if (initial_search == TRUE) {
@ -1565,7 +1556,6 @@ exec_as.mo <- function(x,
next next
} }
# no results found: make them UNKNOWN ---- # no results found: make them UNKNOWN ----
x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]] x[i] <- microorganismsDT[mo == "UNKNOWN", ..property][[1]]
if (initial_search == TRUE) { if (initial_search == TRUE) {

View File

@ -27,6 +27,10 @@ set_mo_history <- function(x, mo, uncertainty_level, force = FALSE, disable = FA
return(base::invisible()) return(base::invisible())
} }
# don't save codes that are in a code data set already
mo <- mo[!x %in% microorganisms.codes$code & !x %in% microorganisms.translation$mo_old]
x <- x[!x %in% microorganisms.codes$code & !x %in% microorganisms.translation$mo_old]
if (base::interactive() | force == TRUE) { if (base::interactive() | force == TRUE) {
mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force) mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force)
warning_new_write <- FALSE warning_new_write <- FALSE

Binary file not shown.

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -42,7 +42,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>
@ -225,9 +225,9 @@
</div> </div>
<div id="amr-0-7-1-9082" class="section level1"> <div id="amr-0-7-1-9083" class="section level1">
<h1 class="page-header"> <h1 class="page-header">
<a href="#amr-0-7-1-9082" class="anchor"></a>AMR 0.7.1.9082<small> Unreleased </small> <a href="#amr-0-7-1-9083" class="anchor"></a>AMR 0.7.1.9083<small> Unreleased </small>
</h1> </h1>
<p><small>Last updated: 23-Sep-2019</small></p> <p><small>Last updated: 23-Sep-2019</small></p>
<div id="breaking" class="section level3"> <div id="breaking" class="section level3">
@ -1280,7 +1280,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
<div id="tocnav"> <div id="tocnav">
<h2>Contents</h2> <h2>Contents</h2>
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="#amr-0-7-1-9082">0.7.1.9082</a></li> <li><a href="#amr-0-7-1-9083">0.7.1.9083</a></li>
<li><a href="#amr-0-7-1">0.7.1</a></li> <li><a href="#amr-0-7-1">0.7.1</a></li>
<li><a href="#amr-0-7-0">0.7.0</a></li> <li><a href="#amr-0-7-0">0.7.0</a></li>
<li><a href="#amr-0-6-1">0.6.1</a></li> <li><a href="#amr-0-6-1">0.6.1</a></li>

View File

@ -80,7 +80,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9081</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -80,7 +80,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9082</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span>
</span> </span>
</div> </div>