Skip to content

Commit

Permalink
go back to just being normal function - don't need to be iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Aug 19, 2024
1 parent ba06c5b commit 924c00d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions snpdb/liftover.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
from collections import defaultdict
from functools import reduce
from typing import Iterable, Optional, Union
from typing import Iterable, Optional

from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -219,7 +219,7 @@ def _liftover_using_existing_contig(allele, dest_genome_build: GenomeBuild) -> t
conversion_tool = AlleleConversionTool.SAME_CONTIG
# Return variant_id so we can create it directly
variant = variant_allele.variant
yield conversion_tool, variant
return conversion_tool, variant


def _liftover_using_dest_variant_coordinate(allele, dest_genome_build: GenomeBuild,
Expand Down Expand Up @@ -321,9 +321,9 @@ def _liftover_using_source_variant_coordinate(allele, source_genome_build: Genom


def allele_can_attempt_liftover(allele, genome_build) -> bool:
for conversion_tool, variant in _liftover_using_existing_contig(allele, genome_build):
if conversion_tool and variant:
return True
conversion_tool, variant = _liftover_using_existing_contig(allele, genome_build)
if conversion_tool and variant:
return True

for conversion_tool, variant_coordinate, _error_message in _liftover_using_dest_variant_coordinate(allele, genome_build):
if conversion_tool and variant_coordinate:
Expand Down
6 changes: 2 additions & 4 deletions snpdb/tests/test_liftover.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def setUpTestData(cls):
def test_liftover_using_existing_variant(self):
clingen_api = MockClinGenAlleleRegistryAPI()
# This is on chr3 - it is created for 37 but not 38
result = list(_liftover_using_existing_contig(self.allele, GenomeBuild.grch38()))[0]
conversion_tool, variant = result
conversion_tool, variant = _liftover_using_existing_contig(self.allele, GenomeBuild.grch38())
self.assertIsNone(conversion_tool)
self.assertIsNone(variant)

# MT variant exists in 37 - shares same contig so should be able to re-use for 38
clingen_allele = get_clingen_allele("CA337095804", clingen_api=clingen_api)
mt_allele = clingen_allele.allele
result = list(_liftover_using_existing_contig(mt_allele, GenomeBuild.grch38()))[0]
conversion_tool, variant = result
conversion_tool, variant = _liftover_using_existing_contig(mt_allele, GenomeBuild.grch38())
self.assertEqual(conversion_tool, AlleleConversionTool.SAME_CONTIG)
self.assertIsNotNone(variant)

Expand Down

0 comments on commit 924c00d

Please sign in to comment.