ensembl.vep package#

Ensembl Python project template library

Subpackages#

Submodules#

ensembl.vep.cli module#

The vep command line.

The first argument selects the command; when it is not a registered one the default is used, so vep --input_file x.vcf still parses. --config FILE may stand anywhere and is taken off first, so vep --config f.toml corpus describe reaches corpus describe. vep -h lists every command and vep <group> -h the verbs of one group, laid out the way git -h lays out its commands.

ensembl.vep.cli.main(argv=None)[source]#

Run a command and return its exit code.

Parameters:

argv (list[str] | None, default: None) – Arguments without the program name, or None for sys.argv[1:].

Returns:

The runner’s exit code, OK after printing a help page, or USAGE if no

command could be resolved, --config is malformed, or the configuration is invalid or unreadable.

Return type:

ExitCode

ensembl.vep.cli.resolve_command(argv)[source]#

Split arguments into a command name and the arguments that belong to it.

A bare group name resolves to that group’s single runner if it has one, otherwise stays unresolved so the caller can list its verbs.

Only a leading flag, or no arguments at all, means the default command. vep takes no positional arguments, so a leading bare word can only be a command, and one that is not registered is an error rather than something to pass to the default.

Parameters:

argv (list[str]) – Arguments without the program name.

Returns:

The command name and the remaining arguments. The name is empty when

the leading word is not a command, or names a group without one of its verbs.

Return type:

tuple[str, list[str]]

ensembl.vep.ensembl_vep_core module#

class ensembl.vep.ensembl_vep_core.FastaParser(file_path=None, mode=None)#

Bases: object

close()#
format#
metadata#
next()#
open(file_path, mode)#
static parse_file(file_path, limit=None)#
static parse_text(data, limit=None)#
reader_mode#
records(limit=10000)#
seek(region)#
class ensembl.vep.ensembl_vep_core.FastaRecord#

Bases: object

Represents a sequence record in a FASTA file.

end#

End coordinate of the sequence

Type:

int

seqid#

Name of the seq region

Type:

str

sequence#

Sequence of the seq region

Type:

str

start#

Start coordinate of the sequence

Type:

int

class ensembl.vep.ensembl_vep_core.GFF3Parser(file_path=None, tabix_path=None, mode=None)#

Bases: object

close()#
format#
index_sequence_names#

Reference sequence names declared by the tabix index, in index order.

Empty when the file is unopened or read sequentially. Callers can use these names to resolve a query contig to the exact spelling the index declares before seeking, instead of retrying alternate spellings on a miss.

metadata#
next()#
open(file_path, mode)#
static parse_file(file_path, limit=None)#
static parse_text(data, limit=None)#
raw_lines(limit=10000)#

Return up to limit record lines, each without its line ending and otherwise verbatim.

The same stream as records, read one step earlier: a line is returned before anything parses it, for a caller that wants the input’s own text rather than a record. Comment, directive and blank lines are skipped, as they are when reading records.

reader_mode#
records(limit=10000, feature_types=None)#

Return up to limit records, optionally keeping only rows whose column 3 (feature type) is in feature_types (compared case-insensitively).

The filter is applied on the Rust side before a matching line is parsed into a record or converted into a Python object: a non-matching line costs one tab-split byte scan, not a full record build.

seek(region)#
class ensembl.vep.ensembl_vep_core.GFF3Record#

Bases: object

Represents a record from one line of a GFF3 file.

attribute_values(key)#

Return every value for an attribute key, or an empty vector when the key is absent.

Equivalent to attributes.get(key, ()), but a linear scan of the stored pairs instead of building a whole dict per call. A repeated key resolves to its last occurrence, as attributes and first_attribute do.

attributes#

The information from the attributes column

Type:

dict[list]

end#

End coordinate of the feature

Type:

int

feature_type#

Class/type of feature (e.g. gene, transcript, exon)

Type:

str

first_attribute(key)#

Return the first value for an attribute key, or None when the key is absent.

Equivalent to attributes[key][0], but a linear scan of the stored pairs instead of building a whole dict per call.

GFF3 allows for one key with a comma-separated array for multiple values.

For repeated keys, noodles-gff keeps each occurrence as its own pair in self.attributes. The attributes getter above builds a dict via set_item, so a repeated key resolves there to its last occurrence – scanning in reverse here matches that, instead of silently returning a different value for the same key.

phase_value#

Value for the phase of the feature (0, 1 or 2)

Type:

int | None

raw_attributes#
score#

Score given to the feature

Type:

float | None

seqid#

Name of the seq region

Type:

str

source#

Source of the annotation

Type:

str

start#

Start coordinate of the feature

Type:

int

strand_symbol#

Symbol representing the strand the feature is on (+, -, . or ?)

Type:

str

class ensembl.vep.ensembl_vep_core.GTFParser(file_path=None, tabix_path=None, mode=None)#

Bases: object

close()#
format#
index_sequence_names#

Reference sequence names declared by the tabix index, in index order.

Empty when the file is unopened or read sequentially. Callers can use these names to resolve a query contig to the exact spelling the index declares before seeking, instead of retrying alternate spellings on a miss.

metadata#
next()#
open(file_path, mode)#
static parse_file(file_path, limit=None)#
static parse_text(data, limit=None)#
raw_lines(limit=10000)#

Return up to limit record lines, each without its line ending and otherwise verbatim.

The same stream as records, read one step earlier: a line is returned before anything parses it, for a caller that wants the input’s own text rather than a record. Comment, directive and blank lines are skipped, as they are when reading records.

reader_mode#
records(limit=10000, feature_types=None)#

Return up to limit records, optionally keeping only rows whose column 3 (feature type) is in feature_types (compared case-insensitively).

The filter is applied on the Rust side before a matching line is parsed into a record or converted into a Python object: a non-matching line costs one tab-split byte scan, not a full record build.

seek(region)#
class ensembl.vep.ensembl_vep_core.GTFRecord#

Bases: object

Represents a record from one line of a GTF file.

attribute_values(key)#

Return every value for an attribute key, or an empty vector when the key is absent.

Equivalent to attributes.get(key, ()), but a linear scan of the stored pairs instead of building a whole dict per call.

attributes#

The information from the attributes column

Type:

dict[list]

end#

End coordinate of the feature

Type:

int

feature_type#

Class/type of feature (e.g. gene, transcript, exon)

Type:

str

first_attribute(key)#

Return the first value for an attribute key, or None when the key is absent.

Equivalent to attributes[key][0], but a linear scan of the stored pairs instead of building a whole dict per call.

phase_value#

Value for the phase of the feature (0, 1 or 2)

Type:

int | None

raw_attributes#
score#

Score given to the feature

Type:

float | None

seqid#

Name of the seq region

Type:

str

source#

Source of the annotation

Type:

str

start#

Start coordinate of the feature

Type:

int

strand_symbol#

Symbol representing the strand the feature is on (+, -, . or ?)

Type:

str

class ensembl.vep.ensembl_vep_core.TabixParser(file_path=None, tabix_path=None)#

Bases: object

close()#
format#
metadata#

Return a metadata dict. The “header” key is lazily populated with header lines from the file on first access.

next()#
open(file_path)#
records(limit=None)#
seek(region)#
class ensembl.vep.ensembl_vep_core.VCFMetadata#

Bases: object

Represents the metadata from a VCF file

alt#
contig#
file_format#
filter#
format#
header#

The file’s header lines verbatim, kept because a parsed header cannot be written back out as the input spelled it and VCF output re-emits the input’s own header.

info#
is_empty()#
keys()#
other#
samples#
class ensembl.vep.ensembl_vep_core.VCFParser(file_path=None, tabix_path=None, mode=None)#

Bases: object

close()#
format#
metadata#
next()#
open(file_path, mode)#
static parse_file(file_path, limit=None)#
static parse_text(data, limit=None)#
raw_lines(limit=10000)#

Return up to limit record lines, each without its line ending and otherwise verbatim.

The same stream as records, read one step earlier: a line is returned before anything parses it, for a caller that wants the input’s own text rather than a record.

reader_mode#
static record_count(file_path, scan=False)#

Return how many records a VCF file holds, or None when nothing declares it.

The count comes from the file’s index, which answers in one small read. Without an index there is no count unless scan is set, which reads the whole file: an input of a billion lines makes that pass the slowest part of a run, so a caller that only wants it for progress reporting leaves it off and does without the count.

A static method, like parse_file: the count neither depends on the mode a reader was opened in nor disturbs a stream being read.

Parameters:
  • file_path – The VCF file to count.

  • scan (default: False) – Whether to count by reading the file when no index declares it.

records(limit=10000)#
seek(region)#
class ensembl.vep.ensembl_vep_core.VCFRecord#

Bases: object

Represents a record in a VCF file

alt#

Representation of each alternate allele

Type:

list[str]

chrom#

Name of the seq region

Type:

str

filter#

Value of the FILTER field

Type:

str | None

id#

Variant id e.g. from dbSNP

Type:

str | None

info#

Information from the INFO field

Type:

dict

pos#

Position of the variant

Type:

int

qual#

Quality score for the variant

Type:

float | None

reference#

Sequence of the reference allele

Type:

str

samples#

Genotype information for each sample

Type:

list[dict]

ensembl.vep.ensembl_vep_core.batch_contain_span(variant_mins, variant_maxs, feature_starts, feature_ends)#

contain_feature for a whole batch: does each variant span swallow its feature whole?

ensembl.vep.ensembl_vep_core.batch_overlap_any_interval(variant_mins, variant_maxs, interval_starts, interval_ends, offsets)#

Does each variant span overlap any interval in its own context’s interval list?

The kernel behind overlap_exon/overlap_intron. Interval lists are passed CSR-style – one flat (starts, ends) pair plus an offsets array of length count + 1, where context i owns intervals offsets[i]..offsets[i + 1], so a batch spanning many transcripts is still exactly three arrays and no nesting. Contexts sharing a transcript can point at the same slice, which is the common case for the heavy-locus corpus.

ensembl.vep.ensembl_vep_core.batch_overlap_span(variant_mins, variant_maxs, feature_starts, feature_ends)#

overlap_feature for a whole batch: does each variant span touch its own feature’s span?

ensembl.vep.ensembl_vep_core.batch_variant_shapes(reference_lengths, alternate_lengths)#

Return four variant shape facts from two length arrays, in one crossing.

Parameters:
  • list[int (alternate_lengths)

  • ...] (Lengths of alternate alleles.)

  • list[int

  • ...]

Returns:

bitmaps representing the facts (is_snv, is_short_insertion, is_short_deletion, length_change_inframe).

Return type:

tuple(bytes, bytes, bytes, bytes)

Raises:

ValueError – If the lengths of the two allele list are not the same length.

Example

from ensembl.vep.ensembl_vep_core import batch_variant_shapes
reference_lengths = [1, 0, 3, 2, 2]
alternate_lengths = [1, 4, 0, 0, 2]
shape_masks = batch_variant_shapes(reference_lengths, alternate_lengths)
ensembl.vep.ensembl_vep_core.sum_as_string(a, b)#
ensembl.vep.ensembl_vep_core.translate_dna(coding_sequence, table_id=1)#

Expose DNA translation to Python with table 1 as the default.