Mercurial > repos > iuc > ebi_metagenomics_run_downloader
annotate ebeye_urllib.py @ 0:e2e9fae080ad draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
author | iuc |
---|---|
date | Thu, 01 Dec 2016 15:27:59 -0500 |
parents | |
children | 6155fa39a899 |
rev | line source |
---|---|
0
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
2 # ====================================================================== |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
6 # ====================================================================== |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
7 # Load libraries |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
8 import platform |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
9 import os |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
10 import urllib |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
11 import re |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
12 from optparse import OptionParser |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
13 from gzip import GzipFile |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
14 from xmltramp2 import xmltramp |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
15 # python2 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
16 from StringIO import StringIO |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
17 import urllib2 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
18 # python3 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
19 # import urllib.request as urllib2 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
20 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
21 |
e2e9fae080ad
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 |
e2e9fae080ad
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' |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
24 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
25 # Debug level |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
26 debugLevel = 0 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
27 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
28 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
29 # Debug print |
e2e9fae080ad
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): |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
33 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
34 |
e2e9fae080ad
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. |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
36 def getUserAgent(): |
e2e9fae080ad
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) |
e2e9fae080ad
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__ |
e2e9fae080ad
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 $' |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
40 clientVersion = '0' |
e2e9fae080ad
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: |
e2e9fae080ad
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] |
e2e9fae080ad
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' % ( |
e2e9fae080ad
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__), |
e2e9fae080ad
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(), |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
46 urllib_agent |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
47 ) |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
51 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
52 |
e2e9fae080ad
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 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
57 # python 2 |
e2e9fae080ad
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="%/:=&?~#+!$,;'@()*[]") |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
59 # python 3 |
e2e9fae080ad
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="%/:=&?~#+!$,;'@()*[]") |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
61 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
62 try: |
e2e9fae080ad
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() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
64 http_headers = { |
e2e9fae080ad
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, |
e2e9fae080ad
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' |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
67 } |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
70 # python2 |
e2e9fae080ad
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') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
72 # python3 |
e2e9fae080ad
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') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
74 result = None |
e2e9fae080ad
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': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
76 # python2 |
e2e9fae080ad
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() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
78 # python3 |
e2e9fae080ad
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') |
e2e9fae080ad
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': |
e2e9fae080ad
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() |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
83 # python2 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
84 gz = GzipFile( |
e2e9fae080ad
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), |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
86 mode="r") |
e2e9fae080ad
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() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
88 # python3 |
e2e9fae080ad
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') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
90 else: |
e2e9fae080ad
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') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
92 resp.close() |
e2e9fae080ad
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: |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
94 raise ex |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
97 return result |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
98 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
99 |
e2e9fae080ad
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): |
e2e9fae080ad
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: |
e2e9fae080ad
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': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
103 return True |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
104 return False |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
105 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
106 |
e2e9fae080ad
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): |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
108 searchable = [] |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
109 retrievable = [] |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
110 |
e2e9fae080ad
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: |
e2e9fae080ad
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": |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
113 continue |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
114 |
e2e9fae080ad
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':] |
e2e9fae080ad
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: |
e2e9fae080ad
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": |
e2e9fae080ad
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')) |
e2e9fae080ad
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": |
e2e9fae080ad
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')) |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
122 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
123 |
e2e9fae080ad
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): |
e2e9fae080ad
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): |
e2e9fae080ad
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':] |
e2e9fae080ad
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: |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
129 else: |
e2e9fae080ad
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( |
e2e9fae080ad
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':]) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
132 |
e2e9fae080ad
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') |
e2e9fae080ad
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, {}) |
e2e9fae080ad
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') |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
138 return domains |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
139 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
140 |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
142 def getDomainHierarchy(): |
e2e9fae080ad
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' |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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'] |
e2e9fae080ad
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, {}) |
e2e9fae080ad
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) |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
150 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
151 |
e2e9fae080ad
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. |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
155 retVal = False |
e2e9fae080ad
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: |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
157 retVal = True |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
158 else: |
e2e9fae080ad
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: |
e2e9fae080ad
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: |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
161 retVal = True |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
164 return retVal |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
165 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
166 |
e2e9fae080ad
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 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
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' |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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'])) |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
176 return numberOfResults |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
177 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
178 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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':] |
e2e9fae080ad
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) |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
185 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
186 |
e2e9fae080ad
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 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
192 start = 0 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
193 |
e2e9fae080ad
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) |
e2e9fae080ad
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")) |
e2e9fae080ad
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): |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
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) |
e2e9fae080ad
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' |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
202 |
e2e9fae080ad
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: |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
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 |
e2e9fae080ad
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) |
e2e9fae080ad
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' |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
210 |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
212 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
213 |
e2e9fae080ad
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): |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
215 output = "" |
e2e9fae080ad
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) |
e2e9fae080ad
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: |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
218 sep = "" |
e2e9fae080ad
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':]: |
e2e9fae080ad
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) |
e2e9fae080ad
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':] |
e2e9fae080ad
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: |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
223 sub_sep = "" |
e2e9fae080ad
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':]: |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
226 sub_sep = "," |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
227 sep = "\t" |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
228 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
231 sub_sep = "" |
e2e9fae080ad
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':]: |
e2e9fae080ad
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)) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
234 sub_sep = "," |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
235 sep = "\t" |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
238 sub_sep = "" |
e2e9fae080ad
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':]: |
e2e9fae080ad
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)) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
241 sub_sep = "," |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
242 output += "\n" |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
244 return output |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
245 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
246 |
e2e9fae080ad
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): |
e2e9fae080ad
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: |
e2e9fae080ad
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': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
250 return True |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
251 return False |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
252 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
253 |
e2e9fae080ad
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): |
e2e9fae080ad
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: |
e2e9fae080ad
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': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
257 return True |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
258 return False |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
259 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
260 |
e2e9fae080ad
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): |
e2e9fae080ad
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) |
e2e9fae080ad
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' |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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':] |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
268 fieldURL = '' |
e2e9fae080ad
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: |
e2e9fae080ad
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':]: |
e2e9fae080ad
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) |
e2e9fae080ad
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) |
e2e9fae080ad
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') |
e2e9fae080ad
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) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
275 print fieldURL |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
276 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
277 |
e2e9fae080ad
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__': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
279 # Usage message |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
280 usage = """ |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
281 %prog getDomainHierarchy |
e2e9fae080ad
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> |
e2e9fae080ad
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> |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
284 """ |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
285 |
e2e9fae080ad
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" |
e2e9fae080ad
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. " |
e2e9fae080ad
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/" |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
290 parser = OptionParser( |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
291 usage=usage, |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
292 description=description, |
e2e9fae080ad
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') |
e2e9fae080ad
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() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
295 |
e2e9fae080ad
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 |
e2e9fae080ad
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: |
e2e9fae080ad
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() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
299 |
e2e9fae080ad
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 |
e2e9fae080ad
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': |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
302 getDomainHierarchy() |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
303 |
e2e9fae080ad
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 |
e2e9fae080ad
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': |
e2e9fae080ad
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: |
e2e9fae080ad
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.') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
308 else: |
e2e9fae080ad
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]) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
310 |
e2e9fae080ad
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 |
e2e9fae080ad
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': |
e2e9fae080ad
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: |
e2e9fae080ad
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.') |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
315 else: |
e2e9fae080ad
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]) |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
317 |
e2e9fae080ad
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 |
e2e9fae080ad
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ebi_tools commit 7a9c88c1c80b80aaa63e55e9d9125b6a4dd695ac
iuc
parents:
diff
changeset
|
319 else: |
e2e9fae080ad
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') |
e2e9fae080ad
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() |