annotate operation_filter.py @ 0:5b3c6135a982

Imported from capsule None
author devteam
date Tue, 01 Apr 2014 10:53:10 -0400
parents
children 5f72be09cfd3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
1 # runs after the job (and after the default post-filter)
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
2 import os
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
3 from galaxy import eggs
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
4 from galaxy import jobs
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
5 from galaxy.tools.parameters import DataToolParameter
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
6
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
7 from galaxy.jobs.handler import JOB_ERROR
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
8
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
9 # Older py compatibility
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
10 try:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
11 set()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
12 except:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
13 from sets import Set as set
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
14
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
15 #def exec_before_process(app, inp_data, out_data, param_dict, tool=None):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
16 # """Sets the name of the data"""
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
17 # dbkeys = sets.Set( [data.dbkey for data in inp_data.values() ] )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
18 # if len(dbkeys) != 1:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
19 # raise Exception, '<p><font color="yellow">Both Queries must be from the same genome build</font></p>'
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
20
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
21 def validate_input( trans, error_map, param_values, page_param_map ):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
22 dbkeys = set()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
23 data_param_names = set()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
24 data_params = 0
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
25 for name, param in page_param_map.iteritems():
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
26 if isinstance( param, DataToolParameter ):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
27 # for each dataset parameter
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
28 if param_values.get(name, None) != None:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
29 dbkeys.add( param_values[name].dbkey )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
30 data_params += 1
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
31 # check meta data
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
32 try:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
33 param = param_values[name]
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
34 if isinstance( param.datatype, trans.app.datatypes_registry.get_datatype_by_extension( 'gff' ).__class__ ):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
35 # TODO: currently cannot validate GFF inputs b/c they are not derived from interval.
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
36 pass
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
37 else: # Validate interval datatype.
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
38 startCol = int( param.metadata.startCol )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
39 endCol = int( param.metadata.endCol )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
40 chromCol = int( param.metadata.chromCol )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
41 if param.metadata.strandCol is not None:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
42 strandCol = int ( param.metadata.strandCol )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
43 else:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
44 strandCol = 0
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
45 except:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
46 error_msg = "The attributes of this dataset are not properly set. " + \
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
47 "Click the pencil icon in the history item to set the chrom, start, end and strand columns."
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
48 error_map[name] = error_msg
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
49 data_param_names.add( name )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
50 if len( dbkeys ) > 1:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
51 for name in data_param_names:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
52 error_map[name] = "All datasets must belong to same genomic build, " \
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
53 "this dataset is linked to build '%s'" % param_values[name].dbkey
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
54 if data_params != len(data_param_names):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
55 for name in data_param_names:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
56 error_map[name] = "A dataset of the appropriate type is required"
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
57
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
58 # Commented out by INS, 5/30/2007. What is the PURPOSE of this?
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
59 def exec_after_process(app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
60 """Verify the output data after each run"""
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
61 items = out_data.items()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
62
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
63 for name, data in items:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
64 try:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
65 if stderr and len( stderr ) > 0:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
66 raise Exception( stderr )
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
67
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
68 except Exception, exc:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
69 data.blurb = JOB_ERROR
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
70 data.state = JOB_ERROR
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
71
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
72 ## def exec_after_process(app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
73 ## pass
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
74
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
75
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
76 def exec_after_merge(app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
77 exec_after_process(
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
78 app, inp_data, out_data, param_dict, tool=tool, stdout=stdout, stderr=stderr)
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
79
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
80 # strip strand column if clusters were merged
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
81 items = out_data.items()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
82 for name, data in items:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
83 if param_dict['returntype'] == True:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
84 data.metadata.chromCol = 1
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
85 data.metadata.startCol = 2
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
86 data.metadata.endCol = 3
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
87 # merge always clobbers strand
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
88 data.metadata.strandCol = None
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
89
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
90
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
91 def exec_after_cluster(app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
92 exec_after_process(
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
93 app, inp_data, out_data, param_dict, tool=tool, stdout=stdout, stderr=stderr)
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
94
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
95 # strip strand column if clusters were merged
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
96 if param_dict["returntype"] == '1':
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
97 items = out_data.items()
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
98 for name, data in items:
5b3c6135a982 Imported from capsule None
devteam
parents:
diff changeset
99 data.metadata.strandCol = None