Consume a SELECT query of flat event-by-transcript-by-sample calls through the bundled native replay stream. DuckDB derives complete phase-set domains and sorts the calls. Each output row is one occupied shared path, with CDS, protein, carrier keys and all contributing events. Incomplete calls and projection/edit failures retain provenance without inventing sequence.
Arguments
- con
An open DuckDB connection with DuckVEP loaded.
- calls_query
One nonempty SELECT query supplying the call relation.
- model_name
Name of an already loaded DuckVEP model.
- phase_policy
Strict GT/PS interpretation, or `vep_compat` for the called-slot order of the pinned executable VEP release. Decoded missing calls remain incomplete; source-record input uses the pinned raw parser and explicitly conditional missing-slot interpretation.
- ...
Named positive integer workspace capacities accepted by `duckvep_haplotypes`, such as `max_active_events`, `max_active_carriers`, `max_sequence_bases`, `max_ploidy`, `max_phase_sets`, and `workspace_limit`.
- input_mode
`alt_events` for decoded per-ALT calls, or `source_records` for raw GT and complete source ALT lists under `vep_compat`.
- hgvs
Whether to request bounded protein HGVS for supported completed paths.
- table_name
Optional output table name.
- overwrite
Whether to replace an existing output table.
Details
`nominal_length_diff` is the signed sum of projected replacement ALT-minus-REF lengths before clipping at the current CDS end. It is zero for reference-only replay and NA without a CDS. Known and conditional paths retain this value; overlapping replacements can produce a different rebuilt CDS length change.
`coding_blocks` groups physical edits that share an alternate codon or displace then restore the reading frame. Each block gives one-based reference `cds_start`, transcript-oriented `reference`/`alternate` spans, zero-based `alt_start0` in the rebuilt CDS, `length_change`, `sequence_flags` and `event_indices`: one source event ID per physical edit in ascending CDS order. An ID can repeat for several differing islands, within or across blocks; the list length is the physical edit count. Join IDs to `contributors` for raw alleles and input provenance. Spans include retained bases between edits; they are not aligned differences or HGVS normalization. An insertion has empty reference; a deletion has empty alternate. Unknown sequences have NULL blocks, not an empty known result. Blocks reuse `max_leaf_edits` capacity and the per-call workspace limit.
`cds_differences` instead contains aligned differing runs: zero-based `ref_start0`, `alt_start0`, and `alignment_start0`, with borrowed sequence spans materialized as `reference` and `alternate`. An empty span denotes a gap. The reference uses replay's uppercase DNA spelling; model bytes stay immutable. Runs join only when adjacent columns have the same gap/non-gap type on both sides. Indel-bearing paths use VEP's pure-Perl global-alignment score and tie order; substitution-only paths compare corresponding positions. Repeated sequence can therefore place a difference away from its contributing event. Differences are not HGVS normalization or event-provenance reassignment. Unknown sequences have NULL differences. `max_alignment_cells` bounds the exact traceback band and `max_leaf_differences` bounds output runs; exhaustion is an error, not approximate alignment or discarded differences.
`protein_differences` has the same span fields and alignment mode, with positions in amino acids. Its reference follows Ensembl's start-methionine, terminal-stop and curated single-residue peptide-edit rules. Haplosaurus then appends `*` only for an exact uppercase TAA/TAG/TGA raw-CDS suffix, including nonstandard-table and partial-CDS cases. The alternate is the displayed first-stop prefix without reference peptide edits. Unknown paths and reference CDS shorter than one codon have NULL protein differences; identical known proteins have an empty list. Both difference axes reuse the same native scratch and are separately subject to the alignment-cell and run limits.
`prediction_status`, `prediction_reason`, `haplotype_consequences`, `haplotype_impact`, `nmd_prediction` and `nmd_exceptions` classify the whole edited product. The rules and the authority each is checked against are in the haplotype contract (`design/duckvep_haplotype_contract.md`); in short:
* Records compose at their own reference coordinates. Records that agree compose once and keep their identities; two that claim one base or insertion site differently are `edit_conflict`. * `strict` reads GT and PS as written. An unphased heterozygous call needs no phase when it is the sample's only heterozygous call on the transcript. A missing allele or undefined phase is `incomplete_input`. `vep_compat` reads GT slots in order, as VEP's haplotype mode does, and then classifies like `strict`. * The edited CDS is translated with the transcript's genetic code, with curated translations and RNA editing as part of the reference. A lost stop reads through the stored 3' flank. `start_lost` stands alone; otherwise the terms are `stop_gained`, `stop_lost`, `frameshift_variant` while the frame stays displaced, `protein_altering_variant` or `synonymous_variant` for a restored frame, and missense, in-frame, stop-retained and start-retained terms. Changes after the first stop are contributors with role `post_stop`. * A path with no whole product to rebuild (an edit crossing a CDS end or an exon boundary, an essential splice-site record, an in-frame stop in the reference CDS) is `predicted` with reason `per_record_terms`: the union of its records' per-variant terms, without NMD. * `nmd_prediction` applies rule `ejc50` to a new premature stop: `trigger` when the stop lies more than 50 bases before the last exon junction, otherwise `escape`. `nmd_exceptions` adds `start_proximal` and `long_exon` without changing it, and `nmd_stop_position`, `nmd_junction_position` and `nmd_contributors` give the evidence.
`carrier_predictions` repeats the prediction per carrier, so one ineligible carrier (a triploid call, say) does not hide the others; the row-level fields need every carrier to be predicted. `contributor_provenance` lists every source of the path (applied, omitted, shadowed, unapplied and post-stop) with its original operands, carrier evidence and role. Sequence deduplication never drops a contributor.
With `hgvs = TRUE`, a multi-record path whose records are proven cis gets compound `hgvsc` and `hgvsp` names for the joint allele, and a single-record path gets the per-variant names. A status other than `ok` keeps NULL text with its reason. HGVS buffers count toward `workspace_limit`; exhaustion is an error, never truncated text.
`stop_in_displaced_frame` reports whether any of the first translated stop codon's three bases overlaps a frame-displaced span of the rebuilt CDS. Displacement starts at a frame-changing edit and ends after the alternate bases of the restoring edit, or continues downstream if unrestored. It is FALSE for no stop or a stop after frame restoration, and NA when sequence is unavailable. It is a sequence fact, not a combined SO consequence or a claim that a restored DNA frame rescues the protein.
Input must contain one row per `event_index`, `transcript_index`, `sample_index`, with columns `seq_region`, `position`, `reference`, `alternate`, `alt_index`, `alleles`, `phase_before` and nullable `phase_set`. Event indices identify individual ALT events; retain their source-record mapping. Transcript ordinals belong to the named model. Candidate selection is explicit in this input relation.
With `input_mode = "source_records"`, the required columns are `event_index`, `seq_region`, `position`, `reference`, `alternates` (a character list), `transcript_index`, `sample_index`, and `gt` (original VCF text). Here `event_index` identifies the whole source record. This mode requires `vep_compat`: the pinned file profile consumes two slots and ignores PS. Missing calls and undefined slots can yield `conditional` sequence with evidence bit 8; this is not known phase or biological rescue. Contributor `alt_index` is 0 for REF, a positive source ALT ordinal, or NA for an undefined slot's full-REF deletion. Source ALT strings must be nonempty and nonmissing. Projection failures still withhold sequence. Raw spelling must be retained at ingestion; it cannot be reconstructed losslessly from decoded GT arrays.
Preparation reads committed objects on the registry's retained connection; caller-local temporary objects and uncommitted changes are not visible. One preparation may run per registry at a time. Nested or concurrent preparation returns a busy error; completed scans use independent native workspaces. The native-v2 host stages calls on `con` with `duckvep_haplotype_load_sql` and reads them with `duckvep_haplotype_scan`. Caller-local temporary objects are therefore visible to preparation on that host.