import collections


def load_empirical_regions_bed(empirical_regions_bed, sel_pop):
    """Load the list of empirical regions containing putatively selected variants"""
    chrom2regions = collections.defaultdict(collections.OrderedDict)

    with open(empirical_regions_bed) as empirical_regions_bed_in:
        for line in empirical_regions_bed_in:
            
            chrom, beg, end, *rest = line.strip().split('\t')
            if sel_pop:
                region_name, region_sel_pop = rest
                if region_sel_pop != sel_pop:
                    continue
            else:
                region_sel_pop = None
                
            chrom2regions[chrom].setdefault(f'{chrom}:{beg}-{end}', []).append(region_sel_pop)
    return chrom2regions