Skip to content

Commit

Permalink
some fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
KateSakharova committed Feb 6, 2024
1 parent 18d4641 commit bfb1b54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 32 deletions.
10 changes: 5 additions & 5 deletions emgapi/management/commands/populate_metagenomics_exchange.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2017-2022 EMBL - European Bioinformatics Institute
# Copyright 2017-2024 EMBL - European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -96,7 +96,7 @@ def handle(self, *args, **options):
def process_to_index_and_update_records(self, analyses_to_index_and_update):
logging.info(f"Indexing {len(analyses_to_index_and_update)} new analyses")

for page in Paginator(analyses_to_index_and_update, 100):
for page in Paginator(analyses_to_index_and_update, settings.METAGENOMICS_EXCHANGE_PAGINATOR_NUMBER):
jobs_to_update = []
for ajob in page:
metadata = self.mgx_api.generate_metadata(
Expand Down Expand Up @@ -152,7 +152,7 @@ def process_to_index_and_update_records(self, analyses_to_index_and_update):
logging.debug(f"No edit for {ajob}, metadata is correct")

AnalysisJob.objects.bulk_update(
jobs_to_update, ["last_mgx_indexed", "mgx_accession"], batch_size=100
jobs_to_update, ["last_mgx_indexed", "mgx_accession"], batch_size=settings.METAGENOMICS_EXCHANGE_PAGINATOR_NUMBER
)

def process_to_delete_records(self, analyses_to_delete):
Expand All @@ -161,7 +161,7 @@ def process_to_delete_records(self, analyses_to_delete):
"""
logging.info(f"Processing {len(analyses_to_delete)} analyses to remove")

for page in Paginator(analyses_to_delete, 100):
for page in Paginator(analyses_to_delete, settings.METAGENOMICS_EXCHANGE_PAGINATOR_NUMBER):
jobs_to_update = []

for ajob in page:
Expand Down Expand Up @@ -192,5 +192,5 @@ def process_to_delete_records(self, analyses_to_delete):

# BULK UPDATE #
AnalysisJob.objects.bulk_update(
jobs_to_update, ["last_mgx_indexed"], batch_size=100
jobs_to_update, ["last_mgx_indexed"], batch_size=settings.METAGENOMICS_EXCHANGE_PAGINATOR_NUMBER
)
4 changes: 2 additions & 2 deletions emgapi/metagenomics_exchange.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2018-2023 EMBL - European Bioinformatics Institute
# Copyright 2018-2024 EMBL - European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@ class MetagenomicsExchangeAPI:
"""Metagenomics Exchange API Client"""

def __init__(self, base_url=None):
self.base_url = base_url if base_url else settings.METAGENOMICS_EXCHANGE_API
self.base_url = base_url or settings.METAGENOMICS_EXCHANGE_API
self.__token = settings.METAGENOMICS_EXCHANGE_API_TOKEN
self.broker = settings.METAGENOMICS_EXCHANGE_MGNIFY_BROKER

Expand Down
21 changes: 0 additions & 21 deletions emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,27 +1687,6 @@ def __str__(self):
return 'Assembly:{} - Sample:{}'.format(self.assembly, self.sample)


class MetagenomicsExchangeModel(models.Model):
"""Model to track Metagenomics Exchange population
https://www.ebi.ac.uk/ena/registry/metagenome/api/
"""
last_updated_me = models.DateTimeField(
db_column='LAST_UPDATED_ME',
auto_now=True
)
last_populated_me = models.DateTimeField(
db_column='LAST_POPULATED_ME',
null=True,
blank=True,
help_text="Date at which this model was last appeared in Metagenomics Exchange"
)

objects_for_population = MetagenomicsExchangeQueryset.as_manager()

class Meta:
abstract = True


class AnalysisJobQuerySet(BaseQuerySet, MySQLQuerySet, SuppressQuerySet, SelectRelatedOnlyQuerySetMixin):

def __init__(self, *args, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions emgcli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ def create_secret_key(var_dir):
METAGENOMICS_EXCHANGE_MGNIFY_BROKER = "EMG"
METAGENOMICS_EXCHANGE_API = ""
METAGENOMICS_EXCHANGE_API_TOKEN = ""
METAGENOMICS_EXCHANGE_PAGINATOR_NUMBER = 100
try:
METAGENOMICS_EXCHANGE_API = EMG_CONF['emg']['me_api']
if EMG_CONF['emg'].get('me_api_token'):
METAGENOMICS_EXCHANGE_API_TOKEN = os.getenv('METAGENOMICS_EXCHANGE_API_TOKEN')
if not METAGENOMICS_EXCHANGE_API_TOKEN:
METAGENOMICS_EXCHANGE_API_TOKEN = EMG_CONF['emg']['me_api_token']
else:
METAGENOMICS_EXCHANGE_API_TOKEN = os.getenv('METAGENOMICS_EXCHANGE_API_TOKEN')
except KeyError:
warnings.warn("The metagenomics exchange API and Token are not configured properly")
warnings.warn("The metagenomics exchange API and Token are not configured properly")

0 comments on commit bfb1b54

Please sign in to comment.