Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make asynchronous download optional #17

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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