view measure_image_area_occupied.xml @ 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 91e03287f285
children
line wrap: on
line source

<tool id="cp_measure_image_area_occupied" name="MeasureImageAreaOccupied" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@">
    <description>with CellProfiler</description>

    <macros>
        <import>macros.xml</import>
        <token name="@VERSION_SUFFIX@">1</token>
    </macros>

    <edam_operations>
        <edam_operation>operation_3443</edam_operation>
    </edam_operations>
    <xrefs>
        <xref type="bio.tools">CellProfiler</xref>
        <xref type="biii">cellprofiler</xref>
    </xrefs>

    <expand macro="py_requirements"/>
    <expand macro="cmd_modules" />

    <configfiles>
        <inputs name="inputs" />
        <configfile name="script_file">
import json
import sys
import os

FOURSPACES=@SPACES@

input_json_path = sys.argv[1]
input_pipeline= sys.argv[2]

params = json.load(open(input_json_path, "r"))

def writemiao():
    _str = "\nMeasureImageAreaOccupied:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:4|show_window:False|notes:\\x5B\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    hidden = len(params['rpt_area'])

    _str += FOURSPACES + "Hidden:%d\n" % hidden

    for area in params['rpt_area']:
        _str += FOURSPACES + "Measure the area occupied in a binary image, or in objects?:%s\n" % area['con_area']['objects_or_image']

        obj_flag = area['con_area']['objects_or_image']

        if obj_flag == "Objects":
            _str += FOURSPACES + "Select objects to measure:%s\n" % area['con_area']['objects_to_measure']
            _str += FOURSPACES + "Select a binary image to measure:None\n"
        else:
            _str += FOURSPACES + "Select objects to measure:None\n"
            _str += FOURSPACES + "Select a binary image to measure:%s\n" % area['con_area']['image_to_measure']

    return _str


with open(input_pipeline) as fin:
    lines = fin.readlines()

    k, v = lines[4].strip().split(':')

    module_count = int(v)
    new_count = module_count + 1
    lines[4] = k + ":%d\n" % new_count
    with open("output.cppipe", "w") as f:
        f.writelines(lines)
        f.write(writemiao())

    f.close()
        </configfile>
    </configfiles>

    <inputs>
        <expand macro="input_pipeline_param" />
        <repeat name="rpt_area" title="new area" min="1">
            <conditional name="con_area">
                <param name="objects_or_image" label="Measure the area occupied in a binary image, or in objects?" type="select">
                    <help>
                        <![CDATA[
                            The area can be measured in two ways:
                            <br> - Binary Image: The area occupied by the foreground in a binary (black and white) image.
                            <br> - Objects: The area occupied by previously-identified objects.
                            ]]>
                    </help>
                    <option value="Binary image">Binary image</option>
                    <option value="Objects">Objects</option>
                </param>
                <when value="Objects">
                    <param name="objects_to_measure" label="Enter the name of the objects to measure" type="text">
                        <expand macro="text_validator" />
                    </param>
                </when>
                <when value="Binary image">
                    <param name="image_to_measure" label="Enter the name of a binary image to measure" type="text">
                        <expand macro="text_validator" />
                    </param>
                </when>
            </conditional>
        </repeat>
    </inputs>

    <outputs>
        <expand macro="output_pipeline_param" />
    </outputs>

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />
            <repeat name="rpt_area">
                <conditional name="con_area">
                    <param name="objects_or_image" value="Objects" />
                    <param name="objects_to_measure" value="Nuclei" />
                </conditional>
            </repeat>
            <repeat name="rpt_area">
                <conditional name="con_area">
                    <param name="objects_or_image" value="Objects" />
                    <param name="objects_to_measure" value="Nucleoli" />
                </conditional>
            </repeat>
            <expand macro="test_out_file" file="measure_image_area_occupied.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[

            .. class:: infomark

            **What it does**
            This tool reports the sum of the areas and perimeters of the objects defined by one of the Identify modules, or the area of the foreground in a binary image.
            If the input image has a mask (for example, created by the MaskImage module), the measurements made by this module will take the mask into account by ignoring the pixels outside the mask.
            You can use this tool to measure the number of pixels above a given threshold if you precede it with thresholding performed by Threshold, and then select the binary image output by Threshold to be measured by this module.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />
</tool>