ensembl.vep.sources.file.gxf package#

Shared GXF-backed data model object sources.

Submodules#

ensembl.vep.sources.file.gxf.transcript module#

Shared GXF-based transcript source.

This module contains the common transcript-building workflow used by both file formats:

  • buffer records from the parser in streaming order,

  • group the buffered records into transcript-sized blocks,

  • build Transcript, Gene, Exon, and Translation objects (introns are derived lazily by Transcript itself), and

  • reuse Slice and Gene instances across records that share the same region.

Only the parser-specific record identity and parent resolution rules are left to the concrete GFF3 and GTF adapters.

class ensembl.vep.sources.file.gxf.transcript.GXFRecord(*args, **kwargs)[source]#

Bases: Protocol

Minimal parser record interface shared by GFF3 and GTF records.

Variables:
  • feature_type (str) – Raw feature type reported by the parser.

  • seqid (str) – Sequence-region name for the record.

  • start (int) – Genomic start position, 1-based inclusive.

  • end (int) – Genomic end position, 1-based inclusive.

  • strand_symbol (str) – Strand symbol from the parser record.

  • phase_value (str | None) – Phase string for coding features, if present.

  • attributes (dict[str, tuple[str, ...]]) – Parsed key/value attributes from the record.

attribute_values(key)[source]#

Return every attribute value for a key, empty when absent.

Return type:

list[str]

attributes: dict[str, tuple[str, ...]]#
end: int#
feature_type: str#
first_attribute(key)[source]#

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

Return type:

str | None

phase_value: int | None#
seqid: str#
start: int#
strand_symbol: str#
class ensembl.vep.sources.file.gxf.transcript.GXFTranscriptSource[P: Parser](*, sequence_source=None, slice_cache=WeakSliceCache(), file_path, adaptor, reference_region_resolver=None, source_region_resolver=None, transcript_pool=None)[source]#

Bases: FileFeatureSource[P, GXFRecord, Transcript], ABC, Generic[P]

Transcript source backed by GFF3 or GTF file.

Variables:
  • gene_feature_types (frozenset[str]) – Lower-cased feature types that identify a gene record.

  • transcript_feature_types (frozenset[str]) – Lower-cased feature types that identify a transcript record.

  • exon_feature_types (frozenset[str]) – Lower-cased feature types that identify an exon record.

  • coding_feature_types (frozenset[str]) – Lower-cased feature types that contribute to the transcript translation.

  • reference_region_resolver (SequenceRegionResolver | None) – Resolve raw GXF names to the shared reference names used by model slices.

  • source_region_resolver (SequenceRegionResolver | None) – Resolve model slice names to names accepted by indexed GXF queries.

  • transcript_pool (FeaturePool[Transcript] | None) – Cross-payload cache of built transcripts, assigned by the owning worker; None disables reuse.

adaptor: P#
close()[source]#

Close the region-query parser and the attached sequence source.

coding_feature_types: ClassVar[frozenset[str]] = frozenset({'cds'})#
exon_feature_types: ClassVar[frozenset[str]] = frozenset({'exon'})#
gene_feature_types: ClassVar[frozenset[str]] = frozenset({'gene'})#
get_features_by_region(region=None, *, seq_region_name=None, start=None, end=None)[source]#

Return complete transcripts whose spans meet one query region.

Two queries, because one is not enough: stage 1 finds the transcript rows overlapping the region, stage 2 queries the full span of each candidate not already pooled, so exons and coding records outside the region are kept. Results are in stage-1 (file) order whether a transcript came from the pool or was just built, which is what fixes CSQ order.

A region without coordinates queries the whole sequence region, and so assembles every transcript on it.

Return type:

list[Transcript]

abstractmethod get_parent_ids(record)[source]#

Return the parent identifiers for a GFF3/GTF record, if they exist.

Plural because one GFF3 row may name several parents: an exon shared by two transcripts arrives as a single record with Parent=transcript:1,transcript:2, and taking only the first would drop it from every transcript but one.

Parameters:

record (GXFRecord) – The record to inspect.

Returns:

A tuple of parent identifiers, or an empty tuple when the record has no parent.

Return type:

tuple[str, ...]

abstractmethod get_record_id(record)[source]#

Return the stable identifier for a GFF3/GTF record.

Parameters:

record (GXFRecord) – The record to inspect.

Returns:

The record identifier, or None when the record is not identified.

Return type:

str | None

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

Return the records an indexed query over one region reads, assembling nothing.

Unlike the file-backed default this resolves the region into the file’s own spelling, and falls back to chr prefix variants when the name the index declares finds nothing – which happens for an unindexed GXF with no ##sequence-region directive.

Parameters:
  • region (str | None, default: None) – The region (e.g., “chr1:1000-2000”) to read.

  • seq_region_name (str | None, default: None) – The name of the sequence region, in reference spelling.

  • start (int | None, default: None) – Inclusive query start.

  • end (int | None, default: None) – Inclusive query end.

  • **kwargs (object) – feature_types, a frozenset of record types to keep. Matching happens on the Rust side, before a non-matching line is parsed into a record.

Returns:

The records the query read, empty when the region is unreadable.

Return type:

list[GXFRecord]

iter_all_features()[source]#

Yield transcripts by streaming the file sequentially.

Returns:

Transcripts built from the entire file.

Return type:

Iterator[Transcript]

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

Yield complete transcripts intersecting one query region.

One region is the batch of one: an indexed query cannot serve this, because a transcript’s exons reach outside the queried region, so the answer is the same sequential pass iter_features_by_regions makes. Callers with an index want get_features_by_region, which queries each candidate’s full span instead.

Parameters:
  • region (str | None, default: None) – The region (e.g., “chr1:1000-2000”) to get transcripts from.

  • seq_region_name (str | None, default: None) – The name of the sequence region (e.g., “chr1”).

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

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

Returns:

Transcripts intersecting the region.

Return type:

Iterator[Transcript]

iter_features_by_regions(intervals_by_region)[source]#

Yield only transcripts intersecting reference-space query intervals.

This source’s own method, not part of the FeatureSource contract: a format whose record already carries a whole feature answers each region on its own, and gains nothing from the batch. Here one pass serves every requested interval, so a whole input buffer costs one read of the file rather than one per region.

The record predicate runs before transcript, exon, CDS, and gene models are built, which keeps the unindexed fallback bounded by the current payload rather than the source size.

Parameters:

intervals_by_region (Mapping[str, Sequence[tuple[int, int]]]) – 1-based inclusive (start, end) intervals, keyed by sequence-region name.

Returns:

Transcripts intersecting any requested interval.

Return type:

Iterator[Transcript]

records_to_features(records)[source]#

Convert a batch of records into transcripts, with a fresh gene and slice context.

The records must be complete and contiguous: every exon, CDS and gene row of each transcript present, in file order. One transcript is many records, so a partial set builds partial models rather than failing – which is why the region and streaming getters are overridden instead of composing this one record at a time.

Fresh dictionaries are passed every time: _build_transcripts defaults to shared mutable dictionaries, which would carry genes and slices over from one call to the next.

Parameters:

records (list[GXFRecord]) – The records to convert, in file order.

Returns:

The transcripts they describe.

Return type:

list[Transcript]

reference_region_resolver: SequenceRegionResolver | None#
property sequence_region_names: frozenset[str]#

Return the tabix index’s reference names together with ##sequence-region names.

A header can declare a contig that has no rows, and so no index entry.

source_region_resolver: SequenceRegionResolver | None#
transcript_feature_types: ClassVar[frozenset[str]] = frozenset({'transcript'})#
transcript_pool: Optional[FeaturePool[Transcript]]#
property transcript_pool_poisoned: bool#

Return whether a repeated transcript id has disabled pooling for this source.