ensembl.vep.annotators.consequence.rules package#
Boolean consequence rules over fact atoms.
The checked-in catalogue belongs here because only rule construction, validation, and editing consume it; the fact layer remains independent of catalogue metadata.
Submodules#
ensembl.vep.annotators.consequence.rules.catalogue module#
Load the checked-in overlap consequence catalogue (data/overlap_consequences.json).
The catalogue is the shared source of term, accession, rank, tier, impact, formula, subsumption,
and ontology-parent metadata. when uses fact names and nested not, all, and any
expressions. subsumes declares terms suppressed when both rules fire, while
so_supported_parents records represented Sequence Ontology parents.
Fallback terms listed in EXCLUDED_TERMS intentionally have no when formula. All other
applicability conditions, including feature-kind checks, remain explicit in catalogue formulas.
- ensembl.vep.annotators.consequence.rules.catalogue.ACCESSION_PATTERN = re.compile('^SO:\\d{7}$')#
Shape of a Sequence Ontology accession, e.g.
SO:0001627.
- class ensembl.vep.annotators.consequence.rules.catalogue.ConsequenceDefinition(term, accession, rank, tier, impact, when, subsumes=tuple(), so_supported_parents=tuple(), notes=None)[source]#
Bases:
objectRepresent one parsed entry from the overlap consequence catalogue.
- Variables:
term (str) – The SO term, e.g. “missense_variant”.
accession (str) – The SO accession, e.g. “SO:0001583”.
rank (int) – Severity rank; 1 is most severe.
tier (int) – Tier grouping used by VEP’s own evaluation order.
impact (ConsequenceImpact | None) – The IMPACT rating.
when (object | None) – A JSON boolean expression over fact atom names or None if this term is on EXCLUDED_TERMS.
subsumes (tuple[str, ...]) – Term names this consequence suppresses when when evaluated as true.
so_supported_parents (tuple[str, ...]) – SO ontology parent accessions that are also represented in this catalogue.
notes (str | None) – Free-text notes, if any.
- accession: str#
- impact: ConsequenceImpact | None#
- notes: str | None = None#
- rank: int#
- so_supported_parents: tuple[str, ...]#
- subsumes: tuple[str, ...]#
- term: str#
- tier: int#
- when: object | None#
- ensembl.vep.annotators.consequence.rules.catalogue.DEFAULT_TERM = 'intergenic_variant'#
Fallback term applied by an annotator’s caller when nothing else matched.
- ensembl.vep.annotators.consequence.rules.catalogue.ENTRY_KEY_ORDER = ('term', 'accession', 'rank', 'tier', 'impact', 'so_supported_parents', 'when', 'subsumes', 'notes')#
Canonical per-entry key order, matching every existing schema-5 entry, so a freshly built entry round-trips identically to a hand-edited one.
- ensembl.vep.annotators.consequence.rules.catalogue.EXCLUDED_TERMS = frozenset({'intergenic_variant', 'sequence_variant'})#
Catalogue terms with no
whendocumented.
- ensembl.vep.annotators.consequence.rules.catalogue.catalogue_digest(path=None)[source]#
Return a short digest of a catalogue file’s bytes, the packaged catalogue by default.
What a frozen expectation records beside its terms, so a later mismatch can be told apart: the catalogue changed under it, or the annotator did.
- Return type:
str
- ensembl.vep.annotators.consequence.rules.catalogue.catalogue_path()[source]#
Return the filesystem path of the packaged catalogue.
Resolved as a package resource rather than relative to this file, so it survives being installed. Writing to it is refused unless the caller asks for it explicitly – see ensembl.vep.annotators.consequence.rules.editing.
- Return type:
Path
- ensembl.vep.annotators.consequence.rules.catalogue.dump_catalogue(payload)[source]#
Return a catalogue payload as JSON text, in the checked-in formatting.
- Return type:
str
- ensembl.vep.annotators.consequence.rules.catalogue.load_catalogue(path=None)[source]#
Return a catalogue’s raw JSON payload, for editing rather than evaluation.
load_consequence_definitionsis the counterpart that parses the payload into rules; this keeps every key, including any the schema has that the parser ignores.- Parameters:
path (
Path|None, default:None) – The catalogue to read, or None for the packaged one.- Returns:
The payload as parsed from JSON.
- Return type:
dict[str,Any]- Raises:
ValueError – If the payload’s
schema_versionis unsupported.
- ensembl.vep.annotators.consequence.rules.catalogue.load_consequence_definitions()[source]#
Load and parse the package consequence catalogue.
- Returns:
Every catalogue entry, sorted by
(rank, term).- Return type:
tuple[ConsequenceDefinition,...]- Raises:
ValueError – If the catalogue’s
schema_versionis unsupported, or a term appears more than once.
ensembl.vep.annotators.consequence.rules.editing module#
Add and remove consequence catalogue entries.
Never infer a when formula. An entry without one is marked for review because conformance tests
cannot detect a formula that every strategy evaluates consistently but incorrectly.
- ensembl.vep.annotators.consequence.rules.editing.accession_index(entries)[source]#
Build an accession -> entry lookup.
- Parameters:
entries (
list[dict[str,Any]]) – The catalogue’sconsequenceslist.- Returns:
Every entry, keyed by its SO accession.
- Return type:
dict[str,dict[str,Any]]
- ensembl.vep.annotators.consequence.rules.editing.apply_add(payload, *, term, accession, impact, rank=None, tier=3, so_parent=(), subsumes=(), no_derive_subsumes=False, when=None, allow_missing_when=False, notes=None)[source]#
Add a term to a catalogue payload, without writing anything.
- Parameters:
payload (
dict[str,Any]) – The payload to add to, mutated in place.term (
str) – The SO term to add.accession (
str|None) – Its SO accession.impact (
str|None) – Its impact bucket.rank (
int|None, default:None) – 1-based rank to insert at, or None to append after the highest.tier (
int, default:3) – Tier grouping.so_parent (
tuple[str,...], default:()) – SO parent accessions, used to derivesubsumes.subsumes (
tuple[str,...], default:()) – Extra terms to subsume, on top of the derived ones.no_derive_subsumes (
bool, default:False) – Skip deriving fromso_parent.when (
str|None, default:None) – Thewhenpayload as JSON, or None to write a placeholder.allow_missing_when (
bool, default:False) – Accept the placeholder rather than refusing.notes (
str|None, default:None) – Free-text notes.
- Returns:
(payload, messages), or None if the additionwas rejected because no
whenwas given and it was not explicitly allowed.
- Return type:
tuple[dict[str,Any],list[str]] |None- Raises:
ValueError – On a usage error – missing accession or impact, duplicate term or accession, unknown subsumes target, or a malformed accession.
- ensembl.vep.annotators.consequence.rules.editing.apply_remove(payload, *, term)[source]#
Remove a term from a catalogue payload, without writing anything.
- Parameters:
payload (
dict[str,Any]) – The payload to remove from, mutated in place.term (
str) – The SO term to remove.
- Returns:
(payload, messages). Removal is never a needs-reviewcase, so unlike
apply_addthis always succeeds when the term exists.
- Return type:
tuple[dict[str,Any],list[str]]- Raises:
ValueError – If no entry named
termexists.
- ensembl.vep.annotators.consequence.rules.editing.build_entry(*, term, accession, rank, tier, impact, so_supported_parents, when, subsumes, notes)[source]#
Build a new catalogue entry dict in the canonical, round-trippable key order.
- Parameters:
term (
str) – The SO term name.accession (
str) – The SO accession.rank (
int) – Severity rank.tier (
int) – Tier grouping.impact (
str) – One of ConsequenceImpact’s values.so_supported_parents (
Sequence[str]) – SO parent accessions also represented in the catalogue.when (
object|None) – A compiled-and-validatedwhenpayload, or None for a needs-review placeholder (see resolve_when).subsumes (
tuple[str,...]) – Term names this entry suppresses when it also fires.notes (
str|None) – Free-text notes, if any.
- Returns:
- The new entry, with keys present/ordered exactly as an existing schema-4
catalogue entry would have them (
when/subsumes/notesomitted, not null/empty, when absent).
- Return type:
dict[str,Any]
- ensembl.vep.annotators.consequence.rules.editing.derive_subsumes(so_parent_accessions, entries_by_accession)[source]#
Walk
so_supported_parentstransitively to propose asubsumesset.Direction: if the new term A is_a an existing catalogue term B (B is one of A’s SO parents), A is the more specific term, so A subsumes B – suppressing B whenever A also fires. Walking stays inside the catalogue: an SO parent accession not represented here cannot be proposed (there is nothing to subsume), and a present-but-
when-less ancestor (an EXCLUDED_TERMS-style term, see consequence/rules/catalogue.py) is skipped from the proposal itself – it can never appear in a compiled FactRuleSet, so declaring a rule subsumes it would fail validation – but is still noted, and its own further-up parents are still walked past it.- Parameters:
so_parent_accessions (
Sequence[str]) – The new term’s immediate SO parent accessions.entries_by_accession (
dict[str,dict[str,Any]]) – accession -> catalogue entry lookup.
- Returns:
- The proposed, sorted
subsumesterm tuple, and a list of human-readable notes about the walk (skipped/unknown/excluded ancestors).
- The proposed, sorted
- Return type:
tuple[tuple[str,...],list[str]]
- ensembl.vep.annotators.consequence.rules.editing.insert_at_rank(entries, new_entry, requested_rank)[source]#
Insert
new_entryatrequested_rank, shifting later ranks down to make room.- Parameters:
entries (
list[dict[str,Any]]) – The catalogue’sconsequenceslist (not mutated).new_entry (
dict[str,Any]) – The entry to insert; itsrankkey is set by this function.requested_rank (
int|None) – The 1-based rank to insert at, or None to append after the current highest rank.
- Returns:
- A new list, sorted by rank, with
new_entryinserted and every colliding/later rank shifted up by one.
- A new list, sorted by rank, with
- Return type:
list[dict[str,Any]]- Raises:
ValueError – If
requested_rankis outside1..(current highest rank + 1).
- ensembl.vep.annotators.consequence.rules.editing.next_rank(entries)[source]#
Return the rank one past the current highest rank.
- Parameters:
entries (
list[dict[str,Any]]) – The catalogue’sconsequenceslist.- Returns:
max(rank for every entry) + 1, or 1 ifentriesis empty.- Return type:
int
- ensembl.vep.annotators.consequence.rules.editing.remove_term(entries, term)[source]#
Remove
term, clean up every other entry’ssubsumes, and close the rank gap.- Parameters:
entries (
list[dict[str,Any]]) – The catalogue’sconsequenceslist (not mutated).term (
str) – The term to remove. Caller has already verified it exists.
- Returns:
- The remaining entries (rank-sorted, gap closed),
and the sorted list of terms whose
subsumesreferencedtermand were cleaned.
- Return type:
tuple[list[dict[str,Any]],list[str]]
- ensembl.vep.annotators.consequence.rules.editing.resolve_when(when_argument, known_atoms)[source]#
Resolve
--wheninto a validated payload, or a needs-review placeholder.- Parameters:
when_argument (
str|None) – The raw--whenJSON text, or None if not given.known_atoms (
list[str]) – Every registered fact atom name (ensembl.vep.annotators.consequence. facts.base.atom_names()), used to validate an explicitwhen.
- Returns:
(when_payload, messages, needs_review).when_payloadis a compiled-valid JSON payload ifwhen_argumentwas given, else None.needs_reviewis True wheneverwhen_payloadis None.
- Return type:
tuple[object|None,list[str],bool]- Raises:
ValueError – If
when_argumentis not valid JSON, does not compile to an expression, or references an atom name that is not registered.
ensembl.vep.annotators.consequence.rules.expressions module#
Boolean expression tree for consequence rules.
- class ensembl.vep.annotators.consequence.rules.expressions.And(*children)[source]#
Bases:
ExprCombine child expressions with logical conjunction.
- class ensembl.vep.annotators.consequence.rules.expressions.Atom(name)[source]#
Bases:
ExprRepresent one fact atom by name.
- evaluate_partial(known)[source]#
Return this atom’s known value, if assigned.
- Return type:
bool|None
- name: str#
- class ensembl.vep.annotators.consequence.rules.expressions.Expr[source]#
Bases:
objectRepresent a Boolean expression over fact atoms.
- atoms()[source]#
Return every fact atom referenced by this expression.
- Returns:
The referenced fact atom names.
- Return type:
set[str]
- cost()[source]#
Return the cold cost of evaluating this expression.
- Returns:
The total cost of every atom referenced, counting each shared dependency once.
- Return type:
int
- evaluate(fact_context)[source]#
Evaluate this expression against a fact context, computing facts as needed.
- Parameters:
fact_context (
FactContext) – The overlap to evaluate against.- Returns:
The expression’s truth value.
- Return type:
bool
- evaluate_partial(known)[source]#
Evaluate this expression against a partial (Kleene) assignment.
Returns True/False when the atoms in
knownalready settle the formula, and None when they do not. This is what lets an annotator decide a rule from cheap facts alone and never touch the expensive tiers.- Parameters:
known (
dict[str,bool]) – A partial assignment of fact atom names to boolean values.- Returns:
The expression’s truth value if settled by
known, else None.- Return type:
bool|None
- class ensembl.vep.annotators.consequence.rules.expressions.Not(child)[source]#
Bases:
ExprNegate one child expression.
- class ensembl.vep.annotators.consequence.rules.expressions.Or(*children)[source]#
Bases:
ExprCombine child expressions with logical disjunction.
- ensembl.vep.annotators.consequence.rules.expressions.all_of(*operands)[source]#
Build a conjunction from a mix of Expr nodes and bare fact atom names.
- ensembl.vep.annotators.consequence.rules.expressions.any_of(*operands)[source]#
Build a disjunction from a mix of Expr nodes and bare fact atom names.
- ensembl.vep.annotators.consequence.rules.expressions.expr_from_json(payload)[source]#
Compile a JSON boolean expression payload (as used in the consequence catalogue) into an Expr.
The payload grammar is:
a bare string -> Atom
{"not": <payload>}-> Not{"all": [<payload>, ...]}-> And{"any": [<payload>, ...]}-> Or
- Parameters:
payload (
object) – A JSON-decoded boolean expression, in the grammar above.- Returns:
The compiled expression tree.
- Return type:
- Raises:
ValueError – If
payloaddoes not match the grammar above.
ensembl.vep.annotators.consequence.rules.rulesets module#
Compile and evaluate rank-ordered consequence rules.
Rules do not reference other rules. Subsumption expresses suppression between firing terms, while
FactRule.cheap_guard derives inexpensive preconditions directly from each formula. Keeping both
relationships declarative prevents hand-maintained predicates or guard tables from drifting.
- class ensembl.vep.annotators.consequence.rules.rulesets.FactRule(*, term, accession, rank, tier=3, impact, when, subsumes=(), feature_type=<class 'ensembl.vep.models.feature.Feature'>, overlapping_feature_type=<class 'ensembl.vep.models.variation.variation_allele.VariationAllele'>, notes=None)[source]#
Bases:
objectRepresent one SO term as a Boolean formula and catalogue metadata.
- Variables:
term (str) – The SO term, e.g. “missense_variant”.
accession (str) – The SO accession, e.g. “SO:0001583”.
rank (int) – Severity rank; 1 is most severe.
tier (int) – Tier grouping, carried through from the catalogue.
impact (ConsequenceImpact | None) – The IMPACT rating.
when (Expr) – The boolean formula over fact atoms that must hold for this term to apply.
subsumes (tuple[str, ...]) – Term names this rule suppresses when evaluated as true.
feature_type (type[Feature]) – The overlapped feature type this rule applies to.
overlapping_feature_type (type[Feature]) – The overlapping feature type (variant allele).
notes (str | None) – Free-text notes, if any.
- accession: str#
- atoms()[source]#
Return every fact atom referenced by this rule.
- Returns:
The referenced fact atom names.
- Return type:
set[str]
- cheap_guard()[source]#
Return inexpensive top-level positive conjuncts.
This is the automatically-derived equivalent of VEP’s hand-maintained
includehash.- Returns:
- Names of top-level atoms in a top-level conjunction whose
closure cost is at most BOUNDS.
- Return type:
frozenset[str]
- impact: ConsequenceImpact | None#
- notes: str | None#
- rank: int#
- subsumes: tuple[str, ...]#
- term: str#
- tier: int#
- class ensembl.vep.annotators.consequence.rules.rulesets.FactRuleSet(*, rules)[source]#
Bases:
objectStore rank-ordered fact rules and term lookup.
Covers every overlapped-feature class, and there is no per-class subset to select: a rule restricted to one class says so in its own formula, via the FREE class facts in consequence/facts/kind.py. See build_fact_ruleset.
- Variables:
- ensembl.vep.annotators.consequence.rules.rulesets.build_fact_ruleset()[source]#
Compile a FactRuleSet from the packaged consequence catalogue.
- Returns:
The compiled, rank-ordered rule set, covering every feature class.
- Return type:
- ensembl.vep.annotators.consequence.rules.rulesets.build_fact_ruleset_from_definitions(definitions)[source]#
Compile a rule set from catalogue definitions.
The single compilation path:
build_fact_rulesetreads the packaged catalogue and delegates here, and the catalogue editor compiles its candidate entries the same way, so a change cannot validate against a rule set built differently from the one the annotators will use.Entries with no
when(see EXCLUDED_TERMS in consequence/rules/catalogue.py) are skipped, since there is no fact-atom formula to compile for them.- Parameters:
definitions (
Iterable[ConsequenceDefinition]) – The entries to compile.- Returns:
The compiled, rank-ordered rule set.
- Return type:
- ensembl.vep.annotators.consequence.rules.rulesets.coding_terms()[source]#
Return the catalogue terms whose rule reads
overlap_cds.Derived rather than tabulated: a rule that reads the CDS is a coding rule, and that is the whole definition.
- Return type:
frozenset[str]
- ensembl.vep.annotators.consequence.rules.rulesets.prune(ruleset, hit_terms, *, apply_default=True)[source]#
Drop terms superseded by another term that fired.
- Parameters:
ruleset (
FactRuleSet) – The rule sethit_termswere matched against.hit_terms (
list[str]) – Every term whose rule matched, in any order.apply_default (
bool, default:True) – If True, substitute[DEFAULT_TERM]when nothing survives pruning. If False, return an empty list instead and let the caller decide whether/how to apply a default term.
- Returns:
hit_termswith every subsumed term removed. Empty (ifapply_defaultisFalse) or
[DEFAULT_TERM](otherwise) when nothing survives.
- Return type:
list[str]
- ensembl.vep.annotators.consequence.rules.rulesets.subsumes_topological_order(ruleset)[source]#
Order the rules so a rule comes after a rule that can suppress it.
After every rule has been evaluated, the subsumed terms are dropped. A rule whose term is certain to be suppressed by a higher-ranked term therefore evaluated for nothing. Evaluating in this order instead lets a scan skip such a rule outright.
The
subsumesgraph is acyclic. TheRulePairFinding.contradictory_inandfind_subsumption_cyclesin rules/validation.py both reject cycles. So, a depth-first post-order is a valid topological sort. A cycle, were one ever introduced, it would not degrade to an infinite loop, and the conformance suite would catch the resulting output difference.- Parameters:
ruleset (
FactRuleSet) – The rule set to order.- Returns:
- Every rule in
ruleset, ordered so that a rule appears after every rule that (transitively) subsumes it.
- Every rule in
- Return type:
tuple[FactRule,...]
ensembl.vep.annotators.consequence.rules.validation module#
Validate consequence rule structure and satisfiability.
Validation has three tiers:
StructuralChecksvalidates references, ranks, subsumption, and catalogue metadata.RuleReachabilityandRulePairFindingsearch boundedFactAssignmentSpaceinstances.Optional
SolverChecksasks equivalent whole-rule-set questions through an SAT solver.
- class ensembl.vep.annotators.consequence.rules.validation.FactAssignmentSpace(*, support)[source]#
Bases:
objectDefine consistent Boolean fact assignments over an atom support.
Centralises
requiresclosure, declared axioms, enumeration, and satisfiability searches used by single-rule and pairwise validation.- Variables:
support (tuple[str, ...]) – The atom names this space is defined over, sorted.
- allows(assignment)[source]#
Return whether an assignment over this support violates no
requires/axiom.- Parameters:
assignment (
dict[str,bool]) – A full assignment over some atom support.- Returns:
- False if the assignment sets some atom True while a declared
requiresof it is False in the same assignment, or violates an exclusivity/equivalence axiom; True otherwise (i.e. this is an assignment a real Context could actually produce, as far as the declared constraints can tell).
- False if the assignment sets some atom True while a declared
- Return type:
bool
- consistent_assignments()[source]#
Yield every assignment over this support consistent with
requires/the declared axioms.- Yields:
dict[str, bool] – One consistent full assignment per iteration.
- classmethod for_rule(rule)[source]#
Return the space a rule’s formula must be evaluated over to be judged soundly.
- Parameters:
rule (
FactRule) – The rule to compute a support for.- Returns:
- The space over
rule.atoms(), extended by therequiresclosure and by any declared axiom atoms that touch it, sorted for a deterministic enumeration order.
- The space over
- Return type:
- satisfies(expression)[source]#
Return whether an expression has a consistent assignment over
support.This searches different combinations of values of atoms making up an expression to check whether given the logical constraints of the expression, it is possible for the expression to be satisfied. It is just checking if it is possible for the expression to be satisfied, so it stops as soon as it finds a valid set of assignments.
- Parameters:
expression (
Expr) – The expression whose satisfiability is being checked.- Returns:
True if at least one consistent assignment satisfies
expression.- Return type:
bool
- support: tuple[str, ...]#
- class ensembl.vep.annotators.consequence.rules.validation.RulePairFinding(*, kind, term_a, term_b, message)[source]#
Bases:
objectRecord one pairwise rule-validation finding.
- Variables:
kind (str) – Either
"CONTRADICTORY"(the two rules’ formulas can never both hold) or"REDUNDANT"(ruleterm_asubsumesterm_bandterm_a’s formula logically entailsterm_b’s, confirming the subsumption is logically grounded). Both kinds are informational governance signal, not build-breaking errors – see RulePairFinding.contradictory_in/RulePairFinding.redundant_in.term_a (str) – The first rule’s term.
term_b (str) – The second rule’s term.
message (str) – Human-readable description.
- classmethod contradictory_in(ruleset, *, max_union_support=18)[source]#
Find rule pairs whose formulas can never both hold, and that do not subsume each other.
This is informational rather than an error: two rules never co-firing is often simply how the ruleset is meant to work (e.g.
stop_gainedandsynonymous_variantare naturally mutually exclusive), not a defect. It is useful context for a catalogue reviewer – a pair that should be able to co-fire but this check finds contradictory would be worth a second look – rather than something a script should fail the build over.- Parameters:
ruleset (
FactRuleSet) – The rule set to check every pair of.max_union_support (
int, default:18) – Skip a pair whose combined atom support exceeds this size, so a future larger catalogue degrades to “fewer pairs checked” rather than a slow/unbounded enumeration.
- Returns:
One
"CONTRADICTORY"finding per such pair.- Return type:
list[RulePairFinding]
- kind: str#
- message: str#
- classmethod redundant_in(ruleset, *, max_union_support=18)[source]#
Find declared
subsumesedges whose entailment is confirmed by the formulas themselves.For each declared
A subsumes B, check whetherA.whenlogically entailsB.whenover every valid assignment of their combined support (i.e. whenever A’s formula could possibly be true, B’s formula is necessarily true too). Where it holds, the subsumption is logically redundant in the sense that A firing already guarantees B’s condition holds – thesubsumesdeclaration is provably sound, not merely asserted. Where it does not hold under this bounded axiom set, that is not reported as an error: most of this catalogue’s subsumption edges rely on domain knowledge broader than the small declared axiom set here (e.g. “a deletion spanning the whole transcript necessarily also overlaps every intron and UTR” is true, but nothing in _EXCLUSIVITY_AXIOM_PAIRS encodes it), so a pair not appearing in this report is inconclusive, not suspect.- Parameters:
ruleset (
FactRuleSet) – The rule set to check every declaredsubsumesedge of.max_union_support (
int, default:18) – Skip an edge whose combined atom support exceeds this size.
- Returns:
One
"REDUNDANT"finding per confirmed-entailed edge.- Return type:
list[RulePairFinding]
- term_a: str#
- term_b: str#
- class ensembl.vep.annotators.consequence.rules.validation.RuleReachability(*, term, support, valid_assignment_count, satisfying_assignment_count)[source]#
Bases:
objectRepresent the Tier 2 reachability result for one rule.
- Variables:
term (str) – The rule’s SO term.
support (tuple[str, ...]) – The atom support (see atom_support_for_rule) the rule was enumerated over.
valid_assignment_count (int) – Number of assignments over
supportconsistent with the declaredrequires/axioms.satisfying_assignment_count (int) – Of those, the number for which the rule’s
whenevaluates True.
- classmethod for_rule(rule)[source]#
Determine whether a rule is reachable within its fact-assignment space.
- Parameters:
rule (
FactRule) – The rule to check.- Returns:
- The enumeration result.
evaluate_partialnever returns None here, because
supportis constructed to be a superset ofrule.atoms().
- The enumeration result.
- Return type:
- property is_reachable: bool#
Return whether a valid assignment satisfies the rule.
- satisfying_assignment_count: int#
- support: tuple[str, ...]#
- term: str#
- classmethod unreachable_in(ruleset)[source]#
Return every rule whose
whenformula is unsatisfiable under the Tier 2 axioms.An unreachable rule is dead code: it can never contribute a term to any output, which – unlike the CONTRADICTORY/REDUNDANT findings below – is a genuine defect rather than informational context, so callers (the validation script, the test suite) should treat a non-empty result as a build-breaking error.
- Parameters:
ruleset (
FactRuleSet) – The rule set to check.- Returns:
- The unreachable rules’ results (
is_reachableFalse for all of them), or an empty list if every rule is reachable.
- The unreachable rules’ results (
- Return type:
list[RuleReachability]
- valid_assignment_count: int#
- class ensembl.vep.annotators.consequence.rules.validation.SolverChecks[source]#
Bases:
objectRun whole-rule-set validation through z3.
- classmethod findings(ruleset)[source]#
Run the whole-ruleset reachability and subsumption-soundness queries via z3.
- Parameters:
ruleset (
FactRuleSet) – The rule set to check.- Returns:
- Findings, prefixed
"UNREACHABLE (z3): ..."(a rule whose formula is unsatisfiable under the axioms – a real defect) or
"NOT ENTAILED (z3): ..."(a declaredsubsumesedge not backed by formula entailment – informational, see RulePairFinding.redundant_in’s docstring for why that is not automatically a bug).
- Findings, prefixed
- Return type:
list[str]- Raises:
RuntimeError – If
z3is not installed. Install the optionalvalidationextra (pip install '.[validation]'/uv sync --extra validation) to use this.
- class ensembl.vep.annotators.consequence.rules.validation.StructuralChecks[source]#
Bases:
objectRun validation checks that require no formula evaluation.
Grouped rather than left as loose functions because they share one subject - the declared shape of a rule set.
- classmethod missing_when_terms()[source]#
Cross-check EXCLUDED_TERMS against the catalogue.
build_fact_rulesetsilently skips any catalogue entry without awhen, on the documented assumption that every such entry is listed inEXCLUDED_TERMS. This check makes that assumption checked rather than trusted: a catalogue edit that adds awhen-less term without updatingEXCLUDED_TERMS(or vice versa) would otherwise silently under- or over-cover the ruleset.- Returns:
- One description per catalogue entry whose
when-presence disagrees with its EXCLUDED_TERMSmembership, or an empty list if they agree everywhere.
- One description per catalogue entry whose
- Return type:
list[str]
- classmethod ruleset_problems(ruleset)[source]#
Run structural checks over a rule set.
Rank inversions are warnings rather than errors on purpose: VEP has real ones (
splice_donor_region_variantis ranked belowsplice_region_variantyet suppresses it), so ranking order and suppression order are genuinely two different orders. Making that visible is more useful than pretending one implies the other.- Parameters:
ruleset (
FactRuleSet) – The rule set to validate.- Returns:
(errors, warnings). A non-emptyerrorslist meansthe rule set is broken (unknown/internal fact reference, duplicate rank, mutual/cyclic suppression); a non-empty
warningslist flags rank inversions, which are expected and not a failure.
- Return type:
tuple[list[str],list[str]]
- classmethod subsumes_so_parent_drift(ruleset)[source]#
Report where the declared
subsumesgraph disagrees with the SOso_supported_parents.These are two genuinely different relations that happen to overlap a lot:
subsumesis VEP’s empirical suppression behaviour (term A, if it fires, hides term B), whileso_supported_parentsis the Sequence Ontology’sis_aparent graph (term A is a kind of term B), restricted to parents also represented in this catalogue. A rule can subsume a term it is not an SO child of (e.g. suppressing a sibling), and a rule can have an SO parent it does not need to suppress (the parent’s ownwhenmay already be false whenever the child’s is true, with no pruning required). So this report is informational context for a catalogue reviewer, not a pass/fail check – drift here is common and often fine; it is a prompt to look, not a bug report.- Parameters:
ruleset (
FactRuleSet) – The rule set to report drift for.- Returns:
- One description per rule with at least one asymmetry between its
subsumes set and its SO-parent-derived term set, or an empty list if every rule’s two sets match exactly.
- One description per rule with at least one asymmetry between its
- Return type:
list[str]
- classmethod subsumption_cycles(ruleset)[source]#
Detect every cycle in the
subsumesgraph via DFS.Stronger than a pairwise mutual-suppression check (which only catches 2-cycles: A subsumes B and B subsumes A): a longer cycle (A subsumes B subsumes C subsumes A) would let
prunedrop every term in the cycle whenever any one of them fires, which is never the intended suppression shape and is worth surfacing on its own even though the pairwise check in ruleset_problems also happens to catch the 2-cycle case.- Parameters:
ruleset (
FactRuleSet) – The rule set to inspect.- Returns:
- One description per distinct cycle found (deduplicated by member-set, so a
cycle reached via two different DFS roots is reported once), or an empty list if the
subsumesgraph is acyclic.
- Return type:
list[str]
- classmethod term_and_rank_uniqueness(entries)[source]#
Check term/rank uniqueness across every entry, including
when-less ones.ruleset_problems only sees entries that made it into a FactRuleSet (i.e. have a
when), so a duplicate rank between twowhen-less entries – or between awhen-less entry and a compiled rule – would otherwise go unnoticed.- Parameters:
entries (
list[dict[str,Any]]) – The candidate catalogue’sconsequenceslist.- Returns:
- One description per duplicate term or rank found, or an empty list if every
term and rank is unique.
- Return type:
list[str]
- class ensembl.vep.annotators.consequence.rules.validation.ValidationReport(*, errors, warnings, missing_when_problems, so_parent_drift, unreachable_rules, contradictory_pairs, redundant_pairs=list())[source]#
Bases:
objectCombine structural and bounded-search validation results.
- Variables:
errors (list[str]) – From validate_ruleset; non-empty means the ruleset is broken.
warnings (list[str]) – From validate_ruleset; expected rank inversions.
missing_when_problems (list[str]) – From report_missing_when_terms; non-empty means the catalogue and
EXCLUDED_TERMShave drifted apart – treat as an error.so_parent_drift (list[str]) – From report_subsumes_so_parent_drift; informational.
unreachable_rules (list[RuleReachability]) – From RuleReachability.unreachable_in; non-empty means a rule can never fire – treat as an error.
contradictory_pairs (list[RulePairFinding]) – From RulePairFinding.contradictory_in; informational.
redundant_pairs (list[RulePairFinding]) – From RulePairFinding.redundant_in; informational.
- contradictory_pairs: list[RulePairFinding]#
- errors: list[str]#
- classmethod for_catalogue_entries(entries, baseline_entries)[source]#
Validate a candidate
consequenceslist before it is ever written to disk.Reuses ensembl.vep.annotators.consequence.rules.validation’s structural (Tier 1) and enumeration (Tier 2) checks over a FactRuleSet built from the candidate entries (see _ruleset_from_entries) – not the packaged catalogue, which is what makes this safe to call before a real term has been added or removed on disk. The two checks that hardcode a call to the packaged load_consequence_definitions() (report_missing_when_terms, report_subsumes_so_parent_drift) are intentionally not reused here, since they are defined in terms of the checked-in EXCLUDED_TERMS/catalogue rather than a candidate in-memory one; a needs-review,
when-less addition is instead surfaced separately, at add-time, by resolve_when’s NEEDS REVIEW banner.Unreachable-rule findings are diffed against
baseline_entries(the catalogue before this add/remove was applied) rather than treated as build-breaking outright: the checked-in catalogue already carries one known, pre-existing dead rule (feature_truncation). Treating every unreachable rule as build-breaking here would permanently refuse every write against the real catalogue, for a reason unrelated to whatever term is being added or removed. A rule unreachable in both the baseline and the candidate is downgraded to an informational warning; one that only became unreachable in the candidate is a genuine regression introduced by this operation and stays build-breaking.- Parameters:
entries (
list[dict[str,Any]]) – The candidate catalogue’sconsequenceslist.baseline_entries (
list[dict[str,Any]]) – The catalogue’sconsequenceslist before this operation, used only to distinguish pre-existing unreachable rules from new ones.
- Returns:
- errors/unreachable_rules non-empty means refuse to write; warnings are
informational only (see ValidationReport.has_errors).
- Return type:
- classmethod for_ruleset(ruleset)[source]#
Run every Tier 1 + Tier 2 check over a rule set. Pure Python, always on; no z3 required.
- Parameters:
ruleset (
FactRuleSet) – The rule set to validate.- Returns:
- The combined result. See ValidationReport.has_errors for the
build-breaking subset.
- Return type:
- property has_errors: bool#
Return whether the report contains a build-breaking finding.
- missing_when_problems: list[str]#
- redundant_pairs: list[RulePairFinding]#
- so_parent_drift: list[str]#
- unreachable_rules: list[RuleReachability]#
- warnings: list[str]#