From f9819b15416eb1c596f8e84167f1336f6885fdd6 Mon Sep 17 00:00:00 2001 From: Michael Lamkin Date: Mon, 6 Mar 2023 10:54:47 -0800 Subject: [PATCH] fix: Fixed faulty coord file parsing logic (#196) --- haptools/sim_genotype.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/haptools/sim_genotype.py b/haptools/sim_genotype.py index 51f83a93..5ed6ab07 100644 --- a/haptools/sim_genotype.py +++ b/haptools/sim_genotype.py @@ -382,16 +382,12 @@ def numeric_alpha(x): # sort coordinate files to ensure coords read are in sorted order # remove all chr files not found in chroms list all_coord_files = glob.glob(f'{coords_dir}/*.map') - if region: - try: - all_coord_files = [coord_file for coord_file in all_coord_files \ - if f"chr{region['chr']}" in coord_file] - except: - raise Exception(f"Unable to find region chromosome {region['chr']} in map file directory.") - else: - all_coord_files = [coord_file for coord_file in all_coord_files \ - if re.search(r'(?<=chr)(X|\d+)', coord_file).group() in chroms] - all_coord_files.sort(key=numeric_alpha) + all_coord_files = [coord_file for coord_file in all_coord_files \ + if re.search(r'(?<=chr)(X|\d+)', coord_file).group() in chroms] + all_coord_files.sort(key=numeric_alpha) + + if len(all_coord_files) != len(chroms): + raise Exception(f"Unable to find all chromosomes {chroms} in map file directory.") # coords list has form chroms x coords coords = []