def reassign_representative(cur_representative_id, cur_aai,
    new_representative_id, new_aai, trusted_user_genomes):
    """Determines best representative genome.

    Genomes are preferentially assigned to representatives based on
    source repository (RefSeq => GenBank => Trusted User => User) and AAI.
    """
    source_order = {'R': 0, 'G': 1, 'U': 2}
    if not cur_representative_id:
        return new_representative_id, new_aai
    cur_source = source_order[cur_representative_id[0]]
    new_source = source_order[new_representative_id[0]]
    if new_representative_id in trusted_user_genomes:
        new_source = source_order['G']
    if new_source < cur_source:
        return new_representative_id, new_aai
    elif new_source == cur_source:
        if new_aai > cur_aai:
            return new_representative_id, new_aai
    return cur_representative_id, cur_aai
