ensembl.vep.common package#

Common utilities.

Submodules#

ensembl.vep.common.codons module#

Codon table and DNA translation utilities.

ensembl.vep.common.codons.CODON_TABLE: dict[str, str] = {'AAA': 'K', 'AAC': 'N', 'AAG': 'K', 'AAT': 'N', 'ACA': 'T', 'ACC': 'T', 'ACG': 'T', 'ACT': 'T', 'AGA': 'R', 'AGC': 'S', 'AGG': 'R', 'AGT': 'S', 'ATA': 'I', 'ATC': 'I', 'ATG': 'M', 'ATT': 'I', 'CAA': 'Q', 'CAC': 'H', 'CAG': 'Q', 'CAT': 'H', 'CCA': 'P', 'CCC': 'P', 'CCG': 'P', 'CCT': 'P', 'CGA': 'R', 'CGC': 'R', 'CGG': 'R', 'CGT': 'R', 'CTA': 'L', 'CTC': 'L', 'CTG': 'L', 'CTT': 'L', 'GAA': 'E', 'GAC': 'D', 'GAG': 'E', 'GAT': 'D', 'GCA': 'A', 'GCC': 'A', 'GCG': 'A', 'GCT': 'A', 'GGA': 'G', 'GGC': 'G', 'GGG': 'G', 'GGT': 'G', 'GTA': 'V', 'GTC': 'V', 'GTG': 'V', 'GTT': 'V', 'TAA': '*', 'TAC': 'Y', 'TAG': '*', 'TAT': 'Y', 'TCA': 'S', 'TCC': 'S', 'TCG': 'S', 'TCT': 'S', 'TGA': '*', 'TGC': 'C', 'TGG': 'W', 'TGT': 'C', 'TTA': 'L', 'TTC': 'F', 'TTG': 'L', 'TTT': 'F'}#

Standard nuclear codons mapped to one-letter amino acids or * for stop codons.

ensembl.vep.common.codons.DEFAULT_GENETIC_CODE_TABLE_ID = 1#

Default NCBI genetic-code table identifier.

ensembl.vep.common.codons.GENETIC_CODE_TABLE_IDS: frozenset[int] = frozenset({1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33})#

Supported NCBI genetic-code table identifiers.

ensembl.vep.common.codons.STOP_CODONS: frozenset[str] = frozenset({'TAA', 'TAG', 'TGA'})#

Standard nuclear stop codons.

ensembl.vep.common.codons.get_stop_codons(table_id=1)[source]#

Return stop codons for an NCBI genetic-code table.

Return type:

frozenset[str]

ensembl.vep.common.codons.translate_dna(coding_sequence, table_id=1)[source]#

Translate a coding-orientation DNA sequence.

Parameters:
  • coding_sequence (str) – Uppercase DNA sequence in transcript-sense orientation.

  • table_id (int, default: 1) – NCBI genetic-code table identifier.

Returns:

One-letter amino acid sequence, using * for stop codons and X for unknown

or incomplete codons.

Return type:

str

Raises:

ValueError – If table_id is not an NCBI genetic-code table identifier.

ensembl.vep.common.constants module#

Common constants.

ensembl.vep.common.constants.CANONICAL_DNA_BASES = 'ACGT'#

Unambiguous DNA bases used when generating synthetic sequence.

ensembl.vep.common.constants.COMPRESSION_SUFFIXES = ('.gz', '.bgz', '.bz2', '.zst')#

Suffixes that name how a file is compressed rather than what it holds.

ensembl.vep.common.constants.DEFAULT_DISTANCE = 5000#

Bases either side of a feature that still pair with it, as Perl VEP’s --distance defaults.

One home for a value three layers have to agree on: the pairing window the overlap finder expands by, the is_upstream/is_downstream facts, and the zone map that prefills them.

ensembl.vep.common.constants.EMPTY_ALLELE = '-'#

VEP’s spelling of an empty allele.

ensembl.vep.common.constants.GFF_TO_ENSEMBL_PHASE = {0: ExonPhase.ZERO, 1: ExonPhase.TWO, 2: ExonPhase.ONE}#

A CDS row’s GFF phase (bases to skip to reach a codon) as an Ensembl exon phase (bases of the first codon on what came before), converted as Bio::EnsEMBL::VEP::AnnotationSource::File:: BaseGXF::_convert_phase does.

ensembl.vep.common.constants.INPUT_FORMAT_EXTENSIONS = {'vcf': ('.vcf', '.bcf')}#

The input formats a run reads, and the file extensions each one owns.

Here rather than beside the sources because --format offers these names and the configuration package cannot import the sources, which import it.

ensembl.vep.common.constants.UNKNOWN_VALUE = '?'#

Placeholder printed where a label’s field is not available.

ensembl.vep.common.constants.VCF_BASES = frozenset({'A', 'C', 'G', 'N', 'T'})#

Base characters accepted in a plain VCF allele, including the unknown base N.

ensembl.vep.common.constants.VCF_PLAIN_ALLELE_CHARACTERS = frozenset({'.', 'A', 'C', 'G', 'N', 'T'})#

Characters accepted in a non-symbolic VCF allele.

ensembl.vep.common.containers module#

Common containers.

Containers are for collection data (generally without any behavior).

class ensembl.vep.common.containers.Attribute(*, name, value, code=None, description=None)[source]#

Bases: object

Container for an attribute of a feature.

Variables:
  • name (str) – Name of the attribute.

  • value (str) – Value of the attribute.

  • code (str | None) – Code of the attribute.

  • description (str | None) – Description of the attribute.

code: str | None#
description: str | None#
name: str#
value: str#
class ensembl.vep.common.containers.ExternalDB(*, id, name, description=None, url=None, release=None)[source]#

Bases: object

Container for external database information.

Variables:
  • id (str) – Unique identifier for the external database.

  • name (str) – Name of the external database.

  • description (str | None) – Description of the external database.

  • url (str | None) – URL where this external database can be accessed.

  • release (str | None) – Release version of the external database.

description: str | None#
id: str#
name: str#
release: str | None#
url: str | None#
class ensembl.vep.common.containers.ExternalReference(*, accession_id, name, description=None, assignment_method=None, url=None, source=None)[source]#

Bases: object

Container for external reference information.

Variables:
  • accession_id (str) – Accession ID of the external reference.

  • name (str) – Name of the external reference.

  • description (str | None) – Description of the external reference.

  • assignment_method (str | None) – Method used to assign this reference, e.g., DIRECT.

  • url (str | None) – URL where this external reference can be accessed.

  • source (ExternalDB) – Source database for this reference.

accession_id: str#
assignment_method: str | None#
description: str | None#
name: str#
source: ExternalDB | None#
url: str | None#
class ensembl.vep.common.containers.Locus(*, seq_region_name=None, start, end, allele_string=None)[source]#

Bases: object

Container for a genomic position and (optionally) alleles.

Variables:
  • seq_region_name (str | None) – Name of the sequence region.

  • start (int) – Start position of the locus.

  • end (int) – End position of the locus.

  • allele_string (str | None) – String representation of the alleles. It could be in the format “{reference_allele}/{alternate_allele}”, or just “allele” where allele could be either reference or alternate.

allele_string: str | None#
end: int#
seq_region_name: str | None#
start: int#
class ensembl.vep.common.containers.PredictionResult(*, tool, score, result, classification=None, version=None, modes=(), reference_data=())[source]#

Bases: object

Container for a prediction result of a program.

Variables:
  • plugin_name (str) – Name of the plugin that generated this prediction.

  • consequence (str) – Consequence term predicted by the plugin.

  • score (float | None) – Score associated with the prediction, if applicable.

  • description (str | None) – Description of the prediction.

classification: float | None#
modes: tuple[str] | tuple[()]#
reference_data: tuple[ExternalDB] | tuple[()]#
result: str#
score: int#
tool: str#
version: str | None#
class ensembl.vep.common.containers.SequenceEdit(*, footprint, start, end, replacement)[source]#

Bases: object

Container for edit caused by a variant on a spliced sequence.

Offsets are relative to whatever Mapper produced them, for example, same variant yields a different SequenceEdit against a CDS mapper than against a cDNA mapper.

Variables:
  • footprint (tuple[int, int]) – (low, high) inclusive offsets the variant covers.

  • start (int) – Start of the half-open range to replace.

  • end (int) – End of that range, exclusive. Equal to start for a pure insertion.

  • replacement (str) – The allele string to replace with. Generally the alternate allele, strand-corrected to transcript sense and empty for a pure deletion.

end: int#
footprint: tuple[int, int]#
property length_change: int#

Net change in sequence length this edit makes.

The change in sequence length is calculated as (replaced allele length - edited allele length). Derived here rather than at each call site so the arithmetic lives next to the geometry it comes from.

Returns:

The net length change.

Return type:

int

replacement: str#
start: int#

ensembl.vep.common.enums module#

Common enums.

class ensembl.vep.common.enums.ClassSOTerm(*values)[source]#

Bases: Enum

Sequence Ontology term describing the class of a variation.

The first block is what infer_variant_so_term can derive from an allele string alone – the classes a short variant can have. The second block is structural-variant only which may may need INFO/SVTYPE to be derived.

ALU_DELETION = 'Alu_deletion'#
ALU_INSERTION = 'Alu_insertion'#
CHROMOSOME_BREAKPOINT = 'chromosome_breakpoint'#
COPY_NUMBER_GAIN = 'copy_number_gain'#
COPY_NUMBER_LOSS = 'copy_number_loss'#
COPY_NUMBER_VARIATION = 'copy_number_variation'#
DELETION = 'deletion'#
DUPLICATION = 'duplication'#
HERV_DELETION = 'HERV_deletion'#
HERV_INSERTION = 'HERV_insertion'#
INDEL = 'indel'#
INSERTION = 'insertion'#
INTERCHROMOSOMAL_BREAKPOINT = 'interchromosomal_breakpoint'#
INTRACHROMOSOMAL_BREAKPOINT = 'intrachromosomal_breakpoint'#
INVERSION = 'inversion'#
LINE1_DELETION = 'LINE1_deletion'#
LINE1_INSERTION = 'LINE1_insertion'#
LOSS_OF_HETEROZYGOSITY = 'loss_of_heterozygosity'#
MOBILE_ELEMENT_DELETION = 'mobile_element_deletion'#
MOBILE_ELEMENT_INSERTION = 'mobile_element_insertion'#
NOVEL_SEQUENCE_INSERTION = 'novel_sequence_insertion'#
PROBE = 'probe'#
SEQUENCE_ALTERATION = 'sequence_alteration'#
SNV = 'SNV'#
SUBSTITUTION = 'substitution'#
SVA_DELETION = 'SVA_deletion'#
SVA_INSERTION = 'SVA_insertion'#
TANDEM_DUPLICATION = 'tandem_duplication'#
TANDEM_REPEAT = 'tandem_repeat'#
TRANSLOCATION = 'translocation'#
class ensembl.vep.common.enums.ConsequenceImpact(*values)[source]#

Bases: Enum

Impact of a consequence.

HIGH = 'HIGH'#
LOW = 'LOW'#
MODERATE = 'MODERATE'#
MODIFIER = 'MODIFIER'#
class ensembl.vep.common.enums.CoordSystemLevel(*values)[source]#

Bases: Enum

Coordinate system level.

CHROMOSOME = 1#
CONTIG = 3#
TOPLEVEL = 2#
class ensembl.vep.common.enums.CostTier(*values)[source]#

Bases: IntEnum

The declared cost tiers a fact can be registered with, cheapest first.

An IntEnum rather than a plain int alias, so a tier is both a real integer (comparable, summable, sortable) and a self-naming, enumerable value: CostTier.MAPPING.name instead of a hand-maintained {20: "MAPPING"} lookup, and list(CostTier) for anything that wants every tier without duplicating this declaration.

The numbers are relative in magnitude and not absolute. The declared relative magnitudes do not match measured wall-clock time. Treat the tier ordering as load-bearing and the numeric ratios as illustrative only.

BOUNDS = 1#

Comparing against a single bound (e.g. transcript start/end).

FREE = 0#

Arithmetic on the variant alone.

INTERVAL = 5#

Scanning exon/intron interval lists.

MAPPING = 20#

Genomic -> CDS coordinate mapping.

SEQUENCE = 60#

Extracting sequence, splicing in the alt allele, translating.

TRANSCRIPT_SEQUENCE = 200#

Rebuilding or translating the whole CDS or cDNA, not just the touched codon window.

classmethod label(cost)[source]#

Return the name of the tier cost belongs to, or the number itself.

A declared cost is a member, so this is cost.name. The measured-cost override (data/fact_costs.json, opt-in) sets arbitrary profiled integers that match no tier, so the numeric fallback is the normal case there rather than an error.

Return type:

str

class ensembl.vep.common.enums.ExonPhase(*values)[source]#

Bases: Enum

Phase of an exon.

ONE = 1#
TWO = 2#
UNKNOWN = -1#
ZERO = 0#
class ensembl.vep.common.enums.Readthrough(*values)[source]#

Bases: IntEnum

How far translation may run when a variant destroys the stop codon.

Opt-in, and NONE by default. An IntEnum because the levels are ordered rather than independent, each one extends the previous.

BEYOND_TRANSCRIPT = 2#

As UTR, and if that still yields no stop, continue into raw genomic sequence past the transcript’s own boundary, read directly from the attached slice (bounded by MAX_READTHROUGH_BASES). Trusts that the attached slice already covers the flank.

NONE = 0#

Stop at the (possibly shifted) CDS end. Translation never enters the UTR.

UTR = 1#

Continue into the 3’ UTR, looking for the next in-frame stop. Stays entirely within the transcript’s own spliced sequence.

class ensembl.vep.common.enums.SourceType(*values)[source]#

Bases: Enum

Type of annotation/input source.

CACHE = 'cache'#
DB = 'db'#
FILE = 'file'#
class ensembl.vep.common.enums.StartMethod(*values)[source]#

Bases: str, Enum

Multiprocessing worker start methods.

AUTO = 'auto'#
FORK = 'fork'#
FORKSERVER = 'forkserver'#
SPAWN = 'spawn'#
class ensembl.vep.common.enums.Strand(*values)[source]#

Bases: Enum

Genomic strand.

FORWARD = 1#
REVERSE = -1#
UNKNOWN = 0#

ensembl.vep.common.methods module#

Common functions.

ensembl.vep.common.methods.format_coords(start, end)[source]#

Return a coordinate range the way VEP prints one.

A single position when start and end agree, the lower bound first when they are reversed (an insertion’s end is start - 1), and ? for a missing bound.

Return type:

str

ensembl.vep.common.methods.format_region_string(region=None, *, seq_region_name=None, start=None, end=None)[source]#
Format a region string into “seq_region_name:start-end”

from either an existing region or seq_region_name/start/end values.

Parameters:
  • region (str | None, default: None) – A region string in the format “seq_region_name:start-end”.

  • seq_region_name (str | None, default: None) – Sequence ID (e.g. chromosome name).

  • start (int | None, default: None) – Start coordinate (1-based).

  • end (int | None, default: None) – End coordinate (1-based).

Return type:

str

Returns:

A region string in the format “seq_region_name:start-end”.

ensembl.vep.common.methods.infer_symbolic_variant_so_term(allele_string, svtype=None)[source]#

Infer the SO term for a symbolic structural variant.

This mirrors the symbolic variant normalization performed by Perl VEP’s get_SO_term. A VCF-compliant symbolic allele takes precedence over svtype so that subtype information in values such as <INS:ME:ALU> is retained. svtype is used as a fallback for a missing or non-standard allele.

Parameters:
  • allele_string (str) – Symbolic alternate allele or breakend string.

  • svtype (str | None, default: None) – Optional structural variant type from VCF INFO/SVTYPE.

Return type:

ClassSOTerm | None

Returns:

The inferred structural variant SO term, or None if the type is unsupported.

ensembl.vep.common.methods.infer_variant_so_term(allele_string, ref_correct=False)[source]#

Return the SO term for the class of the variation.

Parameters:
  • allele_string (str) – The allele string for the variation.

  • ref_correct (bool, default: False) – Whether the first allele is known to be the reference.

Return type:

ClassSOTerm | None

Returns:

The SO term string for the variation.

ensembl.vep.common.methods.invalidate(instance, *invalidate_names)[source]#

Clear the named cached properties of a class object when the attributes are set.

Deleting an unset cached property raises AttributeError almost every time (a freshly built object has nothing cached yet), so this uses try/except rather than contextlib.suppress: zero-cost when nothing is raised (Python 3.11+), and no context manager allocated per name either way.

Parameters:
  • instance (object) – The object whose cached properties should be cleared.

  • *invalidate_names (str) – The names of the cached properties to invalidate.

Returns:

None

Return type:

None

ensembl.vep.common.methods.invalidates(*cached_names)[source]#

Return an attrs on_setattr hook that clears named cached properties.

Parameters:

*cached_names (str) – The names of the cached properties to invalidate.

Returns:

An attrs on_setattr hook function.

Return type:

Callable

ensembl.vep.common.methods.is_resolved(instance, name)[source]#

Return whether a slot-backed cached property is already resolved without triggering computation.

Parameters:
  • instance (object) – Object that owns the cached property.

  • name (str) – Protected cached-property name (for example, “_cds”).

Returns:

True if the value is already present (seeded or previously computed),

False if reading it would still trigger computation.

Return type:

bool

Raises:

AttributeError – If name is not a descriptor on the instance type hierarchy.

ensembl.vep.common.methods.parse_region_string(region)[source]#

Split a region string into its sequence-region name and optional bounds.

The inverse of format_region_string: “1:100-200” -> (“1”, 100, 200), “1:100” -> (“1”, 100, None), “1” -> (“1”, None, None). A name may itself contain “:” (as HLA contigs do), so only the last “:” separates the coordinates, and only when what follows parses as bounds.

Parameters:

region (str) – A region string in the format “seq_region_name[:start[-end]]”.

Returns:

The name, start and end.

Return type:

tuple[str, int | None, int | None]

Raises:

ValueError – If region is empty, or its coordinates are not positive integers.

ensembl.vep.common.methods.resets_attrs(*attrs)[source]#

Return an attrs on_setattr hook that resets named attributes.

Parameters:

*attrs (tuple[str, Any]) – list of tuples (name, default_value) where * name is the attribute name to reset * default_value is the value to reset the attribute to on each call

Returns:

An on_setattr hook function.

Return type:

Callable

ensembl.vep.common.methods.reverse_complement(sequence)[source]#

Return the reverse complement of a nucleotide sequence.

Parameters:

sequence (str) – The sequence to reverse complement.

Return type:

str

Returns:

The reverse complement of the sequence.

ensembl.vep.common.methods.setup_logging(level='INFO', log_file=None)[source]#

Set up logging configuration. Call once, from the application entry point.

Configures the ensembl.vep logger rather than the root one, so importing this package does not take over an embedding application’s logging. Repeated calls replace the handlers rather than stacking them. Propagation is left on: turning it off silently disables pytest’s caplog for the rest of the process.

Records go to stderr, as in Perl VEP, so a verb that prints its report to stdout stays redirectable.

The level is also the tracing switch – a derivation trace is recorded only when the calling strategy’s logger is at DEBUG.

Parameters:
  • level (str, default: 'INFO') – The logging level to use (default: “INFO”).

  • log_file (str | PathLike | None, default: None) – File to append records to, in addition to stderr, or None for stderr only.

ensembl.vep.common.methods.shift_sequence(seq, *, post_seq, pre_seq, start, end, reverse=False)[source]#

Calculate the maximum possible 3’ (or 5’) shift for an allele sequence.

Slides the allele along the flanking sequence as long as the leading/trailing base matches the next flanking base, updating coordinates and the HGVS allele string accordingly.

Parameters:
  • seq (str) – The allele sequence to shift.

  • post_seq (str) – 3’ flanking sequence (downstream).

  • pre_seq (str) – 5’ flanking sequence (upstream).

  • start (int) – Variant start coordinate.

  • end (int) – Variant end coordinate.

  • reverse (bool, default: False) – If True, shift in the 5’ direction; otherwise 3’.

Return type:

tuple[int, str, int, int, bool]

Returns:

Tuple of (shift_length, shifted_seq, new_start, new_end, changed).

Raises:

ValueError – If seq, post_seq, or pre_seq is None.

ensembl.vep.common.methods.trim_sequences(ref, alt, *, start=0, end=None, empty_to_dash=False, end_first=False, strand=Strand.FORWARD)[source]#

Trim common sequence from a ref/alt allele pair to give minimal alleles.

Trims matching bases from the start then end (or end then start if end_first=True), adjusting coordinates accordingly.

Parameters:
  • ref (str) – Reference allele sequence.

  • alt (str) – Alternate allele sequence.

  • start (int, default: 0) – Start coordinate (default 0).

  • end (int | None, default: None) – End coordinate (default: start + len(ref) - 1).

  • empty_to_dash (bool, default: False) – If True, replace empty alleles with “-“.

  • end_first (bool, default: False) – If True, trim from end before start.

  • strand (Strand, default: Strand.FORWARD) – 1 for forward, -1 for reverse strand.

Return type:

tuple[str, str, int, int, bool]

Returns:

Tuple of (new_ref, new_alt, new_start, new_end, changed).

Raises:

ValueError – If ref or alt is None.

ensembl.vep.common.mixins module#

Common mixins. Mixins are for reusable behavior without data.

class ensembl.vep.common.mixins.CachedAttributeGuardMixin[source]#

Bases: object

Mixin that guards against setting attributes that are internal properties and/or invalidate cached properties when their dependencies change.

Caveat: These can be very expansive as it will be called every time any attribute is updated.

Currently not in use as a less preferable method. Instead, name mangling is used for guarding update to internal properties and attrs’ on_setattr hook for invalidation.

class ensembl.vep.common.mixins.UnsafeSetterMixin[source]#

Bases: object

Can be used to temporarily disable cache invalidation to allow faster but unsafe attribute update.

Caveat: This can be very expansive in terms of storage as it stores the type(self) for every instance. It also create a temporary subclass under the unsafe context although that gets cleaned up after the context exits.

It also allows setting of cached properties directly using seed_attrs and seed_and_invalidate_attrs which can lead to inconsistent state if not used carefully.

assign_without_hooks(**values)[source]#

Assign real (non-derived) fields directly, via object.__setattr__.

Unlike seed_attrs, which seeds a protected cached-property slot (_name), this sets the real field (name) – bypassing not just any on_setattr hook but also any validator or converter attrs would normally run.

Only for building a brand-new object, before construction is complete and before anything has read a value derived from the field being set: an already-live object’s hooks, validators and converters would not run, so its invariants could break silently.

Parameters:

**values (object) – Field name to value, exactly as the attrs field is declared (no leading underscore).

seed_and_invalidate_attrs(**seeds)[source]#

(Pre-)populate derived and cached attributes, by name, without triggering their normal derivation and invalidate dependent derived attributes. Don’t invalidate dependent derived attributes if they have also been seeded in the call to seed_and_invalidate_attrs.

This depends on the class having a SEED_INVALIDATES mapping that defines which derived attributes should be invalidated when a given attribute is seeded.

Parameters:
  • object – The object to seed.

  • **seeds (object) – Cached-property name (without the leading underscore) with value to seed, e.g. transcript.seed_and_invalidate_attrs(translation=my_translation, cds=my_cds).

seed_attrs(**seeds)[source]#

(Pre-)populate derived and cached attributes, by name, without triggering their normal derivation.

Writes directly into each named protected slot (object.__setattr__, bypassing on_setattr hooks and any setter), exactly as a normal cached_property computation would populate it on first access.

Seeded attribute can be cleared by the invalidates() hooks that clear a computed value. Therefore, Seeding a property derived from such a field must happen after that field is set, or the seed is invalidated before anything ever reads it.

A derived attribute’s computation may depend on other derived attributes. Seeding a derived attribute does not invalidate derived attributes that depend on it. Use seed_and_invalidate_attrs() if you want to seed and invalidate dependent derived attributes.

Parameters:
  • object – The object to seed.

  • **seeds (object) – Cached-property name (without the leading underscore) with value to seed, e.g. transcript.seed_attrs(cds=my_cds).

unsafe()[source]#

Context manager that temporarily swaps the class of this instance to a version with an unsafe __setattr__ that bypasses attrs’ on_setattr hooks.

ensembl.vep.common.vcf module#

How VCF spells a set of alleles: the trimming VEP applies, and the padding base an indel needs.

ensembl.vep.common.vcf.trim_right(alleles)[source]#

Remove the bases every allele ends with, never trimming an allele away entirely.

A port of ensembl-variation’s Utils::Sequence::trim_right: trimming stops as soon as any allele is down to one base, or the alleles no longer share their last base.

Return type:

list[str]

ensembl.vep.common.vcf.vcf_record_alleles(start, alleles, base_at)[source]#

Return the POS and the alleles a VCF record spells a short variant with.

A port of ensembl-variation’s VariationFeature::to_VCF_record. Alleles of length one – SNVs and MNVs – are written as they are. Otherwise the common trailing bases are trimmed, and a padding base is added unless every allele already starts with the same base. A symbolic allele is wrapped in angle brackets.

One deliberate difference: at position 1 there is no preceding base, and Perl takes whatever the slice returns there. The VCF specification pads with the following base instead (VCF v4.5 specification, §1.6.1 “Fixed fields”, item 4 “REF”), and so does this.

Parameters:
  • start (int) – 1-based start, in VEP’s trimmed convention – an insertion sits before start.

  • alleles (Sequence[str]) – The reference first, then the alternates; - or an empty string for an empty allele.

  • base_at (Callable[[int], str]) – Returns the reference base at a 1-based position, and is only called when a padding base is needed.

Returns:

The record’s position, and its alleles with the reference first.

Return type:

tuple[int, list[str]]