From 1520fb01c40e577001e01e046e20626a7c88a7fd Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 7 Jul 2025 16:05:21 -0400 Subject: [PATCH] feat: throw a more specific error for failed attempt to overwrite existing annotation column --- src/ga4gh/vrs/extras/annotator/vcf.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ga4gh/vrs/extras/annotator/vcf.py b/src/ga4gh/vrs/extras/annotator/vcf.py index a0e93cb1..cad985b5 100644 --- a/src/ga4gh/vrs/extras/annotator/vcf.py +++ b/src/ga4gh/vrs/extras/annotator/vcf.py @@ -29,6 +29,10 @@ class VcfAnnotatorArgsError(VcfAnnotatorError): """Raise for improper args passed to VCF annotator""" +class ExistingVcfAnnotationError(VcfAnnotatorError): + """Raise for VCF annotator input that already has VRS object annotations""" + + class FieldName(str, Enum): """Define VCF field names for VRS annotations""" @@ -215,6 +219,8 @@ def annotate( validation checks fail, although all instances of failed validation are logged as warnings regardless. :raise VCFAnnotatorError: if no output formats are selected + :raise ExistingVcfAnnotationError: if attempting to output an annotated VCF + and the input already contains annotations. """ self.raise_for_output_args(output_vcf_path, **kwargs) # This can be pushed up to the click arg parsing too @@ -223,7 +229,10 @@ def annotate( ) vcf = pysam.VariantFile(filename=pysam_in_filename, mode="r") if output_vcf_path: - self._update_vcf_header(vcf, compute_for_ref, vrs_attributes) + try: + self._update_vcf_header(vcf, compute_for_ref, vrs_attributes) + except ValueError as e: + raise ExistingVcfAnnotationError(e.args[0] if e.args else None) from e pysam_out_filename = ( "-" if output_vcf_path == "-" else str(output_vcf_path.absolute()) )