def split_alignments_by_chrom(alignments_file, get_temp_path):
    """Split an alignments file into several files, one per chromosome.

    get_temp_path is a function that returns a new temporary file path.

    Returns a dictionary, {chrom_name: alignmentfile_path}."""
    paths = {}
    cur_chrom = None
    output_path = get_temp_path()
    output = open(output_path, 'w')
    for line in alignments_file:
        fields = line.split()
        line_chrom = fields[0]
        if line_chrom != cur_chrom:
            output.close()
            output_path = get_temp_path()
            cur_chrom = line_chrom
            paths[cur_chrom] = output_path
            output = open(output_path, 'w')
        output.write(line)
    return paths