ensembl.vep.corpus package#

Corpus construction and management.

A corpus contains variants and their (variant, feature) overlaps, however they were obtained. Keeping variants explicit preserves inputs with no feature overlap instead of forcing consumers to reconstruct variants from derived overlap records. The synthetic generator lives here rather than under annotators/ because it depends only on common and models and backs the session-scoped fixtures of the whole test suite, not one subsystem.

Subpackages#

Submodules#

ensembl.vep.corpus.annotate module#

A whole corpus in the shape an annotated file has: one variation per variant, its overlaps attached.

A corpus holds variants plus overlaps against their standalone alleles. A run – and anything reading a run’s output, like the summary – works on Variation objects whose alleles carry their overlaps. This rebuilds that shape, including variants with no overlaps, so a corpus can be summarised or written exactly as an annotated file would be.

ensembl.vep.corpus.annotate.annotate_and_attach(annotator, allele, overlaps)[source]#

Annotate an allele’s overlaps in one batch and attach them, consequences first.

The order is load-bearing. VariationAllele.transcript_variation_alleles carries on_setattr=invalidates("_overlap_consequences"), and that aggregate is built lazily from the overlaps’ own consequences. Assigning the consequences first means the aggregate is always computed from complete overlaps; the other way round, anything reading it in between would cache a stale, empty answer.

Parameters:
  • annotator (Annotator[OverlapConsequence]) – The annotator to run.

  • allele (VariationAllele) – The allele the overlaps belong to. An allele with no overlaps is attached an empty list, which is what makes it intergenic downstream.

  • overlaps (Sequence[TranscriptVariationAllele]) – The allele’s overlaps, each already built against allele.

ensembl.vep.corpus.annotate.annotated_variations(corpus, annotator)[source]#

Yield one annotated variation per generated variant, in corpus order.

A variant’s overlaps are contiguous in a corpus – one per feature in its flank window – so grouping by name preserves their order. Variants with no overlaps are still yielded with an empty attached-overlap collection.

Parameters:
Yields:

Variation – Each variant, its allele’s overlaps rebuilt against it and annotated.

ensembl.vep.corpus.annotate.variation_for(name, allele)[source]#

Return a single-allele variation with a corpus allele’s coordinates and alleles.

An empty allele stays an empty string, the corpus’s own spelling, so the rebuilt allele is the same allele the corpus overlap was annotated against.

Return type:

Variation

ensembl.vep.corpus.base module#

The corpus contract.

class ensembl.vep.corpus.base.Corpus[source]#

Bases: ABC

Provide inputs for transcript consequence annotation across sequence regions.

Implementations may generate or load their data from any backend. The biological contract is intentionally transcript-oriented for the annotators available today; adding regulatory or motif annotation will require a corresponding feature-level extension to this interface.

Variables:
  • spec (CorpusSpec) – Specification used to construct the corpus.

  • sequence_regions (tuple[Slice, ...]) – Referenced sequence regions in stable order.

  • named_variants (tuple[NamedVariant, ...]) – Stable names paired with variation alleles.

  • transcripts (tuple[Transcript, ...]) – Transcripts in stable order.

  • named_overlaps (tuple[NamedOverlap, ...]) – Named overlaps in stable order.

  • description (str) – Short human-readable corpus description.

close()[source]#

Release resources owned by the corpus.

property description: str#

Return a short description of the corpus.

abstract property named_overlaps: tuple[tuple[str, TranscriptVariationAllele], ...]#

Return every named transcript overlap in stable corpus order.

abstract property named_variants: tuple[tuple[str, VariationAllele], ...]#

Return every variant in stable corpus order.

abstract property sequence_regions: tuple[Slice, ...]#

Return every sequence region referenced by the corpus.

abstract property spec: CorpusSpec#

Return the specification that constructed the corpus.

abstract property transcripts: tuple[Transcript, ...]#

Return every transcript in stable corpus order.

ensembl.vep.corpus.base.NamedOverlap#

A corpus variant name and one transcript overlap for its allele.

alias of tuple[str, TranscriptVariationAllele]

ensembl.vep.corpus.base.NamedVariant#

A stable corpus name and its variation allele.

alias of tuple[str, VariationAllele]

ensembl.vep.corpus.combine module#

Combine corpora into one consumer-facing corpus.

class ensembl.vep.corpus.combine.CombinedCorpus(*, spec, corpora)[source]#

Bases: Corpus

Present several corpora through one flattened corpus view.

Variables:
  • spec (CorpusSpec) – Specification describing the combined construction.

  • corpora (tuple[Corpus, ...]) – Component corpora in traversal and cleanup order.

Sequence regions, variants, transcripts, and overlaps are flattened and validated when the combined corpus is constructed.

close()[source]#

Release every component corpus.

corpora: tuple[Corpus, ...]#
property named_overlaps: tuple[tuple[str, TranscriptVariationAllele], ...]#

Return every component transcript overlap.

property named_variants: tuple[tuple[str, VariationAllele], ...]#

Return every component variant.

property sequence_regions: tuple[Slice, ...]#

Return every component sequence region.

property spec: CorpusSpec#

Return the combined construction specification.

property transcripts: tuple[Transcript, ...]#

Return every component transcript.

ensembl.vep.corpus.combine.combine_corpora(specification, corpora)[source]#

Return one validated corpus over the supplied component corpora.

Parameters:
  • specification (CorpusSpec) – Specification identifying the combined corpus.

  • corpora (tuple[Corpus, ...]) – Components in traversal and cleanup order.

Returns:

Flattened view of all component corpora.

Return type:

CombinedCorpus

Raises:

ValueError – If no components were supplied or their memberships conflict.

ensembl.vep.corpus.describe module#

Describing what a corpus holds, before any annotator has said anything about it.

Shape only: chromosomes, transcripts, variants by class, how the variants pair into overlaps, and the overlap listing that gives vep explain its --name/--index/--variant selectors. What an annotator makes of the corpus is a run summary, and lives with the stats.

class ensembl.vep.corpus.describe.ChromosomeShape(*, name, length, transcripts, variants, overlaps)[source]#

Bases: object

One chromosome’s totals.

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

  • length (int) – Length in bases.

  • transcripts (int) – Transcripts on it.

  • variants (int) – Distinct variants on it.

  • overlaps (int) – Overlaps those variants pair into.

classmethod build(sequence_region, corpus)[source]#

Build one sequence region’s corpus totals.

Return type:

ChromosomeShape

length: int#
name: str#
overlaps: int#
transcripts: int#
variants: int#
class ensembl.vep.corpus.describe.CorpusDescription(*, kind, chromosomes, transcripts, variant_classes, batch_size, transcripts_per_chunk, overlaps)[source]#

Bases: object

A corpus’s shape, as tables.

Variables:
  • kind (str) – Which corpus kind this describes.

  • chromosomes (tuple[ChromosomeShape, ...]) – Per-chromosome totals.

  • transcripts (tuple[TranscriptShape, ...]) – Every transcript.

  • variant_classes (tuple[tuple[str, int], ...]) – Class -> distinct variants, largest first.

  • batch_size (int) – The chunk size transcripts_per_chunk was measured at.

  • transcripts_per_chunk (float) – Mean distinct transcripts per chunk of overlaps – the number that says whether a batch shares work between overlaps or not.

  • overlaps (tuple[OverlapEntry, ...]) – The selectable overlaps, in source order.

batch_size: int#
classmethod build(corpus, *, select=None, batch_size=256)[source]#

Build a description of one corpus.

Parameters:
  • corpus (Corpus) – The corpus to describe.

  • select (str | None, default: None) – Keep only the overlaps of the variant with this name.

  • batch_size (int, default: 256) – Overlaps per chunk, for the sharing measure.

Returns:

The description.

Return type:

CorpusDescription

chromosome_rows()[source]#

Return the chromosome table, in CHROMOSOME_HEADERS order.

Return type:

list[tuple[object, ...]]

chromosomes: tuple[ChromosomeShape, ...]#
class_rows()[source]#

Return the variant-class table, in CLASS_HEADERS order.

Return type:

list[tuple[object, ...]]

kind: str#
overlap_rows()[source]#

Return the overlap listing, in OVERLAP_HEADERS order.

Return type:

list[tuple[object, ...]]

overlaps: tuple[OverlapEntry, ...]#
transcript_rows()[source]#

Return the transcript table, in TRANSCRIPT_HEADERS order.

Return type:

list[tuple[object, ...]]

transcripts: tuple[TranscriptShape, ...]#
transcripts_per_chunk: float#
variant_classes: tuple[tuple[str, int], ...]#
class ensembl.vep.corpus.describe.OverlapEntry(*, index, name, feature, locus, alleles)[source]#

Bases: object

One selectable overlap, as vep explain addresses it.

Variables:
  • index (int) – Position in the source’s order, for --index.

  • name (str) – The variant’s name, for --name.

  • feature (str) – The transcript’s stable id, for --transcript.

  • locus (str) – CHR:POS, the first part of a --variant selector.

  • alleles (str) – REF>ALT, the rest of it, with - for an empty allele.

alleles: str#
classmethod build(index, name, overlap)[source]#

Build one selectable overlap entry at its corpus index.

Return type:

OverlapEntry

feature: str#
index: int#
locus: str#
name: str#
class ensembl.vep.corpus.describe.TranscriptShape(*, stable_id, chromosome, strand, start, end, exons, coding, biotype, overlaps)[source]#

Bases: object

One transcript’s shape and how many overlaps reach it.

Variables:
  • stable_id (str) – The transcript’s stable id.

  • chromosome (str) – Sequence region name.

  • strand (str) – + or -.

  • start (int) – Genomic start.

  • end (int) – Genomic end.

  • exons (int) – Exon count.

  • coding (bool) – Whether it carries a translation.

  • biotype (str) – Its own biotype, or its gene’s, or empty.

  • overlaps (int) – Overlaps pairing a variant with it.

biotype: str#
classmethod build(transcript, overlap_count)[source]#

Build one transcript’s shape, or None when it has no sequence region.

Return type:

TranscriptShape | None

chromosome: str#
coding: bool#
end: int#
exons: int#
overlaps: int#
stable_id: str#
start: int#
strand: str#
ensembl.vep.corpus.describe.describe_variant(allele)[source]#

Return a variant’s locus and alleles, spelled the way --variant accepts them.

A long allele is abbreviated with its length, so the listing stays a table; the full selector for such a variant is its name.

Return type:

tuple[str, str]

ensembl.vep.corpus.describe.variant_class(allele)[source]#

Return a variant’s class from its trimmed alleles alone.

Return type:

str

ensembl.vep.corpus.overlap module#

Construct corpus transcript overlaps.

ensembl.vep.corpus.overlap.build_transcript_overlaps(named_variants, transcripts, *, window=5000)[source]#

Return same-region variant-transcript pairs within window bases.

Parameters:
  • named_variants (Sequence[tuple[str, VariationAllele]]) – Named alleles in stable corpus order.

  • transcripts (Sequence[Transcript]) – Candidate transcripts in stable corpus order.

  • window (int, default: 5000) – Flanking bases included on either side of each transcript.

Returns:

Matching pairs in variant then transcript order.

Return type:

tuple[tuple[str, TranscriptVariationAllele], ...]

Raises:

ValueError – If window is negative.

ensembl.vep.corpus.registry module#

Corpus factories and their registry.

ensembl.vep.corpus.registry.CorpusFactory#

Build a corpus from its specification.

alias of Callable[[CorpusSpec], Corpus]

exception ensembl.vep.corpus.registry.CorpusOptionsError[source]#

Bases: ValueError

A configured corpus name, parameter, or external input cannot be used.

ensembl.vep.corpus.registry.available_corpora()[source]#

Return registered corpus names in sorted order.

Return type:

tuple[str, ...]

ensembl.vep.corpus.registry.build_corpus(specification)[source]#

Build the corpus described by specification.

Parameters:

specification (CorpusSpec) – Registered name and factory parameters.

Returns:

Constructed corpus implementation.

Return type:

Corpus

Raises:

KeyError – If the requested corpus kind is not registered.

ensembl.vep.corpus.registry.build_corpus_from_options(options)[source]#

Build a configured corpus with one user-facing error type.

Parameters:

options (object) – Configuration-like object carrying corpus attributes.

Returns:

Constructed corpus implementation.

Return type:

Corpus

Raises:

CorpusOptionsError – If configuration, lookup, or external input cannot be used.

ensembl.vep.corpus.registry.corpus_factory(name)[source]#

Return the factory registered under name or one of its aliases.

Parameters:

name (str) – Canonical name or alias.

Returns:

Registered corpus constructor.

Return type:

Callable[[CorpusSpec], Corpus]

Raises:

KeyError – If name is not registered.

ensembl.vep.corpus.registry.corpus_spec_from_options(options)[source]#

Build a specification from command options.

Parameters:

options (object) – Configuration-like object carrying corpus attributes.

Returns:

Normalised construction specification.

Return type:

CorpusSpec

Raises:

CorpusOptionsError – If an option cannot form a valid specification.

ensembl.vep.corpus.registry.register_corpus(name, *, aliases=())[source]#

Register a corpus factory and any compatibility aliases.

Parameters:
  • name (str) – Canonical registry name.

  • aliases (tuple[str, ...], default: ()) – Additional names resolving to the same factory.

Returns:

Factory decorator.

Return type:

Callable[[Callable[[CorpusSpec], Corpus]], Callable[[CorpusSpec], Corpus]]

Raises:

ValueError – If a name is blank, repeated, or already registered.

ensembl.vep.corpus.spec module#

The registered corpus and parameters to construct.

ensembl.vep.corpus.spec.CorpusParameter: TypeAlias = str | int | float | bool | None#

A scalar parameter accepted by a registered corpus factory.

class ensembl.vep.corpus.spec.CorpusSpec(*, kind='synthetic.all', parameters=None, fuzz=None, step=None, genome_seed=None, boundary_seed=None, fuzz_seed=None, heavy_genome_seed=None, sweep_seed=None)[source]#

Bases: object

Describe a registered corpus construction.

parameters is deliberately open: each registered factory owns its parameter validation. Synthetic convenience arguments remain available alongside generic factory parameters.

Variables:
  • kind (str) – Registered corpus name.

  • parameters (Mapping[str, CorpusParameter]) – Factory-owned construction parameters.

as_dict()[source]#

Return the JSON-compatible representation.

Return type:

dict[str, object]

property boundary_seed: int#

Return the boundary-variant seed.

classmethod from_dict(value)[source]#

Build a specification from its JSON-compatible representation.

Parameters:

value (Mapping[str, object]) – Mapping produced by as_dict.

Returns:

Decoded construction specification.

Return type:

CorpusSpec

Raises:
  • TypeError – If the kind or parameters have invalid types.

  • ValueError – If decoded built-in parameters are invalid.

classmethod from_options(options)[source]#

Build a specification from corpus configuration attributes.

Parameters:

options (object) – Configuration-like object with kind and corpus parameters.

Returns:

Normalised construction specification.

Return type:

CorpusSpec

Raises:
  • TypeError – If configured generic parameters have invalid types.

  • ValueError – If generic parameters are malformed or built-in values are invalid.

property fuzz: int#

Return the default synthetic corpus random-variant count.

property fuzz_seed: int#

Return the random-variant seed.

property genome_seed: int#

Return the default synthetic genome seed.

property heavy_genome_seed: int#

Return the heavy-locus genome seed.

kind: str#
property kinds: tuple[str, ...]#

Return the concrete corpus kinds represented by the specification.

parameter(name, default=None)[source]#

Return one factory parameter or default when absent.

Parameters:
  • name (str) – Parameter name.

  • default (str | int | float | bool | None, default: None) – Value returned when the parameter is absent.

Returns:

Configured or default scalar value.

Return type:

str | int | float | bool | None

parameter_hash()[source]#

Return a short stable digest of the requested construction.

Return type:

str

property parameters: dict[str, str | int | float | bool | None]#

Return a copy of the registered factory parameters.

seeds_by_kind()[source]#

Return synthetic seeds for the selected built-in corpora.

Return type:

dict[str, dict[str, int]]

property step: int#

Return the heavy-locus sweep step.

property sweep_seed: int#

Return the heavy-locus sweep seed.

with_parameters(**parameters)[source]#

Return a specification with selected parameters replaced.

Parameters:

parameters (str | int | float | bool | None) – Scalar values to add or replace.

Returns:

New specification retaining the same corpus kind.

Return type:

CorpusSpec

ensembl.vep.corpus.validation module#

Corpus consistency validation.

ensembl.vep.corpus.validation.validate_corpus(sequence_regions, named_variants, transcripts, named_overlaps)[source]#

Reject inconsistent corpus membership and relationships.