Skip to contents

reorder_alleles() takes in two length-2 character vectors of HLA alleles, and if they're not in the same order, reorders the 2nd to match the 1st. This can be useful when you have multiple sources of HLA typings for one individual that you're trying to match up.

Usage

reorder_alleles(in_order, to_order)

Arguments

in_order, to_order

A character vector of two HLA alleles of a certain locus. The order of to_order will be reversed, to match in_order, if necessary.

Value

A vector with the same alleles as to_order, possible reordered.

Details

If the vectors contain alleles in different nomenclatures / of different resolutions, the order is determined based on scaling down the resolution. First it tries to scale down to the 2-field level; if still all alleles differ from each other, it tries the serological split level, and finally the serological broad level.

Examples

reorder_alleles(in_order = c("A1", "A2"), to_order = c("A2", "A1"))
#> [1] "A1" "A2"
# can accommodate missing/homozygous typings
reorder_alleles(in_order = c("A1", NA), to_order = c("A2", "A1"))
#> [1] "A1" "A2"
# still works if the typings are in a different format/resolution
reorder_alleles(in_order = c("A1", "A2"), to_order = c("A*02:01", "A*01:01"))
#> [1] "A*01:01" "A*02:01"