From 924c00d07567d2ce323e66c1d38460f97cf71652 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Mon, 19 Aug 2024 15:29:17 +0930 Subject: [PATCH] go back to just being normal function - don't need to be iterator --- snpdb/liftover.py | 10 +++++----- snpdb/tests/test_liftover.py | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/snpdb/liftover.py b/snpdb/liftover.py index db21d56be..5e85153db 100644 --- a/snpdb/liftover.py +++ b/snpdb/liftover.py @@ -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 @@ -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, @@ -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: diff --git a/snpdb/tests/test_liftover.py b/snpdb/tests/test_liftover.py index 1d061eefe..ef70bbe93 100644 --- a/snpdb/tests/test_liftover.py +++ b/snpdb/tests/test_liftover.py @@ -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)