Annotation import loads every transcript version for the build: an 11 minute wait to load one variant's result

Open
#2,963 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

This issue has not been assessed yet.

Description

🤖 Written by Claude

When an annotation run loads its VEP results into the database, the importer first builds a lookup of every transcript version for the build and consortium (annotation/vcf_files/bulk_vep_vcf_annotation_inserter.py:BulkVEPVCFAnnotationInserter.transcript_versions_by_id, which calls genes/models/models_gene.py:TranscriptVersion.transcript_versions_by_id). It does this once per run, whatever the run's size, to turn each transcript accession in the VEP output into a TranscriptVersion pk.

Seen on a test deployment: a GRCh38 run with a single variant took 11 minutes to load its result. The time went on that one query, reading from disk with a cold cache. The same step took 1 minute on GRCh37 and under a second on T2T. Nothing failed, but a classification import that creates one new variant waits that long for its annotation.

Why it is slow

  • It loads far more than it needs. VEP only reports transcripts from the annotation version's gene annotation release, and on the RefSeq builds the release is about a third of the transcript versions we hold:

    Build All transcript versions (build + consortium) In the gene annotation release
    GRCh37 (RefSeq) 201,945 82,466
    GRCh38 (RefSeq) 542,377 178,369
    T2T (Ensembl) 238,489 236,037
  • Each row needs a read from the genes_transcriptversion table itself (about 5 GB, as each row carries its cdot JSON), because no index holds transcript_id, version and id together. With a cold cache that is one slow disk read per transcript version.

The release is enough. Each VariantAnnotationVersion is tied to one GeneAnnotationRelease, the specific RefSeq or Ensembl release VEP was run with, so VEP's output can only name transcript versions in that release (ReleaseTranscriptVersion). The mitochondrial "fake" transcripts the importer matches (the 13 coding ones, fake-rna-ND4 and so on) are in the release too; the 24 tRNA/rRNA ones are not, and VEP reports nothing the importer links to them.

Ideas to try

Look at the size of the annotation run and pick a strategy to suit. Try a few and measure, cold and warm:

  1. Very small runs: look up each transcript version as it is needed.
  2. Medium runs: read a batch of VEP records, collect the transcript accessions in it, and fetch them in one query with __in=.
  3. Huge runs: load the gene annotation release's transcript versions up front (the fake ones the importer needs are in it).

Index: adding id to the unique (transcript_id, version, genome_build_id) index (INCLUDE (id)) would let all three strategies answer from the index without reading the table. Decide this alongside the strategies, as it may make some of them unnecessary.

The gene lookup next to it (gene_identifiers) loads every gene version for the build the same way, so it is worth a look while there.

Dominant language
Python
Stars
31
Forks
4
Avg merge
4h 52m
Merged PRs (30d)
183

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SACGF/variantgrid

All issues in SACGF/variantgrid

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.