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