From 22485e1a9d4d8280006cc4da8ada9be51feb17d9 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Tue, 3 Sep 2024 09:05:04 -0400 Subject: [PATCH 1/2] feat: optionally suppress console output (#445) --- src/ga4gh/vrs/extras/vcf_annotation.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ga4gh/vrs/extras/vcf_annotation.py b/src/ga4gh/vrs/extras/vcf_annotation.py index 766e57ed..7fe9bb33 100644 --- a/src/ga4gh/vrs/extras/vcf_annotation.py +++ b/src/ga4gh/vrs/extras/vcf_annotation.py @@ -109,10 +109,18 @@ class SeqRepoProxyType(str, Enum): show_default=True, help="Require validation checks to pass in order to return a VRS object" ) +@click.option( + "--silent", + "-s", + is_flag=True, + default=False, + help="Suppress messages printed to stdout" +) def annotate_click( # pylint: disable=too-many-arguments vcf_in: str, vcf_out: Optional[str], vrs_pickle_out: Optional[str], vrs_attributes: bool, seqrepo_dp_type: SeqRepoProxyType, seqrepo_root_dir: str, - seqrepo_base_url: str, assembly: str, skip_ref: bool, require_validation: bool + seqrepo_base_url: str, assembly: str, skip_ref: bool, require_validation: bool, + silent: bool, ) -> None: """Annotate VCF file via click @@ -124,7 +132,8 @@ def annotate_click( # pylint: disable=too-many-arguments start = timer() msg = f"Annotating {vcf_in} with the VCF Annotator..." _logger.info(msg) - click.echo(msg) + if not silent: + click.echo(msg) annotator.annotate( vcf_in, vcf_out=vcf_out, vrs_pickle_out=vrs_pickle_out, vrs_attributes=vrs_attributes, assembly=assembly, @@ -132,7 +141,8 @@ def annotate_click( # pylint: disable=too-many-arguments ) end = timer() msg = f"VCF Annotator finished in {(end - start):.5f} seconds" - _logger.info(msg) + if not silent: + _logger.info(msg) click.echo(msg) class VCFAnnotator: # pylint: disable=too-few-public-methods From 70332f191fda6f0c9971700f691b0072f2024c27 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Tue, 3 Sep 2024 09:21:57 -0400 Subject: [PATCH 2/2] chore: update VCF annotator type annotations for 3.10-12 (#444) --- src/ga4gh/vrs/extras/vcf_annotation.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ga4gh/vrs/extras/vcf_annotation.py b/src/ga4gh/vrs/extras/vcf_annotation.py index 7fe9bb33..5bef5d02 100644 --- a/src/ga4gh/vrs/extras/vcf_annotation.py +++ b/src/ga4gh/vrs/extras/vcf_annotation.py @@ -7,7 +7,6 @@ import logging import pickle from enum import Enum -from typing import Dict, List, Optional from timeit import default_timer as timer import click @@ -117,7 +116,7 @@ class SeqRepoProxyType(str, Enum): help="Suppress messages printed to stdout" ) def annotate_click( # pylint: disable=too-many-arguments - vcf_in: str, vcf_out: Optional[str], vrs_pickle_out: Optional[str], + vcf_in: str, vcf_out: str | None, vrs_pickle_out: str | None, vrs_attributes: bool, seqrepo_dp_type: SeqRepoProxyType, seqrepo_root_dir: str, seqrepo_base_url: str, assembly: str, skip_ref: bool, require_validation: bool, silent: bool, @@ -185,8 +184,8 @@ def __init__(self, seqrepo_dp_type: SeqRepoProxyType = SeqRepoProxyType.LOCAL, @use_ga4gh_compute_identifier_when(VrsObjectIdentifierIs.MISSING) def annotate( # pylint: disable=too-many-arguments,too-many-locals - self, vcf_in: str, vcf_out: Optional[str] = None, - vrs_pickle_out: Optional[str] = None, vrs_attributes: bool = False, + self, vcf_in: str, vcf_out: str | None = None, + vrs_pickle_out: str | None = None, vrs_attributes: bool = False, assembly: str = "GRCh38", compute_for_ref: bool = True, require_validation: bool = True ) -> None: @@ -283,8 +282,8 @@ def annotate( # pylint: disable=too-many-arguments,too-many-locals pickle.dump(vrs_data, wf) def _get_vrs_object( # pylint: disable=too-many-arguments,too-many-locals - self, vcf_coords: str, vrs_data: Dict, vrs_field_data: Dict, assembly: str, - vrs_data_key: Optional[str] = None, output_pickle: bool = True, + self, vcf_coords: str, vrs_data: dict, vrs_field_data: dict, assembly: str, + vrs_data_key: str | None = None, output_pickle: bool = True, output_vcf: bool = False, vrs_attributes: bool = False, require_validation: bool = True ) -> None: @@ -362,11 +361,11 @@ def _get_vrs_object( # pylint: disable=too-many-arguments,too-many-locals vrs_field_data[self.VRS_STATES_FIELD].append(alt) def _get_vrs_data( # pylint: disable=too-many-arguments,too-many-locals - self, record: pysam.VariantRecord, vrs_data: Dict, assembly: str, # pylint: disable=no-member - additional_info_fields: List[str], vrs_attributes: bool = False, + self, record: pysam.VariantRecord, vrs_data: dict, assembly: str, # pylint: disable=no-member + additional_info_fields: list[str], vrs_attributes: bool = False, output_pickle: bool = True, output_vcf: bool = True, compute_for_ref: bool = True, require_validation: bool = True - ) -> Dict: + ) -> dict: """Get VRS data for record's reference and alt alleles. :param pysam.VariantRecord record: A row in the VCF file