Skip to contents

df_to_gl() takes in a data frame with HLA typings, and summarizes these columns into a single column with GL Strings.

Usage

df_to_gl(
  df,
  namespace = "hla",
  version_or_date = NULL,
  col_typing = "glstring",
  loci = c("A", "B", "C", "DPA1", "DPB1", "DQA1", "DQB1", "DRB1", "DRB."),
  suffixes = c("1", "2"),
  sep = "_"
)

Arguments

df

A dataframe with HLA typings. The names of each HLA typing column should follow the format {locus}{sep}{suffix}, e.g. "A_1" or "DPB1_2".

namespace

Specification of the HLA nomenclature system. Defaults to "hla".

version_or_date

Specification of the version of the namespace used, or the date the GL String was constructed. If not specified, uses today's date as the default.

col_typing

The name for the new column with the GL Strings.

loci

A string or character vector with the loci you are interested in. Only these alleles will be returned. Defaults to all. DRB. is used for DRB3, DRB4, and DRB5.

suffixes

What differentiates the alleles for each locus (defaults to "1" and "2") in the column names.

sep

What separates the loci from the suffixes in the column names.

Value

A dataframe with the same amount of rows, but where the columns with typings of individual alleles have been replaced with a single GL String.

See also

Examples

# Make a dataframe following the default naming scheme, with two typings
df_in <- tidyr::tibble(
  id = c("001", "002"),
  A_1 = c("A*01:01", "A*03:01"),
  A_2 = c(NA, "A*02:01"),
  B_1 = c("B*07:01", "B*07:02"),
  B_2 = c("B*08:01", "B*08:02"),
  C_1 = c("C*01:01", "C*01:02"),
  C_2 = c("C*03:04", NA)
)
df_in |>
  dplyr::group_by(id) |> # make one GL string for each typing
  df_to_gl()
#> # A tibble: 2 × 2
#>   id    glstring                                                                
#>   <chr> <chr>                                                                   
#> 1 001   hla#2024-12-22#HLA-A*01:01^HLA-B*07:01+HLA-B*08:01^HLA-C*01:01+HLA-C*03…
#> 2 002   hla#2024-12-22#HLA-A*02:01+HLA-A*03:01^HLA-B*07:02+HLA-B*08:02^HLA-C*01…