annotate tools/mira4/mira4_validator.py @ 0:6a88b42ce6b9 draft

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