ensembl.vep.parsers package#

Parser interfaces.

Submodules#

ensembl.vep.parsers.fasta module#

FASTA parser interface backed by the Rust parser.

class ensembl.vep.parsers.fasta.FastaParser(*, file_path=None, mode='auto')[source]#

Bases: Parser[FastaRecord]

Parser facade for FASTA files.

Variables:
  • format (str) – The format of the file being parsed.

  • file_path (str | Path | None) – The path to the file being parsed.

  • mode (str) – The reader mode, either “auto”, “query” or “sequential”. Default is “auto”, which will attempt to use “query” mode and fall back to “sequential” if the file is not indexed.

close()[source]#

Close the parser.

file_path: str | Path | None#
format: str#
property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

mode: str#
next()[source]#

Return the next FASTA record, or None at EOF.

Returns:

The next FASTA record, or None if there are no more records.

Return type:

FastaRecord | None

open(file_path, mode='auto')[source]#

Open a FASTA file.

Parameters:
  • file_path (str | Path) – The path to the FASTA file to be parsed.

  • mode (str, default: 'auto') – The mode in which to open the file.

Returns:

The parser instance.

Return type:

FastaParser

static parse_file(file_path, limit=None)[source]#

Parse FASTA records from a file.

Parameters:
  • file_path (str | Path) – The path to the FASTA file to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of Fasta records.

Return type:

list[FastaRecord]

static parse_text(data, limit=None)[source]#

Parse FASTA records from text.

Parameters:
  • data (str) – The FASTA text to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of Fasta records.

Return type:

list[FastaRecord]

property reader_mode: str#

Return the configured reader mode.

records(limit=10000)[source]#

Return records from the current stream position.

Parameters:

limit (int | None, default: 10000) – The maximum number of records to return. Default is 10000.

Returns:

A list of FASTA records.

Return type:

list[FastaRecord]

seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a FASTA record or subsequence.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to.

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

class ensembl.vep.parsers.fasta.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

ensembl.vep.parsers.gff3 module#

GFF3 parser interface backed by the Rust noodles-gff parser.

class ensembl.vep.parsers.gff3.GFF3Parser(*, file_path=None, tabix_path='tabix', mode='auto')[source]#

Bases: Parser[GFF3Record]

Parser facade for GFF3 files.

Variables:
  • format (str) – The format of the file being parsed.

  • file_path (str | Path | None) – The path to the file being parsed.

  • tabix_path (str) – The path to the tabix executable.

  • mode (str) – The reader mode, either “auto”, “query” or “sequential”. Default is “auto”, which will attempt to use “query” mode and fall back to “sequential” if the file is not indexed.

close()[source]#

Close the parser.

file_path: str | Path | None#
format: str#
property index_sequence_names: list[str]#

Return reference sequence names declared by the tabix index.

Empty when the file is unopened, read sequentially, or falls back to the system tabix executable.

Returns:

The reference sequence names the index declares.

Return type:

list[str]

property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

mode: str#
next()[source]#

Return the next GFF3 record, or None at EOF or ##FASTA.

Returns:

The next GFF3 record,

or None if the end of the file or a ##FASTA directive is reached.

Return type:

GFF3Record | None

open(file_path, mode='auto')[source]#

Open a GFF3 file.

Parameters:
  • file_path (str | Path) – The path to the GFF3 file to be parsed.

  • mode (str, default: 'auto') – The mode in which to open the file.

Returns:

The parser instance.

Return type:

GFF3Parser

static parse_file(file_path, limit=None)[source]#

Parse GFF3 records from a file.

Parameters:
  • file_path (str | Path) – The path to the GFF3 file to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of GFF3 records.

Return type:

list[GFF3Record]

static parse_text(data, limit=None)[source]#

Parse GFF3 records from text.

Parameters:
  • data (str) – The GFF3 text to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of GFF3 records.

Return type:

list[GFF3Record]

raw_lines(limit=10000)[source]#

Return record lines from the current stream position without line endings.

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

Parameters:

limit (int | None, default: 10000) – The maximum number of lines to return. Default is 10000.

Returns:

The record lines, in input order.

Return type:

list[str]

property reader_mode: str#

Return the configured reader mode.

records(limit=10000, feature_types=None)[source]#

Return records from the current stream position.

Parameters:
  • limit (int | None, default: 10000) – The maximum number of records to return. Default is 10000.

  • feature_types (Iterable[str] | None, default: None) – When given, only rows whose column 3 matches one of these values (case-insensitively) are returned. The Rust side applies this before a non-matching line is parsed into a record or converted into a Python object.

Returns:

A list of GFF3 records.

Return type:

list[GFF3Record]

seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a region and make next() stream matching records.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to..

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

tabix_path: str | Path | None#
class ensembl.vep.parsers.gff3.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

ensembl.vep.parsers.gtf module#

GTF parser interface backed by the Rust noodles-gtf parser.

class ensembl.vep.parsers.gtf.GTFParser(*, file_path=None, tabix_path='tabix', mode='auto')[source]#

Bases: Parser[GTFRecord]

Parser facade for GTF files.

Variables:
  • format (str) – The format of the file being parsed.

  • file_path (str | Path | None) – The path to the file being parsed.

  • tabix_path (str) – The path to the tabix executable.

  • mode (str) – The reader mode, either “auto”, “query” or “sequential”. Default is “auto”, which will attempt to use “query” mode and fall back to “sequential” if the file is not indexed.

close()[source]#

Close the parser.

file_path: str | Path | None#
format: str#
property index_sequence_names: list[str]#

Return reference sequence names declared by the tabix index.

Empty when the file is unopened, read sequentially, or falls back to the system tabix executable.

Returns:

The reference sequence names the index declares.

Return type:

list[str]

property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

mode: str#
next()[source]#

Return the next GTF record, or None at EOF.

Returns:

The next GTF record,

or None if the end of the file reached.

Return type:

GTFRecord | None

open(file_path, mode='auto')[source]#

Open a GTF file.

Parameters:

file_path (str | Path) – The path to the GTF file to be parsed.

Returns:

The parser instance.

Return type:

GTFParser

static parse_file(file_path, limit=None)[source]#

Parse GTF records from a file.

Parameters:
  • file_path (str | Path) – The path to the GTF file to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of GTF records.

Return type:

list[GTFRecord]

static parse_text(data, limit=None)[source]#

Parse GTF records from text.

Parameters:
  • data (str) – The GTF text to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of GTF records.

Return type:

list[GTFRecord]

raw_lines(limit=10000)[source]#

Return record lines from the current stream position without line endings.

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

Parameters:

limit (int | None, default: 10000) – The maximum number of lines to return. Default is 10000.

Returns:

The record lines, in input order.

Return type:

list[str]

property reader_mode: str#

Return the configured reader mode.

records(limit=10000, feature_types=None)[source]#

Return records from the current stream position.

Parameters:
  • limit (int | None, default: 10000) – The maximum number of records to return. Default is 10000.

  • feature_types (Iterable[str] | None, default: None) – When given, only rows whose column 3 matches one of these values (case-insensitively) are returned. The Rust side applies this before a non-matching line is parsed into a record or converted into a Python object.

Returns:

A list of GTF records.

Return type:

list[GTFRecord]

seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a region and make next() stream matching records.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to..

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

tabix_path: str | Path | None#
class ensembl.vep.parsers.gtf.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

ensembl.vep.parsers.parser module#

Parser interface.

class ensembl.vep.parsers.parser.Parser[T](*, format)[source]#

Bases: ABC, Generic[T]

Parser interface.

Variables:
  • format (str) – The format of the file being parsed.

  • metadata (dict) – A dictionary containing metadata about the file being parsed.

abstractmethod close()[source]#

Close the parser.

format: str#
property index_sequence_names: list[str]#

Return reference sequence names declared by the index.

Returns:

The reference sequence names, or an empty list when the parser has no index or does not expose this information.

Return type:

list[str]

property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

abstractmethod next()[source]#

Return the next raw row from the active region query.

Returns:

The next raw row, or None if there are no more rows.

Return type:

Optional[T]

abstractmethod open(file_path, mode)[source]#

Open a file for parsing.

Parameters:
  • file_path (str) – The path to the file to be parsed.

  • mode (str) – The mode in which to open the file.

Returns:

The parser instance.

Return type:

Parser

static parse_file(file_path, limit=None)[source]#

Parse a file and return a list of records.

Parameters:
  • file_path (str | Path) – The path to the file to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of records parsed from the file.

Return type:

list[T]

static parse_text(data, limit=None)[source]#

Parse raw text data and return a list of records.

Parameters:
  • data (str) – The raw text data to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of records parsed from the raw text data.

Return type:

list[T]

records(limit=None)[source]#

Return all records from the active region query.

Parameters:

limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of records from the active region query.

Return type:

list[T]

abstractmethod seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a region and make next() stream matching raw rows.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to.

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

ensembl.vep.parsers.tabix module#

Tabix parser interface backed by Rust.

class ensembl.vep.parsers.tabix.TabixParser(*, file_path=None, tabix_path='tabix')[source]#

Bases: Parser[str]

Parser facade for tabix-indexed row streams.

Variables:
  • format (str) – The format of the file being parsed.

  • file_path (str | Path | None) – The path to the file to be parsed.

  • tabix_path (str | Path | None) – The path to the tabix executable.

  • _parser (_RustTabixParser) – The underlying Rust tabix parser.

close()[source]#

Close the parser.

file_path: str | Path | None#
format: str#
property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

next()[source]#

Return the next raw row from the active region query.

Returns:

The next raw row from the active region query, or None if there are no more rows.

Return type:

str | None

open(file_path, mode=None)[source]#

Open a tabix-indexed BGZF file.

Parameters:
  • file_path (str | Path) – The path to the file to be parsed.

  • mode (str | None, default: None) – The mode in which to open the file.

Returns:

The parser instance.

Return type:

TabixParser

records(limit=None)[source]#

Return raw rows from the active region query.

Parameters:

limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of raw rows from the active region query.

Return type:

list[str]

seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a region and make next() stream matching raw rows.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to.

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

tabix_path: str | Path | None#

ensembl.vep.parsers.vcf module#

VCF parser interface backed by the Rust noodles-vcf parser.

class ensembl.vep.parsers.vcf.VCFParser(*, file_path=None, tabix_path='tabix', mode='auto')[source]#

Bases: Parser[VCFRecord]

Parser facade for VCF files.

Variables:
  • format (str) – The format of the file being parsed.

  • file_path (str | Path | None) – The path to the file being parsed.

  • tabix_path (str) – The path to the tabix executable.

  • mode (str) – The reader mode, either “auto”, “query” or “sequential”. Default is “auto”, which will attempt to use “query” mode and fall back to “sequential” if the file is not indexed.

close()[source]#

Close the parser.

file_path: str | Path | None#
format: str#
property metadata: dict#

Return parsed file metadata.

Returns:

The metadata dictionary.

Return type:

dict

mode: str#
next()[source]#

Return the next VCF record, or None at EOF.

Returns:

The next VCF record,

or None if the end of the file.

Return type:

VCFRecord | None

open(file_path, mode='auto')[source]#

Open a VCF file.

Parameters:
  • file_path (str | Path) – The path to the VCF file to be parsed.

  • mode (str, default: 'auto') – The mode in which to open the file.

Returns:

The parser instance.

Return type:

VCFParser

static parse_file(file_path, limit=None)[source]#

Parse VCF records from a file.

Parameters:
  • file_path (str | Path) – The path to the VCF file to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of VCF records.

Return type:

list[VCFRecord]

static parse_text(data, limit=None)[source]#

Parse VCF records from text.

Parameters:
  • data (str) – The VCF text to parse.

  • limit (int | None, default: None) – The maximum number of records to return. If None, return all records.

Returns:

A list of VCF records.

Return type:

list[VCFRecord]

raw_lines(limit=10000)[source]#

Return record lines from the current stream position without line endings.

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

Parameters:

limit (int | None, default: 10000) – The maximum number of lines to return. Default is 10000.

Returns:

The record lines, in input order.

Return type:

list[str]

property reader_mode: str#

Return the configured reader mode.

static record_count(file_path, scan=False)[source]#

Return the declared VCF record count, if available.

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; on an input of a billion lines that pass dominates a run, so a caller that only wants the count for progress reporting leaves it off and does without.

Parameters:
  • file_path (str | Path) – The path to the VCF file to count.

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

Returns:

The record count, or None when no index declares it and scan is False.

Return type:

int | None

records(limit=10000)[source]#

Return records from the current stream position.

Parameters:

limit (int | None, default: 10000) – The maximum number of records to return. Default is 10000.

Returns:

A list of VCF records.

Return type:

list[VCFRecord]

seek(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Seek to a region and make next() stream matching records.

Parameters:
  • region (str | None, default: None) – The region to seek to, in the format “chr:start-end”.

  • seq_region_name (str | None, default: None) – The name of the region to seek to..

  • start (int | None, default: None) – The start position of the region to seek to.

  • end (int | None, default: None) – The end position of the region to seek to.

Returns:

True if the seek was successful, False otherwise.

Return type:

bool

tabix_path: str | Path | None#
class ensembl.vep.parsers.vcf.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]