def write_bed_file(bed_default_dict, output_file):
    """Write default dict to a bed file
    :param bed_default_dict: default dict created from aggregate_methylbeds
    :param output_file: path to output file
    """
    with open(output_file, 'w') as fh:
        for chromosome, strand_dict in bed_default_dict.items():
            for strand, start_dict in strand_dict.items():
                for start, coverage_list in start_dict.items():
                    coverage_total = 0
                    percentage_total = 0
                    max_percentage = 0
                    for x in coverage_list:
                        coverage_total += x[1]
                        percentage_total += x[1] * x[2]
                        max_percentage += x[1] * 100
                    color = x[0]
                    if max_percentage != 0:
                        percentage = int(percentage_total / max_percentage *
                            100)
                        print('\t'.join([chromosome, start, str(int(start) +
                            1), '.', str(coverage_total), strand, start,
                            str(int(start) + 1), color, str(coverage_total),
                            str(percentage)]), file=fh)
