ensembl.vep.caches package#

Cache implementations.

Submodules#

ensembl.vep.caches.binned_cache module#

UCSC-style binned feature cache.

class ensembl.vep.caches.binned_cache.BinnedCache[ObjectT](*args, **kwargs)[source]#

Bases: Protocol[ObjectT]

Cache of objects keyed by sequence region and interval.

add(seq_region_name, value, interval, *, key=None)[source]#

Cache one object under its interval.

clear()[source]#

Clear cached state.

get_objects(seq_region_name, intervals)[source]#

Return cached objects that meet any query interval.

Return type:

list[ObjectT]

class ensembl.vep.caches.binned_cache.BinnedFeatureCache[ObjectT][source]#

Bases: Generic[ObjectT]

Source-feature cache using UCSC hierarchical bins.

A feature is stored in its smallest enclosing bin. Cache membership is partitioned by sequence-region name. An optional stable key prevents a source from adding the same logical feature after overlapping fetches.

add(seq_region_name, value, interval, *, key=None)[source]#

Cache a feature under its smallest enclosing bin.

Parameters:
  • seq_region_name (str) – Sequence region containing the feature.

  • value (ObjectT) – Cached source feature.

  • interval (Interval) – Feature interval in sequence-region coordinates.

  • key (Hashable | None, default: None) – Stable source identity used to ignore a repeated logical feature.

clear()[source]#

Clear cached features.

get_objects(seq_region_name, intervals)[source]#

Return cached candidates that meet any query interval.

Return type:

list[ObjectT]

ensembl.vep.caches.codon_cache module#

Cache codon and peptide edits shared across consequence annotations.

Caches are instance-scoped and keyed by the complete codon-window edit. Key construction uses the same mapping functions as the _codon_alleles fact so cache identity cannot drift from fact evaluation.

class ensembl.vep.caches.codon_cache.CodonCache(*args, **kwargs)[source]#

Bases: Protocol

Define storage used to reuse codon and peptide edits.

Implementations provide get_codon_edit and clear. The default prefill method contains the storage-independent fact integration.

clear()[source]#

Clear cached state.

get_codon_edit(key, loader)[source]#

Return the cached codon edit, loading it on a miss.

Parameters:
  • key (CodonEditKey) – Full-edit cache key.

  • loader (Callable[[], CodonEdit]) – Loader used when key is not cached.

Returns:

Cached or newly loaded codon edit.

Return type:

CodonEdit

prefill(fact_context)[source]#

Prefill codon and peptide facts when the overlap is coding.

Run after zone-map prefill and before fact evaluation so cache hits avoid mapping and sequence work. Non-coding and non-exonic overlaps are ignored.

Parameters:

fact_context (FactContext[TranscriptVariationAllele]) – Overlap to prefill.

class ensembl.vep.caches.codon_cache.CodonEdit(*, reference_codon, alternate_codon, reference_peptide, alternate_peptide)[source]#

Bases: object

Store the mapping and sequence result for one codon-window edit.

Variables:
  • reference_codon (str) – The reference codon window, transcript-sense.

  • alternate_codon (str) – reference_codon with the variant allele spliced in.

  • reference_peptide (str) – The amino acid translation of reference_codon.

  • alternate_peptide (str) – The amino acid translation of alternate_codon.

alternate_codon: str#
alternate_peptide: str#
reference_codon: str#
reference_peptide: str#
class ensembl.vep.caches.codon_cache.CodonEditKey(seq_region_name, codon_window_genomic_positions, padding, strand, variant_min, variant_max, reference_allele, alternate_allele)[source]#

Bases: NamedTuple

Identify one codon-window edit.

The key is deliberately over-inclusive: extra fields can reduce the hit rate, while omitted fields can reuse an incorrect consequence. A NamedTuple keeps hot-path construction and hashing inexpensive while retaining named fields.

Variables:
  • seq_region_name (str) – Region the codon window sits on.

  • codon_window_genomic_positions (tuple[int, ...]) – Genomic positions of the whole codon(s).

  • padding (int) – Window bases with no genomic position – the N before a CDS that starts part-way through a codon. Without it that first codon’s key could equal a partial last codon’s on another transcript over the same bases.

  • strand (int) – Reading direction, as Strand.value.

  • variant_min (int) – Low genomic bound of the edit, fixing where in the window it falls.

  • variant_max (int) – High genomic bound of the edit.

  • reference_allele (str) – Reference bases.

  • alternate_allele (str) – Alternate bases.

alternate_allele: str#

Alias for field number 7

classmethod build(fact_context)[source]#

Build a key for the codon window touched by a variant.

Parameters:

fact_context (FactContext[TranscriptVariationAllele]) – Overlap being evaluated. Reads and memoises the _cds_footprint fact.

Returns:

Cache key, or None if the variant touches no codon window.

Return type:

CodonEditKey | None

codon_window_genomic_positions: tuple[int, ...]#

Alias for field number 1

padding: int#

Alias for field number 2

reference_allele: str#

Alias for field number 6

seq_region_name: str#

Alias for field number 0

strand: int#

Alias for field number 3

variant_max: int#

Alias for field number 5

variant_min: int#

Alias for field number 4

class ensembl.vep.caches.codon_cache.CodonEditLRUCache(*, enabled=True, max_entries=65536)[source]#

Bases: CodonCache

Store codon edits in an instance-scoped LRU cache.

eq=False preserves identity semantics for mutable shared state.

Variables:
  • enabled (bool) – Whether caching is enabled.

  • max_entries (int) – Maximum number of entries to retain.

  • hit_count (int) – Number of lookups served from the cache.

  • miss_count (int) – Number of lookups that invoked loader.

clear()[source]#

Clear the cache contents.

enabled: bool#
get_codon_edit(key, loader)[source]#

Return the cached codon edit, loading and storing it on a miss.

Parameters:
  • key (CodonEditKey) – Full-edit cache key.

  • loader (Callable[[], CodonEdit]) – Loader used when key is not cached.

Returns:

Cached or newly loaded codon edit.

Return type:

CodonEdit

hit_count: int#
max_entries: int#
miss_count: int#

ensembl.vep.caches.feature_pool module#

The cross-payload feature pool contract, and the transcript pool that implements it.

BinnedFeatureCache (the worker’s per-payload transcript cache) is cleared before every new payload, so a worker that revisits the same gene across many payloads – a dense or targeted input, or simply a long run of variants on one chromosome – rebuilds the same Transcript from GXF records every time. Building one is not free: grouping records, constructing Exon/Translation objects, and resolving the shared Gene.

Transcript objects are never mutated after GXFTranscriptSource builds them, so reusing the same object across payloads is safe – the only growth over a transcript’s pooled lifetime is whatever cached_property values get resolved on it (introns, spliced sequence, CDS, translated sequence, and so on), which is why the pool is bounded by bytes rather than kept forever.

TranscriptPool is keyed by (region, stable_id, start, end) – the same fields BinnedFeatureCache already uses as its own dedup key – and mirrors ZoneMapCache’s byte-budgeted LRU shape: build outside the pool, insert and evict under a lock.

ensembl.vep.caches.feature_pool.DEFAULT_TRANSCRIPT_POOL_BYTES = 134217728#

Default byte budget for TranscriptPool, shared by the config default and every call site.

ensembl.vep.caches.feature_pool.FeatureKey#

(seq_region_name, stable_id, start, end) – a built feature’s pool identity.

Matches BinnedFeatureCache.add’s own dedup key, so a feature is addressed the same way whether the caller means “the cache for this payload” or “the pool across payloads”.

alias of tuple[str, str, int, int]

class ensembl.vep.caches.feature_pool.FeaturePool[FeatureT: Feature](*args, **kwargs)[source]#

Bases: Protocol[FeatureT]

Define an interchangeable cache of built features, reused across payloads.

A source builds features from its own records; a pool lets the next payload reuse those objects instead of rebuilding them. Implementations decide what to retain and when to evict, so a pool is a hint, never a source of truth: get may miss at any time and put may discard what it was given.

Variables:
  • max_bytes (int) – Byte budget for pooled features. <= 0 disables the pool.

  • hit_count (int) – Number of get calls served from the pool so far.

  • miss_count (int) – Number of get calls that found nothing so far.

clear()[source]#

Clear pooled features.

get(key)[source]#

Return the pooled feature for a key, or None on a miss.

Return type:

Optional[FeatureT]

hit_count: int#
max_bytes: int#
miss_count: int#
put(key, feature)[source]#

Offer a freshly built feature to the pool.

ensembl.vep.caches.feature_pool.TranscriptKey#

(seq_region_name, stable_id, start, end) – the FeatureKey spelling a transcript pool uses.

alias of tuple[str, str, int, int]

class ensembl.vep.caches.feature_pool.TranscriptPool(*, max_bytes=134217728)[source]#

Bases: FeaturePool[Transcript]

A byte-budgeted, least-recently-used cache of built Transcript models.

Reuse across payloads within one worker – a payload’s own BinnedFeatureCache is still cleared every time (BufferedWorker._begin_payload); this pool is what survives that clear. Construct one per worker and hand it to GXFTranscriptSource.transcript_pool.

Only one sequence region is held at a time: inserting a transcript from a different region than the one currently pooled drops every entry from the old region first. A sorted VCF input visits one region for a long run of payloads before moving to the next, so this keeps the common case (many payloads over the same region) cheap without holding memory for regions no longer being annotated. It is a size optimisation, not a correctness requirement – a transcript is always addressed by its full key, so nothing breaks if the same region is revisited later; it is just a pool miss.

eq=False keeps identity semantics: this is a shared, mutable instance, not a value object, so two pools with equal counters must not compare equal.

Variables:
  • max_bytes (int) – Byte budget for pooled transcripts. <= 0 disables the pool: get always misses and put never stores anything. Default is DEFAULT_TRANSCRIPT_POOL_BYTES.

  • hit_count (int) – Number of get calls served from the pool so far.

  • miss_count (int) – Number of get calls that found nothing so far.

  • eviction_count (int) – Number of entries evicted for being over the byte budget so far.

  • seq_region_eviction_count (int) – Number of entries dropped so far because the pooled seq_region changed.

clear()[source]#

Clear the pool contents.

eviction_count: int#
get(key)[source]#

Return the pooled transcript for key, moving it to most-recently-used.

Parameters:

key (tuple[str, str, int, int]) – The transcript’s pool identity.

Returns:

The cached transcript, or None on a miss (including when the pool is disabled).

Return type:

Transcript | None

hit_count: int#
max_bytes: int#
miss_count: int#
put(key, transcript)[source]#

Insert a freshly built transcript, evicting by seq_region_name change and then by byte budget.

A no-op when the pool is disabled (max_bytes <= 0).

Parameters:
  • key (tuple[str, str, int, int]) – The transcript’s pool identity. key[0] is the seq_region_name.

  • transcript (Transcript) – The built transcript to store.

seq_region_eviction_count: int#

ensembl.vep.caches.interval_tree module#

Augmented interval-list feature indexing.

IntervalTree wraps ailist, so interval intersection runs in C over the whole batch rather than in Python per feature. FeatureIntervalTreeCache shares one tree per region and source, the way zone_map.py pairs a structure with the cache that reuses it. Interval is the query value the rest of the package builds, and keeps the insertion-point representation the matchers depend on.

class ensembl.vep.caches.interval_tree.FeatureIntervalTreeCache[source]#

Bases: object

Shared interval trees keyed by region and source.

Nothing is evicted yet; the cache is bounded by how many regions a run touches.

clear()[source]#

Clear every cached tree.

get_interval_tree(seq_region_name, start, end, source)[source]#

Return the interval tree for one region and source, building it on a miss.

Parameters:
  • seq_region_name (str) – The sequence region name.

  • start (int) – The 1-based inclusive start coordinate.

  • end (int) – The inclusive end coordinate.

  • source (FeatureSource) – The source whose features the tree holds.

Returns:

The cached or newly built tree.

Return type:

IntervalTree

Raises:

ValueError – If the span is not a 1-based ordered interval.

class ensembl.vep.caches.interval_tree.Interval(*, start, end)[source]#

Bases: object

Inclusive genomic interval or interbase insertion point.

start=end+1 denotes an insertion before start. The interval index expands that point to its two flanking bases only for candidate retrieval. Matchers retain the zero-width insertion semantics.

Variables:
  • start (int) – Inclusive start coordinate.

  • end (int) – Inclusive end coordinate, or start - 1 for an insertion.

end: int#
property is_insertion: bool#

Return whether the interval is a zero-width insertion point.

property lookup_end: int#

Return the inclusive end used for candidate retrieval.

property lookup_start: int#

Return the inclusive start used for candidate retrieval.

start: int#
class ensembl.vep.caches.interval_tree.IntervalTree[FeatureT: IntervalLike](*, features=list())[source]#

Bases: Generic[FeatureT]

Feature index for overlap and proximity queries.

Variables:

features (list[FeatureT]) – The indexed features, in the order they were added.

add_features(features)[source]#

Add features to the index.

Parameters:

features (list[FeatureT]) – The features to add.

features: list[FeatureT]#
get_nearest_features(start, end, k=10)[source]#

Return the k indexed features nearest an inclusive interval.

Parameters:
  • start (int) – The 1-based inclusive start coordinate.

  • end (int) – The inclusive end coordinate.

  • k (int, default: 10) – How many features to return.

Returns:

The nearest features, nearest first.

Return type:

list[FeatureT]

Raises:

ValueError – If the start coordinate is not 1-based.

get_nearest_features_by_feature(feature, k=10)[source]#

Return the k indexed features nearest another feature’s span.

Parameters:
  • feature (IntervalLike) – The feature whose span is queried.

  • k (int, default: 10) – How many features to return.

Returns:

The nearest features, nearest first.

Return type:

list[FeatureT]

Raises:

ValueError – If the feature’s coordinates are not 1-based.

get_overlapping_features(start, end)[source]#

Return every indexed feature overlapping an inclusive interval.

Parameters:
  • start (int) – The 1-based inclusive start coordinate.

  • end (int) – The inclusive end coordinate.

Returns:

The overlapping features, in the order they were added.

Return type:

list[FeatureT]

Raises:

ValueError – If the start coordinate is not 1-based.

get_overlapping_features_by_feature(feature)[source]#

Return every indexed feature overlapping another feature’s span.

Parameters:

feature (IntervalLike) – The feature whose span is queried.

Returns:

The overlapping features, in the order they were added.

Return type:

list[FeatureT]

Raises:

ValueError – If the feature’s coordinates are not 1-based.

get_overlapping_positions(start, end)[source]#

Return the positions in features of every feature overlapping an interval.

A caller querying several intervals deduplicates and orders positions far more cheaply than the features themselves, which is why the positions are public.

Parameters:
  • start (int) – The 1-based inclusive start coordinate.

  • end (int) – The inclusive end coordinate.

Returns:

The matching positions, ascending.

Return type:

list[int]

Raises:

ValueError – If the start coordinate is not 1-based.

class ensembl.vep.caches.interval_tree.IntervalTreeCache(*args, **kwargs)[source]#

Bases: Protocol

Region-based interval-tree cache.

clear()[source]#

Clear cached state.

get_interval_tree(seq_region_name, start, end, source)[source]#

Return the interval tree for one region and source.

Return type:

IntervalTree

class ensembl.vep.caches.interval_tree.IntervalTreeKey(*, seq_region_name, start, end, source_id)[source]#

Bases: object

Identity of one cached interval tree.

Variables:
  • seq_region_name (str) – The sequence region the tree covers.

  • start (int) – The 1-based inclusive start of the covered span.

  • end (int) – The inclusive end of the covered span.

  • source_id (int | None) – Identity of the feature source the tree was filled from.

end: int#
seq_region_name: str#
source_id: int | None#
start: int#

ensembl.vep.caches.mapper_cache module#

Cache expanded mapper indexes used by consequence annotation.

MapperIndex accelerates repeated coordinate conversion but varies substantially in size, so the LRU cache uses a byte budget rather than an entry count.

class ensembl.vep.caches.mapper_cache.MapperIndexCache(*args, **kwargs)[source]#

Bases: Protocol

Define storage used to reuse mapper indexes.

clear()[source]#

Clear cached state.

get_index(transcript, loader)[source]#

Return the cached mapper index, loading it on a miss.

Parameters:
  • transcript (Transcript) – Transcript used to key the cache by stable ID.

  • loader (Callable[[], MapperIndex]) – Loader used when the transcript is not cached.

Returns:

Cached or newly loaded mapper index.

Return type:

MapperIndex

class ensembl.vep.caches.mapper_cache.MapperIndexLRUCache(*, enabled=True, max_bytes=67108864)[source]#

Bases: object

Store mapper indexes in an instance-scoped, byte-budget LRU cache.

Entries use transcript stable IDs because Transcript is not hashable. eq=False preserves identity semantics for mutable shared state.

Variables:
  • enabled (bool) – Whether caching is enabled.

  • max_bytes (int) – Maximum estimated size of cached entries in bytes.

  • hit_count (int) – Number of lookups served from the cache.

  • miss_count (int) – Number of lookups that invoked loader.

clear()[source]#

Clear the cache contents.

enabled: bool#
get_index(transcript, loader)[source]#

Return the cached mapper index, loading and storing it on a miss.

Parameters:
  • transcript (Transcript) – Transcript used to key the cache.

  • loader (Callable[[], MapperIndex]) – Loader used when the transcript is not cached.

Returns:

Cached or newly loaded mapper index.

Return type:

MapperIndex

hit_count: int#
max_bytes: int#
miss_count: int#

ensembl.vep.caches.sequence_cache module#

Sequence cache.

class ensembl.vep.caches.sequence_cache.SequenceBinnedLRUCache(*, enabled=True, chunk_power=18, max_chunks=1024)[source]#

Bases: object

An in-memory LRU cache for fixed-size sequence chunks (or bins).

Variables:
  • enabled (bool) – Whether the cache is enabled. Default is True.

  • chunk_power (int) – The power of two for the chunk size. Default is 18 (chunk size of 2^18 = 262,144).

  • max_chunks (int) – The maximum number of chunks to keep in the cache. Default is 1024.

chunk_power: int#
property chunk_size: int#

Return the cache chunk size.

chunk_start(position)[source]#

Return the start coordinate of the chunk containing the given position.

Position is 1-based inclusive. The returned chunk start is also 1-based inclusive.

Parameters:

position (int) – position of sequence in coordinate space.

Returns:

chunk start coordinate.

Return type:

int

clear()[source]#

Clear the cache contents.

enabled: bool#
get_sequence(seq_region_name, start, end, loader)[source]#

Return sequence for a span using binned chunk caching when useful.

Parameters:
  • seq_region_name (str) – The sequence region name.

  • start (int) – Start position of the sequence span.

  • end (int) – End position of the sequence span.

  • loader (Callable[[str, int, int], str | None]) – Loader used when sequence is not cached.

Returns:

The requested sequence, or None if unavailable.

Return type:

str | None

max_chunks: int#
property max_span: int#

Return the largest sequence that can be stored in the cache.

class ensembl.vep.caches.sequence_cache.SequenceCache(*args, **kwargs)[source]#

Bases: Protocol

Interface for sequence caches.

clear()[source]#

Clear cached state.

get_sequence(seq_region_name, start, end, loader)[source]#

Return sequence for a span.

Parameters:
  • seq_region_name (str) – The sequence region name.

  • start (int) – 1-based inclusive start coordinate.

  • end (int) – 1-based inclusive end coordinate.

  • loader (Callable[[str, int, int], str | None]) – Loader used when sequence is not cached.

Returns:

The requested sequence, or None if unavailable.

Return type:

str | None

ensembl.vep.caches.slice_cache module#

Slice cache.

class ensembl.vep.caches.slice_cache.SliceCache(*args, **kwargs)[source]#

Bases: Protocol

Interface for caches that construct and share Slice objects.

clear()[source]#

Clear cached state.

get_slice(seq_region_name, sequence_source=None, *, start=1, end=None, strand=Strand.FORWARD)[source]#

Return the matching slice, constructing it on a cache miss.

Return type:

Slice

class ensembl.vep.caches.slice_cache.SliceKey(*, sequence_source_id, seq_region_name, start, end, strand)[source]#

Bases: object

Identity of a cached slice.

end: int#
seq_region_name: str#
sequence_source_id: int | None#
start: int#
strand: Strand#
class ensembl.vep.caches.slice_cache.WeakSliceCache[source]#

Bases: object

Share slices without extending their lifetime.

Cached slices remain available while a feature or another consumer holds a strong reference. The cache entry is removed automatically after the last strong reference is released.

clear()[source]#

Clear all live cache entries.

get_slice(seq_region_name, sequence_source=None, *, start=1, end=None, strand=Strand.FORWARD)[source]#

Return the matching slice, constructing it on a cache miss.

If end is omitted, the complete sequence-region length is loaded from sequence_source. A slice cannot be constructed when neither an explicit end nor a resolvable sequence-region length is available.

Parameters:
  • seq_region_name (str) – Name of the sequence region.

  • sequence_source (SequenceSource | None, default: None) – Sequence provider used to resolve a missing end and attached to a newly built slice.

  • start (int, default: 1) – 1-based inclusive slice start.

  • end (int | None, default: None) – 1-based inclusive slice end. Defaults to the complete sequence-region length.

  • strand (Strand, default: Strand.FORWARD) – Slice orientation relative to the sequence region.

Return type:

Slice

Returns:

The shared Slice for the requested identity.

Raises:

ValueError – If the coordinates are invalid or the sequence-region length cannot be resolved.

ensembl.vep.caches.zone_map module#

Cache transcript geometry as positional-fact zones.

Zone boundaries partition a transcript and its flanks into spans with constant positional facts. Each zone stores a fact bitmask, allowing variant spans to be evaluated with a binary search and short bitwise union instead of repeated interval scans. Allele-dependent sequence facts remain outside the zone map.

ZoneMapCache reuses maps across variants and evicts least-recently-used maps by estimated byte size. Computed facts are inserted through FactContext.prefill without charging their normal evaluation cost.

ensembl.vep.caches.zone_map.DEFAULT_ZONE_MAP_BYTES = 268435456#

Default byte budget for a zone-map cache.

ensembl.vep.caches.zone_map.MEMO_FACT_NAMES: tuple[str, ...] = ('overlap_feature', 'overlap_exon', 'overlap_cds', 'overlap_start_codon', 'overlap_stop_codon')#

Facts written to each overlap memo as well as returned in columns.

These facts appear in another fact’s requirements and must remain available through get_fact. The remaining served facts are read directly from columns by columnar annotators.

class ensembl.vep.caches.zone_map.ZoneMap(*, lowest_position, highest_position, starts=(), masks=(), inverted=())[source]#

Bases: object

Partition a transcript and its flanks into positional-fact zones.

starts[i] is the first genomic position of zone i and masks[i] its fact bitmask; each zone ends immediately before the next start. hash=False reflects the unhashable array used for starts.

Variables:
  • lowest_position (int) – Lowest genomic position covered by any zone.

  • highest_position (int) – Highest genomic position covered by any zone.

  • starts (array[int]) – Ascending zone starts packed as signed 64-bit integers.

  • masks (tuple[int, ...]) – Fact mask for each corresponding zone start.

  • inverted (tuple[tuple[int, int, int], ...]) – Degenerate (bit, start, end) intervals matched when a variant spans both bounds.

classmethod build(transcript, upstream_distance=5000, downstream_distance=5000)[source]#

Build the positional-fact zones for a transcript.

Splice windows use intron_offsets_to_genomic_span, matching the per-variant facts. Coding intervals come from the transcript’s CDS, UTR, and codon mappings.

Parameters:
  • transcript (Transcript) – Transcript to compile.

  • upstream_distance (int, default: 5000) – Bases before the 5’ end that is_upstream covers.

  • downstream_distance (int, default: 5000) – Bases past the 3’ end that is_downstream covers.

Returns:

Compiled zone partition.

Return type:

ZoneMap

estimated_bytes()[source]#

Estimate the heap space used by this zone map.

Container sizes are combined with a fixed allowance for the zone-map object and cache bookkeeping. Interned mask integers are not charged per map.

Returns:

Estimated size in bytes.

Return type:

int

highest_position: int#
inverted: tuple[tuple[int, int, int], ...]#
lookup(min_position, max_position)[source]#

Return the union of masks for every zone overlapped by a span.

Parameters:
  • min_position (int) – Inclusive lower bound of the genomic span.

  • max_position (int) – Inclusive upper bound of the genomic span.

Returns:

Combined mask for overlapping zones and covered inverted intervals.

Return type:

int

lowest_position: int#
masks: tuple[int, ...]#
starts: array[int]#
class ensembl.vep.caches.zone_map.ZoneMapCache(*, max_bytes=268435456, upstream_distance=5000, downstream_distance=5000)[source]#

Bases: object

Store per-transcript zone maps in a byte-budget LRU cache.

Maps are built outside the lock and inserted or evicted while holding it. eq=False preserves identity semantics for mutable shared state.

Variables:
  • max_bytes (int) – Byte budget for cached zone maps.

  • upstream_distance (int) – Upstream distance covered by flank zones.

  • downstream_distance (int) – Downstream distance covered by flank zones.

  • hit_count (int) – Number of cache hits.

  • miss_count (int) – Number of maps built after cache misses.

  • maps_built (int) – Alias for miss_count.

  • eviction_count (int) – Number of entries evicted.

  • build_seconds (float) – Total time spent building zone maps.

  • facts_served (int) – Number of fact values prefilled without evaluation.

build_seconds: float#
clear()[source]#

Clear the cache contents.

columns(fact_contexts)[source]#

Return zone-map facts as bit columns for a context batch.

Facts in MEMO_FACT_NAMES are also written to each context because other facts read them through get_fact.

Parameters:

fact_contexts (Sequence[FactContext]) – Contexts in batch-index order.

Returns:

Fact names mapped to bit columns.

Return type:

dict[str, int]

downstream_distance: int#
eviction_count: int#
facts_served: int#
hit_count: int#
property maps_built: int#

Return the number of zone maps built.

max_bytes: int#
miss_count: int#
prefill(fact_context)[source]#

Prefill every zone-map fact without charging evaluation cost.

Parameters:

fact_context (FactContext[TranscriptVariationAllele]) – Overlap context to prefill.

upstream_distance: int#
zone_map(transcript)[source]#

Return a transcript’s cached zone map, building it on a miss.

Entries are keyed by stable ID and version. Concurrent misses may build the same map more than once, but insertion keeps byte accounting exact.

Parameters:

transcript (Transcript) – Transcript to look up.

Returns:

Transcript zone partition.

Return type:

ZoneMap