annotate tools/mira4_0/mira4_validator.py @ 4:1713289d9908 draft default tip

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