-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwf.py
executable file
·331 lines (293 loc) · 9.97 KB
/
wf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import sys
import os
import logging
import re
import aljamia
import klibrate
import sanxot
import sanxotsieve
# Module metadata variables
__author__ = "Jose Rodriguez"
__credits__ = ["Marco Trevisan", "Jesus Vazquez"]
__license__ = "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License https://creativecommons.org/licenses/by-nc-nd/4.0/"
__version__ = "1.0.1"
__maintainer__ = "Jose Rodriguez"
__email__ = "[email protected]"
__status__ = "Development"
from cStringIO import StringIO
class capturing(list):
def __enter__(self):
self._stdout = sys.stdout
sys.stdout = self._stringio = StringIO()
return self
def __exit__(self, *args):
self.extend(self._stringio.getvalue().splitlines())
del self._stringio # free up some memory
sys.stdout = self._stdout
class builder:
'''
Handle SanXoT workflow
'''
def __init__(self, outdir, logger=None):
'''
Workflow builder
'''
# prepare tmp workspace ---
self.tmpdir = outdir +"/tmp"
try:
os.makedirs(self.tmpdir)
except:
pass
# create logger instance for a job
if logger is not None:
self.logger = logger
else:
# TODO!! improve the logger instance when it is not given by input
self.logger = logging.getLogger(__name__)
def _convert_dict_list(self, r, o):
'''
Convert the dictionary to list
'''
# init with temporal directory
dlist = []
if self.tmpdir:
dlist.append("-p")
dlist.append(self.tmpdir)
# join dict with requried and optional parameters
params = r.copy()
if o is not None:
if type(o) is dict:
params.update(o)
elif type(o) is str:
dlist.extend( o.split() )
# create parameter list
for key, value in params.iteritems():
dlist.append( str(key) )
if value != "":
dlist.append( str(value) )
return dlist
def _check_params(self, iparams, method):
'''
Check the parameters depending on the method
'''
# TODO!!!
return True
def _print_exception(self, code, msg):
'''
Print the code message
'''
self.logger.exception(msg)
sys.exit(code)
def _get_opt_params(self, core, method, optparams):
'''
Get the optional parameters
'''
optparam = None
if core in optparams and method in optparams[core]:
optparam = optparams[core][method]
return optparam
def aljamia(self, iparams, optparams=None):
'''
Preparate the input data
'''
params = self._convert_dict_list(iparams, optparams)
self.logger.debug( "execute aljamia: "+ " ".join(params) )
try:
with capturing() as outlog:
aljamia.main( params )
except:
self._print_exception(2, "Exception occured: executing aljamia")
def klibrate(self, iparams, optparams=None):
'''
Calibrate data
'''
params = self._convert_dict_list(iparams, optparams)
self.logger.debug( "execute klibrate: "+ " ".join(params) )
try:
with capturing() as outlog:
klibrate.main( params )
except:
self._print_exception(2, "Exception occured: executing klibrate")
def sanxot(self, iparams, optparams=None):
'''
Calibrate data
'''
params = self._convert_dict_list(iparams, optparams)
self.logger.debug( "execute sanxot: "+ " ".join(params) )
try:
with capturing() as outlog:
sanxot.main( params )
except:
self._print_exception(2, "Exception occured: executing sanxot")
def sanxotsieve(self, iparams, optparams=None):
'''
Calibrate data
'''
params = self._convert_dict_list(iparams, optparams)
self.logger.debug( "execute sanxotsieve: "+ " ".join(params) )
try:
with capturing() as outlog:
sanxotsieve.main( params )
except:
self._print_exception(2, "Exception occured: executing sanxotsieve")
def scan2peptide(self, iparams, optparams=None):
'''
Function scan to peptide
'''
corename = "scan2peptide"
coreabrv = "S2P"
# execution ---
method = 'aljamia1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.aljamia({
"-x": iparams['-x'],
"-o": "s2p_uncalibrated.xls",
}, optparam)
# execution ---
method = 'aljamia2'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.aljamia({
"-x": iparams['-x'],
"-o": iparams['-r'],
}, optparam)
# execution ---
method = 'klibrate1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.klibrate({
"-d": "s2p_uncalibrated.xls",
"-r": iparams['-r'],
"-o": iparams['-d'],
}, optparam)
# execution ---
method = 'sanxot1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "s2p_outs",
"-d": iparams['-d'],
"-r": iparams['-r'],
}, optparam)
# execution ---
method = 'sanxotsieve1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxotsieve({
"-d": iparams['-d'],
"-r": iparams['-r'],
"-f": iparams['-f'],
"-V": "s2p_outs_infoFile.txt",
}, optparam)
# execution ---
method = 'sanxot2'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "s2p_nouts",
"-d": iparams['-d'],
"-r": "scans_tagged.xls",
"-o": iparams['-o'],
"-V": "s2p_outs_infoFile.txt",
}, optparam)
def peptide2protein(self, iparams, optparams=None):
'''
Function peptide to protein
'''
corename = "peptide2protein"
coreabrv = "P2Q"
# execution ---
method = 'aljamia1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.aljamia({
"-x": iparams['-x'],
"-o": iparams['-r'],
}, optparam)
# execution ---
method = 'sanxot1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "p2q_outs",
"-d": iparams['-d'],
"-r": iparams['-r'],
}, optparam)
# execution ---
method = 'sanxotsieve1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxotsieve({
"-d": iparams['-d'],
"-r": iparams['-r'],
"-f": iparams['-f'],
"-V": "p2q_outs_infoFile.txt",
}, optparam)
# execution ---
method = 'sanxot2'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "p2q_nouts",
"-d": iparams['-d'],
"-r": "peptides_tagged.xls",
"-o": iparams['-o'],
"-V": "p2q_outs_infoFile.txt",
}, optparam)
def peptide2category(self):
'''
Function peptide to category
'''
print("peptide to category")
def protein2category(self, iparams, optparams=None):
'''
Function protein to category
'''
corename = "protein2category"
coreabrv = "Q2C"
# execution ---
method = 'sanxot1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "q2c_outs",
"-d": iparams['-d'],
"-r": iparams['-r'],
}, optparam)
# execution ---
method = 'sanxotsieve1'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxotsieve({
"-d": iparams['-d'],
"-r": iparams['-r'],
"-f": iparams['-f'],
"-V": "q2c_outs_infoFile.txt",
}, optparam)
# execution ---
method = 'sanxot2'
self.logger.info(coreabrv+": execute "+method)
optparam = self._get_opt_params(corename, method, optparams)
self.sanxot({
"-a": "q2c_nouts",
"-d": iparams['-d'],
"-r": "proteins_tagged.xls",
"-o": iparams['-o'],
"-V": "q2c_outs_infoFile.txt",
}, optparam)
def peptide2all(self):
'''
Function peptide to all
'''
print("peptide to all")
def protein2all(self):
'''
Function protein to all
'''
print("protein to all")
def protein2all(self):
'''
Function category to all
'''
print("category to all")