annotate ebeye_urllib.py @ 3:42d5e40fcd0b draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 31d1c92a4c12b6a78693dc5091a08536a075285e
author iuc
date Thu, 09 Feb 2017 12:02:58 -0500
parents b6029f2c71cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
1 #!/usr/bin/env python
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
2 # ======================================================================
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
3 # Script derived from the EB-eye (REST) Python client available at
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
4 # http://www.ebi.ac.uk/Tools/webservices/services/eb-eye_rest
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
5 # and distributed under the Apache License
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
6 # ======================================================================
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
7 # Load libraries
3
42d5e40fcd0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 31d1c92a4c12b6a78693dc5091a08536a075285e
iuc
parents: 2
diff changeset
8
42d5e40fcd0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 31d1c92a4c12b6a78693dc5091a08536a075285e
iuc
parents: 2
diff changeset
9 from __future__ import print_function
42d5e40fcd0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 31d1c92a4c12b6a78693dc5091a08536a075285e
iuc
parents: 2
diff changeset
10
2
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
11 import os
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
12 import platform
2
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
13 import re
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
14 import urllib
2
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
15 import urllib2
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
16 from gzip import GzipFile
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
17 from optparse import OptionParser
2
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
18 from StringIO import StringIO
b6029f2c71cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents: 0
diff changeset
19
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
20 from xmltramp2 import xmltramp
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
21
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
22 # Service base URL
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
23 baseUrl = 'http://www.ebi.ac.uk/ebisearch/ws/rest'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
24
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
25 # Debug level
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
26 debugLevel = 0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
27
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
28
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
29 # Debug print
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
30 def printDebugMessage(functionName, message, level):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
31 if(level <= debugLevel):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
32 print ('[' + functionName + '] ' + message)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
33
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
34
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
35 # User-agent for request.
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
36 def getUserAgent():
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
37 printDebugMessage('getUserAgent', 'Begin', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
38 urllib_agent = 'Python-urllib/%s' % urllib2.__version__
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
39 clientRevision = '$Revision: 2468 $'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
40 clientVersion = '0'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
41 if len(clientRevision) > 11:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
42 clientVersion = clientRevision[11:-2]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
43 user_agent = 'EBI-Sample-Client/%s (%s; Python %s; %s) %s' % (
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
44 clientVersion, os.path.basename(__file__),
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
45 platform.python_version(), platform.system(),
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
46 urllib_agent
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
47 )
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
48 printDebugMessage('getUserAgent', 'user_agent: ' + user_agent, 12)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
49 printDebugMessage('getUserAgent', 'End', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
50 return user_agent
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
51
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
52
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
53 # Wrapper for a REST (HTTP GET) request
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
54 def restRequest(url):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
55 printDebugMessage('restRequest', 'Begin', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
56 printDebugMessage('restRequest', 'url: ' + url, 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
57 # python 2
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
58 url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
59 # python 3
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
60 # url = urllib.request.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
61
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
62 try:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
63 user_agent = getUserAgent()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
64 http_headers = {
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
65 'User-Agent': user_agent,
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
66 'Accept-Encoding': 'gzip'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
67 }
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
68 req = urllib2.Request(url, None, http_headers)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
69 resp = urllib2.urlopen(req)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
70 # python2
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
71 encoding = resp.info().getheader('Content-Encoding')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
72 # python3
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
73 # encoding = resp.info().__getitem__('Content-Encoding')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
74 result = None
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
75 if encoding is None or encoding == 'identity':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
76 # python2
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
77 result = resp.read()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
78 # python3
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
79 # result = str(resp.read(), 'utf-8')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
80 elif encoding == 'gzip':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
81 result = resp.read()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
82 printDebugMessage('restRequest', 'result: ' + str(result), 21)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
83 # python2
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
84 gz = GzipFile(
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
85 fileobj=StringIO(result),
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
86 mode="r")
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
87 result = gz.read()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
88 # python3
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
89 # result = str(gzip.decompress(result), 'utf-8')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
90 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
91 raise Exception('Unsupported Content-Encoding')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
92 resp.close()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
93 except urllib2.HTTPError as ex:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
94 raise ex
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
95 printDebugMessage('restRequest', 'result: ' + result, 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
96 printDebugMessage('restRequest', 'End', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
97 return result
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
98
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
99
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
100 def hasSubdomains(domainInfo):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
101 for dir in domainInfo._dir:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
102 if dir._name == 'subdomains':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
103 return True
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
104 return False
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
105
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
106
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
107 def extractUsefulFields(fieldInfos):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
108 searchable = []
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
109 retrievable = []
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
110
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
111 for fieldInfo in fieldInfos:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
112 if fieldInfo('id') == "$facets":
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
113 continue
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
114
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
115 options = fieldInfo['options']['option':]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
116 for option in options:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
117 if option("name") == "searchable" and str(option) == "true":
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
118 searchable.append(fieldInfo('id'))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
119 if option("name") == "retrievable" and str(option) == "true":
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
120 retrievable.append(fieldInfo('id'))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
121 return searchable, retrievable
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
122
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
123
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
124 def extractLowerLevelDomains(domainInfo, domains):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
125 if hasSubdomains(domainInfo):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
126 subdomains = domainInfo['subdomains']['domain':]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
127 for subdomain in subdomains:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
128 domains = extractLowerLevelDomains( subdomain, domains)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
129 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
130 searchable, retrievable = extractUsefulFields(
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
131 domainInfo['fieldInfos']['fieldInfo':])
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
132
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
133 domain_id = domainInfo('id')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
134 domains.setdefault(domain_id, {})
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
135 domains[domain_id]["name"] = domainInfo('name')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
136 domains[domain_id]["searchable_fields"] = sorted(searchable)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
137 domains[domain_id]["retrievable_fields"] = sorted(retrievable)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
138 return domains
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
139
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
140
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
141 # Get domain Hierarchy
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
142 def getDomainHierarchy():
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
143 requestUrl = baseUrl + '/allebi'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
144 xmlDoc = restRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
145 doc = xmltramp.parse(xmlDoc)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
146 allebi = doc['domains']['domain']
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
147 lower_level_domains = extractLowerLevelDomains(allebi, {})
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
148 printDebugMessage('getDomainHierarchy', 'End', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
149 return lower_level_domains
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
150
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
151
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
152 # Check if a databaseInfo matches a database name.
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
153 def is_database(dbInfo, dbName):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
154 printDebugMessage('is_database', 'Begin', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
155 retVal = False
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
156 if str(dbInfo.name) == dbName:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
157 retVal = True
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
158 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
159 for dbAlias in dbInfo.aliasList:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
160 if str(dbAlias) == dbName:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
161 retVal = True
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
162 printDebugMessage('is_database', 'retVal: ' + str(retVal), 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
163 printDebugMessage('is_database', 'End', 11)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
164 return retVal
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
165
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
166
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
167 # Get number of results
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
168 def getNumberOfResults(domain, query):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
169 printDebugMessage('getNumberOfResults', 'Begin', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
170 requestUrl = baseUrl + '/' + domain + '?query=' + query + '&size=0'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
171 printDebugMessage('getNumberOfResults', requestUrl, 2)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
172 xmlDoc = restRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
173 doc = xmltramp.parse(xmlDoc)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
174 numberOfResults = int(str(doc['hitCount']))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
175 printDebugMessage('getNumberOfResults', 'End', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
176 return numberOfResults
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
177
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
178
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
179 def makeRequest(requestUrl):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
180 xmlDoc = restRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
181 doc = xmltramp.parse(xmlDoc)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
182 entries = doc['entries']['entry':]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
183 formatted_output = printEntries(entries)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
184 return formatted_output
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
185
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
186
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
187 # Get search results
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
188 def getResults(domain, query, fields):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
189 numberOfResults = getNumberOfResults(domain, query)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
190 maximum_size = 100
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
191 quotient = numberOfResults / maximum_size
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
192 start = 0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
193
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
194 printDebugMessage('getResults', 'Begin', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
195 request_output = "%s\tlink\n" % (fields.replace(",", "\t"))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
196 for i in range(quotient):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
197 start = maximum_size * i
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
198 requestUrl = baseUrl + '/' + domain + '?query=' + query
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
199 requestUrl += '&fields=' + fields + '&size=' + str(maximum_size)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
200 requestUrl += '&start=' + str(start) + '&fieldurl=true'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
201 request_output += makeRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
202
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
203 if (numberOfResults % 100) > 0:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
204 start = maximum_size * quotient
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
205 remainder = numberOfResults - start
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
206 requestUrl = baseUrl + '/' + domain + '?query=' + query
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
207 requestUrl += '&fields=' + fields + '&size=' + str(remainder)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
208 requestUrl += '&start=' + str(start) + '&fieldurl=true'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
209 request_output += makeRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
210
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
211 print(request_output)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
212
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
213
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
214 def printEntries(entries):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
215 output = ""
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
216 printDebugMessage('printEntries', 'Begin', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
217 for entry in entries:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
218 sep = ""
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
219 for field in entry['fields']['field':]:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
220 output += "%s" % (sep)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
221 fields = field['values']['value':]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
222 if len(fields) > 0:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
223 sub_sep = ""
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
224 for value in field['values']['value':]:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
225 output += "%s%s" % (sub_sep, value)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
226 sub_sep = ","
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
227 sep = "\t"
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
228
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
229 if hasFieldUrls(entry):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
230 output += "%s" % (sep)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
231 sub_sep = ""
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
232 for fieldurl in entry['fieldURLs']['fieldURL':]:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
233 output += "%s%s" % (sub_sep, str(fieldurl))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
234 sub_sep = ","
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
235 sep = "\t"
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
236 if hasViewUrls(entry):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
237 output += "%s" % (sep)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
238 sub_sep = ""
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
239 for viewurl in entry['viewURLs']['viewURL':]:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
240 output += "%s%s" % (sub_sep, str(viewurl))
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
241 sub_sep = ","
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
242 output += "\n"
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
243 printDebugMessage('printEntries', 'End', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
244 return output
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
245
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
246
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
247 def hasFieldUrls(entry):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
248 for dir in entry._dir:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
249 if dir._name == 'fieldURLs':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
250 return True
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
251 return False
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
252
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
253
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
254 def hasViewUrls(entry):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
255 for dir in entry._dir:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
256 if dir._name == 'viewURLs':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
257 return True
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
258 return False
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
259
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
260
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
261 def getRunLink(run_id):
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
262 printDebugMessage('getEntries', 'Begin', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
263 requestUrl = baseUrl + '/metagenomics_runs/entry/' + run_id + '?fieldurl=true'
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
264 printDebugMessage('getEntries', requestUrl, 2)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
265 xmlDoc = restRequest(requestUrl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
266 doc = xmltramp.parse(xmlDoc)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
267 entries = doc['entries']['entry':]
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
268 fieldURL = ''
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
269 for entry in entries:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
270 for fieldurl in entry['fieldURLs']['fieldURL':]:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
271 fieldURL += str(fieldurl)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
272 printDebugMessage('getEntries', 'End', 1)
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
273 p = re.compile('http')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
274 fieldURL = p.sub('https', fieldURL)
3
42d5e40fcd0b planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 31d1c92a4c12b6a78693dc5091a08536a075285e
iuc
parents: 2
diff changeset
275 print(fieldURL)
0
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
276
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
277
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
278 if __name__ == '__main__':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
279 # Usage message
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
280 usage = """
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
281 %prog getDomainHierarchy
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
282 %prog getResults <domain> <query> <fields>
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
283 %prog getRunLink <runId>
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
284 """
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
285
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
286 description = "Tools to query and download data from several EMBL-EBI databases"
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
287 description += "The searching tools are using the EB-eye search engine. "
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
288 description += "http://www.ebi.ac.uk/ebisearch/"
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
289 # Process command-line options
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
290 parser = OptionParser(
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
291 usage=usage,
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
292 description=description,
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
293 version='1.0')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
294 (options, args) = parser.parse_args()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
295
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
296 # No arguments, print usage
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
297 if len(args) < 1:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
298 parser.print_help()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
299
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
300 # Get domain hierarchy
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
301 elif args[0] == 'getDomainHierarchy':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
302 getDomainHierarchy()
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
303
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
304 # Get search results
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
305 elif args[0] == 'getResults':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
306 if len(args) < 4:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
307 print ('domain, query and fields should be given.')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
308 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
309 getResults(args[1], args[2], args[3])
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
310
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
311 # Get run link results
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
312 elif args[0] == 'getRunLink':
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
313 if len(args) < 2:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
314 print ('run id should be given.')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
315 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
316 getRunLink(args[1])
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
317
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
318 # Unknown argument combination, display usage
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
319 else:
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
320 print ('Error: unrecognised argument combination')
bb7989bd88ba planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff changeset
321 parser.print_help()