Mercurial > repos > bgruening > cp_overlay_outlines
annotate image_math.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 | 
| rev | line source | 
|---|---|
| 
0
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
2 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
4 import json | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
5 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
6 from cp_common_functions import build_header | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
7 from cp_common_functions import concat_conditional | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
8 from cp_common_functions import get_json_value | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
9 from cp_common_functions import get_pipeline_lines | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
10 from cp_common_functions import get_total_number_of_modules | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
11 from cp_common_functions import INDENTATION | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
12 from cp_common_functions import update_module_count | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
13 from cp_common_functions import write_pipeline | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
14 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
15 MODULE_NAME = "ImageMath" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
16 OUTPUT_FILENAME = "output.cppipe" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
17 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
18 operator_map = { | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
19 "add": "Add", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
20 "subtract": "Subtract", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
21 "multiply": "Multiply", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
22 "divide": "Divide", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
23 "average": "Average", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
24 "minimum": "Minimum", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
25 "maximum": "Maximum", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
26 "invert": "Invert", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
27 "log_2": "Log transform (base 2)", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
28 "log_legacy": "Log transform (legacy)", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
29 "and": "And", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
30 "or": "Or", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
31 "not": "Not", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
32 "equals": "Equals" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
33 } | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
34 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
35 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
36 def build_main_block(input_params): | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
37 """Creates the main block of the CP pipeline with the parameters that don't depend on conditional choices""" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
38 operation = operator_map[get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
39 input_params, 'operation.operation')] | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
40 result = INDENTATION.join([f"{INDENTATION}Operation:{operation}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
41 f"Raise the power of the result by:{get_json_value(input_params,'operation.op_results.raise_the_power_of_the_result_by')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
42 f"Multiply the result by:{get_json_value(input_params,'operation.op_results.multiply_the_result_by')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
43 f"Add to result:{get_json_value(input_params,'operation.op_results.add_to_result')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
44 f"Set values less than 0 equal to 0?:{get_json_value(input_params,'operation.op_results.set_values_less_than_0_equal_to_0')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
45 f"Set values greater than 1 equal to 1?:{get_json_value(input_params,'operation.op_results.set_values_greater_than_1_equal_to_1')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
46 f"Ignore the image masks?:{get_json_value(input_params,'ignore_the_image_masks')}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
47 f"Name the output image:{get_json_value(input_params,'name_output_image')}" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
48 ]) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
49 return result | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
50 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
51 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
52 def build_variable_block(inputs_galaxy): | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
53 result = "" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
54 first_image_block = build_first_image_block( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
55 get_json_value(inputs_galaxy, 'operation.first_image')) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
56 result += f"\n{first_image_block}" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
57 second_image_block = build_second_image_block( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
58 get_json_value(inputs_galaxy, 'operation.second_image')) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
59 result += f"\n{second_image_block}" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
60 return result | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
61 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
62 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
63 def build_first_image_block(input_params): | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
64 """Creates the block of parameters for the first operator in operations""" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
65 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
66 value_select = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
67 input_params, 'image_or_measurement_first.image_or_measurement_first') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
68 image_name = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
69 input_params, 'image_or_measurement_first.select_the_first_image') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
70 value_multiply = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
71 input_params, 'multiply_the_first_image_by') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
72 category = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
73 input_params, 'image_or_measurement_first.category_first.category_first') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
74 measurement = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
75 input_params, 'image_or_measurement_first.category_first.measurement_first') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
76 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
77 result = INDENTATION.join( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
78 [f"{INDENTATION}Image or measurement?:{value_select}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
79 f"Select the first image:{image_name}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
80 f"Multiply the first image by:{value_multiply}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
81 f"Measurement:{concat_conditional(category, measurement)}" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
82 ]) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
83 return result | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
84 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
85 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
86 def build_second_image_block(input_params): | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
87 """Creates the block of parameters for the second operator in binary operations""" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
88 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
89 value_select = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
90 input_params, 'image_or_measurement_second.image_or_measurement_second') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
91 image_name = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
92 input_params, 'image_or_measurement_second.select_the_second_image') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
93 value_multiply = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
94 input_params, 'multiply_the_second_image_by') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
95 category = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
96 input_params, 'image_or_measurement_second.category_second.category_second') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
97 measurement = get_json_value( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
98 input_params, 'image_or_measurement_second.category_second.measurement_second') | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
99 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
100 result = INDENTATION.join( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
101 [f"{INDENTATION}Image or measurement?:{value_select}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
102 f"Select the second image:{image_name}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
103 f"Multiply the second image by:{value_multiply}\n", | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
104 f"Measurement:{concat_conditional(category, measurement)}" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
105 ]) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
106 return result | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
107 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
108 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
109 if __name__ == "__main__": | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
110 parser = argparse.ArgumentParser() | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
111 parser.add_argument( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
112 '-p', '--pipeline', | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
113 help='CellProfiler pipeline' | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
114 ) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
115 parser.add_argument( | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
116 '-i', '--inputs', | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
117 help='JSON inputs from Galaxy' | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
118 ) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
119 args = parser.parse_args() | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
120 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
121 pipeline_lines = get_pipeline_lines(args.pipeline) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
122 inputs_galaxy = json.load(open(args.inputs, "r")) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
123 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
124 current_module_num = get_total_number_of_modules(pipeline_lines) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
125 current_module_num += 1 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
126 pipeline_lines = update_module_count(pipeline_lines, current_module_num) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
127 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
128 header_block = build_header(MODULE_NAME, current_module_num) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
129 main_block = build_main_block(inputs_galaxy) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
130 variable_block = build_variable_block(inputs_galaxy) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
131 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
132 module_pipeline = f"\n{header_block}{main_block}{variable_block}\n" | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
133 pipeline_lines.append(module_pipeline) | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
134 | 
| 
 
39006f6fd6bf
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 35da2dcd86747c9bff138e100dbe08c6106f3780"
 
bgruening 
parents:  
diff
changeset
 | 
135 write_pipeline(OUTPUT_FILENAME, pipeline_lines) | 
