ensembl.vep.annotators.consequence.strategies package#
Interchangeable ways to evaluate the consequence rule set.
ConsequenceAnnotator is the shared implementation each strategy subclasses. The modules
beside it are the strategies themselves. Importing this package registers every consequence.*
annotator as an import side effect.
Registry names represent evaluation strategies rather than strategy-cache combinations. Callers configure zone-map and codon caches independently through the annotator context.
linear– rank-ordered scan with a cheap-guard digest cache. The conformance reference.staged– cheap facts first, thenrequirespropagation; expensive tier only on demand.columnar– bit-parallel over a batch; cuts dispatch, not fact cost.columnar-staged– both of the above: bit-parallel with forced-false staging masks.columnar-kernels– columnar staging with selected columns filled by native batch kernels.
What was regular.columnar-staged-zonemap is now
ColumnarStagedAnnotator(zone_map=ZoneMapCache(), codon_cache=CodonEditLRUCache()).
Submodules#
ensembl.vep.annotators.consequence.strategies.base module#
Shared consequence annotator implementation.
- class ensembl.vep.annotators.consequence.strategies.base.ConsequenceAnnotator[RulesetT](ruleset, annotator_context=None, *, zone_map=None, codon_cache=None, readthrough=None)[source]#
Bases:
ABC,Generic[RulesetT]Implement shared behaviour for compiled consequence-rule annotators.
- Variables:
name (str) – The registry name this annotator is registered under.
ruleset (RulesetT) – The compiled rule set this annotator evaluates.
last_trace (AnnotationTrace | None) – The derivation trace recorded by the most recent
annotate_feature_overlapcall, or None if that call did not trace (the annotators did not opt-in). The nativerust.*annotators never set this.annotator_context (AnnotatorContext) – The run-scoped caches this annotator evaluates against.
- annotate_feature_overlap(overlap)[source]#
Calculate consequences for a feature overlap.
Supplied in terms of the batch method, so implementing
annotate_feature_overlapsis enough to get both halves of the contract.If your batch method is a loop over this one, you must override this one too. A strategy that evaluates per overlap (
linear/staged) implements the real work here and a plain loop there. Implementing only a looping batch method leaves this delegation pointing back at it, and the pair recurses until RecursionError.- Parameters:
overlap (
FeatureOverlap) – The overlap to annotate.- Returns:
The consequences that apply. May be empty.
- Return type:
list[OverlapConsequence]
- abstractmethod annotate_feature_overlaps(overlaps)[source]#
Calculate consequences for a batch of overlaps at once.
- Parameters:
overlaps (
Sequence[FeatureOverlap]) – The overlaps to annotate, in order.- Returns:
One consequence list per overlap, same order.
- Return type:
list[list[OverlapConsequence]]
- property cache_hits: int#
Return candidate-cache hits recorded on this annotator’s context.
- Returns:
The hit count. Shared with any other annotator given the same context.
- Return type:
int
- property cache_misses: int#
Return candidate-cache misses recorded on this annotator’s context.
- Returns:
The miss count. Shared with any other annotator given the same context.
- Return type:
int
- name: str = 'base'#
ensembl.vep.annotators.consequence.strategies.columnar module#
Evaluate consequence rules bit-parallel across an overlap batch.
Each fact is represented by a Python integer whose bit i contains the value for overlap i.
Rule formulas become bitwise operations, paying Python dispatch once per rule and batch rather than
once per rule and overlap.
Evaluation orders conjuncts by closure cost and carries a live mask of unresolved overlaps. A fact column is materialised only for that mask, while each plan node guarantees correct bits within its input mask and zero elsewhere. Because child masks and results only shrink, unpopulated bits cannot affect a decided result.
- class ensembl.vep.annotators.consequence.strategies.columnar.BitColumnBuffer(fact_contexts)[source]#
Bases:
objectMaterialise fact bit-columns lazily for one overlap batch.
- column(fact_name, live_mask)[source]#
Return the bit-column for
fact_namewithinlive_mask.- Parameters:
fact_name (
str) – The fact atom to materialise a column for.live_mask (
int) – The set of overlap indices (as bits) the caller needs an answer for.
- Returns:
- Bits set for every overlap index in
live_maskwhere the fact is true. Bits outside
live_maskare not guaranteed to mean anything.
- Bits set for every overlap index in
- Return type:
int
- seed(fact_name, column, known_mask)[source]#
Mark a fact’s column as already computed for every context in
known_mask.For a caller that produced the whole column by cheaper means than calling
get_factper context. Unlike FactContext.prefill this does not touch the per-overlap memo, so a fact seeded here is visible to the rule loop but not to aget_factcall inside another fact’s body. Therefore only seed leaf facts nothing else reads, or prefill the memo as well.- Parameters:
fact_name (
str) – The fact atom being seeded.column (
int) – Bitiset where the fact is true for contexti.known_mask (
int) – The contexts this column is exact for.
- class ensembl.vep.annotators.consequence.strategies.columnar.ColumnarFactsAnnotator(ruleset=None, batch_size=256, annotator_context=None, *, zone_map=None, codon_cache=None)[source]#
Bases:
ConsequenceAnnotator[FactRuleSet]Evaluate consequence rules bit-parallel over overlap batches.
- Variables:
name (str) – Registry name, “consequence.columnar”.
ruleset (FactRuleSet) – The compiled rule set this annotator evaluates.
batch_size (int) – Maximum number of overlaps evaluated together as one bit-parallel batch.
last_traces (list[AnnotationTrace]) – One derivation per overlap in the most recent annotate_feature_overlaps call, in the same order, or an empty list if that call did not trace. The inherited last_trace attribute mirrors this list’s final entry.
- annotate_feature_overlaps(overlaps)[source]#
Calculate consequences for a batch of overlaps at once.
- Parameters:
overlaps (
Sequence[FeatureOverlap]) – The overlaps to annotate, in order.- Returns:
One consequence list per input overlap, same order.
- Return type:
list[list[OverlapConsequence]]- Raises:
TypeError – If any element of
overlapsis not a TranscriptVariationAllele.
- last_traces: list[AnnotationTrace]#
- name: str = 'consequence.columnar'#
- ensembl.vep.annotators.consequence.strategies.columnar.DEFAULT_BATCH_SIZE = 256#
Default maximum number of overlaps evaluated together as one bit-parallel batch. Increase to amortise the plan-walking overhead over more overlaps, decrease to reduce peak memory usage. It has been observed that increasing does not always improve speed, because of big-int arithmetic overhead.
- class ensembl.vep.annotators.consequence.strategies.columnar.RulePlan(*, root_plan_node)[source]#
Bases:
objectRepresent a rule as a cost-ordered bit-parallel evaluation plan.
- Variables:
root_plan_node (PlanNode) – The root of the compiled plan.
- evaluate(live_mask, bit_columns)[source]#
Evaluate this plan over a live mask, short-circuiting as children settle.
- Parameters:
live_mask (
int) – The set of overlap indices (as bits) still undecided.bit_columns (
BitColumnBuffer) – The batch’s lazily-materialised fact columns.
- Returns:
Bits set for every overlap index in
live_maskwhere the rule evaluates True.- Return type:
int
- root_plan_node: _AtomPlanNode | _NotPlanNode | _AndPlanNode | _OrPlanNode#
- class ensembl.vep.annotators.consequence.strategies.columnar.RulePlanSet(*, ruleset, plans)[source]#
Bases:
objectPair a rule set with one compiled plan per rule.
- Variables:
ruleset (FactRuleSet) – The compiled rule set, in rank order.
plans (tuple[RulePlan, ...]) – One compiled plan per rule in
ruleset.rules, same order.
- classmethod build(ruleset)[source]#
Compile one plan per rule in
ruleset.- Parameters:
ruleset (
FactRuleSet) – The rule set to compile plans for.- Returns:
The rule set paired with its compiled plans.
- Return type:
- evaluate_over_columns(bit_columns, context_count)[source]#
Evaluate every rule bit-parallel over a column buffer according to their plan.
The column buffer here, already built, gets populated via plain lazy materialisation.
- Parameters:
bit_columns (
BitColumnBuffer) – The batch’s fact columns.context_count (
int) – Number of overlaps in this chunk.
- Returns:
One consequence list per input context, same order.
- Return type:
list[list[OverlapConsequence]]
- hit_terms_by_context(bit_columns, context_count)[source]#
Return the terms that evaluated as true for each fact context.
- Parameters:
bit_columns (
BitColumnBuffer) – The batch’s fact columns.context_count (
int) – Number of overlaps in this chunk.
- Returns:
The terms that fired for each fact context, in rule rank order.
- Return type:
list[list[str]]
- ruleset: FactRuleSet#
ensembl.vep.annotators.consequence.strategies.columnar_kernels module#
Columnar-staged evaluation whose cheapest fact columns are filled by native batch kernels.
Only flat integer arrays cross the native boundary; model objects remain in Python. Kernels process whole columns because a scalar boundary crossing costs more than the operations being accelerated.
The seeded facts cover short-variant shape and feature-span comparisons that remain per-context work after zone-map prefill. Exon and intron kernels are not seeded here because building their CSR arrays costs more than the Python scan when a zone map has not already supplied the values.
- class ensembl.vep.annotators.consequence.strategies.columnar_kernels.ColumnarKernelsAnnotator(ruleset=None, batch_size=256, annotator_context=None, *, zone_map=None, codon_cache=None)[source]#
Bases:
ColumnarStagedAnnotatorEvaluate staged columns with native kernels for inexpensive facts.
Identical output to ColumnarStagedAnnotator by construction: the kernels compute the same formulas, and everything they do not seed falls through to the ordinary Python path.
- Variables:
name (str) – Registry name, “consequence.columnar-kernels”.
kernel_calls (int) – Number of FFI crossings made so far.
columns_seeded (int) – Number of (fact, overlap) values filled by a kernel so far.
- name: str = 'consequence.columnar-kernels'#
- seed_columns(fact_contexts)[source]#
Compute every kernel-backed fact for the whole chunk, in a couple of FFI crossings.
The short-variant shape facts are returned as columns only and not prefilled into each context’s memo as nothing reads them through
get_fact. The overlap_feature and contain_feature are different, as every positional fact declaresrequires=("overlap_feature",), those two are additionally prefilled into each memo. This per-context fan-out is the single most expensive part of this strategy, which is why it is confined to the two facts that genuinely need it.- Parameters:
fact_contexts (
Sequence[FactContext]) – The chunk’s contexts, batch-index order.- Returns:
Fact name -> bit column for the whole chunk.
- Return type:
dict[str,int]
- ensembl.vep.annotators.consequence.strategies.columnar_kernels.SEEDED_FACT_NAMES: tuple[str, ...] = ('is_snv', 'is_short_insertion', 'is_short_deletion', 'is_short', 'overlap_feature', 'contain_feature')#
Facts filled by native kernels and checked against their Python implementations in tests.
ensembl.vep.annotators.consequence.strategies.columnar_staged module#
Combine bit-parallel rule evaluation with staged fact propagation.
Cheap fact columns are materialised for the complete chunk. A topological sweep of the acyclic
requires graph then propagates false bits into forced-false masks without per-context fixpoint
work. This matches implied_false while preserving batch evaluation.
Forced-false masks may derive only from full-chunk columns or earlier forced masks. Values from a column populated for a smaller live mask cannot establish facts outside that mask.
- class ensembl.vep.annotators.consequence.strategies.columnar_staged.ColumnarStagedAnnotator(ruleset=None, batch_size=256, annotator_context=None, *, zone_map=None, codon_cache=None)[source]#
Bases:
ConsequenceAnnotator[FactRuleSet]Evaluate bit-parallel rules while avoiding unnecessary expensive facts.
- Variables:
name (str) – Registry name, “consequence.columnar-staged”.
ruleset (FactRuleSet) – The compiled rule set this annotator evaluates.
batch_size (int) – Maximum number of overlaps evaluated together as one bit-parallel batch.
last_traces (list[AnnotationTrace]) – One derivation per overlap in the most recent annotate_feature_overlaps call, in the same order, or an empty list if that call did not trace. The inherited last_trace attribute mirrors this list’s final entry.
- annotate_feature_overlaps(overlaps)[source]#
Calculate consequences for a batch of transcript/variant-allele overlaps at once.
- Parameters:
overlaps (
Sequence[FeatureOverlap]) – The overlaps to annotate, in order. Every element must be a TranscriptVariationAllele.- Returns:
One consequence list per input overlap, same order.
- Return type:
list[list[OverlapConsequence]]- Raises:
TypeError – If any element of
overlapsis not a TranscriptVariationAllele.
- last_traces: list[AnnotationTrace]#
- name: str = 'consequence.columnar-staged'#
- seed_columns(fact_contexts)[source]#
Return fact columns already known for the whole chunk.
Extension point for a subclass that can compute a fact for every context in the chunk at once by some cheaper route than per-context
get_fact(see ColumnarKernelsAnnotator).A returned column must be exact for every context in the chunk, since it is marked fully known. A partially-correct column would be read as authoritative and could lead to incorrect results. Returning nothing (the default) leaves every column to the ordinary lazy path.
- Parameters:
fact_contexts (
Sequence[FactContext]) – The chunk’s contexts, batch-index order.- Returns:
Fact name -> bit column, bit
ibeing the value for contexti.- Return type:
dict[str,int]
- ensembl.vep.annotators.consequence.strategies.columnar_staged.topological_requires_order()[source]#
Return facts with requirements in topological order.
Ordered so every atom in a fact’s
requiresprecedes the fact itself, an explicit topological sort over therequiresgraph in REGISTRY, not a reliance on declaration order.- Returns:
Topologically ordered
(fact_name, requires)pairs.- Return type:
list[tuple[str,tuple[str,...]]]- Raises:
ValueError – If the
requiresgraph has a cycle. A cycle or a bad forward reference must fail loudly at annotator construction, not silently under-propagate at evaluation time.
ensembl.vep.annotators.consequence.strategies.linear module#
Evaluate consequence rules in rank order.
For each overlap, the strategy computes cheap guard facts, uses their digest to cache candidate rules, evaluates candidates in rank order, and applies subsumption.
This strategy is the conformance reference. Every other consequence strategy must produce the same
ordered OverlapConsequence terms for the same input.
- class ensembl.vep.annotators.consequence.strategies.linear.LinearFactsAnnotator(ruleset=None, annotator_context=None, *, zone_map=None, codon_cache=None)[source]#
Bases:
ConsequenceAnnotator[FactRuleSet]Evaluate a fact rule set with a rank-ordered linear scan.
There is also a cheap guard to find shorter candidate rule lists, implemented by a digest-keyed candidate cache.
- Variables:
name (str) – Registry name, “consequence.linear”.
ruleset (FactRuleSet) – The compiled rule set this annotator evaluates.
- annotate_feature_overlap(overlap)[source]#
Calculate consequences for an overlap.
- Parameters:
overlap (
FeatureOverlap) – The overlap to annotate.- Returns:
- The consequences that apply, in rank order. Empty if
nothing matched.
- Return type:
list[OverlapConsequence]- Raises:
TypeError – If overlap is not a TranscriptVariationAllele (subclass of FeatureOverlap).
- annotate_feature_overlaps(overlaps)[source]#
Calculate consequences for a batch of overlaps, one at a time.
- Parameters:
overlaps (
Sequence[FeatureOverlap]) – The overlaps to annotate, in order.- Returns:
One consequence list per input overlap, same order.
- Return type:
list[list[OverlapConsequence]]
- name: str = 'consequence.linear'#
ensembl.vep.annotators.consequence.strategies.staged module#
Evaluate cheap facts before requesting expensive facts.
The strategy computes atoms below DEFAULT_CHEAP_ATOM_MAX_CLOSURE_COST, extends the assignment
through implied_false, and partially evaluates each rule using three-valued logic.
A variant in an intron has overlap_exon = False, which makes overlap_cds false, which settles
stop_gained, frameshift_variant, missense_variant and the rest of the coding tier as
false without translating sequence.
- class ensembl.vep.annotators.consequence.strategies.staged.CheapAtomAlphabet(*, atom_names=())[source]#
Bases:
objectStore fact atoms that are inexpensive enough to evaluate eagerly.
- Variables:
atom_names (tuple[str, ...]) – Every atom referenced by any rule in the rule set this was built from whose closure_cost is at most the threshold it was built with, sorted in ascending closure cost order so the cheapest facts are computed first.
- atom_names: tuple[str, ...]#
- classmethod build(rules, max_closure_cost=6)[source]#
Collect the cheap atoms referenced anywhere in
rules, cheapest first.- Parameters:
rules (
tuple[FactRule,...]) – The rules to collect atoms from.max_closure_cost (
int, default:6) – Only atoms whose closure_cost is at most this count as cheap.
- Returns:
The sorted alphabet of cheap atoms.
- Return type:
- class ensembl.vep.annotators.consequence.strategies.staged.StagedFactsAnnotator(ruleset=None, annotator_context=None, early_subsumption_skip=False, *, cheap_atom_max_closure_cost=6, zone_map=None, codon_cache=None)[source]#
Bases:
ConsequenceAnnotator[FactRuleSet]Evaluate all applicable terms while deferring expensive facts.
- Variables:
name (str) – Registry name, “consequence.staged”.
ruleset (FactRuleSet) – The compiled rule set this annotator evaluates.
settled_early (int) – Number of (rule, overlap) decisions settled from cheap facts alone, across every call so far.
needed_expensive (int) – Number of (rule, overlap) decisions that stayed undecided after staging and had to fall through to evaluate, across every call so far.
cheap_atom_max_closure_cost (int) – Closure-cost ceiling for the atoms computed up front.
early_subsumption_skip (bool) – Whether the subsumes-topological early-skip scan is enabled. Off by default.
skipped_by_subsumption (int) – Number of (rule, overlap) evaluations elided by the early-skip scan. Stays 0 when
early_subsumption_skipis False.
- annotate_feature_overlap(overlap)[source]#
Calculate consequences for an overlap.
- Parameters:
overlap (
FeatureOverlap) – The overlap to annotate. Must be a TranscriptVariationAllele.- Returns:
- The consequences that apply, in rank order. Empty if
nothing matched – the caller applies a default/fallback term.
- Return type:
list[OverlapConsequence]- Raises:
TypeError – If
overlapis not a TranscriptVariationAllele.
- annotate_feature_overlaps(overlaps)[source]#
Calculate consequences for a batch of overlaps, one at a time.
- Parameters:
overlaps (
Sequence[FeatureOverlap]) – The overlaps to annotate, in order.- Returns:
One consequence list per input overlap, same order.
- Return type:
list[list[OverlapConsequence]]
- name: str = 'consequence.staged'#