Skip to contents

reduce_to_nth_field() takes in a string or character vector of HLA alleles, and reduces their resolution to the specified number of fields.

Usage

reduce_to_nth_field(allele, n)

Arguments

allele

A string or character vector with (an) HLA allele(s).

n

An integer. Can technically be anything, but the function will normally only do something with integers between 1 and 3, as these are the only possible number of fields in the current nomenclature (4 fields is the maximum and therefore cannot be further reduced).

Value

A string or character vector of the same length as allele, with the truncated alleles in each element. Alleles already at the desired level of resolution will be returned unchanged.

Details

N.B. This does not do a "proper" reduction, but simply truncates the string to the last field delimiter (":"). It does not take into account G or P groups, nor null/alternatively expressed alleles. These cannot be simply be reduced to a lower field, but reduce_to_nth_field() simply strips off these suffixes and does it anyway.

Examples

reduce_to_nth_field("B*07:14:01", 2)
#> [1] "B*07:14"

# These won't do anything, as the resolution is equal to `n`:
reduce_to_nth_field("A2", 1)
#> [1] "A2"
reduce_to_nth_field("B*07:14:01", 3)
#> [1] "B*07:14:01"

allele_vec <- c("A*01:AABJE", "B*42:08", "C*01:02:01:26")
reduce_to_nth_field(allele_vec, 1)
#> [1] "A*01" "B*42" "C*01"