Phased diploid genotypes (read with phased = TRUE in gen_tibble()) are
stored in the same file backed matrix (a bigstatsr::FBM.code256) as
unphased ones, using one byte per genotype:
Format
code_phased is a numeric vector of length 256. phased_bytes is
an integer matrix with 256 rows (bytes 0 to 255) and two columns (hap1
and hap2).
Details
| byte | genotype | dosage (code256) |
| 0 | 0|0 | 0 |
| 1 | 0|1 | 1 |
| 2 | 1|1 | 2 |
| 3 | missing | NA |
| 4 | 1|0 | 1 |
Bytes 0 to 3 have the same meaning as in unphased diploid data (where byte 3
is the missing value), so that code that reads or writes the raw bytes keeps
working; only the second orientation of a heterozygote (1|0) uses a new
byte. The code256 of the matrix, code_phased, translates each byte into
a dosage, so that all functions that decode genotypes through code256 see
phased data as ordinary unphased dosages. code_phased is also how phased
data are recognised (is_phased()): it differs from the codes used for
unphased (bigsnpr::CODE_012), imputed (bigsnpr::CODE_IMPUTE_PRED) and
dosage (bigsnpr::CODE_DOSAGE) data, as it is the only one that decodes
byte 4 as 1.
phased_bytes gives, for each byte, the alleles carried by the first and
second haplotype of an individual (NA for missing, and for bytes that are
not used).
