Skip to content

Commit

Permalink
Merge pull request #17 from lozuponelab/async_optional
Browse files Browse the repository at this point in the history
Make asynchronous download optional
  • Loading branch information
sterrettJD authored Jan 17, 2024
2 parents 0039a66 + f1ed254 commit 1f8e92c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion KEGG_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.7'
__version__ = '0.0.8'
10 changes: 7 additions & 3 deletions KEGG_parser/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def kegg_download_manager_synchronous(list_of_ids, wait=1):
return [raw_record for raw_records in results for raw_record in raw_records.split('///')[:-1]]


def get_from_kegg_api(loop, list_of_ids, parser, try_async=True):
if try_async == False:
print("KEGG parser will try to download data sequentially.")
return [parser(raw_record) for raw_record in kegg_download_manager_synchronous(list_of_ids)]

def get_from_kegg_api(loop, list_of_ids, parser):
try:
return [parser(raw_record) for raw_record in loop.run_until_complete(kegg_download_manager(loop, list_of_ids))]
except ValueError:
Expand All @@ -82,10 +85,11 @@ def get_from_kegg_api(loop, list_of_ids, parser):
time.sleep(30)
return [parser(raw_record) for raw_record in kegg_download_manager_synchronous(list_of_ids)]

def get_kegg_record_dict(list_of_ids, parser, records_file_loc=None, verbose=False):

def get_kegg_record_dict(list_of_ids, parser, records_file_loc=None, verbose=False, try_async=True):
if records_file_loc is None:
loop = asyncio.get_event_loop()
records = get_from_kegg_api(loop, list_of_ids, parser)
records = get_from_kegg_api(loop, list_of_ids, parser, try_async=try_async)
else:
records = get_from_kegg_flat_file(records_file_loc, list_of_ids, parser)
if verbose:
Expand Down
4 changes: 2 additions & 2 deletions KEGG_parser/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def split_module_reaction(current_dict, current_entry_name, current_entry_data):
'COMPOUND': add_module_orthology, 'COMMENT': return_self, 'DBLINKS': add_nested_dict
}

NOT_CAPTURED_KO_FIELDS = ('REFERENCE', 'AUTHORS', 'TITLE', 'JOURNAL', 'SEQUENCE', 'BRITE', 'SYMBOL')
NOT_CAPTURED_KO_FIELDS = ('REFERENCE', 'AUTHORS', 'TITLE', 'JOURNAL', 'SEQUENCE', 'BRITE', 'SYMBOL', 'REACTION')

NOT_CAPTURED_RN_FIELDS = ('REFERENCE', 'AUTHORS', 'TITLE', 'JOURNAL')
NOT_CAPTURED_RN_FIELDS = ('REFERENCE', 'AUTHORS', 'TITLE', 'JOURNAL', 'BRITE')

NOT_CAPTURED_CO_FIELDS = ('BRITE', 'ATOM', 'BOND', 'BRACKET', 'ORIGINAL', 'REPEAT', 'NODE', 'EDGE', 'SEQUENCE',
'GENE', 'ORGANISM', 'TYPE', 'EFFICACY', 'PRODUCT', 'CLASS', 'DISEASE', 'TARGET',
Expand Down

0 comments on commit 1f8e92c

Please sign in to comment.