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

no overwriting taxonomy when adding microorganisms

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-01-12 11:33:28 +01:00
parent 1029aa2fdc
commit 51906d6f97
4 changed files with 21 additions and 18 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.2.9089 Version: 1.8.2.9090
Date: 2023-01-07 Date: 2023-01-12
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@ -1,4 +1,4 @@
# AMR 1.8.2.9089 # AMR 1.8.2.9090
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*

View File

@ -136,12 +136,13 @@ add_custom_microorganisms <- function(x) {
stop_ifnot(all(x$rank %in% AMR_env$MO_lookup$rank), stop_ifnot(all(x$rank %in% AMR_env$MO_lookup$rank),
"the 'rank' column can only contain these values: ", vector_or(AMR_env$MO_lookup$rank)) "the 'rank' column can only contain these values: ", vector_or(AMR_env$MO_lookup$rank))
} else { } else {
x$rank <- ifelse(!is.na(x$subspecies), "subspecies", x$rank <- ifelse(x$subspecies != "", "subspecies",
ifelse(!is.na(x$species), "species", ifelse(x$species != "", "species",
ifelse(!is.na(x$genus), "genus", ifelse(x$genus != "", "genus",
stop("in add_custom_microorganisms(): the 'genus' column cannot be empty", stop("in add_custom_microorganisms(): the 'genus' column cannot be empty",
call. = FALSE)))) call. = FALSE))))
} }
x$source <- "Added by user"
if (!"fullname" %in% colnames(x)) { if (!"fullname" %in% colnames(x)) {
x$fullname <- trimws2(paste(x$genus, x$species, x$subspecies)) x$fullname <- trimws2(paste(x$genus, x$species, x$subspecies))
} }
@ -150,6 +151,11 @@ add_custom_microorganisms <- function(x) {
if (!"class" %in% colnames(x)) x$class <- "" if (!"class" %in% colnames(x)) x$class <- ""
if (!"order" %in% colnames(x)) x$order <- "" if (!"order" %in% colnames(x)) x$order <- ""
if (!"family" %in% colnames(x)) x$family <- "" if (!"family" %in% colnames(x)) x$family <- ""
x$kingdom[is.na(x$kingdom)] <- ""
x$phylum[is.na(x$phylum)] <- ""
x$class[is.na(x$class)] <- ""
x$order[is.na(x$order)] <- ""
x$family[is.na(x$family)] <- ""
for (col in colnames(x)) { for (col in colnames(x)) {
if (is.list(AMR_env$MO_lookup[, col, drop = TRUE])) { if (is.list(AMR_env$MO_lookup[, col, drop = TRUE])) {
@ -160,17 +166,12 @@ add_custom_microorganisms <- function(x) {
# fill in other columns # fill in other columns
x$status <- "accepted" x$status <- "accepted"
x$prevalence <- 1 x$prevalence <- 1
x$kingdom <- AMR_env$MO_lookup$kingdom[match(x$genus, AMR_env$MO_lookup$genus)]
x$phylum <- AMR_env$MO_lookup$phylum[match(x$genus, AMR_env$MO_lookup$genus)]
x$class <- AMR_env$MO_lookup$class[match(x$genus, AMR_env$MO_lookup$genus)]
x$order <- AMR_env$MO_lookup$order[match(x$genus, AMR_env$MO_lookup$genus)]
x$family <- AMR_env$MO_lookup$family[match(x$genus, AMR_env$MO_lookup$genus)]
x$kingdom[is.na(x$kingdom)] <- "" x$kingdom[which(x$kingdom == "" & x$genus != "")] <- AMR_env$MO_lookup$kingdom[match(x$genus[which(x$kingdom == "" & x$genus != "")], AMR_env$MO_lookup$genus)]
x$phylum[is.na(x$phylum)] <- "" x$phylum[which(x$phylum == "" & x$genus != "")] <- AMR_env$MO_lookup$phylum[match(x$genus[which(x$phylum == "" & x$genus != "")], AMR_env$MO_lookup$genus)]
x$class[is.na(x$class)] <- "" x$class[which(x$class == "" & x$genus != "")] <- AMR_env$MO_lookup$class[match(x$genus[which(x$class == "" & x$genus != "")], AMR_env$MO_lookup$genus)]
x$order[is.na(x$order)] <- "" x$order[which(x$order == "" & x$genus != "")] <- AMR_env$MO_lookup$order[match(x$genus[which(x$order == "" & x$genus != "")], AMR_env$MO_lookup$genus)]
x$family[is.na(x$family)] <- "" x$family[which(x$family == "" & x$genus != "")] <- AMR_env$MO_lookup$family[match(x$genus[which(x$family == "" & x$genus != "")], AMR_env$MO_lookup$genus)]
x$kingdom_index <- AMR_env$MO_lookup$kingdom_index[match(x$genus, AMR_env$MO_lookup$genus)] x$kingdom_index <- AMR_env$MO_lookup$kingdom_index[match(x$genus, AMR_env$MO_lookup$genus)]
x$fullname_lower <- tolower(x$fullname) x$fullname_lower <- tolower(x$fullname)
@ -184,7 +185,9 @@ add_custom_microorganisms <- function(x) {
} }
x$mo <- trimws2(x$mo) x$mo <- trimws2(x$mo)
x$mo[x$mo == ""] <- NA_character_ x$mo[x$mo == ""] <- NA_character_
x$mo[is.na(x$mo)] <- paste0("CUSTOM_", x$mo[is.na(x$mo)] <- paste0("CUSTOM",
seq(from = sum(AMR_env$MO_lookup$source == "Added by user", na.rm = TRUE) + 1, to = nrow(x), by = 1),
"_",
toupper(unname(abbreviate(gsub(" +", " _ ", toupper(unname(abbreviate(gsub(" +", " _ ",
gsub("[^A-Za-z0-9-]", " ", gsub("[^A-Za-z0-9-]", " ",
trimws2(paste(x$genus, x$species, x$subspecies)))), trimws2(paste(x$genus, x$species, x$subspecies)))),

Binary file not shown.