4
|
1 # Called from the Galaxy Tool XML file
|
|
2 # import sys
|
|
3
|
2
|
4
|
|
5 def validate_input(trans, error_map, param_values, page_param_map):
|
|
6 """Validates the min_size/max_size user input, before execution."""
|
|
7 err_list = []
|
|
8 for read_group in param_values["read_group"]:
|
|
9 err = dict()
|
|
10 segments = read_group["segments"]
|
|
11 if str(segments["type"]) != "paired":
|
|
12 err_list.append(dict())
|
|
13 continue
|
|
14
|
|
15 min_size = str(segments["min_size"]).strip()
|
|
16 max_size = str(segments["max_size"]).strip()
|
4
|
17 # sys.stderr.write("DEBUG min_size=%r, max_size=%r\n" % (min_size, max_size))
|
2
|
18
|
4
|
19 # Somehow Galaxy seems to turn an empty field into string "None"...
|
|
20 if min_size == "None":
|
2
|
21 min_size = ""
|
4
|
22 if max_size == "None":
|
2
|
23 max_size = ""
|
|
24
|
4
|
25 if min_size == "" and max_size == "":
|
|
26 # Both missing is good
|
2
|
27 pass
|
4
|
28 elif min_size == "":
|
2
|
29 err["min_size"] = "Minimum size required if maximum size given"
|
4
|
30 elif max_size == "":
|
2
|
31 err["max_size"] = "Maximum size required if minimum size given"
|
4
|
32
|
2
|
33 if min_size:
|
|
34 try:
|
|
35 min_size_int = int(min_size)
|
|
36 if min_size_int < 0:
|
|
37 err["min_size"] = "Minumum size must not be negative (%i)" % min_size_int
|
4
|
38 min_size = None # Avoid doing comparison below
|
2
|
39 except ValueError:
|
|
40 err["min_size"] = "Minimum size is not an integer (%s)" % min_size
|
4
|
41 min_size = None # Avoid doing comparison below
|
2
|
42
|
|
43 if max_size:
|
|
44 try:
|
|
45 max_size_int = int(max_size)
|
4
|
46 if max_size_int < 0:
|
2
|
47 err["max_size"] = "Maximum size must not be negative (%i)" % max_size_int
|
4
|
48 max_size = None # Avoid doing comparison below
|
2
|
49 except ValueError:
|
|
50 err["max_size"] = "Maximum size is not an integer (%s)" % max_size
|
4
|
51 max_size = None # Avoid doing comparison below
|
2
|
52
|
|
53 if min_size and max_size and min_size_int > max_size_int:
|
|
54 msg = "Minimum size must be less than maximum size (%i vs %i)" % (min_size_int, max_size_int)
|
|
55 err["min_size"] = msg
|
|
56 err["max_size"] = msg
|
|
57
|
|
58 if err:
|
4
|
59 err_list.append({"segments": err})
|
2
|
60 else:
|
|
61 err_list.append(dict())
|
|
62
|
|
63 if any(err_list):
|
4
|
64 # Return an error map only if any readgroup gave errors
|
2
|
65 error_map["read_group"] = err_list
|