# To understand how the function works we can see how it alters the allele "HLA-A*02:01":
GLstring_regex("HLA-A*02:01")
# The result is the same allele with extra formatting to escape special characters found
# in a GL string, as well as the ability to accurately search for an allele in a GL string.
# For example, we would not want the allele "HLA-A*02:14" to match to "HLA-A*02:149:01",
# which would happen if we simply escaped the special characters:
library(stringr)
str_view("HLA-A*02:149:01", str_escape("HLA-A*02:14"), match = NA)
# Using `GLstring_regex` prevents this:
str_view("HLA-A*02:149:01", GLstring_regex("HLA-A*02:14"), match = NA)
# Using a longer GL string with multiple alleles and loci:
GL_string <- "HLA-A*02:01:01+HLA-A*68:01^HLA-B*07:01+HLA-B*15:01"
# We can match any allele accurately:
str_view(GL_string, GLstring_regex("HLA-A*68:01"), match = NA)
# Note that alleles supplied with fewer fields than in the GL string will also match:
str_view(GL_string, GLstring_regex("HLA-A*02:01"), match = NA)
Run the code above in your browser using DataLab