Skip to contents

Converts a validated long-format marker genotype table (see checkMarkerGenotypeFile) into a wide id x locus character matrix, the input shape markerKinship consumes.

Usage

buildMarkerGenotypeMatrix(genotype)

Arguments

genotype

dataframe with long-format marker genotype data, as returned by checkMarkerGenotypeFile: columns id, locus, allele1, allele2.

Value

A character matrix with one row per unique id and one column per unique locus. Each cell holds that individual's two alleles at that locus, sorted alphabetically and joined by "/" (e.g. "A/B"), or NA when that individual has no genotype record at that locus.

Details

Row and column order follow first appearance in genotype, not a string sort – a string sort would place "L10" before "L2" for any panel with more than nine loci, silently scrambling locus order.

Examples

library(nprcgenekeepr)
markerGenotype <- data.frame(
  id = c("A", "A", "B", "B"),
  locus = c("L1", "L2", "L1", "L2"),
  allele1 = c("A", "A", "A", "A"),
  allele2 = c("A", "B", "B", "B"),
  stringsAsFactors = FALSE
)
buildMarkerGenotypeMatrix(markerGenotype)
#>   L1    L2   
#> A "A/A" "A/B"
#> B "A/B" "A/B"