annotate tools/mira4_0/mira4_validator.py @ 2:4eb32a3d67d1 draft

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