def add_freqs_to_ec_table(ecs, freqs):
    """
    Add residue and gap frequency as well as conservation info
    to data table by merging EC table and frequencies table

    Parameters
    ----------
    ecs : pd.DataFrame
        EC table generated by pipeline (e.g. _ECs.txt, _CouplingsScores.csv)
    freqs : pd.DataFrame
        Frequency table generated by pipeline (_frequencies.csv) using
        evcouplings.align.protocol.describe_frequencies()
    """
    # rename column names to be more descriptive
    freqs = freqs.rename(
        columns={
            "-": "gap_i",
            "conservation": "cons_i",
        }
    )

    # extract frequency of target residue for each position
    freqs.loc[:, "freq_i"] = [r[r["A_i"]] for idx, r in freqs.iterrows()]

    # limit to relevant columns and create second version
    # for mapping second position suffixed with _j
    freqs_sel_i = freqs[["i", "A_i", "freq_i", "gap_i", "cons_i"]]

    freqs_sel_j = freqs_sel_i.rename(columns={
        c: c.replace("i", "j") for c in freqs_sel_i.columns
    })

    # add frequency/conservation information to table
    ecs_with_freqs = ecs.merge(
        freqs_sel_i, on=["i", "A_i"]
    ).merge(
        freqs_sel_j, on=["j", "A_j"]
    )

    # check nothing went wrong and we kept full table
    assert len(ecs_with_freqs) == len(ecs)

    return ecs_with_freqs