Skip to content

Concept - Select caches in vvMixinInit #876

Description

@Peter-J-Freeman

Testing a concept SeqFetcher.fetch_seq() LRU cache produced a modest improvement in average runtime during benchmarking, but overall execution times were more consistent. The benchmark is also likely to underestimate the benefit in production because VariantValidator commonly exhibits sequence locality.

During gap mapping of VCF files, the converter repeatedly processes the same transcript/genomic accession combinations while generating the different HGVS representations (genomic, transcript, protein and related formats). This results in repeated requests for the same sequence regions within tight processing loops, allowing an LRU cache to eliminate many duplicate sequence retrievals.

Similar locality is expected in routine clinical and research workflows. Variants are commonly analysed in batches originating from the same sequencing sample, gene panel or disease cohort, where multiple variants frequently occur within the same gene or transcript. Successive variants therefore repeatedly access the same transcript and genomic sequence, allowing cached sequence data to be reused across validations. Although the average benchmark improvement is modest, the practical benefit is expected to be greater for real-world batch processing workloads and for gap mapping, where repeated access to the same sequence regions is common.

The same principle may also be applicable to the HGVS Data Provider (HDP). Rather than introducing caching throughout the codebase, it may be possible to wrap the expensive external resources when they are created in vvMixinInit, allowing repeated lookups to be cached transparently while leaving the remainder of VariantValidator unchanged and not relying on cache all implementation via vvhgvs data providers

Current architecture

                 Validator
                     │
         ┌───────────┴───────────┐
         │                       │
    SeqFetcher                 HDP
         │                       │
    fetch_seq()         get_tx_exons()
                        get_tx_identity_info()
                        get_tx_mapping_options()
                        ...
                              │
                          Database

Proposed architecture

                      Validator
                          │
          ┌───────────────┴───────────────┐
          │                               │
 CachedSeqFetcher                  CachedHDP
          │                               │
     SeqFetcher                         HDP
          │                               │
     fetch_seq()                 get_tx_exons()
                                 get_tx_identity_info()
                                 get_tx_mapping_options()
                                 ...
                                       │
                                   Database

Validator initialisation

Current:

self.sf = SeqFetcher(...)
self.hdp = hdp_connect(...)

Proposed:

self.sf = CachedSeqFetcher(
    SeqFetcher(...)
)

self.hdp = CachedHDP(
    hdp_connect(...)
)

No downstream code would require modification, as the Validator would continue to expose the same self.sf and self.hdp interfaces.

The wrapper classes would transparently cache repeated lookups while delegating to the underlying implementations.

class CachedSeqFetcher:

    def __init__(self, seqfetcher):
        self._seqfetcher = seqfetcher

    @lru_cache(maxsize=...)
    def fetch_seq(self, *args):
        return self._seqfetcher.fetch_seq(*args)
class CachedHDP:

    def __init__(self, hdp):
        self._hdp = hdp

    @lru_cache(maxsize=...)
    def get_tx_exons(self, *args):
        return self._hdp.get_tx_exons(*args)

    @lru_cache(maxsize=...)
    def get_tx_identity_info(self, *args):
        return self._hdp.get_tx_identity_info(*args)

    @lru_cache(maxsize=...)
    def get_tx_mapping_options(self, *args):
        return self._hdp.get_tx_mapping_options(*args)

    ...

This keeps the optimisation isolated to a single layer, avoids modifying call sites throughout VariantValidator, and focuses caching on the two most frequently accessed external resources: sequence retrieval and transcript/database lookups. It also provides a single place to tune cache sizes, collect cache statistics or disable caching if required.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions