upstream-extended/iuc/tools/emboss_5/emboss_format_corrector.py
1# EMBOSS format corrector
2import operator
3
4
5# Properly set file formats before job run
6def exec_before_job(app, inp_data=None, out_data=None, tool=None, param_dict=None):
7 # why isn't items an ordered list?
8 items = out_data.items()
9 items = sorted(items, key=operator.itemgetter(0))
10
11 # normal filetype correction
12 data_count = 1
13 for name, data in items:
14 outputType = param_dict.get('out_format' + str(data_count), None)
15 if outputType is not None:
16 if outputType == 'ncbi':
17 outputType = "fasta"
18 elif outputType == 'excel':
19 outputType = "tabular"
20 elif outputType == 'text':
21 outputType = "txt"
22 data = app.datatypes_registry.change_datatype(data, outputType)
23 app.model.context.add(data)
24 app.model.context.flush()
25 data_count += 1
26
27 # html filetype correction
28 data_count = 1
29 for name, data in items:
30 wants_plot = param_dict.get('html_out' + str(data_count), None)
31 ext = "html"
32 if wants_plot == "yes":
33 data = app.datatypes_registry.change_datatype(data, ext)
34 app.model.context.add(data)
35 app.model.context.flush()
36 data_count += 1
37
38 # png file correction
39 data_count = 1
40 for name, data in items:
41 wants_plot = param_dict.get('plot' + str(data_count), None)
42 ext = "png"
43 if wants_plot == "yes":
44 data = app.datatypes_registry.change_datatype(data, ext)
45 app.model.context.add(data)
46 app.model.context.flush()
47 data_count += 1