def most_similar_by_organism(similarities, id_to_organism):
    """
    For each species in the alignment, finds the sequence 
    from that species that is most similar to the target sequence

    Parameters
    ----------
    similarities : pd.DataFrame
        The contents of identities.csv
    id_to_organism :  pd.DataFrame
        The contents of annotation.csv
        
    Returns
    -------
    pd.DataFrame
        With columns id, species, identity_to_query.
        Where each row is the sequence in a particular species
        that was the most similar to the target sequence.
    
    """
    species_to_most_similar = []

    # merge the two data frames
    data = similarities.merge(id_to_organism, on="id")

    # find the most similar in every organism
    most_similar_in_species = data.sort_values(by="identity_to_query").groupby("species").last()
    most_similar_in_species["species"] = most_similar_in_species.index
    most_similar_in_species = most_similar_in_species.reset_index(drop=True)

    return most_similar_in_species