from pathlib import Path


def parse_taxid_names(file_path):
    """
    Parse the names.dmp file and output a dictionary mapping names to taxids
    (multiple different keys) and taxids to scientific names.

    Parameters
    ----------
    file_path : str
        The path to the names.dmp file.

    Returns
    -------
    name2taxid : dict
        Keys are all possible names and values are taxids.
    taxid2name : dict
        Keys are taxids and values are scientific names.
    """

    names = Path(file_path)

    with names.open() as f:
        lines_processed = 0
        name2taxid = {}
        taxid2name = {}
        for line in f:
            lines_processed += 1
            if lines_processed % 1000000 == 0:
                print('processing line', str(lines_processed))
            entries = [entry.strip() for entry in line.split('|')]
            name2taxid[entries[1]] = entries[0]
            if 'scientific name' in line:
                taxid2name[entries[0]] = entries[1]

    return name2taxid, taxid2name