24
|
1 #! /usr/bin/python
|
|
2 # -*- coding: utf8 -*-
|
|
3
|
|
4 """#supported motif databases 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 motif databases to each RSAT server and create loc files for Galaxy.
|
|
23 #
|
|
24 ###########################################################'
|
|
25 #
|
|
26 # List RSAT suppported motif databases.
|
|
27 #
|
|
28 #
|
|
29 #usage: supported-motif-databases_soap.py [-h] -galaxyPath <GALAXY_PATH>
|
|
30 #
|
|
31 #optional arguments:
|
|
32 # -h, --help show this help message and exit
|
|
33 # -galaxyPath <GALAXY_PATH>, --galaxyPath <GALAXY_PATH>
|
|
34 # Galaxy tool_data_path directory (e.i. /myGalaxy
|
|
35 # /galaxy-dist/tool-data)
|
|
36 #
|
|
37 #Version 0.1 - 27/05/2015
|
|
38 #
|
|
39 ###########################################################'"""
|
|
40 __author__ = 'Jocelyn Brayet'
|
|
41 supportedMotifDatabasesVersion = '0.1 - 27/05/2015'
|
|
42
|
|
43 ###########################################################'
|
|
44 ## Import
|
|
45
|
|
46 import argparse
|
|
47 import os
|
|
48 import urllib
|
|
49 from suds.client import Client
|
|
50 import platform
|
|
51
|
|
52 ###########################################################'
|
|
53
|
|
54 ################################ functions ############################################################
|
|
55 ## Define a function to make a service perform the desired request using provided arguments
|
|
56 def call_run_service(rsat_service, args):
|
|
57 """
|
|
58 Run job in RSAT server.
|
|
59 service -> RSAT web service
|
|
60 args -> web service request
|
|
61 """
|
|
62
|
|
63 result = rsat_service.supported_motif_databases(args)
|
|
64 return result
|
|
65
|
|
66 def testNone(argument):
|
|
67 """
|
|
68 Test if argument is None or not.
|
|
69 argument -> argument give by user
|
|
70 """
|
|
71
|
|
72 if not argument is None:
|
|
73 variable = argument[0]
|
|
74 else:
|
|
75 variable = ""
|
|
76 return variable
|
|
77
|
|
78 def recupMotifDatabases(srv,request,dicServ):
|
|
79
|
|
80 """
|
|
81 Recup RSAT organisms in each RSAT server.
|
|
82 srv -> server key in server dictionary
|
|
83 request -> job request
|
|
84 dicServ -> server dictionary
|
|
85 """
|
|
86
|
|
87 # Create the client
|
|
88 client = Client(serverDict[srv])
|
|
89 # Need service interface to perform requests
|
|
90 rsat_service = client.service
|
|
91
|
|
92 print client
|
|
93 # Define client header
|
|
94
|
|
95 userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % (
|
|
96 supportedMotifDatabasesVersion,
|
|
97 os.path.basename( __file__ ),
|
|
98 platform.python_version(),
|
|
99 platform.system()
|
|
100 )
|
|
101
|
|
102 httpHeaders = {'User-agent': userAgent}
|
|
103 client.set_options(headers=httpHeaders)
|
|
104 client.set_options(timeout=300)
|
|
105
|
|
106 result = call_run_service(rsat_service, request)
|
|
107
|
|
108 ###########################################################'
|
|
109 ## Display request results
|
|
110
|
|
111 print '###############################################'
|
|
112 print 'Command performed on server'
|
|
113 print ''
|
|
114 print result.command
|
|
115 print ''
|
|
116 print '###############################################'
|
|
117 print 'Result'
|
|
118 print ''
|
|
119 print result.client
|
|
120
|
|
121 return(result.client)
|
|
122
|
|
123 ###########################################################'
|
|
124
|
|
125 ###########################################################'
|
|
126 # server dictionary
|
|
127 serverDict = {
|
|
128
|
|
129 #http://protists.rsat.eu/
|
|
130 "fr_ens":"http://rsat01.biologie.ens.fr/rsa-tools/web_services/RSATWS.wsdl",
|
|
131 "fr_mrs":"http://rsat-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
132 "fr_ro":"http://rsat.sb-roscoff.fr/web_services/RSATWS.wsdl",
|
|
133 "fr_mrs_2":"http://pedagogix-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
134 "es":"http://floresta.eead.csic.es/rsat/web_services/RSATWS.wsdl",
|
|
135 "mx":"http://embnet.ccg.unam.mx/rsa-tools/web_services/RSATWS.wsdl"
|
|
136
|
|
137 }
|
|
138
|
|
139
|
|
140 if __name__ == '__main__':
|
|
141
|
|
142 # Create the parser
|
|
143 parser = argparse.ArgumentParser(description='List RSAT suppported motif databases.', epilog='Version '+supportedMotifDatabasesVersion)
|
|
144
|
|
145 # List desired arguments
|
|
146 #parser.add_argument('-r', '--return_param', metavar='<RETURN_PARAM>', type=str, nargs=1, help='Return fields. Supported: name,format,file,descr,version,url.', required=True)
|
|
147 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)
|
|
148
|
|
149 # Parse command line
|
|
150 args = parser.parse_args()
|
|
151
|
|
152 # Get values to be used
|
|
153 #output_return = testNone(args.return_param)
|
|
154 galaxyPath = testNone(args.galaxyPath)
|
|
155
|
|
156 for srv in serverDict:
|
|
157
|
|
158 functionResult=""
|
|
159 reslutsTab=list()
|
|
160 finalTab=list()
|
|
161
|
|
162 supportedMotifDatabasesRequest = {
|
|
163
|
|
164 'output' : 'client',
|
|
165 'return' : 'name'
|
|
166
|
|
167 }
|
|
168
|
|
169 functionResult=recupMotifDatabases(srv,supportedMotifDatabasesRequest,serverDict)
|
|
170 reslutsTab=str(functionResult).split("\n")
|
|
171 del reslutsTab[-1]
|
|
172 resultsFile = open(galaxyPath+"/"+"RSAT_motif_databases_"+srv+".loc","w")
|
|
173 for value in reslutsTab:
|
|
174 if not value.startswith("#"):
|
|
175 resultsFile.write(value+"\n")
|
|
176 resultsFile.close()
|
|
177
|
|
178
|
|
179
|
|
180
|
|
181
|
|
182
|
|
183
|
|
184
|
|
185
|
|
186
|
|
187
|
|
188
|