Skip to content
Merged

Dev #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.2.0
Date: 2025-06-06 21:26:53 UTC
SHA: c390a4e79f8ddb3662434d8d4b0e392823443bde
Version: 0.3.0
Date: 2025-06-18 18:26:10 UTC
SHA: 60df41e16cdb635e51b16ff67f857af50e11e0b2
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: immunogenetr
Title: A Comprehensive Toolkit for Clinical HLA Informatics
Version: 0.3.0
Version: 0.3.1
Authors@R: c(
person("Nicholas", "Brown", , "nicholas.brown@pennmedicine.upenn.edu", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-0046-2315")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# immunogenetr 0.3.1

* Updated `HLA_columns_to_GLstring` to fix issues processing DRB3/4/5 alleles.

# immunogenetr 0.3.0

* Updated `ambiguity_table_to_GLstring` to remove duplicate entries from an ambiguity table as it is being processed to a GL string. Added this functionality to `HLA_truncate` so that truncated GL strings could optionally remove duplicates. Added `GLstring_to_ambiguity_table` as an alias for `GL_string_expand_longer`.
Expand Down
25 changes: 16 additions & 9 deletions R/HLA_columns_to_GLstring.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,20 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =
# Remove prefixes and suffixes from column names
mutate(
truncated_names = str_replace(names, prefix_regex, ""),
truncated_names = str_replace(truncated_names, suffix_regex, "")
truncated_names = str_replace(truncated_names, suffix_regex, ""),
truncated_names = HLA_prefix_remove(truncated_names, keep_locus = TRUE)
) %>%
# Use the HLA_validate function to clean up the typing
mutate(allele = HLA_validate(allele)) %>%
mutate(
DRB_locus_raw = case_when(
# When the allele starts with “DRB3*”, “DRB4*” or “DRB5*”
str_detect(allele, regex("DRB[345]\\*", ignore_case = TRUE)) ~ str_c("HLA-DRB", str_extract(allele, "(?<=DRB)[345]")),
# When the allele does not have a "DRB" prefix, instead only has a number prefix
str_detect(allele, regex("^[345]\\*", ignore_case = TRUE)) ~ str_c("HLA-DRB", str_extract(allele, "^[345]")),
TRUE ~ NA_character_
)
) %>%
# Remove any prefixes in alleles
mutate(allele = HLA_prefix_remove(allele)) %>%
# Determine locus name using extended logic
Expand All @@ -111,6 +121,7 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =
str_detect(truncated_names, regex("^Cw[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-Cw", # Handle Cw locus
str_detect(truncated_names, regex("^C[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-C", # Handle C locus
str_detect(truncated_names, regex("^DRB1[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-DRB1", # Handle molecular DRB1 locus
str_detect(truncated_names, regex("^DRB345", ignore_case = TRUE)) ~ "HLA-DRB345", # Handle column with molecular DRB3/4/5 loci
str_detect(truncated_names, regex("^DRB3[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-DRB3", # Handle molecular DRB3 locus
str_detect(truncated_names, regex("^DRB4[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-DRB4", # Handle molecular DRB4 locus
str_detect(truncated_names, regex("^DRB5[:digit:]?\\*?", ignore_case = TRUE)) ~ "HLA-DRB5", # Handle molecular DRB5 locus
Expand Down Expand Up @@ -138,11 +149,7 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =
# Determine if the DR typing is one of the DR51/52/53 loci
mutate(DRB345 = if_else(str_detect(allele, "^5") & locus_from_name == "HLA-DR", TRUE, FALSE)) %>%
# Handle the final locus name for high-resolution DRB alleles
mutate(DRB_locus = if_else(
str_detect(locus_from_name, "DRB"), str_c("HLA-DRB", str_extract(allele, "[1345](?=\\*)")), NA_character_
)) %>%
# Determine the final molecular locus name
mutate(molecular_locus = coalesce(DRB_locus, locus_from_name)) %>%
mutate(molecular_locus = coalesce(DRB_locus_raw, locus_from_name)) %>%
# Record "XX" if there is no typing at any of the selected loci.
mutate(allele = if (all(is.na(allele))) "XX" else allele, .by = c(row_for_function, molecular_locus)) %>%
# Remove any blank values
Expand All @@ -159,7 +166,7 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =

if (nrow(error_table) != 0) {
# Print the columns that caused the error to assist in debugging
abort(format_error(glue::glue("The column(s) {paste(error_column_names, collapse = ', ')} could not be parsed to determine HLA loci.")))
rlang::abort(cli::format_error(glue::glue("The column(s) {paste(error_column_names, collapse = ', ')} could not be parsed to determine HLA loci.")))
}

# Assemble the final type
Expand All @@ -170,7 +177,7 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =
str_glue("{serologic_name}{allele}")
)) %>%
# Group alleles within the same locus
summarise(final_type_2 = str_flatten(final_type, collapse = "+"), .by = c(row_for_function, locus_from_name, DRB345)) %>%
summarise(final_type_2 = str_flatten(final_type, collapse = "+"), .by = c(row_for_function, molecular_locus, DRB345)) %>%
# Assemble GL string with each locus separated by "^"
summarise(GL_string = str_flatten(final_type_2, collapse = "^"), .by = row_for_function)

Expand All @@ -181,5 +188,5 @@ HLA_columns_to_GLstring <- function(data, HLA_typing_columns, prefix_to_remove =
globalVariables(c(
".", "truncated_names", "locus_from_name", "DRB_locus",
"row_for_function", "molecular_locus", "molecular",
"final_type", "DRB345", "final_type_2", "GL_string"
"final_type", "DRB345", "final_type_2", "GL_string", "DRB_locus_raw"
))
3 changes: 1 addition & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

0 errors ✔ | 0 warnings ✔ | 0 notes ✔

* Updated `ambiguity_table_to_GLstring` to remove duplicate entries from an ambiguity table as it is being processed to a GL string. Added this functionality to `HLA_truncate` so that truncated GL strings could optionally remove duplicates. Added `GLstring_to_ambiguity_table` as an alias for `GL_string_expand_longer`.

* Updated `HLA_columns_to_GLstring` to fix issues processing DRB3/4/5 alleles.
97 changes: 97 additions & 0 deletions tests/testthat/test-HLA_columns_to_GLstring.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,101 @@ test_that("HLA_columns_to_GLstring correctly converts HLA columns into a GL stri
expect_true("HLA-A*01:01+HLA-A*11:01^HLA-B*07:02+HLA-B*44:02^HLA-C*03:04+HLA-C*07:01" %in% result)
expect_true("HLA-A*02:01^HLA-B*08:01+HLA-B*40:01^HLA-C*04:01+HLA-C*07:02" %in% result)
expect_true("HLA-A*03:01+HLA-A*26:01^HLA-B*15:01^HLA-C*05:01+HLA-C*08:01" %in% result)

test_1 <- HLA_columns_to_GLstring(HLA_typing_1, c(A1:DPB1_2))
result_1 <- c("HLA-A*24:02+HLA-A*29:02^HLA-C*07:04+HLA-C*16:01^HLA-B*44:02+HLA-B*44:03^HLA-DRB5*01:01+HLA-DRB5*01:01^HLA-DRB1*15:01+HLA-DRB1*15:01^HLA-DQA1*01:02+HLA-DQA1*01:02^HLA-DQB1*06:02+HLA-DQB1*06:02^HLA-DPA1*01:03+HLA-DPA1*01:03^HLA-DPB1*03:01+HLA-DPB1*04:01", "HLA-A*02:01+HLA-A*11:05^HLA-C*07:01+HLA-C*07:02^HLA-B*07:02+HLA-B*08:01^HLA-DRB3*01:01^HLA-DRB4*01:03^HLA-DRB1*03:01+HLA-DRB1*04:01^HLA-DQA1*03:03+HLA-DQA1*05:01^HLA-DQB1*02:01+HLA-DQB1*03:01^HLA-DPA1*01:03+HLA-DPA1*01:03^HLA-DPB1*04:01+HLA-DPB1*04:01", "HLA-A*02:01+HLA-A*26:18^HLA-C*02:02+HLA-C*03:04^HLA-B*27:05+HLA-B*54:01^HLA-DRB3*02:02^HLA-DRB4*01:03^HLA-DRB1*04:04+HLA-DRB1*14:54^HLA-DQA1*01:04+HLA-DQA1*03:01^HLA-DQB1*03:02+HLA-DQB1*05:02^HLA-DPA1*01:03+HLA-DPA1*02:02^HLA-DPB1*02:01+HLA-DPB1*05:01", "HLA-A*29:02+HLA-A*30:02^HLA-C*06:02+HLA-C*07:01^HLA-B*08:01+HLA-B*13:02^HLA-DRB4*01:03+HLA-DRB4*01:03^HLA-DRB1*04:01+HLA-DRB1*07:01^HLA-DQA1*02:01+HLA-DQA1*03:01^HLA-DQB1*02:02+HLA-DQB1*03:02^HLA-DPA1*01:03+HLA-DPA1*02:01^HLA-DPB1*01:01+HLA-DPB1*16:01", "HLA-A*02:05+HLA-A*24:02^HLA-C*07:18+HLA-C*12:03^HLA-B*35:03+HLA-B*58:01^HLA-DRB3*02:02+HLA-DRB3*02:02^HLA-DRB1*03:01+HLA-DRB1*14:54^HLA-DQA1*01:04+HLA-DQA1*05:01^HLA-DQB1*02:01+HLA-DQB1*05:03^HLA-DPA1*01:03+HLA-DPA1*02:01^HLA-DPB1*10:01+HLA-DPB1*124:01", "HLA-A*01:01+HLA-A*24:02^HLA-C*07:01+HLA-C*14:02^HLA-B*49:01+HLA-B*51:01^HLA-DRB3*03:01^HLA-DRB1*08:01+HLA-DRB1*13:02^HLA-DQA1*01:02+HLA-DQA1*04:01^HLA-DQB1*04:02+HLA-DQB1*06:04^HLA-DPA1*01:03+HLA-DPA1*01:04^HLA-DPB1*04:01+HLA-DPB1*15:01", "HLA-A*03:01+HLA-A*03:01^HLA-C*03:03+HLA-C*16:01^HLA-B*15:01+HLA-B*51:01^HLA-DRB4*01:01^HLA-DRB1*01:01+HLA-DRB1*07:01^HLA-DQA1*01:01+HLA-DQA1*02:01^HLA-DQB1*02:02+HLA-DQB1*05:01^HLA-DPA1*01:03+HLA-DPA1*01:03^HLA-DPB1*04:01+HLA-DPB1*04:01", "HLA-A*01:01+HLA-A*32:01^HLA-C*06:02+HLA-C*07:02^HLA-B*08:01+HLA-B*37:01^HLA-DRB3*02:02^HLA-DRB5*01:01^HLA-DRB1*03:01+HLA-DRB1*15:01^HLA-DQA1*01:02+HLA-DQA1*05:01^HLA-DQB1*02:01+HLA-DQB1*06:02^HLA-DPA1*01:03+HLA-DPA1*02:01^HLA-DPB1*04:01+HLA-DPB1*14:01", "HLA-A*03:01+HLA-A*30:01^HLA-C*07:02+HLA-C*12:03^HLA-B*07:02+HLA-B*38:01^HLA-DRB3*01:01^HLA-DRB5*01:01^HLA-DRB1*03:01+HLA-DRB1*15:01^HLA-DQA1*01:02+HLA-DQA1*05:01^HLA-DQB1*02:01+HLA-DQB1*06:02^HLA-DPA1*01:03+HLA-DPA1*01:03^HLA-DPB1*04:01+HLA-DPB1*04:01", "HLA-A*02:05+HLA-A*11:01^HLA-C*07:18+HLA-C*16:02^HLA-B*51:01+HLA-B*58:01^HLA-DRB3*03:01^HLA-DRB5*01:01^HLA-DRB1*13:02+HLA-DRB1*15:01^HLA-DQA1*01:02+HLA-DQA1*01:03^HLA-DQB1*06:01+HLA-DQB1*06:09^HLA-DPA1*01:03+HLA-DPA1*01:03^HLA-DPB1*02:01+HLA-DPB1*104:01")
expect_equal(test_1, result_1)

test_LIS <- HLA_columns_to_GLstring(HLA_typing_LIS, c(mA1Cd.recipient:mDPB12cd.recipient), prefix_to_remove = "m", suffix_to_remove = "cd.recipient")
result_LIS <- c("HLA-A*24:02+HLA-A*02:01^HLA-B*40:02+HLA-B*40:01^HLA-C*03:04^HLA-DRB1*10:01+HLA-DRB1*15:01^HLA-DRB5*01:01^HLA-DQA1*01:05+HLA-DQA1*01:02^HLA-DQB1*05:01+HLA-DQB1*06:02^HLA-DPA1*01:03^HLA-DPB1*02:01+HLA-DPB1*04:01", "HLA-A*03:01+HLA-A*74:01^HLA-B*53:01+HLA-B*57:03^HLA-C*04:01+HLA-C*07:01^HLA-DRB1*11:01+HLA-DRB1*16:02^HLA-DRB3*02:02^HLA-DRB5*02:21^HLA-DQA1*01:02+HLA-DQA1*05:05^HLA-DQB1*03:19+HLA-DQB1*05:02^HLA-DPA1*02:01+HLA-DPA1*02:02^HLA-DPB1*01:01", "HLA-A*11:01+HLA-A*32:01^HLA-B*52:01^HLA-C*12:02^HLA-DRB1*15:02^HLA-DRB5*01:02^HLA-DQA1*01:03^HLA-DQB1*06:01^HLA-DPA1*01:03+HLA-DPA1*02:07^HLA-DPB1*02:01+HLA-DPB1*04:01", "HLA-A*03:01+HLA-A*30:02^HLA-B*14:02^HLA-C*08:02^HLA-DRB1*01:02+HLA-DRB1*13:02^HLA-DRB3*03:01^HLA-DQA1*01:01+HLA-DQA1*01:02^HLA-DQB1*05:01+HLA-DQB1*06:09^HLA-DPA1*02:01^HLA-DPB1*05:01+HLA-DPB1*17:01", "HLA-A*01:01+HLA-A*24:02^HLA-B*07:02^HLA-C*07:02^HLA-DRB1*01:01+HLA-DRB1*15:01^HLA-DRB5*01:01^HLA-DQA1*01:01+HLA-DQA1*01:02^HLA-DQB1*05:01+HLA-DQB1*06:02^HLA-DPA1*01:03+HLA-DPA1*02:01^HLA-DPB1*04:01+HLA-DPB1*11:01", "HLA-A*02:01+HLA-A*30:02^HLA-B*39:11+HLA-B*41:01^HLA-C*07:02+HLA-C*17:01^HLA-DRB1*03:01+HLA-DRB1*04:05^HLA-DRB3*02:02^HLA-DRB4*01:03^HLA-DQA1*05:01+HLA-DQA1*03:03^HLA-DQB1*02:01+HLA-DQB1*02:02^HLA-DPA1*01:03^HLA-DPB1*02:01+HLA-DPB1*04:01", "HLA-A*02:17+HLA-A*32:01^HLA-B*40:02^HLA-C*02:02+HLA-C*03:05^HLA-DRB1*04:11+HLA-DRB1*13:01^HLA-DRB3*02:02^HLA-DRB4*01:03^HLA-DQA1*03:01+HLA-DQA1*01:03^HLA-DQB1*03:02+HLA-DQB1*06:03^HLA-DPA1*01:03^HLA-DPB1*04:02", "HLA-A*11:01+HLA-A*23:01^HLA-B*15:17+HLA-B*44:03^HLA-C*07:01+HLA-C*16:01^HLA-DRB1*07:01^HLA-DRB4*01:01+HLA-DRB4*01:03^HLA-DQA1*02:01^HLA-DQB1*02:02^HLA-DPA1*01:03+HLA-DPA1*02:01^HLA-DPB1*04:01+HLA-DPB1*11:01", "HLA-A*03:01+HLA-A*68:02^HLA-B*08:01+HLA-B*15:03^HLA-C*02:10+HLA-C*03:04^HLA-DRB1*13:04+HLA-DRB1*07:01^HLA-DRB3*02:02^HLA-DRB4*01:03^HLA-DQA1*02:01+HLA-DQA1*05:05^HLA-DQB1*02:02+HLA-DQB1*03:19^HLA-DPA1*01:03+HLA-DPA1*02:02^HLA-DPB1*01:01+HLA-DPB1*02:01", "HLA-A*01:01+HLA-A*02:01^HLA-B*08:01+HLA-B*07:02^HLA-C*07:01+HLA-C*05:01^HLA-DRB1*03:01+HLA-DRB1*04:01^HLA-DRB3*01:01^HLA-DRB4*01:03^HLA-DQA1*05:01+HLA-DQA1*03:03^HLA-DQB1*02:01+HLA-DQB1*03:01^HLA-DPA1*01:03^HLA-DPB1*04:01+HLA-DPB1*06:01")
expect_equal(test_LIS, result_LIS)

test_freq <- HLA_columns_to_GLstring(Haplotype_frequencies, c("HLA-A":"HLA-DPB1"))
result_freq <- c("HLA-A*24:02:01:01^HLA-C*03:04:01:01^HLA-B*40:01:02^HLA-DRB1*08:01:01^HLA-DQA1*04:01:01^HLA-DQB1*04:02:01^HLA-DPA1*01:03:01:04^HLA-DPB1*04:01:01:01", "HLA-A*03:01:01:05^HLA-C*06:02:01:01^HLA-B*47:01:01:03^HLA-DRB4*01:01:01:01^HLA-DRB1*07:01:01:01^HLA-DQA1*02:01:01:01^HLA-DQB1*02:02:01:01^HLA-DPA1*01:03:01:03^HLA-DPB1*06:01:01", "HLA-A*02:01:01:01^HLA-C*05:01:01:02^HLA-B*44:02:01:01^HLA-DRB3*01:01:02:01^HLA-DRB1*03:01:01:01^HLA-DQA1*05:01:01:02^HLA-DQB1*02:01:01^HLA-DPA1*01:03:01:01^HLA-DPB1*02:01:02", "HLA-A*32:01:01^HLA-C*02:02:02:01^HLA-B*40:02:01^HLA-DRB3*02:02:01:02^HLA-DRB1*11:01:01:01^HLA-DQA1*05:05:01:01^HLA-DQB1*03:01:01:03^HLA-DPA1*01:03:01:01^HLA-DPB1*02:01:02", "HLA-A*02:01:01:01^HLA-C*05:01:01:02^HLA-B*44:02:01:01^HLA-DRB5*01:01:01^HLA-DRB1*15:01:01:01^HLA-DQA1*01:02:01:01^HLA-DQB1*06:02:01^HLA-DPA1*01:03:01:02^HLA-DPB1*04:01:01:01", "HLA-A*02:01:01:01^HLA-C*05:01:01:02^HLA-B*44:02:01:01^HLA-DRB4*01:03:01:01^HLA-DRB1*04:01:01:01^HLA-DQA1*03:03:01:01^HLA-DQB1*03:01:01:01^HLA-DPA1*01:03:01:05^HLA-DPB1*04:02:01:02", "HLA-A*02:06:01:01^HLA-C*08:01:01^HLA-B*40:06:01:01^HLA-DRB4*01:03:02^HLA-DRB1*09:01:02^HLA-DQA1*03:02^HLA-DQB1*03:03:02:02^HLA-DPA1*02:01:01:02^HLA-DPB1*09:01:01", "HLA-A*24:02:01:01^HLA-C*07:02:01:01^HLA-B*39:05:01^HLA-DRB5*02:02^HLA-DRB1*16:02:01:02^HLA-DQA1*05:05:01:05^HLA-DQB1*03:01:01:01^HLA-DPA1*01:03:01:05^HLA-DPB1*04:02:01:02", "HLA-A*02:01:01:01^HLA-C*02:02:02:01^HLA-B*40:02:01^HLA-DRB3*02:02:01:02^HLA-DRB1*13:01:01:01^HLA-DQA1*01:03:01:02^HLA-DQB1*06:03:01^HLA-DPA1*01:03:01:01^HLA-DPB1*02:01:02", "HLA-A*24:02:01:01^HLA-C*07:04:01:01^HLA-B*44:02:01:03^HLA-DRB3*02:02:01:02^HLA-DRB1*11:01:01:01^HLA-DQA1*05:05:01:01^HLA-DQB1*03:01:01:03^HLA-DPA1*01:03:01:01^HLA-DPB1*02:01:02")
expect_equal(test_freq, result_freq)


test_separate_DRB_no_prefixes <- tibble(
patient = c("patient1", "patient2", "patient3"),
DRB3_1 = c("03:01", NA, "03:03"),
DRB4_1 = c(NA, "04:02", NA),
DRB5_1 = c(NA, NA, "05:03")
)
result_separate_no_prefixes <- test_separate_DRB_no_prefixes %>%
mutate(GL = HLA_columns_to_GLstring(., HLA_typing_columns = DRB3_1:DRB5_1)) %>%
pull(GL)
expect_equal(
result_separate_no_prefixes,
c("HLA-DRB3*03:01", "HLA-DRB4*04:02", "HLA-DRB3*03:03^HLA-DRB5*05:03")
)

test_separate_DRB_numeric_only <- tibble(
patient = c("patient1", "patient2", "patient3"),
DRB3_1 = c("3*03:01", NA, "3*03:03"),
DRB4_1 = c(NA, "4*04:02", NA),
DRB5_1 = c(NA, NA, "5*05:03")
)
result_separate_numeric_only <- test_separate_DRB_numeric_only %>%
mutate(GL = HLA_columns_to_GLstring(., HLA_typing_columns = DRB3_1:DRB5_1)) %>%
pull(GL)
expect_equal(
result_separate_numeric_only,
c("HLA-DRB3*03:01", "HLA-DRB4*04:02", "HLA-DRB3*03:03^HLA-DRB5*05:03")
)

test_separate_DRB_full_prefix <- tibble(
patient = c("patient1", "patient2", "patient3"),
DRB3_1 = c("DRB3*03:01", NA, "DRB3*03:03"),
DRB4_1 = c(NA, "DRB4*04:02", NA),
DRB5_1 = c(NA, NA, "DRB5*05:03")
)
result_separate_full_prefix <- test_separate_DRB_full_prefix %>%
mutate(GL = HLA_columns_to_GLstring(., HLA_typing_columns = DRB3_1:DRB5_1)) %>%
pull(GL)
expect_equal(
result_separate_full_prefix,
c("HLA-DRB3*03:01", "HLA-DRB4*04:02", "HLA-DRB3*03:03^HLA-DRB5*05:03")
)

test_mixed_DRB_with_prefixes <- tibble(
patient = c("patient1", "patient2", "patient3"),
DRB345_1 = c("DRB3*01:01", "DRB4*04:01", "DRB5*05:01"),
DRB345_2 = c("DRB4*01:01", "DRB5*04:01", "DRB5*05:02")
)
result_mixed_with_prefixes <- test_mixed_DRB_with_prefixes %>%
mutate(GL = HLA_columns_to_GLstring(., HLA_typing_columns = DRB345_1:DRB345_2)) %>%
pull(GL)
expect_equal(
result_mixed_with_prefixes,
c(
"HLA-DRB3*01:01^HLA-DRB4*01:01", "HLA-DRB4*04:01^HLA-DRB5*04:01",
"HLA-DRB5*05:01+HLA-DRB5*05:02"
)
)

test_mixed_DRB_no_prefixes <- tibble(
patient = c("patient1", "patient2", "patient3"),
DRB345_1 = c("3*01:01", "4*04:01", "5*05:01")
)
result_mixed_no_prefixes <- test_mixed_DRB_no_prefixes %>%
mutate(GL = HLA_columns_to_GLstring(., HLA_typing_columns = DRB345_1)) %>%
pull(GL)
expect_equal(
result_mixed_no_prefixes,
c("HLA-DRB3*01:01", "HLA-DRB4*04:01", "HLA-DRB5*05:01")
)

test_sero <- tibble(
patient = c("patient1", "patient2", "patient3"),
A_1 = c("2", "3", "68"),
A_2 = c("", "1", "69"),
DR_1 = c("7", 4, "9"),
DR_2 = c("6", "4", NA),
DRw_1 = c(NA, NA, "52"),
DRw_2 = c("51", "52", "53")
)

test_sero_code <- test_sero %>% HLA_columns_to_GLstring(HLA_typing_columns = A_1:DRw_2)
test_sero_result <- c("HLA-A2^HLA-DR7+HLA-DR6^HLA-DR51", "HLA-A3+HLA-A1^HLA-DR4+HLA-DR4^HLA-DR52", "HLA-A68+HLA-A69^HLA-DR9^HLA-DR52+HLA-DR53")
expect_equal(test_sero_code, test_sero_result)
})