From 4ddde29ee36747f32223df2c1bd67767e8d42df1 Mon Sep 17 00:00:00 2001 From: jkgoodrich <33063077+jkgoodrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:59:29 -0700 Subject: [PATCH 1/2] Use `parse_variant` in gnomad_methods --- gnomad_toolbox/filtering/variant.py | 19 ++++--------------- requirements.txt | 3 ++- setup.py | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/gnomad_toolbox/filtering/variant.py b/gnomad_toolbox/filtering/variant.py index ec00bc7..0de3172 100644 --- a/gnomad_toolbox/filtering/variant.py +++ b/gnomad_toolbox/filtering/variant.py @@ -3,6 +3,7 @@ from typing import Optional, Union import hail as hl +from gnomad.utils.parse import parse_variant from gnomad.utils.reference_genome import get_reference_genome from gnomad_toolbox.load_data import _get_gnomad_release @@ -47,21 +48,8 @@ def get_single_variant( # Determine the reference genome build for the ht. build = get_reference_genome(ht.locus).name - # TODO: Move this to gnomad_methods. - # Parse the variant string if provided. - try: - if variant and ":" not in variant: - contig, position, ref, alt = variant.split("-") - if all([contig, position, ref, alt]): - variant = f"{contig}:{position}:{ref}:{alt}" - variant = hl.eval(hl.parse_variant(variant, reference_genome=build)) - except ValueError: - raise ValueError( - f"Invalid variant format: {variant}. Expected format: chr12-235245-A-C " - f"or chr12:235245:A:C" - ) - # Filter to the Locus of the variant of interest. + variant = parse_variant(variant, contig, position, ref, alt, build) ht = hl.filter_intervals( ht, [hl.interval(variant.locus, variant.locus, includes_end=True)] ) @@ -72,7 +60,8 @@ def get_single_variant( # Check if the variant exists. if ht.count() == 0: hl.utils.warning( - f"No variant found at {variant.locus} with alleles {variant.alleles}" + f"No variant found at {hl.eval(variant.locus)} with alleles " + f"{hl.eval(variant.alleles)}" ) return ht diff --git a/requirements.txt b/requirements.txt index 32706b5..3410cd0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ # We're using the main branch of gnomad_method on github rather than the pip version -git+https://github.com/broadinstitute/gnomad_methods@main +# TODO: Decide on how to handle this. We might just need to have more releases of gnomad_methods. +#git+https://github.com/broadinstitute/gnomad_methods@main hail jupyter jupyter_contrib_nbextensions diff --git a/setup.py b/setup.py index 8bc0d5d..78ab1cb 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/broadinstitute/gnomad-toolbox", - packages=setuptools.find_namespace_packages(include=["gnomad_toolbox.*"]), + packages=setuptools.find_namespace_packages(include=["gnomad_toolbox*"]), project_urls={ "Documentation": "https://broadinstitute.github.io/gnomad-toolbox/", "Source Code": "https://github.com/broadinstitute/gnomad-toolbox", From e542c1b70fd1e1718f7159a1d3f8d8f482407de5 Mon Sep 17 00:00:00 2001 From: jkgoodrich <33063077+jkgoodrich@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:56:37 -0700 Subject: [PATCH 2/2] Uncomment --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3410cd0..702bdab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ # We're using the main branch of gnomad_method on github rather than the pip version # TODO: Decide on how to handle this. We might just need to have more releases of gnomad_methods. -#git+https://github.com/broadinstitute/gnomad_methods@main +git+https://github.com/broadinstitute/gnomad_methods@main hail jupyter jupyter_contrib_nbextensions