annotate operation_filter.py @ 0:d958d5a0d1e8

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