view measure_granularity.xml @ 6:2564f461de62 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:33:44 +0000
parents ac5bea85a391
children
line wrap: on
line source

<tool id="cp_measure_granularity" name="MeasureGranularity" 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 writemg():
    _str = "\nMeasureGranularity:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:3|show_window:False|notes:\\x5B\\'PARAMS\\x3A\\', \\'- Radius\\', \'- Range\\'\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    image_count = len(params['rpt_image'])

    _str += FOURSPACES + "Image count:%d\n" % image_count

    for img in params['rpt_image']:
        obj_count = len(img['rpt_object'])

        _str += FOURSPACES + "Object count:%d\n" % obj_count

        _str += FOURSPACES + "Select an image to measure:%s\n" % img['image_to_measure']

        _str += FOURSPACES + "Subsampling factor for granularity measurements:%s\n" % img['subsampling_factor_granularity']

        _str += FOURSPACES + "Subsampling factor for background reduction:%.2f\n" % img['subsampling_factor_background_reduction']

        _str += FOURSPACES + "Radius of structuring element:%d\n" % img['radius']
        _str += FOURSPACES + "Range of the granular spectrum:%d\n" % img['range_granular_spectrum']

        for obj in img['rpt_object']:
            _str += FOURSPACES + "Select objects to meausre:%s\n" % obj['object_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(writemg())

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

    <inputs>
        <expand macro="input_pipeline_param" />
        <repeat name="rpt_image" title="new image" min="1">
            <param name="image_to_measure" type="text" label="Enter the name of a greyscale image to measure">
                <expand macro="text_validator" />
            </param>

            <param name="subsampling_factor_granularity" type="float" value="0.25" label="Subsampling factor for granularity measurements" help="A factor lower than 1 if the textures of interest are larger than a few pixels. A factor greater than 1 might increase the accuracy but also require more processing time. Images are typically of higher resolution than is required for granularity measurements, so the default value is 0.25."/>

            <param name="subsampling_factor_background_reduction" type="float" value="0.25" min="0.125" max="0.25" label="Subsampling factor for background reduction" help="A small factor should be used if the structures of interest are large." />

            <param name="radius" type="integer" value="10" label="Radius of structuring element" help="This radius should correspond to the radius of the textures of interest after subsampling." />

            <param name="range_granular_spectrum" type="integer" value="16" label="Range of the granular spectrum" help="You may need a trial run to see which granular spectrum range yields informative measurements. Start by using a wide spectrum and narrow it down to the informative range to save time." />

            <repeat name="rpt_object" title="new object">
                <param name="object_to_measure" type="text" label="Enter the name of the object whose granularity will be measured" help="You can select objects from prior modules that identify objects, such as IdentifyPrimaryObjects. If you only want to measure the granularity for the image overall, you can remove all objects.">
                    <expand macro="text_validator" />
                </param>
            </repeat>
        </repeat>
    </inputs>

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

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />
            <repeat name="rpt_image">
                <param name="image_to_measure" value="DNA" />
                <param name="subsampling_factor_granularity" value="0.25" />
                <param name="subsampling_factor_background_reduction" value="0.25" />
                <param name="radius" value="10" />
                <param name="range_granular_spectrum" value="16" />
            </repeat>
            <expand macro="test_out_file" file="measure_granularity.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[

            .. class:: infomark

            **What it does**

            Image granularity is a texture measurement that tries to fit a series of structure elements of increasing size into the texture of the image and outputs a spectrum of measures based on how well they fit. Granularity is measured as described by Ilya Ravkin (in the paper *Bit representation techniques and image processing*). The size of the starting structure element as well as the range of the spectrum is given as input.

            @COMMON_HELP@
            ]]>
    </help>
    <expand macro="citations" />
</tool>