import json


def process_synonyms(genes, synonyms_file):
    """Process a list of genes into a dictionary with synonyms

    The user may select only a subset of genes to look for,
    rather than the entire dictionary. This function creates
    a new dictionary for the genes used by the user.

    Returns:
        dict: Dictionary containing the gene names provided as keys,
            and the synonyms as values.
    """

    with open(synonyms_file) as f:
        gene_to_syns = json.load(f)

    target_to_syns = {}
    targets_lower = [target.lower() for target in genes]

    for symbol, synonyms in gene_to_syns.items():
        if symbol in genes:
            target_to_syns[symbol] = synonyms
        else:
            for synonym in synonyms:
                if synonym.lower() in targets_lower:
                    target_to_syns[synonym] = synonyms
                    target_to_syns[synonym].append(symbol)

    return target_to_syns