Skip to contents

The function converts a VCF genotype matrix (with format "0/0", "0/1", "1/1") to allele dosage values (0, 1, 2) representing the count of the alternative allele. Mostly used within the package. Check out the more flexible convert_to_dosage_flex which works for polyploids.

Usage

convert_to_dosage(GT)

Arguments

GT

A character matrix where each entry represents a genotype in VCF format ("0/0", "0/1", "1/1").

Value

A numeric matrix of the same dimensions as GT, where each value represents the dosage of the alternate allele (0, 1, or 2).

Details

  • Converts the alleles to numeric values and sums them to compute the alternate allele dosage.

  • Retains the original row and column names from the input matrix.

Examples

# Example genotype matrix in VCF format
vcf_matrix <- matrix(c("0/0", "0/1", "1/1",
                       "0/1", "0/0", "1/1"),
                     nrow = 2, ncol = 3,
                     dimnames = list(c("Marker1", "Marker2"),
                                     c("Ind1", "Ind2", "Ind3")))

# Convert to dosage
dosage_matrix <- convert_to_dosage(vcf_matrix)
print(dosage_matrix)
#>         Ind1 Ind2 Ind3
#> Marker1    0    2    0
#> Marker2    1    1    2