ensembl.vep.trace package#
Derivation traces for consequence annotations.
A trace records the facts, rule verdicts, subsumption decisions, and emitted terms for one
overlap. The package sits below annotators because fact evaluation and caches both depend on
its event types.
Only annotation and event types are re-exported here. Reconstruction and aggregation depend on
higher layers that already import this package, so import those features from their modules to
avoid dependency cycles. Comparing and summarising a finished trace is not tracing at all: that
lives in ensembl.vep.explain.
Submodules#
ensembl.vep.trace.annotation module#
Completed annotation traces and text rendering.
An AnnotationTrace is immutable and identifies both its overlap and annotator. Reconstruction
builds it after annotation from the fact memo, rule results, and the small amount of live state in
TraceRecorder. Optional event collections use empty tuples so consumers can iterate without
special cases.
- class ensembl.vep.trace.annotation.AnnotationTrace(*, fact_events=(), rule_events=(), prune_events=(), emitted_terms=(), annotator_name='', overlap_label='')[source]#
Bases:
objectRecord one overlap’s derivation.
- Variables:
fact_events (tuple[FactEvent, ...]) – Facts touched by the derivation, in materialisation order, followed by facts proved false through
requirespropagation.rule_events (tuple[RuleEvent, ...]) – Every rule’s verdict, in rank order.
prune_events (tuple[PruneEvent, ...]) – Every subsumption decision.
emitted_terms (tuple[str, ...]) – Terms remaining after subsumption.
annotator_name (str) – Registered annotator name.
overlap_label (str) – One-line description of the annotated overlap.
- annotator_name: str#
- property avoided_cost: int#
Return the declared cost avoided through
requirespropagation.
- property computed_cost: int#
Return the declared cost charged by this derivation.
- emitted_terms: tuple[str, ...]#
- events_by_origin(origin)[source]#
Return the fact events with one origin, in trace order.
- Return type:
tuple[FactEvent,...]
- format_explanation()[source]#
Return this trace as a human-readable derivation.
- Returns:
Facts, rule verdicts, pruning decisions, and emitted terms.
- Return type:
str
- overlap_label: str#
- prune_events: tuple[PruneEvent, ...]#
- ensembl.vep.trace.annotation.annotation_tracing(*, quiet)[source]#
Enable annotator tracing for the duration of a context.
Tracing uses the annotator logger level instead of adding a second flag to fact evaluation. Quiet mode suppresses the annotator’s debug rendering when the caller renders the same trace.
- Parameters:
quiet (
bool) – Whether to suppress annotator debug records.- Return type:
Iterator[None]
- ensembl.vep.trace.annotation.describe_overlap(overlap)[source]#
Return a one-line label for a transcript and variant overlap.
The object is inspected without importing
TranscriptVariationAlleleso the trace event layer remains independent ofmodels. The allele half is itsdisplay_name, so a trace header names the variant the way every other command names it.- Parameters:
overlap (
object) – Object exposing transcript and overlapping-allele attributes.- Returns:
Label containing the feature and the allele’s name when available.
- Return type:
str
ensembl.vep.trace.events module#
Trace events and recording state for consequence annotations.
This module has no ensembl.vep imports because facts, contexts, and caches depend on its event
types. Higher-level reconstruction belongs in trace.reconstruct.
- class ensembl.vep.trace.events.FactEvent(*, name, value, cost, origin, reads=0, forced_by=())[source]#
Bases:
objectRecord a fact value and how it became known.
- Variables:
name (str) – The fact’s name.
value (object) – The fact’s value.
cost (int) – Cost charged for a computed fact or avoided for a forced-false fact; zero for values supplied by a cache.
origin (FactOrigin) – How the value became known.
reads (int) – Number of
get_factrequests for this fact.forced_by (tuple[str, ...]) – False
requiresatoms that forced the value, when relevant.
- cost: int#
- forced_by: tuple[str, ...]#
- name: str#
- origin: FactOrigin#
- reads: int#
- value: object#
- class ensembl.vep.trace.events.FactOrigin(*values)[source]#
Bases:
EnumIdentify how a fact value became known.
- Variables:
COMPUTED (FactOrigin) – Computed by the registered fact function.
PREFILLED (FactOrigin) – Supplied by a zone map without computation.
CACHED (FactOrigin) – Supplied by the shared-codon cache.
FORCED_FALSE (FactOrigin) – Proved false through
requirespropagation.
- CACHED = 'codon cache hit'#
- COMPUTED = 'computed'#
- FORCED_FALSE = 'forced False by requires'#
- PREFILLED = 'prefilled by zone map'#
- class ensembl.vep.trace.events.PruneEvent(*, dropped_term, subsumed_by)[source]#
Bases:
objectRecord one subsumption decision.
- Variables:
dropped_term (str) – Term removed from the emitted terms.
subsumed_by (str) – Firing term that subsumed
dropped_term.
- dropped_term: str#
- subsumed_by: str#
- class ensembl.vep.trace.events.RuleEvent(*, term, rank, fired, settled_early, reason)[source]#
Bases:
objectRecord a rule verdict for one overlap.
- Variables:
term (str) – The SO term this rule decides.
rank (int) – The rule’s severity rank.
fired (bool) – True if the rule’s formula evaluated True, before subsumption pruning.
settled_early (bool) – Whether a guard or partial evaluation settled the rule.
reason (str) – Formula or partial-evaluation reason for the verdict.
- fired: bool#
- rank: int#
- reason: str#
- settled_early: bool#
- term: str#
- class ensembl.vep.trace.events.TraceRecorder(*, read_counts=dict(), served=dict())[source]#
Bases:
objectCollect live state that cannot be reconstructed after annotation.
Reconstruction derives values and rule outcomes from the completed fact context. The recorder retains only original read counts and cache origins, which replay cannot recover.
- Variables:
read_counts (dict[str, int]) – Number of
get_factrequests by fact name.served (dict[str, FactOrigin]) – Cache origin by fact name.
- note_served(names, origin)[source]#
Record facts supplied by a cache without computation.
- Parameters:
names (
Iterable[str]) – Newly memoised fact names supplied by the cache.origin (
FactOrigin) – Cache origin for the facts.
- read_counts: dict[str, int]#
- served: dict[str, FactOrigin]#
ensembl.vep.trace.reconstruct module#
Reconstruct annotation traces from completed fact evaluation.
The fact memo, rule set, and fired terms provide most of a derivation after annotation. Live recording retains only read counts, cache origins, and the partial assignment used by staged annotation because those values cannot be recovered by replay.
Fact origins are reconstructed as follows:
computed – in the memo, and no cache claimed it.
prefilled / cached – in the memo, and the recorder says which cache put it there.
forced False – False in the staged assignment and absent from the memo, so it was proved False by
requirespropagation without being computed.
Call memo_fact_events before reconstructing rules. Rule reconstruction reads facts again, so
capturing read counts afterwards would include replay activity.
- ensembl.vep.trace.reconstruct.explain_partial_settlement(expr, known)[source]#
Return atom-value pairs that settled a partial expression.
This follows
Expr.evaluate_partialshort-circuiting until it reaches the false conjunct or true disjunct that determined the result.- Parameters:
expr (
Expr) – Expression already settled by partial evaluation.known (
dict[str,bool]) – Partial assignment that settled the expression.
- Returns:
Settling atoms in evaluation order, or an empty list.
- Return type:
list[tuple[str,bool]]
- ensembl.vep.trace.reconstruct.forced_false_events(known, memo)[source]#
Return facts proved false through
requirespropagation.A false value in the closed partial assignment that is absent from the memo was settled without computation.
- Parameters:
known (
Mapping[str,bool]) – Partial assignment used for rule evaluation.memo (
Mapping[str,object]) – Completed fact memo.
- Returns:
Forced-false events with avoided cost and forcing atoms.
- Return type:
tuple[FactEvent,...]
- ensembl.vep.trace.reconstruct.guarded_rule_events(rules, candidate_terms, hit_terms, guard_flags)[source]#
Return rule events that distinguish guard rejection from full evaluation.
A rule outside
candidate_termswas rejected byFactRule.cheap_guardand therefore reports failed guard atoms instead of its unevaluated formula.- Parameters:
rules (
Sequence[FactRule]) – Rules in rank order.candidate_terms (
set[str]) – Terms whose rules passed the guard.hit_terms (
Sequence[str]) – Candidate terms whose rules evaluated true.guard_flags (
Mapping[str,bool]) – Guard values for the overlap.
- Returns:
Rule events in rank order.
- Return type:
tuple[RuleEvent,...]
- ensembl.vep.trace.reconstruct.memo_fact_events(fact_context)[source]#
Return memoised facts in materialisation order.
Dictionary insertion order records when each fact first entered the memo.
- Parameters:
fact_context (
FactContext) – Evaluated context containing the memo and optional recorder.- Returns:
Fact events in materialisation order.
- Return type:
tuple[FactEvent,...]
- ensembl.vep.trace.reconstruct.partial_rule_events(rules, known, hit_terms)[source]#
Return rule events from partial and complete verdicts.
Rules settled by
knownreport the determining atoms. Other rules report that they required full evaluation.
- ensembl.vep.trace.reconstruct.plain_rule_events(rules, hit_terms)[source]#
Return rule events for fully evaluated formulas.
Use this for strategies without staging or a cheap-guard prefilter.
- ensembl.vep.trace.reconstruct.subsumption_events(by_term, hit_terms)[source]#
Return the pruning decisions made by
rules.rulesets.prune.This read-only replay avoids adding trace state to the pruning path.
- Parameters:
by_term (
Mapping[str,FactRule]) – Rules indexed by term.hit_terms (
Sequence[str]) – Terms whose rules fired before pruning.
- Returns:
Pruning events for dropped terms.
- Return type:
tuple[PruneEvent,...]
ensembl.vep.trace.run module#
Run-level aggregation of annotation traces.
AnnotationTrace describes one overlap. RunTrace aggregates fact use, charged and avoided
costs, reached cost tiers, and emitted terms across a run. It remains separate from the lightweight
term-level RunSummary because fact-level tracing is optional and more expensive.
- ensembl.vep.trace.run.FACT_HEADERS = ('Fact', 'Computed', 'Prefilled', 'Cached', 'Forced False', 'Reads', 'Cost', 'Avoided')#
Column headers matching
RunTrace.fact_rows.
- class ensembl.vep.trace.run.FactUsage(*, name, computed=0, prefilled=0, cached=0, forced_false=0, reads=0, charged_cost=0, avoided_cost=0)[source]#
Bases:
objectAggregate one fact’s use across a run.
- Variables:
name (str) – The fact’s name.
computed (int) – Overlaps that computed the fact.
prefilled (int) – Overlaps supplied by a zone map.
cached (int) – Overlaps supplied by the codon cache.
forced_false (int) – Overlaps that proved the fact false without computation.
reads (int) – Total
get_factrequests.charged_cost (int) – Total declared cost charged.
avoided_cost (int) – Total declared cost avoided.
- avoided_cost: int#
- cached: int#
- charged_cost: int#
- computed: int#
- forced_false: int#
- name: str#
- prefilled: int#
- reads: int#
- property touched: int#
Return the number of overlaps that used this fact.
- class ensembl.vep.trace.run.RunTrace(*, overlaps=0, fact_usage=(), term_counts=(), tier_reach=(), charged_cost=0, avoided_cost=0, annotator_name='', cost_table='')[source]#
Bases:
objectRecord fact-level totals for an annotation run.
- Variables:
overlaps (int) – Number of traced overlaps.
fact_usage (tuple[FactUsage, ...]) – Per-fact totals ordered by charged cost.
term_counts (tuple[tuple[str, int], ...]) – Emitted-term counts ordered by frequency.
tier_reach (tuple[tuple[str, int], ...]) – Computed-fact counts by cost tier.
charged_cost (int) – Total declared cost charged.
avoided_cost (int) – Total declared cost avoided.
annotator_name (str) – Annotator represented by the trace.
cost_table (str) – Cost table used for declared fact costs.
- annotator_name: str#
- avoided_cost: int#
- charged_cost: int#
- cost_table: str#
- fact_rows()[source]#
Return the per-fact totals as table rows, in
FACT_HEADERSorder.- Return type:
list[tuple[object,...]]
- classmethod fold(traces, *, annotator_name='', cost_table='')[source]#
Build run-level totals from per-overlap traces.
- Parameters:
traces (
Iterable[AnnotationTrace]) – Derivations to aggregate.annotator_name (
str, default:'') – Annotator that produced the traces.cost_table (
str, default:'') – Cost table used for declared fact costs.
- Returns:
Aggregated run trace.
- Return type:
- overlaps: int#
- sections()[source]#
Return the profile as report sections.
- Return type:
tuple[ReportSection,...]
- property subtitle: str#
Return the report totals and cost-table description.
- term_counts: tuple[tuple[str, int], ...]#
- tier_reach: tuple[tuple[str, int], ...]#
- property title: str#
Return the report title.