from unittest.mock import call


def get_chrom_sizes(hal_path, genome):
    """Get a dict of {chrom_name: length} for a genome from a hal."""
    bed = call(['halStats', '--bedSequences', genome, hal_path])
    lengths = {}
    for line in bed.split("\n"):
        if len(line.strip()) == 0:
            # Empty line
            continue
        fields = line.split()
        lengths[fields[0]] = int(fields[2])
    return lengths