def canonical_species_name(species_name):
    """Get canonical species name from GTDB or NCBI species name."""
    if species_name == 's__':
        return species_name
    species_name = species_name.replace('Candidatus ', '')
    prefix = species_name[0:3]
    full_name = species_name[3:]
    genus, species = full_name.split(' ')
    underscore_pos = genus.rfind('_')
    if underscore_pos != -1:
        genus = genus[0:underscore_pos]
    underscore_pos = species.rfind('_')
    if underscore_pos != -1:
        species = species[0:underscore_pos]
    genus = genus.replace('[', '').replace(']', '')
    species = species.replace('[', '').replace(']', '')
    return prefix + genus + ' ' + species
