AMR/data-raw/loinc.R

104 lines
4.5 KiB
R
Raw Normal View History

2020-01-26 20:20:00 +01:00
# ==================================================================== #
2023-06-26 13:52:02 +02:00
# TITLE: #
2022-10-05 09:12:22 +02:00
# AMR: An R Package for Working with Antimicrobial Resistance Data #
2020-01-26 20:20:00 +01:00
# #
2023-06-26 13:52:02 +02:00
# SOURCE CODE: #
# https://github.com/msberends/AMR #
2020-01-26 20:20:00 +01:00
# #
2023-06-26 13:52:02 +02:00
# PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
# Journal of Statistical Software, 104(3), 1-31. #
2023-05-27 10:39:22 +02:00
# https://doi.org/10.18637/jss.v104.i03 #
2022-10-05 09:12:22 +02:00
# #
2022-12-27 15:16:15 +01:00
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
2020-01-26 20:20:00 +01:00
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
2020-10-08 11:16:03 +02:00
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
2020-01-26 20:20:00 +01:00
# ==================================================================== #
2022-10-30 14:31:45 +01:00
# last updated: 30 October 2022 - Loinc_2.73
2020-01-26 20:20:00 +01:00
# Steps to reproduce:
# 1. Create a fake account at https://loinc.org (sad you have to create one...)
2023-10-20 14:51:48 +02:00
# 2. Download the CSV from https://loinc.org/download/loinc-complete/
# 3. Read file LoincTable/Loinc.csv
2020-01-26 20:20:00 +01:00
loinc_df <- read.csv("data-raw/Loinc.csv",
2022-08-28 10:31:50 +02:00
row.names = NULL,
stringsAsFactors = FALSE
)
2020-01-26 20:20:00 +01:00
# 4. Clean and add
library(dplyr)
library(cleaner)
library(AMR)
2023-10-20 14:51:48 +02:00
# to find the drugs:
loinc_df %>%
filter(COMPONENT %like% "ampicillin|fluconazol|meropenem") %>%
count(CLASS, sort = TRUE)
loinc_df <- loinc_df %>%
filter(CLASS %in% c("DRUG/TOX", "ABXBACT")) %>%
mutate(name = generalise_antibiotic_name(COMPONENT), .before = 1)
2020-01-26 20:20:00 +01:00
2023-10-20 14:51:48 +02:00
# antibiotics
2020-01-26 20:20:00 +01:00
antibiotics$loinc <- as.list(rep(NA_character_, nrow(antibiotics)))
for (i in seq_len(nrow(antibiotics))) {
2022-10-30 14:31:45 +01:00
message(i)
2020-01-26 20:20:00 +01:00
loinc_ab <- loinc_df %>%
2023-10-20 14:51:48 +02:00
filter(name %like% paste0("^", generalise_antibiotic_name(antibiotics$name[i]))) %>%
2020-01-26 20:20:00 +01:00
pull(LOINC_NUM)
if (length(loinc_ab) > 0) {
antibiotics$loinc[i] <- list(loinc_ab)
}
}
2023-10-20 14:51:48 +02:00
# antivirals
antivirals$loinc <- as.list(rep(NA_character_, nrow(antivirals)))
for (i in seq_len(nrow(antivirals))) {
message(i)
loinc_ab <- loinc_df %>%
filter(name %like% paste0("^", generalise_antibiotic_name(antivirals$name[i]))) %>%
pull(LOINC_NUM)
if (length(loinc_ab) > 0) {
antivirals$loinc[i] <- list(loinc_ab)
}
}
2020-06-09 16:31:44 +02:00
# sort and fix for empty values
for (i in 1:nrow(antibiotics)) {
2023-10-20 14:51:48 +02:00
loinc <- as.character(sort(unique(tolower(antibiotics[i, "loinc", drop = TRUE][[1]]))))
loinc <- loinc[loinc != ""]
antibiotics[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
}
for (i in 1:nrow(antivirals)) {
loinc <- as.character(sort(unique(tolower(antivirals[i, "loinc", drop = TRUE][[1]]))))
loinc <- loinc[loinc != ""]
antivirals[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
2020-06-09 16:31:44 +02:00
}
2020-01-26 20:20:00 +01:00
2023-10-20 14:51:48 +02:00
antibiotics <- dataset_UTF8_to_ASCII(as.data.frame(antibiotics, stringsAsFactors = FALSE))
antibiotics <- dplyr::arrange(antibiotics, name)
antivirals <- dataset_UTF8_to_ASCII(as.data.frame(antivirals, stringsAsFactors = FALSE))
antivirals <- dplyr::arrange(antivirals, name)
2022-10-30 14:31:45 +01:00
# remember to update R/aa_globals.R for the documentation
2020-01-26 20:20:00 +01:00
dim(antibiotics) # for R/data.R
2023-10-20 14:51:48 +02:00
usethis::use_data(antibiotics, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)
2020-01-26 20:20:00 +01:00
rm(antibiotics)
2023-10-20 14:51:48 +02:00
dim(antivirals) # for R/data.R
usethis::use_data(antivirals, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)
rm(antivirals)