1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 20:41:58 +02:00

(v0.9.0.9012) Support for LOINC codes

This commit is contained in:
2020-01-26 20:20:00 +01:00
parent 19172b1d48
commit 449d9bde35
35 changed files with 92866 additions and 295 deletions

92370
data-raw/Loinc.csv Normal file

File diff suppressed because one or more lines are too long

View File

@ -59,9 +59,6 @@ for (i in 2:length(unique_ip)) {
ip_tbl.bak <- ip_tbl
# how many?
n_distinct(ip_tbl$country)
# add long and lat
ip_tbl <- ip_tbl %>%
separate(loc, into = c("y", "x"), sep = ",", remove = FALSE, convert = TRUE)
@ -118,7 +115,7 @@ countries_plot_big <- countries_plot +
theme(plot.title = element_text(size = 16, hjust = 0.5),
plot.subtitle = element_text(size = 12, hjust = 0.5)) +
geom_text(aes(x = -170,
y = -70,
y = -75,
label = stringr::str_wrap(paste0("Countries (n = ",
length(countries_name[!is.na(countries_name)]), "): ",
paste(countries_name[!is.na(countries_name)], collapse = ", ")),

52
data-raw/loinc.R Normal file
View File

@ -0,0 +1,52 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# 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. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
# last updated: 20 January 2020 - Loinc_2.67
# Steps to reproduce:
# 1. Create a fake account at https://loinc.org (sad you have to create one...)
# 2. Download the CSV from https://loinc.org/download/loinc-table-file-csv/ (Loinc_2.67_Text_2.67.zip)
# 3. Read Loinc.csv that's in this zip file
loinc_df <- read.csv("data-raw/Loinc.csv",
row.names = NULL,
stringsAsFactors = FALSE)
# 4. Clean and add
library(dplyr)
library(cleaner)
library(AMR)
loinc_df %>% freq(CLASS) # to find the drugs
loinc_df <- loinc_df %>% filter(CLASS == "DRUG/TOX")
ab_names <- antibiotics %>% pull(name) %>% paste0(collapse = "|") %>% paste0("(", ., ")")
antibiotics$loinc <- as.list(rep(NA_character_, nrow(antibiotics)))
for (i in seq_len(nrow(antibiotics))) {
loinc_ab <- loinc_df %>%
filter(COMPONENT %like% paste0("^", antibiotics$name[i])) %>%
pull(LOINC_NUM)
if (length(loinc_ab) > 0) {
antibiotics$loinc[i] <- list(loinc_ab)
}
}
dim(antibiotics) # for R/data.R
usethis::use_data(antibiotics, overwrite = TRUE)
rm(antibiotics)

View File

@ -401,6 +401,8 @@ antibiotics <- antibiotics %>%
antibiotics <- as.data.frame(antibiotics, stringsAsFactors = FALSE)
class(antibiotics$ab) <- "ab"
# REFER TO data-raw/loinc.R FOR ADDING LOINC CODES
dim(antibiotics) # for R/data.R
usethis::use_data(antibiotics, overwrite = TRUE)
rm(antibiotics)

80
data-raw/snomed.R Normal file
View File

@ -0,0 +1,80 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# 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. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
library(AMR)
library(dplyr)
baseUrl <- 'https://browser.ihtsdotools.org/snowstorm/snomed-ct'
edition <- 'MAIN'
version <- '2019-07-31'
microorganisms.snomed <- data.frame(conceptid = character(0),
mo = character(0),
stringsAsFactors = FALSE)
microorganisms$snomed <- ""
# for (i in 1:50) {
for (i in 1:1000) {
if (i %% 10 == 0) {
cat(paste0(i, " - ", cleaner::percentage(i / nrow(microorganisms)), "\n"))
}
mo_data <- microorganisms %>%
filter(mo == microorganisms$mo[i]) %>%
as.list()
if (!mo_data$rank %in% c("genus", "species")) {
next
}
searchTerm <- paste0(
ifelse(mo_data$rank == "genus", "Genus ", ""),
mo_data$fullname,
" (organism)")
url <- paste0(baseUrl, '/browser/',
edition, '/',
version,
'/descriptions?term=', curl::curl_escape(searchTerm),
'&mode=fullText&activeFilter=true&limit=', 250)
results <- url %>%
httr::GET() %>%
httr::content(type = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE) %>%
.$items
if (NROW(results) == 0) {
next
} else {
message("Adding ", crayon::italic(mo_data$fullname))
}
tryCatch(
microorganisms$snomed[i] <- results %>% filter(term == searchTerm) %>% pull(concept.conceptId),
error = function(e) invisible()
)
if (nrow(results) > 1) {
microorganisms.snomed <- microorganisms.snomed %>%
bind_rows(tibble(conceptid = results %>% filter(term != searchTerm) %>% pull(concept.conceptId) %>% unique(),
mo = as.character(mo_data$mo)))
}
}