Repository navigation
feat(annotator): let subclasses abort VCF annotation - #682
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
AbstractVcfAnnotator.annotate() catches every exception raised while processing a record, writes it to that record's VRS_Error INFO field and moves on to the next record. This is the right behavior for per-variant problems, but leaves child classes no way to signal an unrecoverable, global failure from hooks like on_vrs_object(). For example, an implementation that batch-inserts alleles into a database keeps iterating (and retrying the insert on every record) after the database goes away. Add VcfAnnotatorAbortError, a VcfAnnotatorError subclass that annotate() re-raises instead of recording, so annotation stops and the error reaches the caller. The input and output VCF files are now closed in a finally block so an aborted run doesn't leave them open, and the collection hook (e.g. PKL/NDJSON dumps) is not run for an aborted annotation. Closes ga4gh#605
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #605.
Problem
AbstractVcfAnnotator.annotate()catches every exception raised while a record is processed, writes it to that record'sVRS_ErrorINFO field and continues with the next record. That's correct for per-variant problems, but a child class can't signal an unrecoverable, global failure fromon_vrs_object(). For example, AnyVar batch-inserts alleles inon_vrs_object(). If the database becomes unreachable, the annotator keeps iterating and retries the insert (and logs) on every following record.Changes
VcfAnnotatorAbortError(aVcfAnnotatorErrorsubclass). If it is raised while a record is processed,annotate()logs where it stopped and re-raises it instead of recording it inVRS_Error. The error then reaches the caller. Child classes can raise it directly, or chain a lower-level error withraise VcfAnnotatorAbortError(...) from e.finallyblock, so an aborted run doesn't leave them open. A bgzipped output is finalized and can be read back. Most of the diff inannotate()is re-indentation from this;git diff -wshows the real change.on_vrs_object_collection()(e.g. PKL/NDJSON dumps) does not run for an aborted annotation.on_vrs_object()andannotate()docstrings.Other exceptions behave as before.
Tests
Two tests in
tests/extras/test_annotate_vcf.pyuse a smallVcfAnnotatorsubclass that raises fromon_vrs_object()at a chosen allele. Both reuse the existingtest_annotate_vcf_rle.yamlcassette, since they annotate the sametest_rle.vcfinput:test_annotate_vcf_record_error: a plainRuntimeErroris still recorded inVRS_Errorfor that record, and annotation continues.test_annotate_vcf_abort:VcfAnnotatorAbortErrorpropagates out ofannotate(). The PKL dump is not written, and the closed output VCF holds only the record annotated before the abort. This test fails without the change.ruff check,ruff format --checkand the full test suite (pytest --vcr-record=none, 204 passed) pass locally.