Resolves a named caller (and optional design preset) into emission + duration
specs and runs fit() / decode() per (sample, chromosome), returning one
ancestry state per observation unit — coordinate-free: no genomic
intervals. Feed the result to to_segments() to reinstate coordinates and
collapse into common-schema segments; call_ancestry() chains the two.
Data-agnostic: pass the observations in; this function never reads paths.
Usage
call_states(
data,
caller = c("nnil", "bbnil", "catiger", "rtiger", "binhmm", "googa", "atlas",
"lbimpute", "fsfhap", "pedigree"),
family = NULL,
phet = NULL,
pedigree = NULL,
ped_format = c("fam", "fsfhap"),
ped_maxiter = 30L,
ped_tol = 1e-04,
ped_lambda = 0.5,
design = NULL,
rrate = 0.01,
rigidity = NULL,
err = 0.01,
conc = 20,
fit_means = FALSE,
xrate = 0.01,
f_1 = NULL,
f_2 = NULL,
source = "nilHMM",
donor = NA_character_,
parallel = FALSE,
threads = 1L,
seed = 1L,
postprocess = TRUE,
min_reads = 1L,
rtiger_fit = NULL,
bin_size = 1e+06,
cluster_method = c("gauss", "gmm", "kmeans", "rebmix"),
joint_clust = FALSE,
obs_weights = FALSE,
atlas_thresh = 0.95,
atlas_het = 0.25,
atlas_min_reads = 5L,
genotypeerr = 0.05,
recombdist = NULL,
drp = FALSE,
unit = c("bp", "cm"),
germ = 0.05,
gert = 0.1,
p = 0.5,
mr = 0.1,
nir = 0.01
)Arguments
- data
Long observation table with columns
name, chr, posand one of:n_ref, n_altread counts (fromread_counts(); for the count/BetaBinomial callersbbnil/rtiger,binhmm, the GOOGA-threshold transcript callersgooga/atlas, andlbimpute); a pre-called hard-genotype columngin{0,1,2,3}(fromread_vcf_gt(); required by the categorical gt callersnnil/catiger, which never threshold read counts themselves — seecaller— and also accepted byfsfhap/pedigree); or a pre-binnedalt_freq(withstart_bp, end_bp) forbinhmm. Optionallydonor.- caller
One of
"nnil","bbnil","catiger","rtiger","binhmm","googa","atlas","lbimpute","fsfhap","pedigree". The six gt/count grid cells:nnil(gt + geometric),bbnil(count + geometric),catiger(gt + rigidity),rtiger(count + rigidity), plus the GOOGA-threshold transcript pairgooga(gt + geometric, faithful GOOGA) andatlas(gt + rigidity, this work). The gt callersnnil/catigerrequire called genotypes (agcolumn) — they never threshold read counts into genotypes; hard-calling is the user's explicit step (e.g.call_gt()). For the no-HMM per-site genotype baseline (the paper's "control"), call the genotype callercall_gt()directly (prior = "flat"for the maximum-likelihood call,prior = "hwe"for the HWE MAP) — it is a genotype caller, deliberately separate from the ancestry callers here.- family
fsfhapcaller only: per-row family grouping (a vector lengthnrow(data), or supply afamilycolumn ondata). FSFHap pools each family.- phet
fsfhapcaller only: expected heterozygosity. IfNULL, derived fromdesignas(1 - F)/2(BC1S4 → 0.03125); thefsfhapport supports BC1 designs ("BC1S{m}") — other designs route to unported TASSEL paths.- pedigree
pedigreecaller only (required there): aread_pedigree()data.frame (taxon, family, parent1, parent2) or a path.taxonjoins todata$name; ataxonused as a parent but absent fromdatais a latent ungenotyped ancestor. Thepedigreecaller couples a family's relatives by loopy belief propagation over the (pedigree x genome) grid; its emission is input-detected — read counts give the count/BetaBinomial (de novo) path, a hard-callstate/gcolumn gives the categorical gt path (equivalent torefine_ancestry()). It requiresdesignand dispatches per family.- ped_format
pedigreecaller only:read_pedigree()format whenpedigreeis a path ("fam"/"fsfhap").- ped_maxiter, ped_tol, ped_lambda
pedigreecaller only: BP sweeps, convergence tolerance, and damping for the message passing.- design
Breeding-design key for priors (e.g.
"BC2S2","BC2S3"). Required unlessf_1/f_2are supplied.- rrate
Geometric callers (
nnil,bbnil,googa): expected per-marker recombination rate for the geometric duration (self-stay =1 - rrate). A resolution hyperparameter, not an MLE. Holland's nNIL sets it to2 * total_cM / (100 * n_markers)(~30 / n_markersfor a 1500 cM maize map; the factor 2 is the RIL-like doubling for the backcross + self meioses, Haldane & Waddington), and it is optimizable from data by KS-vs-sim (calibrate_r()). Thepedigreecaller also usesrrateas the per-bp recombination fraction for its chromosome transition whendatahas nocmcolumn (else Haldane oncm).- rigidity
Rigidity callers (
catiger,rtiger,atlas): integer minimum run length (e.g.5).- err, conc, fit_means
Count-emission parameters forwarded to
caller_spec().- xrate
Exit rate of nilHMM's rigidity duration (
duration_rigidity()): the per-marker switch probability at the free (post-minimum-run) state — the geometric tail beyond the enforced run. A nilHMM construct, not a RTIGER parameter; the faithfulcaller = "rtiger"port uses onlyrigidity(plusthreads/seed/postprocess) and ignoresxrate.- f_1, f_2
Single-locus priors, used when
designisNULL.- source
Value for the output
sourcecolumn.- donor
Donor/taxon label when
datahas nodonorcolumn.- parallel
If
TRUE, decode samples across cores via RcppParallel (only the fixed-means batched path; control thread count withRcppParallel::setThreadOptions()). Identical results to serial.- threads
Fan-out width for coarse-grained parallelism.
rtiger: E-step threads.fsfhap: family x chromosome units decoded in parallel (parallel::mclapply(), unix only; identical results tothreads = 1L).lbimpute: per-(name, chr) decode fan-out. Other callers ignore it (useparallelfor the batched count path).- seed
RTIGER caller only: the seed for its randomized init.
- postprocess
RTIGER caller only: apply the border re-placement (default TRUE).
- min_reads
Minimum read depth to keep a marker before decoding (default
1L;0Lkeeps everything). For the count-emission callersbbnil/rtigerit drops markers withn_ref + n_alt < min_reads; for the called-genotype callersnnil/catigerit instead drops missing genotypes (g == 3). The intent is uniform — never make a confident call from no data, and keep the callers on the same support for comparability. Zero-read markers carry no emission signal — they only slow decoding, marginally inflatebbnil's fragmentation, and dilutertiger's rigidity run.binhmmis unaffected (it drops truly-empty bins internally; a future per-bin frequency gate would be a separatemin_freq);googa/atlashave their ownatlas_min_readsgate.- rtiger_fit
rtigercaller only: a pre-computed RTIGER fit fromfit_rtiger(), reused across per-chromosome decodes to avoid re-fitting (low-memory decode-reuse path).NULL(default) fits once internally.- bin_size, cluster_method
binhmmcaller only: genomic bin width in bp (default 1 Mb) and the per-bin genotyping backend —"gauss"(default: the anchored 3-state Gaussian-emission HMM; fixes the HET over-call and high-coverage fragmentation of the K=3 clustering), or the original cluster-then-smooth route"gmm"/"kmeans"/"rebmix"(the last needs the suggested rebmix package, for bit-exact rpubs reproduction).joint_clust/obs_weightsapply only to the cluster backends.- joint_clust
binhmmcaller only: ifTRUE, pool all samples' bins and learn one shared set of REF/HET/ALT clusters on raw alt-freq (borrows strength across the cohort; cf.get_joint_ancestry_calls.R); ifFALSE(default), cluster each sample independently on its informative-count-weighted alt-freq. This is joint clustering only; the HMM stays per-sample.- obs_weights
binhmmcaller only,joint_clust = TRUEonly: ifTRUE, weight the (gmm) clustering fit by each bin's informative-variant count (weights the influence, not the alt-freq value).- atlas_thresh, atlas_het, atlas_min_reads
googa/atlascallers only: GOOGA genotype-call thresholds on the donor read fraction — homozygous call when a parent's fraction >=atlas_thresh(0.95), HET when both parents >=atlas_het(0.25), and a minimum ofatlas_min_reads(5) informative reads per gene (else missing). Forgooga/atlas,n_ref/n_altare the recurrent/donor competitive-alignment read counts (ambiguous excluded upstream).- genotypeerr, recombdist, drp, unit
lbimputecaller only (Fragoso et al. 2014):genotypeerris the coverage-independent genotyping-error rate (LB-Imputegenotypeerr, default 0.05) that bounds every emission to[genotypeerr, 1 - genotypeerr];errdoubles as LB-Impute's per-readreaderr(its default is 0.05, higher than the sharederr = 0.01).unitchooses the coordinate the transition decays over:"bp"(default, the faithful LB-Impute model – a uniform genome-wide recombination rate over physical distance) or"cm"(map-aware – uses acmcolumn of genetic positions per marker, so the local recombination rate, e.g. maize centromeric suppression, is captured). Output coordinates are always bp (pos); cM only feeds the transition.recombdistis the coordinate distance over which the recombination probability equalizes (LB-Imputerecombdist); it shares units with the coordinate, so its default is unit-aware (1e7bp = ~50 cM in maize, or50cM) and larger values mean stiffer paths – a validation layer warns on a bp/cMrecombdistmismatch.drp(LB-Impute-dr): whenTRUE, a homozygous->homozygous switch is priced as a single recombination rather than a double event (use for inbred / RIL populations). Forlbimpute,design/f_1,f_2only seed the start distribution (flat if absent) and zero-coverage markers are kept so the transition sees true marker spacing.- germ, gert, p, mr, nir
Genotype-error rates for the
gt(categorical) emission (Holland's nNIL model):germerror on true homozygotes,gerton true heterozygotes,pfraction of hom errors called het,mrmissing rate,nirnon-informative-marker rate. Raisinggerm/gerttoward the platform's real error rate is the native cure for over-fragmentation (isolated miscalled markers are absorbed as errors rather than opening 1-marker segments); calibrate to a clean control, don't crank blindly. Used by the gt (categorical) callersnnil,catiger(which take a suppliedgcolumn) andgooga,atlas(whosegcomes from GOOGA thresholding of competitive counts).
Value
data.frame of per-unit states
(source, donor, name, chr, pos, state; the binhmm caller additionally
carries per-bin start_bp, end_bp). Pass to to_segments() for intervals.
Examples
# Toy single-NIL count table: a REF stretch then a donor (ALT) block.
set.seed(1)
toy <- data.frame(
name = "NIL1", chr = 1L, pos = seq_len(40L) * 1e5L,
n_ref = c(rpois(20, 8), rpois(20, 4)),
n_alt = c(rpois(20, 0), rpois(20, 4)))
st <- call_states(toy, caller = "bbnil", design = "BC2S2", rrate = 1e-4, err = 0.01)
to_segments(st) # or, in one step:
#> source donor name chr start_bp end_bp state
#> 1 nilHMM <NA> NIL1 1 100000 2000000 0
#> 2 nilHMM <NA> NIL1 1 2100000 4000000 1
call_ancestry(toy, caller = "bbnil", design = "BC2S2", rrate = 1e-4, err = 0.01)
#> source donor name chr start_bp end_bp state
#> 1 nilHMM <NA> NIL1 1 100000 2000000 0
#> 2 nilHMM <NA> NIL1 1 2100000 4000000 1