ensembl.vep.explain package#

Overlap selection, annotation, comparison, and summaries for vep explain.

Separate from runner/explain.py, which is only the subcommand: reading the options, choosing which rendering was asked for, and writing it out. Everything a second caller could want – naming and finding the overlaps of a real input, annotating one with tracing on, diffing two derivations, summarising an overlap – lives here.

The package sits above trace: a trace is recorded during annotation, and these modules read one afterwards.

Submodules#

ensembl.vep.explain.annotate module#

Traced annotation of one overlap.

ensembl.vep.explain.annotate.annotate_with_trace(config, annotator_name, overlap)[source]#

Run one annotator over one overlap with tracing on.

Parameters:
  • config (Config) – The run’s configuration, for the annotator and cache options.

  • annotator_name (str) – A registered annotator name.

  • overlap (TranscriptVariationAllele) – The overlap to annotate.

Returns:

The emitted terms, and the derivation – None

for a native rust.* annotator, which never traces.

Return type:

tuple[list[str], AnnotationTrace | None]

ensembl.vep.explain.compare module#

Comparison of traced derivations and assigned terms.

Comparing two traces identifies the first differing fact value, rule verdict, or subsumption path, rather than reporting only different emitted terms. diff_terms compares a trace with terms from an annotator or an already-annotated input when the other side cannot provide a trace.

ensembl.vep.explain.compare.diff_terms(trace, expected_terms, source)[source]#

Compare a derivation with terms assigned by another source.

For a missing expected term, the rule ledger distinguishes a false rule from a fired rule that was later subsumed. Terms absent from the catalogue are reported as unmodelled rather than as rule failures.

Parameters:
  • trace (AnnotationTrace) – Derivation to compare.

  • expected_terms (Sequence[str]) – Terms assigned by the other source.

  • source (str) – Source name used in the report.

Returns:

Comparison with an explanation for each differing term.

Return type:

str

ensembl.vep.explain.compare.diff_traces(trace_a, trace_b)[source]#

Compare two derivations of one overlap.

Parameters:
Returns:

Emitted-term result, shared fact differences, and rule-verdict differences.

Return type:

str

ensembl.vep.explain.selection module#

Overlap selection for consequence explanations.

Explaining one derivation needs one (variant, transcript) pair out of a real input, which is a different job from annotating a whole file: there is no buffering, no output, and reading the whole input to pair every variant would be waste when the caller named one. What it must not be is a second opinion about which pairs exist – so the pairing here is built by the transcript track’s own build_transcript_overlap_finder over the same sources the run path builds, and only the search is explain’s own.

The two kinds of source answer the same question differently: a file is searched for the named variant alone, pairing no more of it than that takes, while a generated corpus is walked, there being nothing to query. OverlapSelection holds that choice for one run, reading each source lazily and at most once, so selecting by name costs one pass and selecting nothing costs none.

class ensembl.vep.explain.selection.FeatureSelector(*, stable_id)[source]#

Bases: object

Feature selector using a stable identifier and optional GFF3 type prefix.

A GFF3 spells a transcript’s id transcript:ENST00000775241 and the reader keeps it, while a caller naturally types ENST00000775241; both name the same feature.

Variables:

stable_id (str) – The stable id the caller typed, either spelling.

matches(feature)[source]#

Return whether a feature is the one this selector names.

A prefix match is not a match: the id after the prefix has to be the same one.

Return type:

bool

classmethod parse(selector)[source]#

Parse a feature selector.

Parameters:

selector (str) – A stable id, e.g. ENST00000775241 or transcript:ENST00000775241.

Returns:

The parsed selector.

Return type:

FeatureSelector

Raises:

ValueError – If the selector is empty.

stable_id: str#
ensembl.vep.explain.selection.NamedOverlap#

One overlap and the name of the variant it came from.

alias of tuple[str, TranscriptVariationAllele]

class ensembl.vep.explain.selection.OverlapSelection(*, config)[source]#

Bases: object

Selectable overlaps and the sources used to find them.

Variables:
  • config (Config) – The run’s configuration; its source, corpus and explain sections say where the overlaps come from and which one is wanted.

  • sources (tuple[InputSource, TranscriptSource] | None) – The two readers, built from the configuration on first use. Assignable so a caller can supply readers of its own – a test over in-memory sequence, say – instead of real files.

all_overlaps()[source]#

Yield every selectable overlap, in the order --index counts.

Pairing every variant means reading both files whole: an un-indexed GFF3 or GTF cannot serve a region query at all, and a caller asking for the listing has asked for all of them. The transcripts are grouped by sequence region once, rather than queried per variant, which is what keeps this one pass over each file.

Return type:

Iterator[tuple[str, TranscriptVariationAllele]]

candidate_overlaps(name=None, selector=None)[source]#

Yield the overlaps that could match, pairing no more of the input than it takes.

A real input is searched for the named variant alone; a generated corpus is walked, there being nothing to query, and is returned unfiltered for the caller to sift.

Parameters:
  • name (str | None, default: None) – The variant name to look for.

  • selector (VariantSelector | None, default: None) – The variant’s locus and alleles, or its identifier.

Yields:

NamedOverlap – Every overlap that still has to be filtered by the caller.

close()[source]#

Release the generated corpus, if one was built.

config: Config#
description()[source]#

Describe where the overlaps come from, for an error or a log line.

Return type:

str

listing()[source]#

Return every selectable overlap, one per line, as index, name and feature.

Return type:

str

select()[source]#

Return the single overlap the selectors identify.

A name or a variant identifies the variant, not the overlap, so one that pairs with several features needs --transcript as well. Saying which stable ids matched is the whole value of the error, so the message names them.

Returns:

The selected overlap and the name it came under.

Return type:

tuple[str, TranscriptVariationAllele]

Raises:
  • LookupError – If nothing matches, if several do and no feature was named, or if the index is past the end.

  • ValueError – If the variant selector is malformed, or an allele number was given without a CHR:POS:ID variant.

sources: tuple[PicklableVCFVariationSource, GFF3TranscriptSource | GTFTranscriptSource] | None#
class ensembl.vep.explain.selection.VariantSelector(*, seq_region_name, position, reference_allele=None, alternate_allele=None, identifier=None, allele_num=1)[source]#

Bases: object

Variant selector written as CHR:POS:REF>ALT or CHR:POS:ID.

The two forms locate a variant differently. REF>ALT names one allele by its minimised coordinates, as the model stores them. ID names a record by the identifier and position the input gives it – a VCF’s ID and POS columns – and allele_num picks one of its alternate alleles.

Variables:
  • seq_region_name (str) – Sequence region name.

  • position (int) – The allele’s start for REF>ALT, the input’s own position for ID.

  • reference_allele (str | None) – Upper-cased reference allele, "" when empty; None for ID.

  • alternate_allele (str | None) – Upper-cased alternate allele, "" when empty; None for ID.

  • identifier (str | None) – The variant’s identifier in the input; None for REF>ALT.

  • allele_num (int) – Which alternate allele an ID selects, counting from 1.

allele_num: int#
alternate_allele: str | None#
identifier: str | None#
matches(allele)[source]#

Return whether an allele is the one this selector names.

Return type:

bool

classmethod parse(selector, *, allele_num=None)[source]#

Parse a selector, with - for an empty allele.

Parameters:
  • selector (str) – CHR:POS:REF>ALT, e.g. chr1:1052:->ACG for an insertion before 1052, or CHR:POS:ID, e.g. 22:15528194:rs123.

  • allele_num (int | None, default: None) – The alternate allele an ID selects, counting from 1. None means the first.

Returns:

The parsed selector.

Return type:

VariantSelector

Raises:

ValueError – If the selector does not have either shape, or allele_num is given for a REF>ALT selector, which already names its allele, or is below 1.

position: int#
property query_span: tuple[int, int]#

Return the 1-based query span covering this variant’s input record.

One base before the position as well, because a VCF anchors an indel on the preceding base and the minimised start of an insertion lies after it.

reference_allele: str | None#
seq_region_name: str#

ensembl.vep.explain.summary module#

Text and HTML summaries of explained overlaps.

The summary describes the variant, transcript, affected positions, codons, and full-sequence changes before presenting how the annotator reached its result.

ensembl.vep.explain.summary.format_summary(overlap)[source]#

Return the summary as an aligned text block headed summary:.

Return type:

str

ensembl.vep.explain.summary.summary_html(overlap)[source]#

Return the summary as an HTML table for an explanation page.

Return type:

str

ensembl.vep.explain.summary.summary_rows(overlap)[source]#

Return applicable overlap details as labelled rows.

Parameters:

overlap (TranscriptVariationAllele) – The overlap to describe.

Returns:

Label-value pairs in reading order.

Return type:

list[tuple[str, str]]