import hashlib


def create_protein_group_id(uniprot_ids):
    """
    In the mass spec datasets, protein groups are ID'd by a string
    of semicolon-separated uniprot IDs.
    This function sorts these IDs alphabetically, then hashes them using hashlib.
    The purpose of this is to generate a unique ID from a unique set of uniprot IDs,
    which can then be used as a primary key for the MassSpecProteinGroup table.
    """

    # split the string into a list
    uniprot_ids = sorted(uniprot_ids.split(';'))

    # serialize the sorted list
    serialized_uniprot_ids = str(uniprot_ids)

    # hash the serialized list
    hashed_uniprot_ids = hashlib.sha256(serialized_uniprot_ids.encode('utf-8')).hexdigest()

    return hashed_uniprot_ids, uniprot_ids