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