comparison cp_common_functions.py @ 2:b6f13e783ac5 draft

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