Skip to content

Commit

Permalink
Merge pull request #8 from broadinstitute/jg/use_gnomad_methods_varia…
Browse files Browse the repository at this point in the history
…nt_parser

Use gnomad_methods variant parser
  • Loading branch information
jkgoodrich authored Dec 20, 2024
2 parents a138ce3 + e542c1b commit 0350630
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
19 changes: 4 additions & 15 deletions gnomad_toolbox/filtering/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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
hail
jupyter
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0350630

Please sign in to comment.