annotate check_remote.py @ 6:4aab5ae907b6 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 7eafac9d91b39e43fd3820ab1431cab1c930bb01"
author iuc
date Mon, 15 Nov 2021 11:47:13 +0000
parents 26ccb678abc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
1 import json
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
2
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
3 import requests
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
4
26ccb678abc8 "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"
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
6
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
7
26ccb678abc8 "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'):
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
9 '''
26ccb678abc8 "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
26ccb678abc8 "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]
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
12 '''
26ccb678abc8 "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']
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
14 params_dict = {}
6
4aab5ae907b6 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 7eafac9d91b39e43fd3820ab1431cab1c930bb01"
iuc
parents: 4
diff changeset
15 query_str = ' AND '.join(['%s="%s"' % (key, value) for (key, value) in query_dict.items()])
4
26ccb678abc8 "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
26ccb678abc8 "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
26ccb678abc8 "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'
26ccb678abc8 "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
26ccb678abc8 "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)
26ccb678abc8 "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'':
26ccb678abc8 "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)
26ccb678abc8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5"
iuc
parents:
diff changeset
23 return []