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