def read_ecs(contents, reaction_masters, master_reactions):
    """
    Read Rhea EC number to Rhea ID mapping data.

    Parameters
    ----------
    contents : iterable of dicts
        EC number string keyed by 'EC' and Rhea ID string keyed by
        'RHEA'.
    reaction_masters : dict
        Mapping from directed reaction Rhea ID strings to undirected
        master reaction Rhea ID strings.
    masters_reactions: dict
        Mapping from undirected master reaction Rhea ID strings to
        directed reaction Rhea ID strings.

    Returns
    -------
    tuple of 2 dicts
        Complementary dicts that map EC numbers to Rhea IDs and vice
        -versa.

        [0] maps EC number strings to Rhea ID strings.

        [1] maps Rhea ID strings to EC number strings.

    """
    ec_reactions, reaction_ecs = {}, {}
    for entry in contents:
        ec = entry['EC']
        rhea = entry['RHEA']
        master = reaction_masters.get(rhea, rhea)
        reactions = master_reactions.get(master, [])
        ec_reactions.setdefault(ec, set()).update(reactions)
        for reaction in reactions:
            reaction_ecs.setdefault(reaction, set()).add(ec)
        print('RHEA: EC {}, reactions {}'.format(ec, reactions))
    for ec, reactions in ec_reactions.items():
        ec_reactions[ec] = list(reactions)
    for reaction, ecs in reaction_ecs.items():
        reaction_ecs[reaction] = list(ecs)
    print('RHEA: {} enzymes found, linked to {} reactions'.format(
        len(ec_reactions), len(reaction_ecs)))
    return ec_reactions, reaction_ecs