Mercurial > repos > bgruening > cp_measure_image_area_occupied
annotate cp_common_functions.py @ 6:a32c3f810ade draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author | bgruening |
---|---|
date | Sun, 05 Nov 2023 09:35:09 +0000 |
parents | 20dbb1f7ec7b |
children |
rev | line source |
---|---|
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
1 INDENTATION = " " |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
2 LINE_NUM_MODULES = 4 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
3 |
4
20dbb1f7ec7b
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
bgruening
parents:
2
diff
changeset
|
4 |
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
5 def get_json_value(json_input, keys_path): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
6 """Returns the value specified in keys_path (using dot notation) or an empty string if the key doesn't exist""" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
7 if not isinstance(json_input, dict): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
8 return "" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
9 keys = keys_path.split(".") |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
10 try: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
11 value = json_input[keys[0]] |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
12 for key in keys[1:]: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
13 value = value[key] |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
14 return value |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
15 except KeyError: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
16 return "" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
17 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
18 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
19 def concat_conditional(a, b): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
20 if a == "" or b == "": |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
21 return "" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
22 else: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
23 return f"{a}_{b}" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
24 |
4
20dbb1f7ec7b
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
bgruening
parents:
2
diff
changeset
|
25 |
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
26 def get_total_number_of_modules(pipeline_lines): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
27 """Gets the number of modules from the header of the previous pipeline""" |
6
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
28 number_of_modules = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[1] |
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
29 return int(number_of_modules) |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
30 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
31 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
32 def get_pipeline_lines(input_pipeline): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
33 """Returns a list with the lines in the .cppipe file""" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
34 with open(input_pipeline) as f: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
35 lines = f.readlines() |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
36 return lines |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
37 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
38 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
39 def update_module_count(pipeline_lines, count): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
40 """Updates the number of modules in the .cppipe header""" |
6
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
41 module_count_entry = pipeline_lines[LINE_NUM_MODULES].strip().split(":")[0] |
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
42 pipeline_lines[4] = f"{module_count_entry}:{count}\n" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
43 return pipeline_lines |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
44 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
45 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
46 def write_pipeline(filename, lines_pipeline): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
47 """Writes the lines composing the pipeline into a file""" |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
48 with open(filename, "w") as f: |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
49 f.writelines(lines_pipeline) |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
50 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
51 |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
52 def build_header(module_name, module_number): |
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
53 """Creates the first line of a module given the name and module number""" |
6
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
54 result = "|".join( |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
55 [ |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
56 f"{module_name}:[module_num:{module_number}", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
57 "svn_version:\\'Unknown\\'", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
58 "variable_revision_number:4", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
59 "show_window:False", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
60 "notes:\\x5B\\x5D", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
61 "batch_state:array(\\x5B\\x5D, dtype=uint8)", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
62 "enabled:True", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
63 "wants_pause:False]\n", |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
64 ] |
a32c3f810ade
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
bgruening
parents:
4
diff
changeset
|
65 ) |
2
534ed7b8ca34
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
bgruening
parents:
diff
changeset
|
66 return result |