view relate_objects.xml @ 6:48102a685037 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:27:30 +0000
parents 3a3033222f61
children
line wrap: on
line source

<tool id="cp_relate_objects" name="RelateObjects" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@">
    <description>with CellProfiler</description>
    <macros>
        <import>macros.xml</import>
        <token name="@VERSION_SUFFIX@">1</token>
        <xml name="distToOtherParents">
            <conditional name="con_other_parent_dist">
                <param name="calc_dist_to_others" label="Calculate distances to other parents?" display="radio" type="select">
                    <option value="Yes">Yes</option>
                    <option value="No">No</option>
                </param>
                <when value="Yes">
                    <repeat name="rpt_parent_name" title="Parent Name">
                        <param name="other_parent_name" type="text" label="Parent name">
                            <expand macro="text_validator" />
                        </param>
                    </repeat>
                </when>
                <when value="No" />
            </conditional>
        </xml>
    </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 writero():
    _str = "\nRelateObjects:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:5|show_window:False|notes:\\x5B\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    _str += FOURSPACES + "Parent objects:%s\n" % params['parent_objects']

    _str += FOURSPACES + "Child objects:%s\n" % params['child_objects']
    _str += FOURSPACES + "Calculate child-parent distances?:%s\n" % params['con_dist']['calc_dist']
    _str += FOURSPACES + "Calculate per-parent means for all child measurements?:%s\n" % params['means_for_all']

    dist_others = params['con_dist']['con_other_parent_dist']['calc_dist_to_others']

    _str += FOURSPACES + "Calculate distances to other parents?:%s\n" % dist_others

    name_flag = params['con_save_child']['save_child_as_new']
    _str += FOURSPACES + "Do you want to save the children with parents as a new object set?:%s\n" % name_flag

    if name_flag == "Yes":
        _str += FOURSPACES + "Name the output object:%s\n" % params['con_save_child']['name_output']
    else:
        _str += FOURSPACES + "Name the output object:None\n"

    if dist_others == "Yes":
        for pname in params['con_dist']['con_other_parent_dist']['rpt_parent_name']:
            _str += FOURSPACES + "Parent name:%s\n" % pname['other_parent_name']

    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(writero())

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

    <inputs>
        <expand macro="input_pipeline_param"/>
        <param name="parent_objects" label="Parent objects" value="Do not use" type="text" help="Parent objects are defined as those objects which encompass the child object. For example, when relating speckles to the nuclei that contain them, the nuclei are the parents.">
            <expand macro="text_validator" />
        </param>
        <param name="child_objects" label="Child objects" value="Do not use" type="text" help="Child objects are defined as those objects contained within the parent object. For example, when relating speckles to the nuclei that contains them, the speckles are the children.">
            <expand macro="text_validator" />
        </param>
        <param name="means_for_all" label="Calculate per-parent means for all child measurements?" display="radio" type="select">
            <help>
                <![CDATA[
                    Select 'Yes' to calculate the per-parent mean values of every upstream measurement made with the children objects and store them as a measurement for the parent. This module must be placed after all the measure modules that make measurements of the children objects.

                    ]]>
            </help>
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <conditional name="con_dist">
            <param name="calc_dist" label="Calculate child-parent distances?" type="select">
                <help>
                    <![CDATA[
                        Choose the method to calculate distances of each child to its parent.
                        For example, these measurements can tell you whether nuclear speckles are located more closely to the center of the nucleus or to the nuclear periphery.
                        <br> - None: Do not calculate any distances. This saves computation time.
                        <br> - Minimum: The distance from the centroid of the child object to the closest perimeter point on the parent object.
                        <br> - Centroid: The distance from the centroid of the child object to the centroid of the parent.
                        <br> - Both: Calculate both the Minimum and Centroid distances.
                        ]]>
                </help>
                <option value="None">None</option>
                <option value="Centroid">Centroid</option>
                <option value="Minimum">Minimum</option>
                <option value="Both">Both</option>
            </param>
            <when value="Centroid">
                <expand macro="distToOtherParents" />
            </when>
            <when value="Minimum">
                <expand macro="distToOtherParents" />
            </when>
            <when value="Both">
                <expand macro="distToOtherParents" />
            </when>
            <when value="None" />
        </conditional>
        <conditional name="con_save_child">
            <param name="save_child_as_new" label="Do you want to save the children with parents as a new object set?" display="radio" type="select" help="Select 'Yes' to save the children objects that do have parents as new object set. Objects with no parents will be discarded.">
                <option value="Yes">Yes</option>
                <option value="No">No</option>
            </param>
            <when value="Yes">
                <param name="name_output" type="text" value="RelateObjects" label="Enter a name for the output object">
                    <expand macro="text_validator" />
                </param>
            </when>
            <when value="No" />
        </conditional>
    </inputs>

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

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />

            <param name="parent_objects" value="Nuclei" />
            <param name="child_objects" value="Nucleoli" />
            <param name="means_for_all" value="Yes" />
            <conditional name="con_dist">
                <param name="calc_dist" value="Both" />
                <conditional name="con_other_parent_dist">
                    <param name="calc_dist_to_others" value="No" />
                </conditional>
            </conditional>
            <conditional name="con_save_child">
                <param name="save_child_as_new" value="Yes" />
                <param name="name_output" value="RelateObjects" />
            </conditional>

            <expand macro="test_out_file" file="relate_objects.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[

            .. class:: infomark

            **What it does**

            RelateObjects assigns relationships; all objects (e.g., speckles) within a parent object (e.g., nucleus) become its children.
            This module allows you to associate child objects with parent objects.
            This is useful for counting the number of children associated with each parent, and for calculating mean measurement values for all children that are associated with each parent.
            An object will be considered a child even if the edge is the only partly touching a parent object.
            If a child object is touching multiple parent objects, the object will be assigned to the parent with maximal overlap.
            For an alternate approach to assigning parent/child relationships, consider using the MaskObjects module.
            If you want to include child objects that lie outside but still near parent objects, you might want to expand the parent objects using ExpandOrShrink or IdentifySecondaryObjects.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />

</tool>