From 759d601312b794aac6e3b3535dbeaa6da9005131 Mon Sep 17 00:00:00 2001 From: kjwinfield Date: Fri, 3 Jan 2025 17:17:18 +0000 Subject: [PATCH] collapse nested ifs --- resources/home/dnanexus/get_variant_info.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/resources/home/dnanexus/get_variant_info.py b/resources/home/dnanexus/get_variant_info.py index 3fd0606..ccf4a42 100644 --- a/resources/home/dnanexus/get_variant_info.py +++ b/resources/home/dnanexus/get_variant_info.py @@ -113,20 +113,18 @@ def get_inheritance(variant, mother_idx, father_idx, p_sex): # if there is a mother in the JSON and the variant is alt_homozygous in # or heterozygous in the mother then can infer maternal inheritance - if mother_idx is not None: - if zygosity(variant, mother_idx) in inheritance_types: - maternally_inherited = True + if (mother_idx is not None and + zygosity(variant, mother_idx) in inheritance_types): + maternally_inherited = True # if there is a father in the JSON and the variant is alt_homozygous in # or heterozygous in the father then can infer paternal inheritance # filter out XY probands here as X should be inherited from mother - if father_idx is not None: - if zygosity(variant, father_idx) in inheritance_types: - if (p_sex == 'MALE' and - variant['variantCoordinates']['chromosome'] == 'X'): - paternally_inherited = False - else: - paternally_inherited = True + if (father_idx is not None and + zygosity(variant, father_idx) in inheritance_types and + not (p_sex == 'MALE' and + variant['variantCoordinates']['chromosome'] == 'X')): + paternally_inherited = True if maternally_inherited and not paternally_inherited: inheritance = "maternal"