Skip to content

Commit

Permalink
Always replace Cw with C in molecular typings
Browse files Browse the repository at this point in the history
  • Loading branch information
lcreteig committed Dec 23, 2024
1 parent c489d28 commit 8864c15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 8 additions & 9 deletions R/clean_hla.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,14 @@ convert_v2_to_v3 <- function(allele) {
# replace v2 with v3 from lookup table
v3s <- ifelse(is_v2(allele), unname(lookup_v3[allele]), allele)
# if not in table
ifelse(is.na(v3s),
stringr::str_replace_all(
allele,
c(
"Cw" = "C", # replace Cw with C
# insert ":" after every 2 digits if followed by 2 digits/letters
r"((\d{2})(?=\d{2}|[A-Z]{2}))" = "\\1:"
)
),
v3s <- ifelse(is.na(v3s),
# insert ":" after every 2 digits if followed by 2 digits/letters
stringr::str_replace_all(allele, r"((\d{2})(?=\d{2}|[A-Z]{2}))", "\\1:"),
v3s
)
# replace all remaining "Cw" with "C", unless it's a serological typing
ifelse(!is.na(v3s) & stringr::str_detect(v3s, "Cw") & !is_serology(v3s),
stringr::str_replace_all(v3s, "Cw", "C"),
v3s
)
}
1 change: 1 addition & 0 deletions tests/testthat/test-clean_hla.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ test_that("v2 heuristic conversion works", {
expect_equal(convert_v2_to_v3("A*02113N"), "A*02:113N")
# Cw is C
expect_equal(convert_v2_to_v3("Cw*0202"), "C*02:02")
expect_equal(convert_v2_to_v3("Cw*02:02"), "C*02:02")
})

test_that("MAC and XX codes work", {
Expand Down

0 comments on commit 8864c15

Please sign in to comment.