import collections
from pathlib import Path


def create_uniprot2interpro_dict(filepath, uniprot_ac_list):
    """
    Creates a dictionary mapping UniProt ACs to InterPro domains.

    Parameters
    ----------
    filepath : the file path to a (filtered) InterPro map file.
    uniprot_ac_list : list
        A list of unique UniProt ACs present in the dataframe.

    Returns
    -------
    dict
        A dictionary mapping UniProt ACs to InterPro domains.

    """
    uniprot2interpro = collections.defaultdict(set)

    mapping_file = Path(filepath)

    with mapping_file.open() as mapping:
        for line in mapping:
            split_line = line.split('\t')
            if split_line[0] in uniprot_ac_list:
                # uniprot2interpro[split_line[0]] = split_line[1]
                uniprot2interpro[split_line[0]].add(split_line[1])
    return uniprot2interpro