shorten_allele: Reduce HLA allele string to specified number of fields

Description Usage Arguments Value Examples

View source: R/munging.R

Description

Reduce a long HLA allele string (i.e. "01:02:01:03g") down to fewer fields, default being 2 fields. NMDP codes are preserved, trailing "G" are removed, NA or empty string input generates NA output, anything else is output as-is, cast as string. No input or output validation is done on the data to ensure it meets expected HLA allele string formats.

Usage

1
shorten_allele(allele, fields = 2)

Arguments

allele

String, including ":" but not initial "A*", so for example "01:02:01:03"

fields

Number of fields to keep, default = 2 which would return "01:02"

Value

character vector with shortened fields

Examples

1
2
3
4
5
dat <- data.frame(HLA_A1 = c("01:02:01:03", "03:ADJRE", "01:02:01:01G"), stringsAsFactors = FALSE)
shorten_allele(dat$HLA_A1)
shorten_allele(dat$HLA_A1, fields = 3)
dat2 <- data.frame(HLA_A1 = c("01:02:01:03", "03:ADJRE", NA, "some_random_string", 2, ""), stringsAsFactors = FALSE)
shorten_allele(dat2$HLA_A1)

bosefalk/CTUtools documentation built on Feb. 4, 2022, 4:10 p.m.