Mercurial > repos > iuc > ebi_search_rest_results
annotate ebeye_urllib.py @ 2:b6029f2c71cb draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
author | iuc |
---|---|
date | Sat, 21 Jan 2017 14:41:05 -0500 |
parents | bb7989bd88ba |
children | 42d5e40fcd0b |
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 |
2
b6029f2c71cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 19ea4feff5ccf3744c549b9a67259947a1cb90ba
iuc
parents:
0
diff
changeset
|
8 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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 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
|
16 |
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 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
|
18 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
19 # 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
|
20 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
|
21 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
22 # Debug level |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
23 debugLevel = 0 |
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 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
26 # Debug print |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
31 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
32 # 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
|
33 def getUserAgent(): |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 clientVersion = '0' |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 urllib_agent |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
44 ) |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
49 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
50 # 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
|
51 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
|
52 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
|
53 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
|
54 # python 2 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
55 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
|
56 # python 3 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
57 # 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
|
58 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
59 try: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
60 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
|
61 http_headers = { |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
62 '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
|
63 '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
|
64 } |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
65 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
|
66 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
|
67 # python2 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
68 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
|
69 # python3 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
70 # 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
|
71 result = None |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
72 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
|
73 # python2 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
74 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
|
75 # python3 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
76 # 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
|
77 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
|
78 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
|
79 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
|
80 # python2 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
81 gz = GzipFile( |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
82 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
|
83 mode="r") |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
84 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
|
85 # python3 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
86 # 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
|
87 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
88 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
|
89 resp.close() |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
90 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
|
91 raise ex |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
92 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
|
93 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
|
94 return result |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
95 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
96 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 return True |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
101 return False |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
102 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
103 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
104 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
|
105 searchable = [] |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
106 retrievable = [] |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
107 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
108 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
|
109 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
|
110 continue |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
111 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
120 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
127 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
|
128 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
|
129 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 return domains |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
136 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
137 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
138 # 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
|
139 def getDomainHierarchy(): |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
148 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
149 # 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
|
150 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
|
151 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
|
152 retVal = False |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
153 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
|
154 retVal = True |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
155 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
156 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
|
157 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
|
158 retVal = True |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
159 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
|
160 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
|
161 return retVal |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
162 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
163 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
164 # 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 return numberOfResults |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
174 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
175 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
183 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
184 # 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 start = 0 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
190 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
208 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
|
209 |
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 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
|
212 output = "" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
213 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
|
214 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
|
215 sep = "" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 sub_sep = "" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
221 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
|
222 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
|
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 sep = "\t" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
225 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
226 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
|
227 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
|
228 sub_sep = "" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
229 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
|
230 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
|
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 sep = "\t" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
233 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
|
234 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
|
235 sub_sep = "" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
236 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
|
237 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
|
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 output += "\n" |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
240 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
|
241 return output |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
242 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
243 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 return True |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
248 return False |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
249 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
250 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 return True |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
255 return False |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
256 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
257 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 fieldURL = '' |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 fieldURL = p.sub('https', fieldURL) |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
272 print fieldURL |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
273 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
274 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
275 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
|
276 # Usage message |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
277 usage = """ |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
278 %prog getDomainHierarchy |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
279 %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
|
280 %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
|
281 """ |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
282 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 # 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
|
287 parser = OptionParser( |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
288 usage=usage, |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
289 description=description, |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
290 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
|
291 (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
|
292 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
293 # 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
|
294 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
|
295 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
|
296 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
297 # 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
|
298 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
|
299 getDomainHierarchy() |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
300 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
301 # 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
|
302 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
|
303 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
|
304 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
|
305 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
306 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
|
307 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
308 # 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
|
309 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
|
310 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
|
311 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
|
312 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
313 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
|
314 |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
315 # 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
|
316 else: |
bb7989bd88ba
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
317 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
|
318 parser.print_help() |