From 202f533f13ce64e8740ec88689971277146ebb18 Mon Sep 17 00:00:00 2001 From: Andy Daykin Date: Wed, 6 Oct 2021 07:21:46 -0700 Subject: [PATCH] Adding a check in the less than method for the VariantCall class to ensure that in cases where there is a mix of arrays and scalar values that the comparison still works --- gcp_variant_transforms/beam_io/vcf_parser.py | 4 ++++ gcp_variant_transforms/beam_io/vcf_parser_test.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/gcp_variant_transforms/beam_io/vcf_parser.py b/gcp_variant_transforms/beam_io/vcf_parser.py index 04afec0c2..ed34339a8 100644 --- a/gcp_variant_transforms/beam_io/vcf_parser.py +++ b/gcp_variant_transforms/beam_io/vcf_parser.py @@ -227,6 +227,10 @@ def __lt__(self, other): if self.sample_id != other.sample_id: return self.sample_id < other.sample_id elif self.genotype != other.genotype: + if(type(self.genotype) is list and type(other.genotype) is not list): + return False + if(type(other.genotype) is list and type(self.genotype) is not list): + return True return self.genotype < other.genotype elif self.phaseset != other.phaseset: return self.phaseset < other.phaseset diff --git a/gcp_variant_transforms/beam_io/vcf_parser_test.py b/gcp_variant_transforms/beam_io/vcf_parser_test.py index 5ea06d3d3..03f48aeb9 100644 --- a/gcp_variant_transforms/beam_io/vcf_parser_test.py +++ b/gcp_variant_transforms/beam_io/vcf_parser_test.py @@ -83,6 +83,14 @@ def test_variant_call_order(self): variant_call_2.phaseset = 1 self.assertGreater(variant_call_2, variant_call_1) + def test_genotype_compare(self): + variant_call_1 = self._default_variant_call() + variant_call_2 = vcfio.VariantCall( + sample_id=hash_name('Sample1'), name='Sample1', genotype=-1, + phaseset=vcfio.DEFAULT_PHASESET_VALUE, info={'GQ': 48}) + + self.assertLess(variant_call_2, variant_call_1) + if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO)