Source code

Download source archive ↓

upstream/tools/cellprofiler/mask_image.xml

1<tool id="cp_mask_image" name="MaskImage" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@">
2    <description>with CellProfiler</description>
3
4    <macros>
5        <import>macros.xml</import>
6        <token name="@VERSION_SUFFIX@">1</token>
7    </macros>
8
9    <edam_operations>
10        <edam_operation>operation_3443</edam_operation>
11    </edam_operations>
12    <xrefs>
13        <xref type="bio.tools">CellProfiler</xref>
14        <xref type="biii">cellprofiler</xref>
15    </xrefs>
16
17    <expand macro="py_requirements"/>
18    <expand macro="cmd_modules" /> 
19
20    <configfiles>
21        <inputs name="inputs"/>
22        <configfile name="script_file">
23import json
24import sys
25import os
26
27FOURSPACES=@SPACES@
28
29input_json_path = sys.argv[1]
30input_pipeline= sys.argv[2]
31
32params = json.load(open(input_json_path, "r"))
33
34def writemi():
35    _str = "\nMaskImage:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:3|show_window:False|notes:\\x5B\'Keep only nucleoli inside the nuclei\\'\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count
36
37    _str += FOURSPACES + "Select the input image:%s\n" % params['input_image']
38    _str += FOURSPACES + "Name the output image:%s\n" % params['name_output_image']
39
40    img_obj = params['con_img_obj']['img_obj']
41
42    _str += FOURSPACES + "Use objects or an image as a mask?:%s\n" % params['con_img_obj']['img_obj']
43
44    if img_obj == "Objects":
45        _str += FOURSPACES + "Select object for mask:%s\n" % params['con_img_obj']['select_obj']
46        _str += FOURSPACES + "Select image for mask:None\n"
47    else:
48        _str += FOURSPACES + "Select object for mask:None\n"
49        _str += FOURSPACES + "Select image for mask:%s\n" % params['con_img_obj']['select_img']
50
51    _str += FOURSPACES + "Invert the mask?:%s\n" % params['invert_mask']
52
53    return _str
54
55with open(input_pipeline) as fin:
56    lines = fin.readlines()
57
58    k, v = lines[4].strip().split(':')
59
60    module_count = int(v)
61    new_count = module_count + 1
62    lines[4] = k + ":%d\n" % new_count
63
64    with open("output.cppipe", "w") as f:
65        f.writelines(lines)
66        f.write(writemi())
67
68    f.close()
69        </configfile>
70    </configfiles>
71
72    <inputs>
73
74        <expand macro="input_pipeline_param" />
75        <param name="input_image" label="Enter the name of the input image" type="text">
76            <expand macro="text_validator" />
77        </param>
78
79        <param name="name_output_image" type="text" label="Enter the name of the resulting image">
80            <expand macro="text_validator" />
81        </param>
82
83        <conditional name="con_img_obj">
84            <param name="img_obj" label="Use objects or an image as a mask?" type="select">
85                <help>
86                    <![CDATA[
87                        You can mask an image in two ways:
88                        <br> - Objects: Using objects created by another module (for instance IdentifyPrimaryObjects).
89                        The module will mask out all parts of the image that are not within one of the objects (unless you invert the mask).
90                        <br> - Image: Using a binary image as the mask, where black portions of the image (false or zero-value pixels) will be masked out.
91                        If the image is not binary, the module will use all pixels whose intensity is greater than 0.5 as the mask’s foreground (white area).
92                        You can use Threshold instead to create a binary image with finer control over the intensity choice.
93                        ]]>
94                </help>
95                <option value="Objects">Objects</option>
96                <option value="Image">Image</option>
97            </param>
98            <when value="Objects">
99                <param name="select_obj" label="Enter the name objects to mask the input image" type="text"/>
100            </when>
101            <when value="Image">
102                <param name="select_img" label="Select image for mask" type="text"/>
103            </when>
104        </conditional>
105        <param name="invert_mask" label="Invert the mask?" type="select" display="radio">
106            <help>
107                <![CDATA[
108                    This option reverses the foreground/background relationship of the mask.
109                    <br> - Select "No" to produce the mask from the foreground (white portion) of the masking image or the area within the masking objects.
110                    <br> - Select "Yes" to instead produce the mask from the background (black portions) of the masking image or the area outside the masking objects.
111                    ]]>
112            </help>
113            <option value="Yes">Yes</option>
114            <option value="No">No</option>
115        </param>
116    </inputs>
117
118    <outputs>
119        <expand macro="output_pipeline_param" />
120    </outputs>
121
122    <tests>
123        <test>
124            <expand macro="test_input_pipeline_param"/>
125            <param name="input_image" value="DNAdarkholes" />
126            <param name="name_output_image" value="MaskDNAdarkholes" />
127            <conditional name="con_img_obj">
128                <param name="img_obj" value="Objects" />
129                <param name="select_obj" value="Nuclei" />
130            </conditional>
131            <param name="invert_mask" value="No" />
132            <expand macro="test_out_file" file="mask_image.cppipe" />
133        </test>
134    </tests>
135
136    <help>
137        <![CDATA[
138            .. class:: infomark
139
140            **What it does**
141
142            This tool masks an image so you can use the mask downstream in the pipeline.
143            The masked image is based on the original image and the masking object or image that is selected.
144            If using a masking image, the mask is composed of the foreground (white portions);
145            if using a masking object, the mask is composed of the area within the object.
146            Note that the image created by this tool for further processing downstream is grayscale.
147            If a binary mask is desired in subsequent tools, use the Threshold tool instead of MaskImage.
148
149            @COMMON_HELP@
150            ]]>
151    </help>
152
153    <expand macro="citations" />
154
155</tool>