Mercurial > repos > iuc > ena_upload
annotate check_remote.py @ 5:e1b3b37aa69f 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:38:10 +0000 |
parents | 26ccb678abc8 |
children | 4aab5ae907b6 |
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 = {} |
26ccb678abc8
"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()]) |
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 [] |