def abs_contact_2_coo_file(abs_contact_file, coo_file):
    """Convert contact maps between old-style and new-style formats.

    A legacy function that converts contact maps from the older GRAAL format to
    the simpler instaGRAAL format. This is useful with datasets generated by
    Hi-C box.

    Parameters
    ----------
    abs_contact_file : str, file or pathlib.Path
        The input old-style contact map.
    coo_file : str, file, or pathlib.Path
        The output path to the generated contact map; must be writable.
    """
    sparse_dict = dict()
    h = open(abs_contact_file, 'r')
    all_lines = h.readlines()
    n_lines = len(all_lines)
    for i in range(1, n_lines):
        line = all_lines[i]
        dat = line.split()
        mates = [int(dat[0]), int(dat[1])]
        mates.sort()
        f1 = mates[0] - 1
        f2 = mates[1] - 1
        if f1 in sparse_dict:
            if f2 in sparse_dict[f1]:
                sparse_dict[f1][f2] += 1
            else:
                sparse_dict[f1][f2] = 1
        else:
            sparse_dict[f1] = dict()
            sparse_dict[f1][f2] = 1
    keys = list(sparse_dict.keys())
    keys.sort()
    h.close()
    h_coo = open(coo_file, 'w')
    h_coo.write('%s\t%s\t%s\n' % ('id_frag_a', 'id_frag_b', 'n_contact'))
    for fa in keys:
        d_fb = sparse_dict[fa]
        keys_b = list(d_fb.keys())
        keys_b.sort()
        for fb in keys_b:
            nc = d_fb[fb]
            h_coo.write('%s\t%s\t%s\n' % (str(fa), str(fb), str(nc)))
    h_coo.close()
    h.close()
