fsfhap is a native port of TASSEL’s
FSFHap (Swarts et al. 2014). Unlike the per-line
callers, it pools each full-sib family: the scattered
introgressions across the family’s lines collectively phase the donor
haplotype, then a 5-state Viterbi-training EM imputes and smooths each
line. It is bit-exact vs TASSEL on its intended populations (backcross
and RIL/inbred). It needs two things the per-line callers don’t: a
called genotype g, and a family
grouping.
Input: HapMap + pedigree
FSFHap’s native inputs are a TASSEL HapMap and a
7-column pedigree. read_hapmap() and
read_pedigree() normalise them to the engine’s canonical
tables. Here we write tiny example files to demonstrate the readers (in
practice you point them at your files):
hmp <- tempfile(fileext = ".hmp.txt")
writeLines(c(
"rs#\talleles\tchrom\tpos\tstrand\tassembly#\tcenter\tprotLSID\tassayLSID\tpanelLSID\tQCcode\tB1_L1\tB1_L2",
"m1\tA/C\t1\t100\t+\tNA\tNA\tNA\tNA\tNA\tNA\tA\tC",
"m2\tA/C\t1\t200\t+\tNA\tNA\tNA\tNA\tNA\tNA\tM\tA"), hmp)
read_hapmap(hmp) # -> name, chr, pos, g (g in {0 A-hom, 1 het, 2 C-hom, 3 NA})
#> name chr pos g
#> 1 B1_L1 1 100 0
#> 2 B1_L1 1 200 1
#> 3 B1_L2 1 100 2
#> 4 B1_L2 1 200 0
# pedigree: family B1 = recurrent parent A x donor B1 (contribution 0.75 / 0.25)
ped_file <- tempfile()
writeLines(c("family\ttaxon\tparent1\tparent2\tp1\tp2\tF",
"B1\tB1_L1\tA\tB1\t0.75\t0.25\t0.9375",
"B1\tB1_L2\tA\tB1\t0.75\t0.25\t0.9375"), ped_file)
read_pedigree(ped_file) # -> taxon, family, parents, contribution1/2, F
#> taxon family parent1 parent2 contribution1 contribution2 F
#> 1 B1_L1 B1 A B1 0.75 0.25 0.9375
#> 2 B1_L2 B1 A B1 0.75 0.25 0.9375You attach the family grouping by joining on the taxon name:
data <- read_hapmap("family.hmp.txt")
ped <- read_pedigree("family_pedigree.txt")
data$family <- ped$family[match(data$name, ped$taxon)]
stopifnot(!anyNA(data$family)) # every sample must be in the pedigreeDesign routing derives phet
Pass a design token (BC{n}S{m}); the
dispatcher selects the parent-calling route and derives the
expected heterozygosity phet = (1 - F)/2 from the
design’s inbreeding coefficient — no magic constant. BC1S4 (the TeoNAM
design) gives F = 0.9375, so phet = 0.03125.
fsfhap supports BC1 designs end-to-end; other designs route
to as-yet-unported TASSEL paths.
Calling on several families
FSFHap pools each family independently, so a realistic run
has more than one — each a distinct donor crossed onto the shared
recurrent parent A. We simulate three
BC1S4 families with simcross,
donors B1, B2, B3
(the TeoNAM design: one backcross to A, then four selfings —
F = 0.9375, so phet = 0.03125). Each family
needs enough segregating markers to phase its donor and clear FSFHap’s
coverage floor, so we use 20 lines × 500 markers. simcross gives real
recombination breakpoints; the donor blocks and residual heterozygosity
fall out of the crossing scheme.
# one BC1S4 family per donor: simulate the truth, then observe genotypes (with
# missingness), and tag the family grouping. 20 lines x 500 markers on chr 1.
sim_family <- function(donor) {
tr <- simulate_nil("BC1S4", n = 20, chr = 1, n_markers = 500, donor = donor,
names = sprintf("%s_L%02d", donor, 1:20))
obs <- simulate_counts(tr, depth = 8, p_missing = 0.1)
data.frame(name = obs$name, donor = obs$donor, family = donor,
chr = obs$chr, pos = obs$pos, g = obs$g)
}
fam <- do.call(rbind, lapply(c("B1", "B2", "B3"), sim_family))
calls <- call_ancestry(fam, caller = "fsfhap", design = "BC1S4")
table(donor = calls$donor, state = calls$state) # per-family state counts
#> state
#> donor 0 1 2
#> B1 48 7 33
#> B2 50 10 41
#> B3 51 12 39
head(calls, 4)
#> source donor name chr start_bp end_bp state
#> 1 nilHMM B1 B1_L01 1 37410 26603076 2
#> 2 nilHMM B1 B1_L01 1 28456494 199588804 0
#> 3 nilHMM B1 B1_L01 1 206384672 222447633 2
#> 4 nilHMM B1 B1_L01 1 223683245 308322690 0Parallelism
Each family × chromosome is an independent unit —
here three families on one chromosome, so three units — and
fsfhap fans them out across cores with threads
(bit-identical to serial):
identical(
call_ancestry(fam, caller = "fsfhap", design = "BC1S4", threads = 1L),
call_ancestry(fam, caller = "fsfhap", design = "BC1S4", threads = 2L)
)
#> [1] TRUEOn a real full-genome cohort this is a large win. On real TeoNAM (all
five families, 51,004 markers, 50 family × chromosome units) the port
runs in 28.6 s on 10 threads vs TASSEL’s 218.5 s — 7.6×
faster, and faster than TASSEL even single-threaded. See
design/FSFHAP_PORT.md for the full benchmark.
When not to use fsfhap
fsfhap assumes homozygous founders and balanced full-sib
segregation. For NILs with heterozygous or outbred
donors (e.g. teosinte), the two-haplotype model breaks down —
use the donor-agnostic nnil caller instead. Het-heavy F2 is
a documented stress case. See vignette("callers") for the
alternatives and ?call_ancestry for the full parameter
list. ```