-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from usegalaxy-eu/remote-check
Automatic check if an object already exists on ENA
- Loading branch information
Showing
5 changed files
with
114 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.5.1" | ||
__version__ = "0.5.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
import requests | ||
|
||
URL = "https://www.ebi.ac.uk/ena/portal/api/search" | ||
DEV_URL = "https://wwwdev.ebi.ac.uk/ena/portal/api/search" | ||
|
||
def identify_action(entry_type, alias, dev): | ||
''' define action ['add' | 'modify'] that needs to be performed for this entry ''' | ||
query = {entry_type + '_alias': alias} | ||
remote_accessions = check_remote_entry(entry_type, query, dev) | ||
if isinstance(remote_accessions, list) and len(remote_accessions) > 0: | ||
print(f'\tFound: {entry_type} entry with alias {alias}') | ||
return True | ||
else: | ||
print(f'\tNo {entry_type} entry found with alias {alias}') | ||
return False | ||
|
||
|
||
def check_remote_entry(entry_type, query_dict, dev): | ||
''' | ||
Checks if an entry with that alias exists in the ENA repos | ||
entry_type = [study | sample | experiment | run] | ||
''' | ||
assert entry_type in ['study', 'sample', 'experiment', 'run'] | ||
params_dict = {} | ||
query_str = ' AND '.join(['%s="%s"' % (key, value) for (key, value) in query_dict.items()]) | ||
params_dict['query'] = query_str | ||
params_dict['result'] = 'read_' + entry_type | ||
params_dict['fields'] = entry_type + '_alias' | ||
params_dict['format'] = 'json' | ||
if dev: | ||
response = requests.post(DEV_URL, data=params_dict) | ||
else: | ||
response = requests.post(URL, data=params_dict) | ||
if response.content != b'': | ||
return json.loads(response.content) | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters