recode_chromosome_codes

Convert chromosome codes between PLINK-style schemes

Description

Re-encodes one or more chromosome columns according to the export formats supported in PLINK 2.0: https://www.cog-genomics.org/plink/2.0/data#export

Usage

recode_chromosome_codes(
  df,
  chromosome.column = "chr",
  out_format = c("26", "M", "MT", "0M", "chr26", "chrM", "chrMT"),
  n_autosomes = 22
)

Arguments

df

A data.frame, tibble, or data.table containing chromosome column(s).

chromosome.column

Character vector; name(s) of column(s) in df to recode, e.g. “chr” or c(“chr”, “chr.lifted”).

out_format

Character; the chromosome coding scheme to output. Must be one of:

"26"

Always numeric (XY/PAR1/PAR2 → numeric code for XY)

"M"

Autosomal numeric; X/Y/M single; XY/PAR1/PAR2 unchanged

"MT"

Autosomal numeric; X/Y/MT two-character; XY/PAR1/PAR2 unchanged

"0M"

Autosomal numeric; 0X/0Y two-character; MT two-character; XY/PAR1/PAR2 unchanged

"chr26"

PAR1/PAR2 unchanged; all others "chr"+numeric code

"chrM"

PAR1/PAR2 unchanged; autosomes/X/Y/M prefixed "chr"; MT → "chrM"

"chrMT"

PAR1/PAR2 unchanged; all others "chr"+canonical label

n_autosomes

Integer number of autosomes. Default is 22.

Value

A copy of df with the specified chromosome column(s) recoded to out_format.