28
|
1 #! /usr/bin/python
|
|
2 # -*- coding: utf8 -*-
|
|
3
|
|
4 """#supported organisms soap - developed by Jocelyn Brayet <jocelyn.brayet@curie.fr>
|
|
5 #Copyright (C) 2015 Institut Curie
|
|
6 #
|
|
7 #This program is free software: you can redistribute it and/or modify
|
|
8 #it under the terms of the GNU General Public License as published by
|
|
9 #the Free Software Foundation, either version 3 of the License, or
|
|
10 #(at your option) any later version.
|
|
11 #
|
|
12 #This program is distributed in the hope that it will be useful,
|
|
13 #but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 #GNU General Public License for more details.
|
|
16 #
|
|
17 #You should have received a copy of the GNU General Public License
|
|
18 #along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 #
|
|
20 ###########################################################'
|
|
21 #
|
|
22 #Recup organisms to each RSAT server and create loc files for Galaxy.
|
|
23 #
|
|
24 ###########################################################'
|
|
25 #
|
|
26 # Client to have list RSAT suppported organisms.
|
|
27 #
|
|
28 #
|
|
29 #usage: supported-organisms_soap.py [-h] -f <OUTPUT_FORMAT> -galaxyPath <GALAXY_PATH>
|
|
30 #
|
|
31 #
|
|
32 #optional arguments:
|
|
33 # -h, --help show this help message and exit
|
|
34 # -f <OUTPUT_FORMAT>, --format <OUTPUT_FORMAT>
|
|
35 # Output format. Supported: html_list, html_table,
|
|
36 # array, text, keys, names, sizes, full, tree,
|
|
37 # html_tree.
|
|
38 # -galaxyPath <GALAXY_PATH>, --galaxyPath <GALAXY_PATH>
|
|
39 # Galaxy tool_data_path directory (e.i. /myGalaxy
|
|
40 # /galaxy-dist/tool-data)
|
|
41 #
|
|
42 #Version 0.1 - 15/04/2015
|
|
43 #
|
|
44 ###########################################################'"""
|
|
45 __author__ = 'Jocelyn Brayet'
|
|
46 supportedOrganismsVersion = '0.1 - 15/04/2015'
|
|
47
|
|
48 ###########################################################'
|
|
49 ## Import
|
|
50
|
|
51 import argparse
|
|
52 import os
|
|
53 import urllib
|
|
54 from suds.client import Client
|
|
55 import platform
|
|
56
|
|
57 ###########################################################'
|
|
58
|
|
59 ################################ functions ############################################################
|
|
60 ## Define a function to make a service perform the desired request using provided arguments
|
|
61 def call_run_service(rsat_service, args):
|
|
62 """
|
|
63 Run job in RSAT server.
|
|
64 service -> RSAT web service
|
|
65 args -> web service request
|
|
66 """
|
|
67
|
|
68 result = rsat_service.supported_organisms(args)
|
|
69 return result
|
|
70
|
|
71 def testNone(argument):
|
|
72 """
|
|
73 Test if argument is None or not.
|
|
74 argument -> argument give by user
|
|
75 """
|
|
76
|
|
77 if not argument is None:
|
|
78 variable = argument[0]
|
|
79 else:
|
|
80 variable = ""
|
|
81 return variable
|
|
82
|
|
83 def recupOrganisms(srv,request,dicServ,path):
|
|
84
|
|
85 """
|
|
86 Recup RSAT organisms in each RSAT server.
|
|
87 srv -> server key in server dictionary
|
|
88 request -> job request
|
|
89 dicServ -> server dictionary
|
|
90 """
|
|
91
|
|
92 # Create the client
|
|
93 client = Client(serverDict[srv])
|
|
94 # Need service interface to perform requests
|
|
95 rsat_service = client.service
|
|
96
|
|
97 # Define client header
|
|
98
|
|
99 userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % (
|
|
100 supportedOrganismsVersion,
|
|
101 os.path.basename( __file__ ),
|
|
102 platform.python_version(),
|
|
103 platform.system()
|
|
104 )
|
|
105
|
|
106 httpHeaders = {'User-agent': userAgent}
|
|
107 client.set_options(headers=httpHeaders)
|
|
108 client.set_options(timeout=300)
|
|
109
|
|
110 result = call_run_service(rsat_service, request)
|
|
111
|
|
112 ###########################################################'
|
|
113 ## Display request results
|
|
114
|
|
115 print '###############################################'
|
|
116 print 'Command performed on server'
|
|
117 print ''
|
|
118 print result.command
|
|
119 print ''
|
|
120 print '###############################################'
|
|
121 print 'Result'
|
|
122 print ''
|
|
123 print result.client
|
|
124
|
|
125 resultsFile = open(path+"/"+"RSAT_organisms_"+srv+".loc","w")
|
|
126 resultsFile.write(result.client)
|
|
127 resultsFile.close()
|
|
128
|
|
129 ###########################################################'
|
|
130
|
|
131 ###########################################################'
|
|
132 # server dictionary
|
|
133 serverDict = {
|
|
134
|
|
135 #http://protists.rsat.eu/
|
|
136 "fr_ens":"http://rsat01.biologie.ens.fr/rsa-tools/web_services/RSATWS.wsdl",
|
|
137 "fr_mrs":"http://rsat-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
138 "fr_ro":"http://rsat.sb-roscoff.fr/web_services/RSATWS.wsdl",
|
|
139 "fr_mrs_2":"http://pedagogix-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
140 "es":"http://floresta.eead.csic.es/rsat/web_services/RSATWS.wsdl",
|
|
141 "mx":"http://embnet.ccg.unam.mx/rsa-tools/web_services/RSATWS.wsdl"
|
|
142
|
|
143 }
|
|
144
|
|
145
|
|
146 if __name__ == '__main__':
|
|
147
|
|
148 # Create the parser
|
|
149 parser = argparse.ArgumentParser(description='Client to download supported-organisms results from RSAT server.', epilog='Version '+supportedOrganismsVersion)
|
|
150
|
|
151 # List desired arguments
|
|
152 parser.add_argument('-f', '--format', metavar='<OUTPUT_FORMAT>', type=str, nargs=1, help='Output format. Supported: html_list, html_table, array, text, keys, names, sizes, full, tree, html_tree.', required=True)
|
|
153 parser.add_argument('-galaxyPath', '--galaxyPath', metavar='<GALAXY_PATH>', type=str, nargs=1, help='Galaxy tool_data_path directory (e.i. /myGalaxy/galaxy-dist/tool-data)', required=True)
|
|
154
|
|
155
|
|
156 # Parse command line
|
|
157 args = parser.parse_args()
|
|
158
|
|
159 # Get values to be used
|
|
160 output_format = testNone(args.format)
|
|
161 galaxyPath = testNone(args.galaxyPath)
|
|
162
|
|
163 supportedOrganismsRequest = {
|
|
164
|
|
165 'output' : 'client',
|
|
166 'format' : output_format
|
|
167
|
|
168 }
|
|
169
|
|
170 for srv in serverDict:
|
|
171
|
|
172 recupOrganisms(srv,supportedOrganismsRequest,serverDict,galaxyPath)
|
|
173
|
|
174
|
|
175
|