comparison dyadAnalysis_wrapper.py @ 26:2f3462ac56aa draft

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