def matrix_to_phylip(filename, leaves, matrix):
    """Write the distance matrix in phylip format."""
    with open(filename, 'w') as f:
        f.write(str(len(leaves)))
        for i in range(len(leaves)):
            f.write('\n' + str(leaves[i].ID))
            for j in range(len(leaves)):
                f.write('\t' + str(matrix[i, j]))
