comparison image_math.py @ 2:c956182d4e2cdraft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
author bgruening Thu, 16 Apr 2020 05:32:53 -0400 f8fa0f6718a3
comparison
equal inserted replaced
1:c0759ca34e20 2:c956182d4e2c
1 #!/usr/bin/env python
2
3 import json
4 import sys
5 import os
6 import argparse
7 from cp_common_functions import *
8
9 MODULE_NAME = "ImageMath"
10 OUTPUT_FILENAME = "output.cppipe"
11
12 operator_map = {
14 "subtract": "Subtract",
15 "multiply": "Multiply",
16 "divide": "Divide",
17 "average": "Average",
18 "minimum": "Minimum",
19 "maximum": "Maximum",
20 "invert": "Invert",
21 "log_2": "Log transform (base 2)",
22 "log_legacy": "Log transform (legacy)",
23 "and": "And",
24 "or": "Or",
25 "not": "Not",
26 "equals": "Equals"
27 }
28
29
30 def build_main_block(input_params):
31 """Creates the main block of the CP pipeline with the parameters that don't depend on conditional choices"""
32 operation = operator_map[get_json_value(
33 input_params, 'operation.operation')]
34 result = INDENTATION.join([f"{INDENTATION}Operation:{operation}\n",
35 f"Raise the power of the result by:{get_json_value(input_params,'operation.op_results.raise_the_power_of_the_result_by')}\n",
36 f"Multiply the result by:{get_json_value(input_params,'operation.op_results.multiply_the_result_by')}\n",
38 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",
39 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",
41 f"Name the output image:{get_json_value(input_params,'name_output_image')}"
42 ])
43 return result
44
45
46 def build_variable_block(inputs_galaxy):
47 result = ""
48 first_image_block = build_first_image_block(
49 get_json_value(inputs_galaxy, 'operation.first_image'))
50 result += f"\n{first_image_block}"
51 second_image_block = build_second_image_block(
52 get_json_value(inputs_galaxy, 'operation.second_image'))
53 result += f"\n{second_image_block}"
54 return result
55
56
57 def build_first_image_block(input_params):
58 """Creates the block of parameters for the first operator in operations"""
59
60 value_select = get_json_value(
61 input_params, 'image_or_measurement_first.image_or_measurement_first')
62 image_name = get_json_value(
63 input_params, 'image_or_measurement_first.select_the_first_image')
64 value_multiply = get_json_value(
65 input_params, 'multiply_the_first_image_by')
66 category = get_json_value(
67 input_params, 'image_or_measurement_first.category_first.category_first')
68 measurement = get_json_value(
69 input_params, 'image_or_measurement_first.category_first.measurement_first')
70
71 result = INDENTATION.join(
72 [f"{INDENTATION}Image or measurement?:{value_select}\n",
73 f"Select the first image:{image_name}\n",
74 f"Multiply the first image by:{value_multiply}\n",
75 f"Measurement:{concat_conditional(category, measurement)}"
76 ])
77 return result
78
79
80 def build_second_image_block(input_params):
81 """Creates the block of parameters for the second operator in binary operations"""
82
83 value_select = get_json_value(
84 input_params, 'image_or_measurement_second.image_or_measurement_second')
85 image_name = get_json_value(
86 input_params, 'image_or_measurement_second.select_the_second_image')
87 value_multiply = get_json_value(
88 input_params, 'multiply_the_second_image_by')
89 category = get_json_value(
90 input_params, 'image_or_measurement_second.category_second.category_second')
91 measurement = get_json_value(
92 input_params, 'image_or_measurement_second.category_second.measurement_second')
93
94 result = INDENTATION.join(
95 [f"{INDENTATION}Image or measurement?:{value_select}\n",
96 f"Select the second image:{image_name}\n",
97 f"Multiply the second image by:{value_multiply}\n",
98 f"Measurement:{concat_conditional(category, measurement)}"
99 ])
100 return result
101
102
103 if __name__ == "__main__":
104 parser = argparse.ArgumentParser()
106 '-p', '--pipeline',
107 help='CellProfiler pipeline'
108 )
110 '-i', '--inputs',
111 help='JSON inputs from Galaxy'
112 )
113 args = parser.parse_args()
114
115 pipeline_lines = get_pipeline_lines(args.pipeline)