ensembl.vep.output.factory package#

Factories for annotated output.

Subpackages#

Submodules#

ensembl.vep.output.factory.base module#

Format-neutral annotated variants and their factory.

The factory is a port of the format-independent half of Perl VEP’s OutputFactory.pm. A variation first becomes a hash of what is known from its position alone (variation_hash). That hash is copied and extended once per (allele, feature) overlap (allele_hash). The copies are then filtered, picked or squashed as the options ask (output_hashes), and build_annotated_variant hands them to AnnotatedVariant.build, which detaches the variant’s own fields. The snapshot is the only thing that crosses a worker boundary and the only thing an output format sees.

Only fields this model can actually supply are ever populated. A column VEP fills from data not carried here yet – HGVS, SIFT, frequencies, co-located variants – stays empty rather than being approximated, which is VEP’s own convention for “not available”. The column layout for a given set of flags is VEP’s, so a downstream tool reading the Format declaration finds what it expects.

Consequences reach an allele through VariationAllele.transcript_variation_alleles. Assigning that list invalidates the allele’s aggregate, so assign each overlap’s consequences first and attach the overlaps afterwards.

class ensembl.vep.output.factory.base.AlleleOverlap(*, allele_number, allele, overlap, consequences)[source]#

Bases: object

One allele of a variation against one feature, with the consequences it was assigned.

Variables:
  • allele_number (int) – The allele’s 1-based position among the variation’s alternates.

  • allele (VariationAllele) – The allele.

  • overlap (TranscriptVariationAllele | None) – The feature overlap, or None for an allele that overlaps nothing – which VEP reports as intergenic.

  • consequences (tuple[OverlapConsequence, ...]) – The consequences, most severe first.

allele: VariationAllele#
allele_number: int#
property allele_seq: str#

Return the allele as VEP writes it, using - when empty.

consequences: tuple[OverlapConsequence, ...]#
overlap: TranscriptVariationAllele | None#
class ensembl.vep.output.factory.base.AnnotatedVariant(*, id, seq_region_name, start, end, strand, allele_string, input_columns=(), annotations=(), most_severe_consequence=None, variant_class=None, assembly_name=None, skipped=False)[source]#

Bases: object

Format-neutral snapshot of one annotated variant.

Variables:
  • id (str | None) – The uploaded or stable variant identifier.

  • seq_region_name (str) – The sequence-region name, as the input spelled it.

  • start (int) – The inclusive genomic start.

  • end (int) – The inclusive genomic end.

  • strand (int) – The genomic strand.

  • allele_string (str) – The reference and alternate alleles separated by /.

  • input_columns (tuple[str, ...]) – The original input columns, when present.

  • annotations (tuple[AnnotationRecord, ...]) – Selected VEP output hashes.

  • most_severe_consequence (str | None) – The most severe emitted consequence term.

  • variant_class (str | None) – The Sequence Ontology class term.

  • assembly_name (str | None) – The assembly name, when known.

  • skipped (bool) – Whether annotation was skipped for this input variant.

allele_string: str#
annotations: tuple[dict[str, object], ...]#
assembly_name: str | None#
classmethod build(variation, record_columns=None, *, annotations=(), assembly_name=None, skipped=False)[source]#

Return the snapshot of one variation, carrying records chosen elsewhere.

Which records a run writes is an output-format question, answered by the output factory; everything here is the variant’s own.

Parameters:
  • variation (Variation) – The variation whose annotation is complete.

  • record_columns (Sequence[str] | None, default: None) – Original input columns, when available.

  • annotations (tuple[dict[str, object], ...], default: ()) – The selected output hashes.

  • assembly_name (str | None, default: None) – Assembly name to expose in structured output.

  • skipped (bool, default: False) – Whether sources could not annotate this variation.

Returns:

The detached snapshot.

Return type:

AnnotatedVariant

end: int#
id: str | None#
input_columns: tuple[str, ...]#
most_severe_consequence: str | None#
seq_region_name: str#
skipped: bool#
start: int#
strand: int#
variant_class: str | None#
class ensembl.vep.output.factory.base.AnnotatedVariantFactory(*, most_severe=False, summary=False, pick=False, pick_allele=False, flag_pick=False, flag_pick_allele=False, pick_order=('mane_select', 'mane_plus_clinical', 'canonical', 'appris', 'tsl', 'biotype', 'ccds', 'rank', 'length', 'ensembl', 'refseq'), no_intergenic=False, variant_class=False, symbol=False, biotype=False, numbers=False, allele_number=False, show_ref_allele=False, transcript_version=False, gene_version=False)[source]#

Bases: object

Factory for detached annotated-variant snapshots.

Variables:
  • most_severe (bool) – One record per variation, carrying only its most severe term.

  • summary (bool) – One record per variation, carrying every distinct term, most severe first.

  • pick (bool) – Keep only the single best (allele, feature) per variation.

  • pick_allele (bool) – Keep the best feature per allele.

  • flag_pick (bool) – Keep everything, and mark the single best with PICK.

  • flag_pick_allele (bool) – Keep everything, and mark the best per allele with PICK.

  • pick_order (tuple[str, ...]) – The criteria the picking flags weigh, in order.

  • no_intergenic (bool) – Write nothing for an allele that overlaps no feature.

  • variant_class (bool) – Add VARIANT_CLASS.

  • symbol (bool) – Add the gene symbol.

  • biotype (bool) – Add the transcript biotype.

  • numbers (bool) – Add exon and intron numbers.

  • allele_number (bool) – Add ALLELE_NUM.

  • show_ref_allele (bool) – Add REF_ALLELE.

  • transcript_version (bool) – Append the version to transcript identifiers.

  • gene_version (bool) – Append the version to gene identifiers.

allele_hash(output_hash, entry)[source]#

Extend a copy of the variation’s hash with one (allele, feature)’s fields, in place.

allele_number: bool#
allele_overlaps(variation)[source]#

Return every (allele, feature) of a variation, grouped by feature.

Grouped by feature and then in allele order, as VEP groups them. An allele with no overlap yields one intergenic entry, unless no_intergenic is set.

Return type:

list[AlleleOverlap]

biotype: bool#
build_annotated_variant(variation, record_columns=None, *, assembly_name=None, skipped=False)[source]#

Detach one annotated variation, carrying the records the flags select.

Parameters:
  • variation (Variation) – The variation whose annotations are complete.

  • record_columns (Sequence[str] | None, default: None) – Original input columns, when available.

  • assembly_name (str | None, default: None) – Assembly name to expose in structured output.

  • skipped (bool, default: False) – Whether sources could not annotate this variation.

Returns:

A serialisable snapshot for stream and file factories.

Return type:

AnnotatedVariant

flag_fields()[source]#

Return the output fields the enabled flags add, in order and without repeats.

Return type:

list[str]

flag_pick: bool#
flag_pick_allele: bool#
gene_version: bool#
most_severe: bool#
no_intergenic: bool#
numbers: bool#
output_hashes(variation, record_columns=None)[source]#

Return the output records of one variation, filtered and picked as the flags ask.

Parameters:
  • variation (Variation) – The variation, its alleles’ overlaps carrying consequences.

  • record_columns (Sequence[str] | None, default: None) – The original VCF columns, if it came from one.

Returns:

One hash per written (allele, feature), or a single squashed

hash under most_severe/summary. Empty under no_intergenic for a variation that overlaps nothing.

Return type:

list[dict[str, object]]

pick: bool#
pick_allele: bool#
pick_order: tuple[str, ...]#
pick_worst(overlaps)[source]#

Return the single overlap the pick order prefers.

A port of VEP’s pick_worst_VariationFeatureOverlapAllele: narrow the candidates one criterion at a time, keeping every candidate tied on it, until one remains; the first of any tie that survives every criterion wins.

Raises:

ValueError – If there is nothing to pick from.

Return type:

AlleleOverlap

show_ref_allele: bool#
summary: bool#
symbol: bool#
transcript_version: bool#
variant_class: bool#
variation_hash(variation, record_columns=None)[source]#

Return what is known about a variation from its position alone.

Return type:

dict[str, object]

class ensembl.vep.output.factory.base.AnnotatedVariants(*, variants, collector)[source]#

Bases: Iterator[AnnotatedVariant]

Closable annotation iterator with its completed run summary.

Variables:
close()[source]#

Release resources held by the underlying annotation iterator.

property collector: RunSummaryCollector#

Return the collector after complete consumption.

Raises:

RuntimeError – If the stream has not been exhausted.

property completed: bool#

Return whether every input variant has been consumed.

property summary: RunSummary#

Return the final summary after complete consumption.

Raises:

RuntimeError – If the stream has not been exhausted.

property variant_count: int#

Return the number of variants yielded to the consumer.

ensembl.vep.output.factory.base.AnnotationRecord#

One VEP output hash, copied from a selected allele-feature annotation.

alias of dict[str, object]

ensembl.vep.output.factory.base.DEFAULT_PICK_ORDER = ('mane_select', 'mane_plus_clinical', 'canonical', 'appris', 'tsl', 'biotype', 'ccds', 'rank', 'length', 'ensembl', 'refseq')#

The order --pick weighs a transcript by, as VEP defaults it. A criterion this model has no data for ties for every candidate and so defers to the next one – exactly VEP’s behaviour when two candidates are equal on a criterion.

ensembl.vep.output.factory.base.DISTANCE_TERMS = frozenset({'downstream_gene_variant', 'upstream_gene_variant'})#

The terms whose output carries a DISTANCE to the transcript.

ensembl.vep.output.factory.base.FLAG_FIELDS = (('allele_number', ('ALLELE_NUM',)), ('show_ref_allele', ('REF_ALLELE',)), ('flag_pick', ('PICK',)), ('flag_pick_allele', ('PICK',)), ('variant_class', ('VARIANT_CLASS',)), ('symbol', ('SYMBOL', 'SYMBOL_SOURCE', 'HGNC_ID')), ('biotype', ('BIOTYPE',)), ('numbers', ('EXON', 'INTRON')))#

Flag -> the output fields it adds, in VEP’s order, for the flags this factory supports.

The whole field list is declared even where only part of it can be filled (SYMBOL_SOURCE, HGNC_ID), so the column layout matches VEP’s for the same flags.