R/ancestry_split.R
read_bed_file.RdReads a PLINK binary genotype file (.bed/.bim/.fam
trio) into an integer matrix, for the case where local ancestry has been
encoded as PLINK genotype calls at ancestry-tract "SNPs" (as consumed by
src/step1_vcf_split_by_ancestry.R): homozygous first allele = pure
EUR/EUR (code 1), heterozygous = mixed AFR/EUR (code 2), homozygous
second allele = pure AFR/AFR (code 3), missing = no call (code 0). This
matches snpStats::read.plink()'s raw numeric convention (values
feed directly into split_diploid/ancestry_split_dosage
as pt_matrix/ancestry without snpStats as a
dependency.
read_bed_file(bed, bim, fam)Integer matrix (variants x samples), dimnamed from the
.bim/.fam files. Values: 0 = no call, 1 = homozygous
first allele, 2 = heterozygous, 3 = homozygous second allele.
ext <- system.file("extdata", package = "lantern")
pt <- read_bed_file(file.path(ext, "toy_ancestry.bed"),
file.path(ext, "toy_ancestry.bim"),
file.path(ext, "toy_ancestry.fam"))
pt[, 1:6] # ancestry tracts x samples, codes 1/2/3
#> S001 S002 S003 S004 S005 S006
#> chr19:1000000-4999999 3 3 3 3 2 2
#> chr19:5000000-8999999 3 2 3 2 3 3
#> chr19:10000000-13999999 3 3 3 3 3 3
#> chr19:15000000-18999999 3 3 2 3 3 3
#> chr19:30000000-33999999 1 3 2 2 3 2
#> chr19:35000000-38999999 3 2 2 3 2 2
#> chr19:40000000-43999999 2 2 2 2 2 3
#> chr19:45000000-48999999 3 3 2 3 3 3