mirror of https://github.com/msberends/AMR.git
reorganised notes and warnings
This commit is contained in:
parent
dec4947103
commit
857f565db0
1
NEWS.md
1
NEWS.md
|
@ -12,6 +12,7 @@
|
||||||
* There will be looked for uncertain results at default - these results will be returned with an informative warning
|
* There will be looked for uncertain results at default - these results will be returned with an informative warning
|
||||||
* Manual now contains more info about the algorithms
|
* Manual now contains more info about the algorithms
|
||||||
* Progress bar will be shown when it takes more than 3 seconds to get results
|
* Progress bar will be shown when it takes more than 3 seconds to get results
|
||||||
|
* Support for formatted console text
|
||||||
* Function `first_isolate`:
|
* Function `first_isolate`:
|
||||||
* Will now use a column named like "patid" for the patient ID (parameter `col_patientid`), when this parameter was left blank
|
* Will now use a column named like "patid" for the patient ID (parameter `col_patientid`), when this parameter was left blank
|
||||||
* Will now use a column named like "key(...)ab" or "key(...)antibiotics" for the key antibiotics (parameter `col_keyantibiotics`), when this parameter was left blank
|
* Will now use a column named like "key(...)ab" or "key(...)antibiotics" for the key antibiotics (parameter `col_keyantibiotics`), when this parameter was left blank
|
||||||
|
|
133
R/mo.R
133
R/mo.R
|
@ -204,6 +204,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notes <- character(0)
|
||||||
failures <- character(0)
|
failures <- character(0)
|
||||||
x_input <- x
|
x_input <- x
|
||||||
# only check the uniques, which is way faster
|
# only check the uniques, which is way faster
|
||||||
|
@ -393,7 +394,11 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
|
||||||
if (grepl("[sS]almonella [A-Z][a-z]+ ?.*", x_trimmed[i])) {
|
if (grepl("[sS]almonella [A-Z][a-z]+ ?.*", x_trimmed[i])) {
|
||||||
# Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica
|
# Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica
|
||||||
x[i] <- microorganismsDT[mo == 'B_SLMNL_ENT', ..property][[1]][1L]
|
x[i] <- microorganismsDT[mo == 'B_SLMNL_ENT', ..property][[1]][1L]
|
||||||
base::message(magenta(paste0("Note: ", italic(x_trimmed[i]), " will be considered a subspecies of ", italic("Salmonella enterica"), " (B_SLMNL_ENT)")))
|
notes <- c(notes,
|
||||||
|
magenta(paste0("Note: ", italic(x_trimmed[i]),
|
||||||
|
" was considered (a subspecies of) ",
|
||||||
|
italic("Salmonella enterica"),
|
||||||
|
" (B_SLMNL_ENT)")))
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,75 +610,78 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
|
||||||
} else {
|
} else {
|
||||||
x[i] <- microorganismsDT[tsn == found[1, tsn_new], ..property][[1]]
|
x[i] <- microorganismsDT[tsn == found[1, tsn_new], ..property][[1]]
|
||||||
}
|
}
|
||||||
renamed_note(name_old = found[1, name],
|
notes <- c(notes,
|
||||||
name_new = microorganismsDT[tsn == found[1, tsn_new], fullname],
|
renamed_note(name_old = found[1, name],
|
||||||
ref_old = found[1, ref],
|
name_new = microorganismsDT[tsn == found[1, tsn_new], fullname],
|
||||||
ref_new = microorganismsDT[tsn == found[1, tsn_new], ref],
|
ref_old = found[1, ref],
|
||||||
mo = microorganismsDT[tsn == found[1, tsn_new], mo])
|
ref_new = microorganismsDT[tsn == found[1, tsn_new], ref],
|
||||||
|
mo = microorganismsDT[tsn == found[1, tsn_new], mo]))
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
# check for uncertain results ----
|
# check for uncertain results ----
|
||||||
if (allow_uncertain == TRUE) {
|
if (allow_uncertain == TRUE) {
|
||||||
# (1) look again for old taxonomic names, now for G. species ----
|
|
||||||
found <- microorganisms.oldDT[name %like% x_withspaces[i]
|
uncertain_fn <- function(x_backup, x_trimmed, x_withspaces, x_withspaces_start) {
|
||||||
| name %like% x_withspaces_start[i]
|
# (1) look again for old taxonomic names, now for G. species ----
|
||||||
| name %like% x[i],]
|
found <- microorganisms.oldDT[name %like% x_withspaces
|
||||||
if (NROW(found) > 0 & nchar(x_trimmed[i]) >= 6) {
|
| name %like% x_withspaces_start
|
||||||
if (property == "ref") {
|
| name %like% x,]
|
||||||
# when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so:
|
if (NROW(found) > 0 & nchar(x_trimmed) >= 6) {
|
||||||
# mo_ref("Chlamydia psittaci) = "Page, 1968" (with warning)
|
if (property == "ref") {
|
||||||
# mo_ref("Chlamydophila psittaci) = "Everett et al., 1999"
|
# when property is "ref" (which is the case in mo_ref, mo_authors and mo_year), return the old value, so:
|
||||||
x[i] <- found[1, ref]
|
# mo_ref("Chlamydia psittaci) = "Page, 1968" (with warning)
|
||||||
} else {
|
# mo_ref("Chlamydophila psittaci) = "Everett et al., 1999"
|
||||||
x[i] <- microorganismsDT[tsn == found[1, tsn_new], ..property][[1]]
|
x <- found[1, ref]
|
||||||
|
} else {
|
||||||
|
x <- microorganismsDT[tsn == found[1, tsn_new], ..property][[1]]
|
||||||
|
}
|
||||||
|
warning(red(paste0('UNCERTAIN - "',
|
||||||
|
x_backup, '" -> ', italic(found[1, name]))),
|
||||||
|
call. = FALSE, immediate. = FALSE)
|
||||||
|
notes <<- c(notes,
|
||||||
|
renamed_note(name_old = found[1, name],
|
||||||
|
name_new = microorganismsDT[tsn == found[1, tsn_new], fullname],
|
||||||
|
ref_old = found[1, ref],
|
||||||
|
ref_new = microorganismsDT[tsn == found[1, tsn_new], ref],
|
||||||
|
mo = microorganismsDT[tsn == found[1, tsn_new], mo]))
|
||||||
|
return(x)
|
||||||
}
|
}
|
||||||
warning(red(paste0('UNCERTAIN - "',
|
|
||||||
x_backup[i], '" -> ', italic(found[1, name]))),
|
|
||||||
call. = FALSE, immediate. = TRUE)
|
|
||||||
renamed_note(name_old = found[1, name],
|
|
||||||
name_new = microorganismsDT[tsn == found[1, tsn_new], fullname],
|
|
||||||
ref_old = found[1, ref],
|
|
||||||
ref_new = microorganismsDT[tsn == found[1, tsn_new], ref],
|
|
||||||
mo = microorganismsDT[tsn == found[1, tsn_new], mo])
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# (2) strip values between brackets ----
|
# (2) strip values between brackets ----
|
||||||
x_backup_stripped <- gsub("( [(].*[)])", "", x_backup[i])
|
x_backup_stripped <- gsub("( [(].*[)])", "", x_backup)
|
||||||
x_backup_stripped <- trimws(gsub(" ", " ", x_backup_stripped, fixed = TRUE))
|
x_backup_stripped <- trimws(gsub(" ", " ", x_backup_stripped, fixed = TRUE))
|
||||||
x_species_stripped <- gsub("( [(].*[)])", "", x_species[i])
|
found <- suppressMessages(suppressWarnings(exec_as.mo(x_backup_stripped, clear_options = FALSE)))
|
||||||
x_species_stripped <- trimws(gsub(" ", " ", x_species_stripped, fixed = TRUE))
|
if (!is.na(found) & nchar(x_trimmed) >= 6) {
|
||||||
|
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||||
|
warning(red(paste0('UNCERTAIN - "',
|
||||||
|
x_backup, '" -> ', italic(microorganismsDT[mo == found[1L], fullname][[1]]), " (", found[1L], ")")),
|
||||||
|
call. = FALSE, immediate. = FALSE)
|
||||||
|
return(found[1L])
|
||||||
|
}
|
||||||
|
|
||||||
found <- microorganismsDT[fullname %like% x_backup_stripped
|
# (3) try to strip off one element and check the remains ----
|
||||||
| fullname %like% x_species_stripped,]
|
look_for_part <- function(z) {
|
||||||
if (NROW(found) > 0 & nchar(x_trimmed[i]) >= 6) {
|
x_strip <- z %>% strsplit(" ") %>% unlist()
|
||||||
x[i] <- found[1, ..property][[1]]
|
if (length(x_strip) > 1 & nchar(x_trimmed) >= 6) {
|
||||||
warning(red(paste0('UNCERTAIN - "',
|
for (i in 1:(length(x_strip) - 1)) {
|
||||||
x_backup[i], '" -> ', italic(found[1, fullname][[1]]), " (", found[1, mo][[1]], ")")),
|
x_strip_collapsed <- paste(x_strip[1:(length(x_strip) - i)], collapse = " ")
|
||||||
call. = FALSE, immediate. = TRUE)
|
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, clear_options = FALSE)))
|
||||||
next
|
if (!is.na(found)) {
|
||||||
}
|
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||||
|
warning(red(paste0('UNCERTAIN - "',
|
||||||
# (3) try to strip off one element and check the remains ----
|
z, '" -> ', italic(microorganismsDT[mo == found[1L], fullname][[1]]), " (", found[1L], ")")),
|
||||||
look_for_part <- function(z) {
|
call. = FALSE, immediate. = FALSE)
|
||||||
x_strip <- z %>% strsplit(" ") %>% unlist()
|
return(found[1L])
|
||||||
if (length(x_strip) > 1 & nchar(x_trimmed[i]) >= 6) {
|
}
|
||||||
for (i in 1:(length(x_strip) - 1)) {
|
|
||||||
x_strip_collapsed <- paste(x_strip[1:(length(x_strip) - i)], collapse = " ")
|
|
||||||
found <- suppressMessages(suppressWarnings(exec_as.mo(x_strip_collapsed, clear_options = FALSE)))
|
|
||||||
if (!is.na(found)) {
|
|
||||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
|
||||||
warning(red(paste0('UNCERTAIN - "',
|
|
||||||
z, '" -> ', italic(microorganismsDT[mo == found[1L], fullname][[1]]), " (", found[1L], ")")),
|
|
||||||
call. = FALSE, immediate. = TRUE)
|
|
||||||
return(found[1L])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return(NA_character_)
|
||||||
}
|
}
|
||||||
return(NA_character_)
|
return(look_for_part(x_backup))
|
||||||
}
|
}
|
||||||
x[i] <- look_for_part(x_backup[i])
|
|
||||||
|
x[i] <- uncertain_fn(x_backup[i], x_trimmed[i], x_withspaces[i], x_withspaces_start[i])
|
||||||
if (!is.na(x[i])) {
|
if (!is.na(x[i])) {
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
@ -773,6 +781,13 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE,
|
||||||
x <- as.integer(x)
|
x <- as.integer(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (length(notes > 0)) {
|
||||||
|
notes <- sort(notes)
|
||||||
|
for (i in 1:length(notes)) {
|
||||||
|
base::message(notes[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +813,7 @@ renamed_note <- function(name_old, name_new, ref_old = "", ref_new = "", mo = ""
|
||||||
msg_plain <- paste0(name_old, ref_old, " -> ", name_new, ref_new)
|
msg_plain <- paste0(name_old, ref_old, " -> ", name_new, ref_new)
|
||||||
msg_plain <- c(getOption("mo_renamed", character(0)), msg_plain)
|
msg_plain <- c(getOption("mo_renamed", character(0)), msg_plain)
|
||||||
options(mo_renamed = sort(msg_plain))
|
options(mo_renamed = sort(msg_plain))
|
||||||
base::message(blue(paste("Note:", msg)))
|
return(blue(paste("Note:", msg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#' @exportMethod print.mo
|
#' @exportMethod print.mo
|
||||||
|
|
Loading…
Reference in New Issue