Count the number of alleles for each locus in an HLA typing string
Source:R/extract_alleles.R
count_alleles.Rd
count_alleles()
takes in a character vector or string of HLA typings, and
returns the number of alleles that the string contains for each locus.
This can be useful when validating whether a typing string contains a typing for each locus. Also, this function can alert you when a typing string contains more than two alleles for each locus, which can be intentional (e.g. when the typing contains both the broad and the split) or a mistake.
Usage
count_alleles(
typings,
loci = c("A", "B", "C", "DPA1", "DPB1", "DQA1", "DQB1", "DRB1", "DRB.")
)
Value
A (list of) named integer vector(s), with the loci as names, and the number of found alleles per locus as values.
Examples
typing <- "A1 A2 B7 B8 Cw3 DQ5 DQ8 DR4 DR11 DR52 DR53"
count_alleles(typing, loci = "A")
#> A
#> 2
count_alleles(typing)
#> A B C DPA1 DPB1 DQA1 DQB1 DRB1 DRB.
#> 2 2 1 0 0 0 2 2 2
# Also works with character vectors
typing <- c("A1 A2 B7 B8 Cw3", "Cw3 Cw7", NA)
count_alleles(typing, loci = c("A", "B", "C"))
#> [[1]]
#> A B C
#> 2 2 1
#>
#> [[2]]
#> A B C
#> 0 0 2
#>
#> [[3]]
#> A B C
#> NA NA NA
#>