Mercurial > repos > peterjc > mira4_assembler
annotate tools/mira4_0/mira4_validator.py @ 38:cee8f9005e43 draft
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 206259620376b322fc8ed99a6efdd3712f38764b
author | peterjc |
---|---|
date | Wed, 11 Jul 2018 12:35:35 -0400 |
parents | 56b421d59805 |
children | bbf14bb9607b |
rev | line source |
---|---|
38
cee8f9005e43
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 206259620376b322fc8ed99a6efdd3712f38764b
peterjc
parents:
32
diff
changeset
|
1 """Python code to validate parameters in the Galaxy XML definition.""" |
cee8f9005e43
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 206259620376b322fc8ed99a6efdd3712f38764b
peterjc
parents:
32
diff
changeset
|
2 |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
3 # Called from the Galaxy Tool XML file |
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
4 # import sys |
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
5 |
25 | 6 |
7 def validate_input(trans, error_map, param_values, page_param_map): | |
38
cee8f9005e43
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 206259620376b322fc8ed99a6efdd3712f38764b
peterjc
parents:
32
diff
changeset
|
8 """Validate the min_size/max_size user input, before execution.""" |
25 | 9 err_list = [] |
10 for read_group in param_values["read_group"]: | |
11 err = dict() | |
12 segments = read_group["segments"] | |
13 if str(segments["type"]) != "paired": | |
14 err_list.append(dict()) | |
15 continue | |
16 | |
17 min_size = str(segments["min_size"]).strip() | |
18 max_size = str(segments["max_size"]).strip() | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
19 # sys.stderr.write("DEBUG min_size=%r, max_size=%r\n" % (min_size, max_size)) |
25 | 20 |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
21 # Somehow Galaxy seems to turn an empty field into string "None"... |
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
22 if min_size == "None": |
25 | 23 min_size = "" |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
24 if max_size == "None": |
25 | 25 max_size = "" |
26 | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
27 if min_size == "" and max_size == "": |
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
28 # Both missing is good |
25 | 29 pass |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
30 elif min_size == "": |
25 | 31 err["min_size"] = "Minimum size required if maximum size given" |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
32 elif max_size == "": |
25 | 33 err["max_size"] = "Maximum size required if minimum size given" |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
34 |
25 | 35 if min_size: |
36 try: | |
37 min_size_int = int(min_size) | |
38 if min_size_int < 0: | |
39 err["min_size"] = "Minumum size must not be negative (%i)" % min_size_int | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
40 min_size = None # Avoid doing comparison below |
25 | 41 except ValueError: |
42 err["min_size"] = "Minimum size is not an integer (%s)" % min_size | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
43 min_size = None # Avoid doing comparison below |
25 | 44 |
45 if max_size: | |
46 try: | |
47 max_size_int = int(max_size) | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
48 if max_size_int < 0: |
25 | 49 err["max_size"] = "Maximum size must not be negative (%i)" % max_size_int |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
50 max_size = None # Avoid doing comparison below |
25 | 51 except ValueError: |
52 err["max_size"] = "Maximum size is not an integer (%s)" % max_size | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
53 max_size = None # Avoid doing comparison below |
25 | 54 |
55 if min_size and max_size and min_size_int > max_size_int: | |
56 msg = "Minimum size must be less than maximum size (%i vs %i)" % (min_size_int, max_size_int) | |
57 err["min_size"] = msg | |
58 err["max_size"] = msg | |
59 | |
60 if err: | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
61 err_list.append({"segments": err}) |
25 | 62 else: |
63 err_list.append(dict()) | |
64 | |
65 if any(err_list): | |
32
56b421d59805
planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents:
25
diff
changeset
|
66 # Return an error map only if any readgroup gave errors |
25 | 67 error_map["read_group"] = err_list |