mirror of
				https://github.com/msberends/AMR.git
				synced 2025-10-31 10:48:15 +01:00 
			
		
		
		
	- Added new function guess_bactid to determine the ID of a microorganism based on genus/species
				
					
				
			- Renamed `ablist` to `antibiotics` - Added support for character vector in join functions - Altered `%like%` to make it case insensitive
This commit is contained in:
		
							
								
								
									
										19
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								.travis.yml
									
									
									
									
									
								
							| @@ -1,2 +1,21 @@ | |||||||
|  | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r | ||||||
|  |  | ||||||
| language: r | language: r | ||||||
| cache: packages | cache: packages | ||||||
|  |  | ||||||
|  | r: | ||||||
|  |   - 3.0 | ||||||
|  |  | ||||||
|  | r_packages: | ||||||
|  |   - covr | ||||||
|  |  | ||||||
|  | after_success: | ||||||
|  |   - Rscript -e 'covr::codecov()' | ||||||
|  |  | ||||||
|  | notifications: | ||||||
|  |   email: | ||||||
|  |     recipients: | ||||||
|  |       - m.s.berends@umcg.nl | ||||||
|  |       - c.f.luz@umcg.nl | ||||||
|  |     on_success: change | ||||||
|  |     on_failure: always | ||||||
|   | |||||||
| @@ -1,13 +1,14 @@ | |||||||
| Package: AMR | Package: AMR | ||||||
| Version: 0.1.1 | Version: 0.1.2 | ||||||
| Date: 2018-03-13 | Date: 2018-03-19 | ||||||
| Title: Antimicrobial Resistance Analysis | Title: Antimicrobial Resistance Analysis | ||||||
| Authors@R: c( | Authors@R: c( | ||||||
|     person( |     person( | ||||||
|         given = c("Matthijs", "S."), |         given = c("Matthijs", "S."), | ||||||
|         family = "Berends", |         family = "Berends", | ||||||
|         email = "m.s.berends@umcg.nl", |         email = "m.s.berends@umcg.nl", | ||||||
|         role = c("aut", "cre")), |         role = c("aut", "cre"), | ||||||
|  |         comment = c(ORCID = "0000-0001-7620-1800")), | ||||||
|     person( |     person( | ||||||
|         given = c("Christian", "F."), |         given = c("Christian", "F."), | ||||||
|         family = "Luz", |         family = "Luz", | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ export(as.rsi) | |||||||
| export(atc_property) | export(atc_property) | ||||||
| export(first_isolate) | export(first_isolate) | ||||||
| export(full_join_bactlist) | export(full_join_bactlist) | ||||||
|  | export(guess_bactid) | ||||||
| export(inner_join_bactlist) | export(inner_join_bactlist) | ||||||
| export(interpretive_reading) | export(interpretive_reading) | ||||||
| export(is.mic) | export(is.mic) | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								NEWS
									
									
									
									
									
								
							| @@ -1,3 +1,9 @@ | |||||||
|  | ## 0.1.2 | ||||||
|  | - Added new function `guess_bactid` to determine the ID of a microorganism based on genus/species | ||||||
|  | - Renamed `ablist` to `antibiotics` | ||||||
|  | - Added support for character vector in join functions | ||||||
|  | - Altered `%like%` to make it case insensitive | ||||||
|  |  | ||||||
| ## 0.1.1 | ## 0.1.1 | ||||||
| - `EUCAST_rules` applies for amoxicillin even if ampicillin is missing | - `EUCAST_rules` applies for amoxicillin even if ampicillin is missing | ||||||
| - Edited column names to comply with GLIMS, the laboratory information system | - Edited column names to comply with GLIMS, the laboratory information system | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								R/atc.R
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								R/atc.R
									
									
									
									
									
								
							| @@ -127,13 +127,13 @@ atc_property <- function(atc_code, | |||||||
|  |  | ||||||
| #' Name of an antibiotic | #' Name of an antibiotic | ||||||
| #' | #' | ||||||
| #' Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}. | #' Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{antibiotics}}. | ||||||
| #' @param abcode a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"} | #' @param abcode a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"} | ||||||
| #' @param from,to type to transform from and to. See \code{\link{ablist}} for its column names. | #' @param from,to type to transform from and to. See \code{\link{antibiotics}} for its column names. | ||||||
| #' @param textbetween text to put between multiple returned texts | #' @param textbetween text to put between multiple returned texts | ||||||
| #' @param tolower return output as lower case with function \code{\link{tolower}}. | #' @param tolower return output as lower case with function \code{\link{tolower}}. | ||||||
| #' @keywords ab antibiotics | #' @keywords ab antibiotics | ||||||
| #' @source \code{\link{ablist}} | #' @source \code{\link{antibiotics}} | ||||||
| #' @export | #' @export | ||||||
| #' @importFrom dplyr %>% filter select slice  | #' @importFrom dplyr %>% filter select slice  | ||||||
| #' @examples | #' @examples | ||||||
| @@ -156,15 +156,15 @@ atc_property <- function(atc_code, | |||||||
| #' # "AMCL" | #' # "AMCL" | ||||||
| abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) { | abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) { | ||||||
|    |    | ||||||
|   ablist <- AMR::ablist |   antibiotics <- AMR::antibiotics | ||||||
|   colnames(ablist) <- colnames(ablist) %>% tolower() |   colnames(antibiotics) <- colnames(antibiotics) %>% tolower() | ||||||
|   from <- from %>% tolower() |   from <- from %>% tolower() | ||||||
|   to <- to %>% tolower() |   to <- to %>% tolower() | ||||||
|    |    | ||||||
|   if (!from %in% colnames(ablist) | |   if (!from %in% colnames(antibiotics) | | ||||||
|       !to %in% colnames(ablist)) { |       !to %in% colnames(antibiotics)) { | ||||||
|     stop(paste0('Invalid `from` or `to`. Choose one of ',  |     stop(paste0('Invalid `from` or `to`. Choose one of ',  | ||||||
|                 colnames(ablist) %>% paste(collapse = ","), '.'), call. = FALSE) |                 colnames(antibiotics) %>% paste(collapse = ","), '.'), call. = FALSE) | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   abcode <- as.character(abcode) |   abcode <- as.character(abcode) | ||||||
| @@ -173,9 +173,9 @@ abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', | |||||||
|     drug <- abcode[i] |     drug <- abcode[i] | ||||||
|     if (!grepl('+', drug, fixed = TRUE) & !grepl(' en ', drug, fixed = TRUE)) { |     if (!grepl('+', drug, fixed = TRUE) & !grepl(' en ', drug, fixed = TRUE)) { | ||||||
|       # bestaat maar uit 1 middel |       # bestaat maar uit 1 middel | ||||||
|       if (any(ablist[, from] == drug)) { |       if (any(antibiotics[, from] == drug)) { | ||||||
|         abcode[i] <- |         abcode[i] <- | ||||||
|           ablist %>% |           antibiotics %>% | ||||||
|           filter(.[, from] == drug) %>% |           filter(.[, from] == drug) %>% | ||||||
|           select(to) %>% |           select(to) %>% | ||||||
|           slice(1) %>% |           slice(1) %>% | ||||||
| @@ -205,7 +205,7 @@ abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', | |||||||
|        |        | ||||||
|       for (j in 1:length(drug.group)) { |       for (j in 1:length(drug.group)) { | ||||||
|         drug.group[j] <- |         drug.group[j] <- | ||||||
|           ablist %>% |           antibiotics %>% | ||||||
|           filter(.[, from] == drug.group[j]) %>% |           filter(.[, from] == drug.group[j]) %>% | ||||||
|           select(to) %>% |           select(to) %>% | ||||||
|           slice(1) %>% |           slice(1) %>% | ||||||
|   | |||||||
							
								
								
									
										61
									
								
								R/data.R
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								R/data.R
									
									
									
									
									
								
							| @@ -18,36 +18,53 @@ | |||||||
|  |  | ||||||
| #' Dataset with 420 antibiotics | #' Dataset with 420 antibiotics | ||||||
| #' | #' | ||||||
| #' A dataset containing all antibiotics with a J0 code, with their DDD's. | #' A dataset containing all antibiotics with a J0 code, with their DDD's. Properties were downloaded from the WHO, see Source. | ||||||
| #' @format A data.frame with 420 observations and 12 variables: | #' @format A data.frame with 420 observations and 16 variables: | ||||||
| #' \describe{ | #' \describe{ | ||||||
| #'   \item{\code{atc}}{ATC code, like \code{J01CR02}} | #'   \item{\code{atc}}{ATC code, like \code{J01CR02}} | ||||||
| #'   \item{\code{molis}}{MOLIS code, like \code{amcl}} | #'   \item{\code{molis}}{MOLIS code, like \code{amcl}} | ||||||
| #'   \item{\code{umcg}}{UMCG code, like \code{AMCL}} | #'   \item{\code{umcg}}{UMCG code, like \code{AMCL}} | ||||||
| #'   \item{\code{official}}{Official name by the WHO, like \code{"amoxicillin and enzyme inhibitor"}} | #'   \item{\code{official}}{Official name by the WHO, like \code{"Amoxicillin and enzyme inhibitor"}} | ||||||
| #'   \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}} | #'   \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}} | ||||||
| #'   \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}} | #'   \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}} | ||||||
| #'   \item{\code{oral_ddd}}{Defined Daily Dose (DDD) according to the WHO, oral treatment} | #'   \item{\code{oral_ddd}}{Defined Daily Dose (DDD), oral treatment} | ||||||
| #'   \item{\code{oral_units}}{Units of \code{ddd_units}} | #'   \item{\code{oral_units}}{Units of \code{ddd_units}} | ||||||
| #'   \item{\code{iv_ddd}}{Defined Daily Dose (DDD) according to the WHO, parenteral treatment} | #'   \item{\code{iv_ddd}}{Defined Daily Dose (DDD), parenteral treatment} | ||||||
| #'   \item{\code{iv_units}}{Units of \code{iv_ddd}} | #'   \item{\code{iv_units}}{Units of \code{iv_ddd}} | ||||||
| #'   \item{\code{atc_group1}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}} | #'   \item{\code{atc_group1}}{ATC group, like \code{"Macrolides, lincosamides and streptogramins"}} | ||||||
| #'   \item{\code{atc_group2}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}} | #'   \item{\code{atc_group2}}{Subgroup of \code{atc_group1}, like \code{"Macrolides"}} | ||||||
|  | #'   \item{\code{atc_group1_nl}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}} | ||||||
|  | #'   \item{\code{atc_group2_nl}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}} | ||||||
|  | #'   \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)} | ||||||
|  | #'   \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)} | ||||||
| #' } | #' } | ||||||
| #' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl} \cr \cr World Health Organization - \url{https://www.whocc.no/atc_ddd_index/} | #' @source - World Health Organization: \url{https://www.whocc.no/atc_ddd_index/} \cr - EUCAST - Expert rules intrinsic exceptional V3.1 \cr - MOLIS (LIS of Certe): \url{https://www.certe.nl} \cr - GLIMS (LIS of UMCG): \url{https://www.umcg.nl} | ||||||
| #' @seealso \code{\link{bactlist}} | #' @seealso \code{\link{bactlist}} | ||||||
| # todo: | # last two columns created with: | ||||||
| # ablist <- ablist %>% mutate(useful_gramnegative = if_else(atc_group2 == 'Tetracyclines', FALSE, TRUE)) | # antibiotics %>% | ||||||
| # ablist <- ablist %>% mutate(useful_gramnegative = if_else(atc_group2 %like% 'Glycopept', FALSE, useful_gramnegative)) | #   mutate(useful_gramnegative =  | ||||||
| # Tbl1 Enterobacteriaceae are also intrinsically resistant to benzylpenicillin, glycopeptides, fusidic acid, macrolides (with some exceptions1), lincosamides, streptogramins, rifampicin, daptomycin and linezolid. | #            if_else( | ||||||
| # Tbl2 Non-fermentative Gram-negative bacteria are also generally intrinsically resistant to benzylpenicillin, first and second generation cephalosporins, glycopeptides, fusidic acid, macrolides, lincosamides, streptogramins, rifampicin, daptomycin and linezolid | #              atc_group1 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' | | ||||||
| # Tbl3 Gram-negative bacteria other than Enterobacteriaceae and non-fermentative Gram-negative bacteria listed are also intrinsically resistant to glycopeptides, lincosamides, daptomycin and linezolid. | #                atc_group2 %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)' | | ||||||
| "ablist" | #                official %like% '(fusidic|glycopeptide|macrolide|lincosamide|daptomycin|linezolid)', | ||||||
|  | #              FALSE, | ||||||
|  | #              NA | ||||||
|  | #            ), | ||||||
|  | #          useful_grampositive = | ||||||
|  | #            if_else( | ||||||
|  | #              atc_group1 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' | | ||||||
|  | #                atc_group2 %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)' | | ||||||
|  | #                official %like% '(aztreonam|temocillin|polymyxin|colistin|nalidixic)', | ||||||
|  | #              FALSE, | ||||||
|  | #              NA | ||||||
|  | #            ) | ||||||
|  | #   ) | ||||||
|  | "antibiotics" | ||||||
|  |  | ||||||
| #' Dataset with ~2500 microorganisms | #' Dataset with ~2500 microorganisms | ||||||
| #' | #' | ||||||
| #' A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}. | #' A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}. | ||||||
| #' @format A data.frame with 2507 observations and 10 variables: | #' @format A data.frame with 2507 observations and 12 variables: | ||||||
| #' \describe{ | #' \describe{ | ||||||
| #'   \item{\code{bactid}}{ID of microorganism} | #'   \item{\code{bactid}}{ID of microorganism} | ||||||
| #'   \item{\code{bactsys}}{Bactsyscode of microorganism} | #'   \item{\code{bactsys}}{Bactsyscode of microorganism} | ||||||
| @@ -56,12 +73,14 @@ | |||||||
| #'   \item{\code{species}}{Species name of microorganism, like \code{"coli"}} | #'   \item{\code{species}}{Species name of microorganism, like \code{"coli"}} | ||||||
| #'   \item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}} | #'   \item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}} | ||||||
| #'   \item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}} | #'   \item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}} | ||||||
| #'   \item{\code{type}}{Type of microorganism in Dutch, like \code{"Bacterie"} and \code{"Schimmel/gist"}} | #'   \item{\code{type}}{Type of microorganism, like \code{"Bacteria"} and \code{"Fungus/yeast"}} | ||||||
| #'   \item{\code{gramstain}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}} | #'   \item{\code{gramstain}}{Gram of microorganism, like \code{"Negative rods"}} | ||||||
| #'   \item{\code{aerobic}}{Type aerobe/anaerobe of bacteria} | #'   \item{\code{aerobic}}{Logical whether bacteria is aerobic} | ||||||
|  | #'   \item{\code{type_nl}}{Type of microorganism in Dutch, like \code{"Bacterie"} and \code{"Schimmel/gist"}} | ||||||
|  | #'   \item{\code{gramstain_nl}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}} | ||||||
| #' } | #' } | ||||||
| #' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} | #' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} | ||||||
| #' @seealso \code{\link{ablist}} \code{\link{bactlist.umcg}} | #' @seealso \code{\link{guess_bactid}} \code{\link{antibiotics}} \code{\link{bactlist.umcg}} | ||||||
| "bactlist" | "bactlist" | ||||||
|  |  | ||||||
| #' Translation table for UMCG with ~1100 microorganisms | #' Translation table for UMCG with ~1100 microorganisms | ||||||
| @@ -90,7 +109,7 @@ | |||||||
| #'   \item{\code{sex}}{sex of the patient} | #'   \item{\code{sex}}{sex of the patient} | ||||||
| #'   \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} | #'   \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} | ||||||
| #'   \item{\code{bactid}}{ID of microorganism, see \code{\link{bactlist}}} | #'   \item{\code{bactid}}{ID of microorganism, see \code{\link{bactlist}}} | ||||||
| #'   \item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}), these column names occur in \code{\link{ablist}} and can be translated with \code{\link{abname}}} | #'   \item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}), these column names occur in \code{\link{antibiotics}} and can be translated with \code{\link{abname}}} | ||||||
| #' } | #' } | ||||||
| #' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} | #' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} | ||||||
| "septic_patients" | "septic_patients" | ||||||
| @@ -357,7 +357,7 @@ first_isolate <- function(tbl, | |||||||
| #' @export | #' @export | ||||||
| #' @importFrom dplyr %>% mutate if_else  | #' @importFrom dplyr %>% mutate if_else  | ||||||
| #' @return Character of length 1. | #' @return Character of length 1. | ||||||
| #' @seealso \code{\link{mo_property}} \code{\link{ablist}} | #' @seealso \code{\link{mo_property}} \code{\link{antibiotics}} | ||||||
| #' @examples  | #' @examples  | ||||||
| #' \donttest{ | #' \donttest{ | ||||||
| #' #' # set key antibiotics to a new variable | #' #' # set key antibiotics to a new variable | ||||||
| @@ -403,7 +403,7 @@ key_antibiotics <- function(tbl, | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   # bactlist aan vastknopen |   # join bactlist | ||||||
|   tbl <- tbl %>% left_join_bactlist(col_bactcode) |   tbl <- tbl %>% left_join_bactlist(col_bactcode) | ||||||
|    |    | ||||||
|   tbl$key_ab <- NA_character_ |   tbl$key_ab <- NA_character_ | ||||||
| @@ -422,7 +422,7 @@ key_antibiotics <- function(tbl, | |||||||
|   list_ab <- c(peni, amox, teic, vanc, clin, line, clar, trsu) |   list_ab <- c(peni, amox, teic, vanc, clin, line, clar, trsu) | ||||||
|   list_ab <- list_ab[list_ab %in% colnames(tbl)] |   list_ab <- list_ab[list_ab %in% colnames(tbl)] | ||||||
|   tbl <- tbl %>% mutate(key_ab = |   tbl <- tbl %>% mutate(key_ab = | ||||||
|                           if_else(gramstain %like% '^Positi[e]?ve', |                           if_else(gramstain %like% '^Positive ', | ||||||
|                                   apply(X = tbl[, list_ab], |                                   apply(X = tbl[, list_ab], | ||||||
|                                         MARGIN = 1, |                                         MARGIN = 1, | ||||||
|                                         FUN = function(x) paste(x, collapse = "")), |                                         FUN = function(x) paste(x, collapse = "")), | ||||||
| @@ -432,7 +432,7 @@ key_antibiotics <- function(tbl, | |||||||
|   list_ab <- c(amox, amcl, pita, cfur, cfot, cfta, cftr, mero, cipr, trsu, gent) |   list_ab <- c(amox, amcl, pita, cfur, cfot, cfta, cftr, mero, cipr, trsu, gent) | ||||||
|   list_ab <- list_ab[list_ab %in% colnames(tbl)] |   list_ab <- list_ab[list_ab %in% colnames(tbl)] | ||||||
|   tbl <- tbl %>% mutate(key_ab = |   tbl <- tbl %>% mutate(key_ab = | ||||||
|                           if_else(gramstain %like% '^Negati[e]?ve', |                           if_else(gramstain %like% '^Negative ', | ||||||
|                                   apply(X = tbl[, list_ab], |                                   apply(X = tbl[, list_ab], | ||||||
|                                         MARGIN = 1, |                                         MARGIN = 1, | ||||||
|                                         FUN = function(x) paste(x, collapse = "")), |                                         FUN = function(x) paste(x, collapse = "")), | ||||||
| @@ -502,3 +502,95 @@ key_antibiotics_equal <- function(x, y, points_threshold = 2, info = FALSE) { | |||||||
|   } |   } | ||||||
|   result |   result | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #' Find bacteria ID based on genus/species | ||||||
|  | #' | ||||||
|  | #' Use this function to determine a valid ID based on a genus (and species). This input could be a full name (like \code{"Staphylococcus aureus"}), an abbreviated name (like \code{"S. aureus"}), or just a genus. You could also use a \code{\link{paste}} of a genus and species column to use the full name as input: \code{x = paste(df$genus, df$species)}, where \code{df} is your dataframe. | ||||||
|  | #' @param x character vector to determine \code{bactid} | ||||||
|  | #' @export | ||||||
|  | #' @importFrom dplyr %>% filter slice pull | ||||||
|  | #' @return Character (vector). | ||||||
|  | #' @seealso \code{\link{bactlist}} for the dataframe that is being used to determine ID's. | ||||||
|  | #' @examples  | ||||||
|  | #' # These examples all return "STAAUR", the ID of S. aureus: | ||||||
|  | #' guess_bactid("stau") | ||||||
|  | #' guess_bactid("STAU") | ||||||
|  | #' guess_bactid("staaur") | ||||||
|  | #' guess_bactid("S. aureus") | ||||||
|  | #' guess_bactid("S aureus") | ||||||
|  | #' guess_bactid("Staphylococcus aureus") | ||||||
|  | #' guess_bactid("MRSA") # Methicillin-resistant S. aureus | ||||||
|  | #' guess_bactid("VISA") # Vancomycin Intermediate S. aureus | ||||||
|  | guess_bactid <- function(x) { | ||||||
|  |   # remove dots and other non-text in case of "E. coli" except spaces | ||||||
|  |   x <- gsub("[^a-zA-Z ]+", "", x) | ||||||
|  |   x.bak <- x | ||||||
|  |   # replace space by regex sign | ||||||
|  |   x <- gsub(" ", ".*", x, fixed = TRUE) | ||||||
|  |   # add start and stop | ||||||
|  |   x_species <- paste(x, 'species') | ||||||
|  |   x <- paste0('^', x, '$') | ||||||
|  |    | ||||||
|  |   for (i in 1:length(x)) { | ||||||
|  |     if (tolower(x[i]) == '^e.*coli$') { | ||||||
|  |       # avoid detection of Entamoeba coli in case of Escherichia coli | ||||||
|  |       x[i] <- 'Escherichia coli' | ||||||
|  |     } | ||||||
|  |     if (tolower(x[i]) == '^st.*au$' | ||||||
|  |         | tolower(x[i]) == '^stau$' | ||||||
|  |         | tolower(x[i]) == '^staaur$') { | ||||||
|  |       # avoid detection of Staphylococcus auricularis in case of S. aureus | ||||||
|  |       x[i] <- 'Staphylococcus aureus' | ||||||
|  |     } | ||||||
|  |     if (tolower(x[i]) == '^p.*aer$') { | ||||||
|  |       # avoid detection of Pasteurella aerogenes in case of Pseudomonas aeruginosa | ||||||
|  |       x[i] <- 'Pseudomonas aeruginosa' | ||||||
|  |     } | ||||||
|  |     # translate known trivial names to genus+species | ||||||
|  |     if (toupper(x.bak[i]) == 'MRSA' | ||||||
|  |         | toupper(x.bak[i]) == 'VISA' | ||||||
|  |         | toupper(x.bak[i]) == 'VRSA') { | ||||||
|  |       x[i] <- 'Staphylococcus aureus' | ||||||
|  |     } | ||||||
|  |     if (toupper(x.bak[i]) == 'MRSE') { | ||||||
|  |       x[i] <- 'Staphylococcus epidermidis' | ||||||
|  |     } | ||||||
|  |     if (toupper(x.bak[i]) == 'VRE') { | ||||||
|  |       x[i] <- 'Enterococcus' | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     # let's try the ID's first | ||||||
|  |     found <- AMR::bactlist %>% filter(bactid == x.bak[i]) | ||||||
|  |      | ||||||
|  |     if (nrow(found) == 0) { | ||||||
|  |       # now try exact match | ||||||
|  |       found <- AMR::bactlist %>% filter(fullname == x[i]) | ||||||
|  |     } | ||||||
|  |     if (nrow(found) == 0) { | ||||||
|  |       # try any match | ||||||
|  |       found <- AMR::bactlist %>% filter(fullname %like% x[i]) | ||||||
|  |     } | ||||||
|  |     if (nrow(found) == 0) { | ||||||
|  |       # try only genus, with 'species' attached | ||||||
|  |       found <- AMR::bactlist %>% filter(fullname %like% x_species[i]) | ||||||
|  |     } | ||||||
|  |     if (nrow(found) == 0) { | ||||||
|  |       # try splitting of characters and then find ID | ||||||
|  |       # like esco = E. coli, klpn = K. pneumoniae, stau = S. aureus | ||||||
|  |       x_length <- nchar(x.bak[i]) | ||||||
|  |       x[i] <- paste0(x.bak[i] %>% substr(1, x_length / 2) %>% trimws(), | ||||||
|  |                      '.* ', | ||||||
|  |                      x.bak[i] %>% substr((x_length / 2) + 1, x_length) %>% trimws()) | ||||||
|  |       found <- AMR::bactlist %>% filter(fullname %like% paste0('^', x[i])) | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (nrow(found) != 0) { | ||||||
|  |       x[i] <- found %>%  | ||||||
|  |         slice(1) %>%  | ||||||
|  |         pull(bactid) | ||||||
|  |     } else { | ||||||
|  |       x[i] <- "" | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   x | ||||||
|  | } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ globalVariables(c('.', | |||||||
|                   'date_lab', |                   'date_lab', | ||||||
|                   'days_diff', |                   'days_diff', | ||||||
|                   'first_isolate_row_index', |                   'first_isolate_row_index', | ||||||
|  |                   'fullname', | ||||||
|                   'genus', |                   'genus', | ||||||
|                   'gramstain', |                   'gramstain', | ||||||
|                   'key_ab', |                   'key_ab', | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								R/join.R
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								R/join.R
									
									
									
									
									
								
							| @@ -4,23 +4,28 @@ | |||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @name join | #' @name join | ||||||
| #' @aliases join inner_join | #' @aliases join inner_join | ||||||
| #' @param x existing table to join | #' @param x existing table to join, also supports character vectors | ||||||
| #' @param by a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")}) | #' @param by a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")}) | ||||||
|  | #' @param suffix if there are non-joined duplicate variables in \code{x} and \code{y}, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2. | ||||||
| #' @param ... other parameters to pass on to \code{dplyr::\link[dplyr]{join}}. | #' @param ... other parameters to pass on to \code{dplyr::\link[dplyr]{join}}. | ||||||
| #' @details As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information. | #' @details As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information. | ||||||
| #' @export | #' @export | ||||||
| #' @examples  | #' @examples  | ||||||
|  | #' left_join_bactlist("STAAUR") | ||||||
|  | #'  | ||||||
| #' df <- data.frame(date = seq(from = as.Date("2018-01-01"), | #' df <- data.frame(date = seq(from = as.Date("2018-01-01"), | ||||||
| #'                             to = as.Date("2018-01-07"), | #'                             to = as.Date("2018-01-07"), | ||||||
| #'                             by = 1), | #'                             by = 1), | ||||||
| #'                  bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR", | #'                  bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR", | ||||||
| #'                                  "ESCCOL", "ESCCOL", "ESCCOL"), | #'                                  "ESCCOL", "ESCCOL", "ESCCOL"), | ||||||
| #'                  stringsAsFactors = FALSE) | #'                  stringsAsFactors = FALSE) | ||||||
| #'                   |  | ||||||
| #' colnames(df) | #' colnames(df) | ||||||
| #' df2 <- left_join_bactlist(df, "bacteria_id") | #' df2 <- left_join_bactlist(df, "bacteria_id") | ||||||
| #' colnames(df2) | #' colnames(df2) | ||||||
| inner_join_bactlist <- function(x, by = 'bactid', ...) { | inner_join_bactlist <- function(x, by = 'bactid', suffix = c("2", ""), ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
| @@ -37,7 +42,10 @@ inner_join_bactlist <- function(x, by = 'bactid', ...) { | |||||||
|  |  | ||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @export | #' @export | ||||||
| left_join_bactlist <- function(x, by = 'bactid', ...) { | left_join_bactlist <- function(x, by = 'bactid', suffix = c("2", ""), ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
| @@ -54,7 +62,10 @@ left_join_bactlist <- function(x, by = 'bactid', ...) { | |||||||
|  |  | ||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @export | #' @export | ||||||
| right_join_bactlist <- function(x, by = 'bactid', ...) { | right_join_bactlist <- function(x, by = 'bactid', suffix = c("2", ""), ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
| @@ -71,7 +82,10 @@ right_join_bactlist <- function(x, by = 'bactid', ...) { | |||||||
|  |  | ||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @export | #' @export | ||||||
| full_join_bactlist <- function(x, by = 'bactid', ...) { | full_join_bactlist <- function(x, by = 'bactid', suffix = c("2", ""), ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
| @@ -85,6 +99,9 @@ full_join_bactlist <- function(x, by = 'bactid', ...) { | |||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @export | #' @export | ||||||
| semi_join_bactlist <- function(x, by = 'bactid', ...) { | semi_join_bactlist <- function(x, by = 'bactid', ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
| @@ -98,6 +115,9 @@ semi_join_bactlist <- function(x, by = 'bactid', ...) { | |||||||
| #' @rdname join | #' @rdname join | ||||||
| #' @export | #' @export | ||||||
| anti_join_bactlist <- function(x, by = 'bactid', ...) { | anti_join_bactlist <- function(x, by = 'bactid', ...) { | ||||||
|  |   if (any(class(x) %in% c('character', 'factor'))) { | ||||||
|  |     x <- data.frame(bactid = x, stringsAsFactors = FALSE) | ||||||
|  |   } | ||||||
|   # no name set to `by` parameter |   # no name set to `by` parameter | ||||||
|   if (is.null(names(by))) { |   if (is.null(names(by))) { | ||||||
|     joinby <- colnames(AMR::bactlist)[1] |     joinby <- colnames(AMR::bactlist)[1] | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								R/misc.R
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								R/misc.R
									
									
									
									
									
								
							| @@ -19,17 +19,20 @@ | |||||||
| # No export, no Rd | # No export, no Rd | ||||||
| "%like%" <- function(vector, pattern) { | "%like%" <- function(vector, pattern) { | ||||||
|   # Source: https://github.com/Rdatatable/data.table/blob/master/R/like.R |   # Source: https://github.com/Rdatatable/data.table/blob/master/R/like.R | ||||||
|  |   # But made it case insensitive | ||||||
|   if (is.factor(vector)) { |   if (is.factor(vector)) { | ||||||
|     as.integer(vector) %in% grep(pattern, levels(vector)) |     as.integer(vector) %in% grep(pattern, levels(vector), ignore.case = TRUE) | ||||||
|   } else { |   } else { | ||||||
|     grepl(pattern, vector) |     grepl(pattern, vector, ignore.case = TRUE) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # No export, no Rd | ||||||
| percent <- function(x, round = 1, ...) { | percent <- function(x, round = 1, ...) { | ||||||
|   base::paste0(base::round(x * 100, digits = round), "%") |   base::paste0(base::round(x * 100, digits = round), "%") | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # No export, no Rd | ||||||
| quasiquotate <- function(deparsed, parsed) { | quasiquotate <- function(deparsed, parsed) { | ||||||
|   # when text: remove first and last " |   # when text: remove first and last " | ||||||
|   if (any(deparsed %like% '^".+"$' | deparsed %like% "^'.+'$")) { |   if (any(deparsed %like% '^".+"$' | deparsed %like% "^'.+'$")) { | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							| @@ -28,7 +28,7 @@ This package is available on CRAN and also here on GitHub. | |||||||
|  |  | ||||||
| ### From GitHub (latest development version) | ### From GitHub (latest development version) | ||||||
| [](https://travis-ci.org/msberends/AMR) | [](https://travis-ci.org/msberends/AMR) | ||||||
| [](https://github.com/msberends/AMR/releases) | [](https://github.com/msberends/AMR/commits/master) | ||||||
| [](https://github.com/msberends/AMR/commits/master) | [](https://github.com/msberends/AMR/commits/master) | ||||||
|  |  | ||||||
| ```r | ```r | ||||||
| @@ -116,7 +116,14 @@ A plot of `rsi_data`: | |||||||
| plot(rsi_data) | plot(rsi_data) | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | A plot of `mic_data` (defaults to bar plot): | ||||||
|  | ```r | ||||||
|  | plot(mic_data) | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Other epidemiological functions: | Other epidemiological functions: | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								data/ablist.rda
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/ablist.rda
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								data/antibiotics.rda
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/antibiotics.rda
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1,34 +0,0 @@ | |||||||
| % Generated by roxygen2: do not edit by hand |  | ||||||
| % Please edit documentation in R/data.R |  | ||||||
| \docType{data} |  | ||||||
| \name{ablist} |  | ||||||
| \alias{ablist} |  | ||||||
| \title{Dataset with 420 antibiotics} |  | ||||||
| \format{A data.frame with 420 observations and 12 variables: |  | ||||||
| \describe{ |  | ||||||
|   \item{\code{atc}}{ATC code, like \code{J01CR02}} |  | ||||||
|   \item{\code{molis}}{MOLIS code, like \code{amcl}} |  | ||||||
|   \item{\code{umcg}}{UMCG code, like \code{AMCL}} |  | ||||||
|   \item{\code{official}}{Official name by the WHO, like \code{"amoxicillin and enzyme inhibitor"}} |  | ||||||
|   \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}} |  | ||||||
|   \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}} |  | ||||||
|   \item{\code{oral_ddd}}{Defined Daily Dose (DDD) according to the WHO, oral treatment} |  | ||||||
|   \item{\code{oral_units}}{Units of \code{ddd_units}} |  | ||||||
|   \item{\code{iv_ddd}}{Defined Daily Dose (DDD) according to the WHO, parenteral treatment} |  | ||||||
|   \item{\code{iv_units}}{Units of \code{iv_ddd}} |  | ||||||
|   \item{\code{atc_group1}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}} |  | ||||||
|   \item{\code{atc_group2}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}} |  | ||||||
| }} |  | ||||||
| \source{ |  | ||||||
| MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl} \cr \cr World Health Organization - \url{https://www.whocc.no/atc_ddd_index/} |  | ||||||
| } |  | ||||||
| \usage{ |  | ||||||
| ablist |  | ||||||
| } |  | ||||||
| \description{ |  | ||||||
| A dataset containing all antibiotics with a J0 code, with their DDD's. |  | ||||||
| } |  | ||||||
| \seealso{ |  | ||||||
| \code{\link{bactlist}} |  | ||||||
| } |  | ||||||
| \keyword{datasets} |  | ||||||
| @@ -4,7 +4,7 @@ | |||||||
| \alias{abname} | \alias{abname} | ||||||
| \title{Name of an antibiotic} | \title{Name of an antibiotic} | ||||||
| \source{ | \source{ | ||||||
| \code{\link{ablist}} | \code{\link{antibiotics}} | ||||||
| } | } | ||||||
| \usage{ | \usage{ | ||||||
| abname(abcode, from = "umcg", to = "official", textbetween = " + ", | abname(abcode, from = "umcg", to = "official", textbetween = " + ", | ||||||
| @@ -13,14 +13,14 @@ abname(abcode, from = "umcg", to = "official", textbetween = " + ", | |||||||
| \arguments{ | \arguments{ | ||||||
| \item{abcode}{a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"}} | \item{abcode}{a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"}} | ||||||
|  |  | ||||||
| \item{from, to}{type to transform from and to. See \code{\link{ablist}} for its column names.} | \item{from, to}{type to transform from and to. See \code{\link{antibiotics}} for its column names.} | ||||||
|  |  | ||||||
| \item{textbetween}{text to put between multiple returned texts} | \item{textbetween}{text to put between multiple returned texts} | ||||||
|  |  | ||||||
| \item{tolower}{return output as lower case with function \code{\link{tolower}}.} | \item{tolower}{return output as lower case with function \code{\link{tolower}}.} | ||||||
| } | } | ||||||
| \description{ | \description{ | ||||||
| Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}. | Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{antibiotics}}. | ||||||
| } | } | ||||||
| \examples{ | \examples{ | ||||||
| abname("AMCL") | abname("AMCL") | ||||||
|   | |||||||
							
								
								
									
										38
									
								
								man/antibiotics.Rd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								man/antibiotics.Rd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | % Generated by roxygen2: do not edit by hand | ||||||
|  | % Please edit documentation in R/data.R | ||||||
|  | \docType{data} | ||||||
|  | \name{antibiotics} | ||||||
|  | \alias{antibiotics} | ||||||
|  | \title{Dataset with 420 antibiotics} | ||||||
|  | \format{A data.frame with 420 observations and 16 variables: | ||||||
|  | \describe{ | ||||||
|  |   \item{\code{atc}}{ATC code, like \code{J01CR02}} | ||||||
|  |   \item{\code{molis}}{MOLIS code, like \code{amcl}} | ||||||
|  |   \item{\code{umcg}}{UMCG code, like \code{AMCL}} | ||||||
|  |   \item{\code{official}}{Official name by the WHO, like \code{"Amoxicillin and enzyme inhibitor"}} | ||||||
|  |   \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}} | ||||||
|  |   \item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}} | ||||||
|  |   \item{\code{oral_ddd}}{Defined Daily Dose (DDD), oral treatment} | ||||||
|  |   \item{\code{oral_units}}{Units of \code{ddd_units}} | ||||||
|  |   \item{\code{iv_ddd}}{Defined Daily Dose (DDD), parenteral treatment} | ||||||
|  |   \item{\code{iv_units}}{Units of \code{iv_ddd}} | ||||||
|  |   \item{\code{atc_group1}}{ATC group, like \code{"Macrolides, lincosamides and streptogramins"}} | ||||||
|  |   \item{\code{atc_group2}}{Subgroup of \code{atc_group1}, like \code{"Macrolides"}} | ||||||
|  |   \item{\code{atc_group1_nl}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}} | ||||||
|  |   \item{\code{atc_group2_nl}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}} | ||||||
|  |   \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)} | ||||||
|  |   \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)} | ||||||
|  | }} | ||||||
|  | \source{ | ||||||
|  | - World Health Organization: \url{https://www.whocc.no/atc_ddd_index/} \cr - EUCAST - Expert rules intrinsic exceptional V3.1 \cr - MOLIS (LIS of Certe): \url{https://www.certe.nl} \cr - GLIMS (LIS of UMCG): \url{https://www.umcg.nl} | ||||||
|  | } | ||||||
|  | \usage{ | ||||||
|  | antibiotics | ||||||
|  | } | ||||||
|  | \description{ | ||||||
|  | A dataset containing all antibiotics with a J0 code, with their DDD's. Properties were downloaded from the WHO, see Source. | ||||||
|  | } | ||||||
|  | \seealso{ | ||||||
|  | \code{\link{bactlist}} | ||||||
|  | } | ||||||
|  | \keyword{datasets} | ||||||
| @@ -4,7 +4,7 @@ | |||||||
| \name{bactlist} | \name{bactlist} | ||||||
| \alias{bactlist} | \alias{bactlist} | ||||||
| \title{Dataset with ~2500 microorganisms} | \title{Dataset with ~2500 microorganisms} | ||||||
| \format{A data.frame with 2507 observations and 10 variables: | \format{A data.frame with 2507 observations and 12 variables: | ||||||
| \describe{ | \describe{ | ||||||
|   \item{\code{bactid}}{ID of microorganism} |   \item{\code{bactid}}{ID of microorganism} | ||||||
|   \item{\code{bactsys}}{Bactsyscode of microorganism} |   \item{\code{bactsys}}{Bactsyscode of microorganism} | ||||||
| @@ -13,9 +13,11 @@ | |||||||
|   \item{\code{species}}{Species name of microorganism, like \code{"coli"}} |   \item{\code{species}}{Species name of microorganism, like \code{"coli"}} | ||||||
|   \item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}} |   \item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}} | ||||||
|   \item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}} |   \item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}} | ||||||
|   \item{\code{type}}{Type of microorganism in Dutch, like \code{"Bacterie"} and \code{"Schimmel/gist"}} |   \item{\code{type}}{Type of microorganism, like \code{"Bacteria"} and \code{"Fungus/yeast"}} | ||||||
|   \item{\code{gramstain}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}} |   \item{\code{gramstain}}{Gram of microorganism, like \code{"Negative rods"}} | ||||||
|   \item{\code{aerobic}}{Type aerobe/anaerobe of bacteria} |   \item{\code{aerobic}}{Logical whether bacteria is aerobic} | ||||||
|  |   \item{\code{type_nl}}{Type of microorganism in Dutch, like \code{"Bacterie"} and \code{"Schimmel/gist"}} | ||||||
|  |   \item{\code{gramstain_nl}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}} | ||||||
| }} | }} | ||||||
| \source{ | \source{ | ||||||
| MOLIS (LIS of Certe) - \url{https://www.certe.nl} | MOLIS (LIS of Certe) - \url{https://www.certe.nl} | ||||||
| @@ -27,6 +29,6 @@ bactlist | |||||||
| A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}. | A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}. | ||||||
| } | } | ||||||
| \seealso{ | \seealso{ | ||||||
| \code{\link{ablist}} \code{\link{bactlist.umcg}} | \code{\link{guess_bactid}} \code{\link{antibiotics}} \code{\link{bactlist.umcg}} | ||||||
| } | } | ||||||
| \keyword{datasets} | \keyword{datasets} | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								man/figures/mic_example.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								man/figures/mic_example.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 4.7 KiB | 
							
								
								
									
										31
									
								
								man/guess_bactid.Rd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								man/guess_bactid.Rd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | % Generated by roxygen2: do not edit by hand | ||||||
|  | % Please edit documentation in R/first_isolates.R | ||||||
|  | \name{guess_bactid} | ||||||
|  | \alias{guess_bactid} | ||||||
|  | \title{Find bacteria ID based on genus/species} | ||||||
|  | \usage{ | ||||||
|  | guess_bactid(x) | ||||||
|  | } | ||||||
|  | \arguments{ | ||||||
|  | \item{x}{character vector to determine \code{bactid}} | ||||||
|  | } | ||||||
|  | \value{ | ||||||
|  | Character (vector). | ||||||
|  | } | ||||||
|  | \description{ | ||||||
|  | Use this function to determine a valid ID based on a genus (and species). This input could be a full name (like \code{"Staphylococcus aureus"}), an abbreviated name (like \code{"S. aureus"}), or just a genus. You could also use a \code{\link{paste}} of a genus and species column to use the full name as input: \code{x = paste(df$genus, df$species)}, where \code{df} is your dataframe. | ||||||
|  | } | ||||||
|  | \examples{ | ||||||
|  | # These examples all return "STAAUR", the ID of S. aureus: | ||||||
|  | guess_bactid("stau") | ||||||
|  | guess_bactid("STAU") | ||||||
|  | guess_bactid("staaur") | ||||||
|  | guess_bactid("S. aureus") | ||||||
|  | guess_bactid("S aureus") | ||||||
|  | guess_bactid("Staphylococcus aureus") | ||||||
|  | guess_bactid("MRSA") # Methicillin-resistant S. aureus | ||||||
|  | guess_bactid("VISA") # Vancomycin Intermediate S. aureus | ||||||
|  | } | ||||||
|  | \seealso{ | ||||||
|  | \code{\link{bactlist}} for the dataframe that is being used to determine ID's. | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								man/join.Rd
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								man/join.Rd
									
									
									
									
									
								
							| @@ -11,39 +11,42 @@ | |||||||
| \alias{anti_join_bactlist} | \alias{anti_join_bactlist} | ||||||
| \title{Join a table with \code{bactlist}} | \title{Join a table with \code{bactlist}} | ||||||
| \usage{ | \usage{ | ||||||
| inner_join_bactlist(x, by = "bactid", ...) | inner_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...) | ||||||
|  |  | ||||||
| left_join_bactlist(x, by = "bactid", ...) | left_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...) | ||||||
|  |  | ||||||
| right_join_bactlist(x, by = "bactid", ...) | right_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...) | ||||||
|  |  | ||||||
| full_join_bactlist(x, by = "bactid", ...) | full_join_bactlist(x, by = "bactid", suffix = c("2", ""), ...) | ||||||
|  |  | ||||||
| semi_join_bactlist(x, by = "bactid", ...) | semi_join_bactlist(x, by = "bactid", ...) | ||||||
|  |  | ||||||
| anti_join_bactlist(x, by = "bactid", ...) | anti_join_bactlist(x, by = "bactid", ...) | ||||||
| } | } | ||||||
| \arguments{ | \arguments{ | ||||||
| \item{x}{existing table to join} | \item{x}{existing table to join, also supports character vectors} | ||||||
|  |  | ||||||
| \item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})} | \item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})} | ||||||
|  |  | ||||||
|  | \item{suffix}{if there are non-joined duplicate variables in \code{x} and \code{y}, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.} | ||||||
|  |  | ||||||
| \item{...}{other parameters to pass on to \code{dplyr::\link[dplyr]{join}}.} | \item{...}{other parameters to pass on to \code{dplyr::\link[dplyr]{join}}.} | ||||||
| } | } | ||||||
| \description{ | \description{ | ||||||
| Join the list of microorganisms \code{\link{bactlist}} easily to an existing table. | Join the list of microorganisms \code{\link{bactlist}} easily to an existing table. | ||||||
| } | } | ||||||
| \details{ | \details{ | ||||||
| As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information. | As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information. | ||||||
| } | } | ||||||
| \examples{ | \examples{ | ||||||
|  | left_join_bactlist("STAAUR") | ||||||
|  |  | ||||||
| df <- data.frame(date = seq(from = as.Date("2018-01-01"), | df <- data.frame(date = seq(from = as.Date("2018-01-01"), | ||||||
|                             to = as.Date("2018-01-07"), |                             to = as.Date("2018-01-07"), | ||||||
|                             by = 1), |                             by = 1), | ||||||
|                  bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR", |                  bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR", | ||||||
|                                  "ESCCOL", "ESCCOL", "ESCCOL"), |                                  "ESCCOL", "ESCCOL", "ESCCOL"), | ||||||
|                  stringsAsFactors = FALSE) |                  stringsAsFactors = FALSE) | ||||||
|                   |  | ||||||
| colnames(df) | colnames(df) | ||||||
| df2 <- left_join_bactlist(df, "bacteria_id") | df2 <- left_join_bactlist(df, "bacteria_id") | ||||||
| colnames(df2) | colnames(df2) | ||||||
|   | |||||||
| @@ -33,5 +33,5 @@ tbl$keyab <- key_antibiotics(tbl) | |||||||
| } | } | ||||||
| } | } | ||||||
| \seealso{ | \seealso{ | ||||||
| \code{\link{mo_property}} \code{\link{ablist}} | \code{\link{mo_property}} \code{\link{antibiotics}} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|   \item{\code{sex}}{sex of the patient} |   \item{\code{sex}}{sex of the patient} | ||||||
|   \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} |   \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information} | ||||||
|   \item{\code{bactid}}{ID of microorganism, see \code{\link{bactlist}}} |   \item{\code{bactid}}{ID of microorganism, see \code{\link{bactlist}}} | ||||||
|   \item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}), these column names occur in \code{\link{ablist}} and can be translated with \code{\link{abname}}} |   \item{\code{peni:mupi}}{38 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}), these column names occur in \code{\link{antibiotics}} and can be translated with \code{\link{abname}}} | ||||||
| }} | }} | ||||||
| \source{ | \source{ | ||||||
| MOLIS (LIS of Certe) - \url{https://www.certe.nl} | MOLIS (LIS of Certe) - \url{https://www.certe.nl} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user