Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_species_to_json():
eq_(human, Species.from_json(human.to_json()))
def test_species_to_dict():
eq_(human, Species.from_dict(human.to_dict()))
def check_species_object(species_name_or_object):
"""
Helper for validating user supplied species names or objects.
"""
if isinstance(species_name_or_object, Species):
return species_name_or_object
elif isinstance(species_name_or_object, str):
return find_species_by_name(species_name_or_object)
else:
raise ValueError("Unexpected type for species: %s : %s" % (
species_name_or_object, type(species_name_or_object)))
def register(cls, latin_name, synonyms, reference_assemblies):
"""
Create a Species object from the given arguments and enter into
all the dicts used to look the species up by its fields.
"""
species = Species(
latin_name=latin_name,
synonyms=synonyms,
reference_assemblies=reference_assemblies)
cls._latin_names_to_species[species.latin_name] = species
for synonym in synonyms:
if synonym in cls._common_names_to_species:
raise ValueError("Can't use synonym '%s' for both %s and %s" % (
synonym,
species,
cls._common_names_to_species[synonym]))
cls._common_names_to_species[synonym] = species
for reference_name in reference_assemblies:
if reference_name in cls._reference_names_to_species:
raise ValueError("Can't use reference '%s' for both %s and %s" % (
reference_name,
species,
def __eq__(self, other):
return (
other.__class__ is Species and
self.latin_name == other.latin_name and
self.synonyms == other.synonyms and
self.reference_assemblies == other.reference_assemblies)
def normalize_reference_name(name):
"""
Search the dictionary of species-specific references to find a reference
name that matches aside from capitalization.
If no matching reference is found, raise an exception.
"""
lower_name = name.strip().lower()
for reference in Species._reference_names_to_species.keys():
if reference.lower() == lower_name:
return reference
raise ValueError("Reference genome '%s' not found" % name)
def normalize_release_properties(ensembl_release, species):
"""
Make sure a given release is valid, normalize it to be an integer,
normalize the species name, and get its associated reference.
"""
ensembl_release = check_release_number(ensembl_release)
if not isinstance(species, Species):
species = find_species_by_name(species)
reference_name = species.which_reference(ensembl_release)
return ensembl_release, species.latin_name, reference_name
def collect_all_installed_ensembl_releases():
genomes = []
for (species, release) in Species.all_species_release_pairs():
genome = EnsemblRelease(release, species=species)
if genome.required_local_files_exist():
genomes.append(genome)
return sorted(genomes, key=lambda g: (g.species.latin_name, g.release))
def find_species_by_name(species_name):
latin_name = normalize_species_name(species_name)
if latin_name not in Species._latin_names_to_species:
raise ValueError("Species not found: %s" % species_name)
return Species._latin_names_to_species[latin_name]