PageRenderTime 34ms CodeModel.GetById 17ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/emboss_5/emboss_format_corrector.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 53 lines | 36 code | 5 blank | 12 comment | 10 complexity | 04460cb400af133c4c7248106669b5b7 MD5 | raw file
 1#EMBOSS format corrector
 2
 3import operator
 4#from galaxy import datatypes
 5
 6#Properly set file formats after job run
 7def exec_after_process( app, inp_data, out_data, param_dict,tool, stdout, stderr):
 8#Properly set file formats before job run
 9#def exec_before_job(trans, inp_data, out_data, param_dict,tool):
10    #why isn't items an ordered list?
11    items = out_data.items()
12    #lets sort it ourselves....
13    items = sorted(items, key=operator.itemgetter(0))
14    #items is now sorted...
15    
16    #normal filetype correction
17    data_count=1
18    for name, data in items:
19        outputType = param_dict.get( 'out_format'+str(data_count), None )
20        #print "data_count",data_count, "name", name, "outputType", outputType
21        if outputType !=None:
22            if outputType == 'ncbi':
23                outputType = "fasta"
24            elif outputType == 'excel':
25                outputType = "tabular"
26            elif outputType == 'text':
27                outputType = "txt"
28            data = app.datatypes_registry.change_datatype(data, outputType)
29            app.model.context.add( data )
30            app.model.context.flush()
31        data_count+=1
32    
33    #html filetype correction
34    data_count=1
35    for name, data in items:
36        wants_plot = param_dict.get( 'html_out'+str(data_count), None )
37        ext = "html"
38        if wants_plot == "yes":
39            data = app.datatypes_registry.change_datatype(data, ext)
40            app.model.context.add( data )
41            app.model.context.flush()
42        data_count+=1
43    
44    #png file correction
45    data_count=1
46    for name, data in items:
47        wants_plot = param_dict.get( 'plot'+str(data_count), None )
48        ext = "png"
49        if wants_plot == "yes":
50            data = app.datatypes_registry.change_datatype(data, ext)
51            app.model.context.add( data )
52            app.model.context.flush()
53        data_count+=1