27
|
1 #! /usr/bin/python
|
|
2 # -*- coding: utf8 -*-
|
|
3
|
|
4 """#oligo analysis 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 #Analysis of oligomer occurrences in nucleotidic of peptidic sequences.
|
|
23 #
|
|
24 ###########################################################'
|
|
25 #
|
|
26 # Client to have list RSAT oligo analysis.
|
|
27 #
|
|
28 #
|
|
29 #usage: oligo-analysis_soap.py [-h] -sequence_file <SEQUENCE_FILE> -length
|
|
30 # <LENGTH> -organism <ORGANISM> -server <SERVEUR>
|
|
31 #
|
|
32 #optional arguments:
|
|
33 # -h, --help show this help message and exit
|
|
34 # -sequence_file <SEQUENCE_FILE>, --sequence_file <SEQUENCE_FILE>
|
|
35 # Input sequence (FASTA file).
|
|
36 # -length <LENGTH>, --length <LENGTH>
|
|
37 # Oligomer length.
|
|
38 # -organism <ORGANISM>, --organism <ORGANISM>
|
|
39 # Organism.
|
|
40 # -stats <STATS>, --stats <STATS>
|
|
41 # List of statistics to return. Supported:occ, mseq,
|
|
42 # freq, proba, ratio, zscore, like, pos, rank.
|
|
43 # -server <SERVEUR>, --server <SERVEUR>
|
|
44 #
|
|
45 #Version 0.1 - 16/04/2015
|
|
46 #
|
|
47 #
|
|
48 ###########################################################'"""
|
|
49 __author__ = 'Jocelyn Brayet'
|
|
50 oligoAnalysisVersion = '0.1 - 16/04/2015'
|
|
51
|
|
52 ###########################################################'
|
|
53 ## Import
|
|
54
|
|
55 import argparse
|
|
56 import os
|
|
57 import urllib
|
|
58 from suds.client import Client
|
|
59 import platform
|
|
60
|
|
61 ###########################################################'
|
|
62
|
|
63 ################################ functions ############################################################
|
|
64 ## Define a function to make a service perform the desired request using provided arguments
|
|
65 def call_run_service(rsat_service, args):
|
|
66 """
|
|
67 Run job in RSAT server.
|
|
68 service -> RSAT web service
|
|
69 args -> web service request
|
|
70 """
|
|
71
|
|
72 result = rsat_service.oligo_analysis(args)
|
|
73 return result
|
|
74
|
|
75 def testNone(argument):
|
|
76 """
|
|
77 Test if argument is None or not.
|
|
78 argument -> argument give by user
|
|
79 """
|
|
80
|
|
81 if not argument is None:
|
|
82 variable = argument[0]
|
|
83 else:
|
|
84 variable = ""
|
|
85 return variable
|
|
86
|
|
87
|
|
88 ###########################################################'
|
|
89 # server dictionary
|
|
90 serverDict = {
|
|
91
|
|
92 "fr_ens":"http://rsat01.biologie.ens.fr/rsa-tools/web_services/RSATWS.wsdl",
|
|
93 "fr_mrs":"http://rsat-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
94 "fr_ro":"http://rsat.sb-roscoff.fr/web_services/RSATWS.wsdl",
|
|
95 "fr_mrs_2":"http://pedagogix-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl",
|
|
96 "es":"http://floresta.eead.csic.es/rsat/web_services/RSATWS.wsdl",
|
|
97 "mx":"http://embnet.ccg.unam.mx/rsa-tools/web_services/RSATWS.wsdl"
|
|
98
|
|
99 }
|
|
100
|
|
101 ###########################################################'
|
|
102
|
|
103 if __name__ == '__main__':
|
|
104
|
|
105 parser = argparse.ArgumentParser(description='Analysis of oligomer occurrences in nucleotidic of peptidic sequences.', epilog='Version '+oligoAnalysisVersion)
|
|
106
|
|
107 ########### compare matrices arguments ####################
|
|
108
|
|
109 parser.add_argument('-sequence_file', '--sequence_file', metavar='<SEQUENCE_FILE>', type=argparse.FileType('r'), nargs=1, help='Input sequence (FASTA file).', required=True)
|
|
110 parser.add_argument('-length', '--length', metavar='<LENGTH>', type=int, nargs=1, help='Oligomer length.', required=True)
|
|
111 parser.add_argument('-organism', '--organism', metavar='<ORGANISM>', type=str, nargs=1, help='Organism.', required=True)
|
|
112 parser.add_argument('-stats', '--stats', metavar='<STATS>', type=str, nargs=1, help='List of statistics to return. Supported:occ, mseq, freq, proba, ratio, zscore, like, pos, rank.', required=False)
|
|
113
|
|
114 ########### galaxy arguments ##############################
|
|
115 parser.add_argument('-server', '--server', metavar='<SERVEUR>', type=str, nargs=1, required=True)
|
|
116 parser.add_argument('-outGalaxy', '--outGalaxy', metavar='<OUT_GALAXY>', type=str, nargs=1, required=True)
|
|
117 ###########################################################
|
|
118
|
|
119 args = parser.parse_args()
|
|
120
|
|
121 sequence_file = args.sequence_file[0].read()
|
|
122 serverValue = testNone(args.server)
|
|
123 length = testNone(args.length)
|
|
124 organism = testNone(args.organism)
|
|
125 stats = testNone(args.stats)
|
|
126 outGalaxyValue = testNone(args.outGalaxy)
|
|
127
|
|
128 ###########################################################'
|
|
129 ## Create the SOAP client to request the RSAT service
|
|
130
|
|
131
|
|
132 # Load Client class from suds
|
|
133 # Define URL for RSAT services
|
|
134 url = serverDict[serverValue]
|
|
135 # Create the client
|
|
136 client = Client(url)
|
|
137
|
|
138 # Need service interface to perform requests
|
|
139 rsat_service = client.service
|
|
140
|
|
141 #print client
|
|
142
|
|
143 # Define client header
|
|
144 userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % (
|
|
145 oligoAnalysisVersion,
|
|
146 os.path.basename( __file__ ),
|
|
147 platform.python_version(),
|
|
148 platform.system()
|
|
149 )
|
|
150
|
|
151 httpHeaders = {'User-agent': userAgent}
|
|
152 client.set_options(headers=httpHeaders)
|
|
153 client.set_options(timeout=300)
|
|
154
|
|
155
|
|
156 oligoAnalysisRequest = {
|
|
157
|
|
158 'output' : 'both',
|
|
159 'format' : 'fasta',
|
|
160 'sequence' : sequence_file,
|
|
161 'length' : length,
|
|
162 'organism' : organism,
|
|
163 'stats' : stats
|
|
164
|
|
165 }
|
|
166
|
|
167
|
|
168 result = call_run_service(rsat_service, oligoAnalysisRequest)
|
|
169
|
|
170
|
|
171 print url
|
|
172
|
|
173 print "###############################################"
|
|
174 print "Command performed on server"
|
|
175 print result.command
|
|
176 print "###############################################"
|
|
177 print "Result"
|
|
178 print result.server
|
|
179
|
|
180 nameFile = "oligo-analysis_results.txt"
|
|
181
|
|
182 urlResult=result.server.replace("$RSAT/public_html/",url.replace("web_services/RSATWS.wsdl",""))
|
|
183
|
|
184 print urlResult
|
|
185
|
|
186 urllib.urlretrieve(urlResult, nameFile)
|
|
187
|
|
188 os.popen("cp "+nameFile+" "+outGalaxyValue)
|
|
189
|
|
190
|
|
191
|