1
|
1
|
|
2 from galaxy.tools.parameters import DataToolParameter
|
|
3
|
|
4 def get_matrix_header( input_dataset ):
|
|
5 """
|
|
6 Not used currently, because the reload of the ckeckboxes did not work.
|
|
7 """
|
|
8 input_handle = open( input_dataset.file_name )
|
|
9 first_header = input_handle.readline()
|
|
10 second_header = input_handle.readline()
|
|
11 return [('%s::%s' % (cname2,cname1), str(int(col_num) + 1), False) for col_num, (cname2, cname1) in enumerate(zip(second_header.split()[1:],first_header.split()[1:])) ]
|
|
12
|
|
13
|
|
14
|
|
15 def _construct_error_map( error_map, rep_dict, rep_parent, child, error_value ):
|
|
16 """
|
|
17 Its no so easy to create a propper error_map for repetitions in Galaxy.
|
|
18 This is a helper function.
|
|
19 """
|
|
20
|
|
21 error_map[ rep_parent ] = [ dict() for t in rep_dict ]
|
|
22 for i in range( len( rep_dict ) ):
|
|
23 error_map[ rep_parent ][i][ child ] = error_value
|
|
24
|
|
25
|
|
26
|
|
27 def validate_input( trans, error_map, param_values, page_param_map ):
|
|
28 """
|
|
29 Validates the user input, before execution.
|
|
30 """
|
|
31 factors = param_values['rep_factorName']
|
|
32 factor_name_list = []
|
|
33 factor_duplication = False
|
|
34 level_duplication = False
|
|
35 overlapping_selection = False
|
|
36
|
|
37 first_condition = True
|
|
38 factor_indieces = list()
|
|
39
|
|
40 for factor in factors:
|
|
41 # factor names should be unique
|
|
42 fn = factor['factorName']
|
|
43 if fn in factor_name_list:
|
|
44 factor_duplication = True
|
|
45 break
|
|
46 factor_name_list.append( fn )
|
|
47
|
|
48 level_name_list = list()
|
|
49 factor_index_list = list()
|
|
50
|
|
51 if first_condition and len( factor['rep_factorLevel'] ) < 2:
|
|
52 # first condition needs to have at least 2 levels
|
|
53 _construct_error_map( error_map, factors, 'rep_factorName', 'rep_factorLevel', [ {'factorLevel': 'The first condition should have at least 2 factor'} for t in factor['rep_factorLevel'] ] )
|
|
54
|
|
55 for level in factor['rep_factorLevel']:
|
|
56 # level names under one factor should be unique
|
|
57 fl = level['factorLevel']
|
|
58 if fl in level_name_list:
|
|
59 level_duplication = True
|
|
60 level_name_list.append( fl )
|
|
61
|
|
62 fi = level['factorIndex']
|
|
63 if fi:
|
|
64 # the checkboxes should not have an overlap
|
|
65 for check in fi:
|
|
66 if check in factor_index_list:
|
|
67 overlapping_selection = True
|
|
68 factor_index_list.append( check )
|
|
69
|
|
70 print set(factor_index_list)
|
|
71 print factor_indieces
|
|
72 if set(factor_index_list) in factor_indieces:
|
|
73 _construct_error_map( error_map, factors, 'rep_factorName', 'rep_factorLevel', [ {'factorLevel': 'It is not allowed to have two identical factors, that means two factors with the same toggeled checked boxes. '} for t in factor['rep_factorLevel'] ] )
|
|
74 else:
|
|
75 factor_indieces.append( set(factor_index_list) )
|
|
76
|
|
77
|
|
78
|
|
79 if level_duplication:
|
|
80 error_map['rep_factorName'] = [ dict() for t in factors ]
|
|
81 for i in range( len( factors ) ):
|
|
82 error_map['rep_factorName'][i]['rep_factorLevel'] = [ {'factorLevel': 'Factor levels for each factor need to be unique'} for t in factor['rep_factorLevel'] ]
|
|
83 break
|
|
84 if overlapping_selection:
|
|
85 error_map['rep_factorName'] = [ dict() for t in factors ]
|
|
86 for i in range( len( factors ) ):
|
|
87 error_map['rep_factorName'][i]['rep_factorLevel'] = [ {'factorIndex': 'The samples from different factors are not allowed to overlap'} for t in factor['rep_factorLevel'] ]
|
|
88 break
|
|
89
|
|
90 first_condition = False
|
|
91
|
|
92 if factor_duplication:
|
|
93 _construct_error_map( error_map, factors, 'rep_factorName', 'factorName', 'Factor names need to be unique' )
|
|
94 """
|
|
95 error_map['rep_factorName'] = [ dict() for t in factors ]
|
|
96 for i in range( len( factors ) ):
|
|
97 error_map['rep_factorName'][i]['factorName'] = 'Factor names need to be unique'
|
|
98 """
|