ensembl.vep.stats package#

Run statistics: the term-level summary a run writes by default, and the opt-in fact profile.

Two planes, kept as two types on purpose. RunSummary costs about a millisecond a run and is on by default; RunTrace (ensembl.vep.trace.run) is fact-level, measured at 1.3-1.7x on the hottest path, and exists only when tracing is on. One merged type would stop the signature saying what it costs to produce. Both satisfy Reportable, so the renderers never branch on which they were handed.

Submodules#

ensembl.vep.stats.profile module#

Fact-level profiling collected by instrumenting an annotation run.

Profiling is opt-in because counting replaces each fact’s compute callback and tracing records every overlap derivation. The process-global callback replacement is restored before returning and is not thread-safe; computed values remain local to each FactContext.

ensembl.vep.stats.profile.count_fact_computations()[source]#

Count every fact compute call and its declared cost, process-wide, for the duration.

Yields:

dict[str, int] –

A live {"computed": ..., "cost": ...} counter, updated as facts are

computed while the block is active.

ensembl.vep.stats.profile.trace_run(annotator, overlaps, *, annotator_name='', cost_table='')[source]#

Annotate every overlap with tracing on and fold the derivations into one run-scoped view.

Parameters:
  • annotator (Annotator[OverlapConsequence]) – The annotator to run. A native one never traces, so its run folds to nothing.

  • overlaps (Sequence[TranscriptVariationAllele]) – The overlaps to annotate, in order.

  • annotator_name (str, default: '') – The annotator’s registry name, for the report.

  • cost_table (str, default: '') – Which cost table the declared costs came from, for the report.

Returns:

The fold.

Return type:

RunTrace

ensembl.vep.stats.report module#

Report contracts and rendering.

class ensembl.vep.stats.report.Reportable(*args, **kwargs)[source]#

Bases: Protocol

Anything that can be rendered as a report.

Members are properties rather than attributes: the implementers are frozen attrs classes, and a Protocol declaring a plain attribute demands a settable one.

sections()[source]#

Return the report sections in rendering order.

Return type:

tuple[ReportSection, ...]

property subtitle: str#

Return one line shown under the title.

property title: str#

Return the document title.

ensembl.vep.stats.report.render_reportable(report, report_format)[source]#

Render any report in the requested format.

Return type:

str

ensembl.vep.stats.summary module#

Term-level annotation run summaries.

Most of it is already on the model: Variation.class_so_term is the variant-classes chart and Variation.most_severe_consequence the most-severe chart. The collector adds only what is genuinely cross-variant – every consequence, the coding ones, variants by chromosome and where along it they fall – and the run’s own metadata. Cheap enough to be on by default: about a microsecond per overlap, against a fact layer called ninety times as often.

ensembl.vep.stats.summary.POSITION_BINS = 10#

How many equal bins a chromosome’s observed span is divided into for the position chart.

class ensembl.vep.stats.summary.RunSummary(*, variants=0, alleles=0, overlaps=0, variant_classes=(), most_severe=(), consequences=(), coding_consequences=(), by_chromosome=(), positions=(), metadata=())[source]#

Bases: object

Term-level summary of an annotation run.

Variables:
  • variants (int) – Variations observed.

  • alleles (int) – Alternate alleles across them.

  • overlaps (int) – Feature overlaps across those alleles.

  • variant_classes (tuple[tuple[str, int], ...]) – Class SO term -> variants.

  • most_severe (tuple[tuple[str, int], ...]) – Most severe term -> variants.

  • consequences (tuple[tuple[str, int], ...]) – Every term -> overlaps carrying it.

  • coding_consequences (tuple[tuple[str, int], ...]) – The coding subset of the above.

  • by_chromosome (tuple[tuple[str, int], ...]) – Chromosome -> variants.

  • positions (tuple[tuple[str, int, int, int, int], ...]) – Chromosome, bin, from, to, variants – the distribution along each chromosome’s observed span. Streaming merges retain exact spans and totals; bin allocation is estimated if a later batch expands a chromosome’s span.

  • metadata (tuple[tuple[str, str], ...]) – The run’s own facts: command, counts, timings.

alleles: int#
by_chromosome: tuple[tuple[str, int], ...]#
coding_consequences: tuple[tuple[str, int], ...]#
consequences: tuple[tuple[str, int], ...]#
metadata: tuple[tuple[str, str], ...]#
most_severe: tuple[tuple[str, int], ...]#
overlaps: int#
positions: tuple[tuple[str, int, int, int, int], ...]#
sections()[source]#

Return the summary as report sections, in the order the Perl summary shows them.

Return type:

tuple[ReportSection, ...]

property subtitle: str#

Return the headline counts.

property title: str#

Return the document title.

variant_classes: tuple[tuple[str, int], ...]#
variants: int#
class ensembl.vep.stats.summary.RunSummaryCollector(*, metadata=dict())[source]#

Bases: object

Incremental collector for a RunSummary.

Variables:

metadata (dict[str, str]) – The run’s own facts, written into the summary as given.

property completed_position_regions: tuple[str, ...]#

Return regions whose raw positions have been released into bounded bins.

delta()[source]#

Return the mergeable counts accumulated so far.

Return type:

RunSummaryDelta

finish()[source]#

Return the summary of everything observed so far.

Return type:

RunSummary

merge(delta)[source]#

Merge a worker-buffer summary delta.

merge_ordered_delta(delta)[source]#

Merge one sequence-region worker delta in arbitrary source order.

Every position in a delta must belong to one sequence region. Deltas for a region may recur after other regions. A bounded histogram per region releases every raw position after merging. Expanding a region’s observed span reprojects its existing counts by bin midpoint, so endpoints and totals stay exact while individual bin counts become an estimate.

Raises:

ValueError – If a delta mixes sequence regions or the region has unordered positions.

metadata: dict[str, str]#
observe(variation)[source]#

Count one variation and everything hanging off it.

Parameters:

variation (Variation) – The variation, with its alleles’ consequences already known – whether assigned by an annotator or read back from a file.

property retained_ordered_position_count: int#

Return the number of raw positions retained by streaming merges.

class ensembl.vep.stats.summary.RunSummaryDelta(*, variants=0, alleles=0, overlaps=0, classes=(), most_severe=(), consequences=(), chromosomes=(), positions=())[source]#

Bases: object

Mergeable summary counts from one worker buffer.

Variables:
  • variants (int) – Number of variants.

  • alleles (int) – Number of alleles.

  • overlaps (int) – Number of feature overlaps.

  • classes (tuple[tuple[str, int], ...]) – Counts by variant class.

  • most_severe (tuple[tuple[str, int], ...]) – Counts by most severe consequence.

  • consequences (tuple[tuple[str, int], ...]) – Counts by consequence term.

  • chromosomes (tuple[tuple[str, int], ...]) – Counts by sequence region.

  • positions (tuple[tuple[str, int], ...]) – Observed positions by sequence region.

alleles: int#
chromosomes: tuple[tuple[str, int], ...]#
classes: tuple[tuple[str, int], ...]#
consequences: tuple[tuple[str, int], ...]#
most_severe: tuple[tuple[str, int], ...]#
overlaps: int#
positions: tuple[tuple[str, int], ...]#
variants: int#