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.
Path to the .bed file.
Path to the .bim file (variant IDs are taken from
column 2). Defaults to bed with its extension replaced by
.bim, the usual PLINK file set layout.
Path to the .fam file (sample IDs are taken from
column 2, i.e. IID). Defaults to bed with its extension replaced
by .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")
# .bim and .fam are found next to the .bed file
pt <- read_bed_file(file.path(ext, "toy_ancestry.bed"))
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