def compute_gene_to_longest_protein(protein_dict):
    """Build a dict gene: protein, where protein is the longest protein that
    that gene has.

    In case of tie, the first seen is the one that remains.
    """
    gene_to_protein = {}

    for protein_id in protein_dict.keys():

        gene_id, _ = protein_dict[protein_id].description.split()[1].split("~~")

        if gene_id in gene_to_protein:
            len_protein_in_dict = len(protein_dict[gene_to_protein[gene_id].id])
            len_new_protein = len(protein_dict[protein_id])

            if len_new_protein > len_protein_in_dict:
                gene_to_protein[gene_id] = protein_dict[protein_id]

        else:
            gene_to_protein[gene_id] = protein_dict[protein_id]

    return gene_to_protein