// If number_of_organisms isn"t specified, default to surveying
// all organisms in the division.
try:
number_of_organisms = int(
SurveyJobKeyValue
.objects
.get(survey_job_id=self.survey_job.id,
key__exact="number_of_organisms")
.value
)
except SurveyJobKeyValue.DoesNotExist:
number_of_organisms = -1
logger.info("Surveying %s division of ensembl.",
ensembl_division,
survey_job=self.survey_job.id)
// The main division has a different base URL for its REST API.
if ensembl_division == "Ensembl":
r = utils.requests_retry_session().get(MAIN_DIVISION_URL_TEMPLATE)
// Yes I"m aware that specieses isn"t a word. However I need to
// distinguish between a singlular species and multiple species.
specieses = r.json()["species"]
else:
r = utils.requests_retry_session().get(DIVISION_URL_TEMPLATE.format(division=ensembl_division))
specieses = r.json()
try:
organism_name = SurveyJobKeyValue.objects.get(survey_job_id=self.survey_job.id, key__exact="organism_name").value
organism_name = organism_name.lower().replace(" ", "_")
except SurveyJobKeyValue.DoesNotExist:
organism_name = None
// Survey jobs are on a per-organism basis.
for species in specieses:
if species["name"] == organism_name:
specieses = [species]
logger.info("Found species " + organism_name + " on Ensembl.",
survey_job=self.survey_job.id)
break
species_surveyed = 0
all_new_species = []
for species in specieses:
if number_of_organisms != -1 and species_surveyed >= number_of_organisms:
break
all_new_species.append(self._generate_files(species))
species_surveyed += 1
return all_new_species