annotate check_remote.py @ 5:ee85ef37962a draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit da03a9fa221bac18771fb317255cca9d89620f4b"
author iuc
date Wed, 27 Oct 2021 16:37:35 +0000
parents 863a964fd1d6
children 1c79c7ee82c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
1 import json
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
2
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
3 import requests
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
4
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
5 URL = "https://www.ebi.ac.uk/ena/portal/api/search"
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
6
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
7
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
8 def check_remote_entry(entry_type, query_dict, out_format='json'):
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
9 '''
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
10 Checks if an entry with that alias exists in the ENA repos
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
11 entry_type = [study | sample | experiment | run]
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
12 '''
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
13 assert entry_type in ['study', 'sample', 'experiment', 'run']
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
14 params_dict = {}
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
15 query_str = ' AND '.join(['%s=%s' % (key, value) for (key, value) in query_dict.items()])
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
16 params_dict['query'] = query_str
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
17 params_dict['result'] = 'read_' + entry_type
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
18 params_dict['fields'] = entry_type + '_alias'
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
19 params_dict['format'] = out_format
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
20 response = requests.post(URL, data=params_dict)
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
21 if response.content != b'':
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
22 return json.loads(response.content)
863a964fd1d6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
23 return []