changeset 0:e59c0e930b1f draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
author imgteam
date Wed, 26 Jun 2024 08:03:08 +0000
parents
children
files create-config.py creators.xml plantseg.xml test-data/sample_ovule.h5 test-data/sample_ovule.tiff test-data/sample_ovule_output.h5 tests.xml
diffstat 7 files changed, 284 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/create-config.py	Wed Jun 26 08:03:08 2024 +0000
@@ -0,0 +1,58 @@
+import argparse
+import json
+
+import yaml
+
+
+# This script genereates the config file required by PlantSeg.
+# For an overview of the config fields, see:
+# https://github.com/kreshuklab/plant-seg/blob/master/examples/config.yaml
+
+
+def listify(d, k, sep=',', dtype=float):
+    if k not in d:
+        return
+    d[k] = [dtype(token.strip()) for token in str(d[k]).split(sep)]
+
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--inputs', type=str, help='Path to the inputs file', required=True)
+    parser.add_argument('--config', type=str, help='Path to the config file', required=True)
+    parser.add_argument('--img_in', type=str, help='Path to the input image', required=True)
+    parser.add_argument('--workers', type=int, default=1)
+    args = parser.parse_args()
+
+    with open(args.inputs, 'r') as fp:
+        inputs = json.load(fp)
+
+    # Set configuration options from the tool wrapper
+    cfg = dict(path=args.img_in)
+    for section_name in (
+        'preprocessing',
+        'cnn_prediction',
+        'cnn_postprocessing',
+        'segmentation',
+        'segmentation_postprocessing',
+    ):
+        cfg[section_name] = inputs[section_name]
+
+    # Set additional required configuration options
+    cfg['preprocessing']['save_directory'] = 'PreProcessing'
+    cfg['preprocessing']['crop_volume'] = '[:,:,:]'
+    cfg['preprocessing']['filter'] = dict(state=False, type='gaussian', filter_param=1.0)
+
+    cfg['cnn_prediction']['device'] = 'cuda'
+    cfg['cnn_prediction']['num_workers'] = args.workers
+    cfg['cnn_prediction']['model_update'] = False
+
+    cfg['segmentation']['name'] = 'MultiCut'
+    cfg['segmentation']['save_directory'] = 'MultiCut'
+
+    # Parse lists of values encoded as strings as actual lists of values
+    listify(cfg['preprocessing'], 'factor')
+    listify(cfg['cnn_prediction'], 'patch')
+
+    with open(args.config, 'w') as fp:
+        fp.write(yaml.dump(cfg))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/creators.xml	Wed Jun 26 08:03:08 2024 +0000
@@ -0,0 +1,23 @@
+<macros>
+
+    <xml name="creators/bmcv">
+        <organization name="Biomedical Computer Vision Group, Heidelberg Universtiy" alternateName="BMCV" url="http://www.bioquant.uni-heidelberg.de/research/groups/biomedical_computer_vision.html" />
+        <yield />
+    </xml>
+
+    <xml name="creators/alliecreason">
+        <person givenName="Allison" familyName="Creason"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/bugraoezdemir">
+        <person givenName="Bugra" familyName="Oezdemir"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/thawn">
+        <person givenName="Till" familyName="Korten"/>
+        <yield/>
+    </xml>
+    
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plantseg.xml	Wed Jun 26 08:03:08 2024 +0000
@@ -0,0 +1,108 @@
+<tool id="plantseg" name="Perform segmentation in densely packed 3-D volumetric images" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
+    <description>with PlantSeg</description>
+    <macros>
+        <import>creators.xml</import>
+        <import>tests.xml</import>
+        <token name="@TOOL_VERSION@">1.8.1</token>
+        <token name="@VERSION_SUFFIX@">0</token>
+    </macros>
+    <creator>
+        <expand macro="creators/bmcv"/>
+    </creator>
+    <edam_operations>
+        <edam_operation>operation_3443</edam_operation>
+    </edam_operations>
+    <xrefs>
+        <xref type="bio.tools">plantseg</xref>
+    </xrefs>
+    <requirements>
+        <requirement type="package" version="@TOOL_VERSION@">plant-seg</requirement>
+        <requirement type="package" version="2.3.1">pytorch</requirement>
+        <requirement type="package" version="0.5.3">bioimageio.spec</requirement>
+        <requirement type="package" version="6.0.1">pyyaml</requirement>
+    </requirements>
+    <command detect_errors="aggressive">
+    <![CDATA[
+
+        ln -s '${img_in}' ./image.${img_in.ext} &&
+        python '$__tool_directory__/create-config.py'
+            --config config.yml
+            --inputs '$inputs'
+            --img_in ./image.${img_in.ext}
+            --workers \${GALAXY_SLOTS:-4} &&
+        plantseg --config config.yml &&
+        ln -s PreProcessing/*/MultiCut/*.h5 'masks.h5'
+
+    ]]>
+    </command>
+    <configfiles>
+        <inputs name="inputs" />
+    </configfiles>
+    <inputs>
+
+        <param name="img_in" type="data" format="tiff,h5" label="3-D volumetric input image" help="The 2-D slices must be stacked along the first axis." />
+
+        <section name="preprocessing" title="Pre-processing" expanded="false">
+            <param name="state" type="boolean" checked="true" label="Enabled" truevalue="true" falsevalue="false" />
+            <param name="factor" type="text" label="Rescaling factor" value="1.0, 1.0, 1.0" help="Comma-separated list of factors (one per axis). Rescaling the volume is essential for the generalization of the networks. The rescaling factor can be computed as the resolution of the volume at hand divided by the resolution of the dataset used in training. Be careful, if the difference is too large check for a different model." />
+            <param name="order" type="integer" min="0" max="3" value="2" label="Order of spline interpolation for rescaling" />
+        </section>
+
+        <section name="cnn_prediction" title="CNN prediction" expanded="false">
+            <param name="state" type="boolean" checked="true" label="Enabled" truevalue="true" falsevalue="false" />
+            <param name="model_name" type="text" label="Model name" value="generic_confocal_3D_unet" />
+            <param name="patch" type="text" label="Patch size" value="100, 160, 160" help="Comma-separated list of pixel counts (one per axis)." />
+            <param name="stride_ratio" type="float" min="0.5" max="0.75" value="0.75" label="Stride ratio" help="Stride between patches will be computed as the product of this and the patch size above." />
+        </section>
+
+        <section name="cnn_postprocessing" title="CNN postprocessing" expanded="false">
+            <param name="state" type="boolean" checked="false" label="Enabled" truevalue="true" falsevalue="false" />
+            <param name="factor" type="text" label="Rescaling factor" value="1.0, 1.0, 1.0" help="Comma-separated list of factors (one per axis)." />
+            <param name="order" type="integer" min="0" max="3" value="2" label="Order of spline interpolation for rescaling" />
+        </section>
+
+        <section name="segmentation" title="Segmentation" expanded="false">
+            <param name="state" type="boolean" checked="true" label="Enabled" truevalue="true" falsevalue="false" />
+            <param name="beta" type="float" min="0" max="1" value="0.5" label="Beta" help="Balance under-/over-segmentation; 0 - aim for undersegmentation, 1 - aim for oversegmentation." />
+            <param name="run_ws" type="boolean" checked="true" label="Run watershed" truevalue="true" falsevalue="false" />
+            <param name="ws_2D" type="boolean" checked="true" label="Use 2-D instead of 3-D watershed" truevalue="true" falsevalue="false" />
+            <param name="ws_threshold" type="float" min="0" max="1" value="0.5" label="Probability maps threshold" />
+            <param name="ws_minsize" type="integer" min="0" value="50" label="Minimum superpixel size" />
+            <param name="ws_sigma" type="float" min="0" value="2.0" label="Gaussian smoothing of the distance transform" />
+            <param name="ws_w_sigma" type="float" min="0" value="0" label="Gaussian smoothing of boundaries" />
+            <param name="post_minsize" type="integer" min="0" value="50" label="Minimum segment size in the final segmentation" />
+        </section>
+
+        <section name="segmentation_postprocessing" title="Segmentation postprocessing" expanded="false">
+            <param name="state" type="boolean" checked="false" label="Enabled" truevalue="true" falsevalue="false" />
+            <param name="factor" type="text" label="Rescaling factor" value="1.0, 1.0, 1.0" help="Comma-separated list of factors (one per axis)." />
+            <param name="order" type="integer" min="0" max="3" value="0" label="Order of spline interpolation for rescaling" />
+        </section>
+
+    </inputs>
+    <outputs>
+        <data format="h5" name="masks" from_work_dir="masks.h5" />
+    </outputs>
+    <tests>
+        <test><!-- Test H5 input -->
+            <param name="img_in" value="sample_ovule.h5" />
+            <output name="masks" value="sample_ovule_output.h5" ftype="h5" compare="sim_size" delta="100" delta_frac="0.1" />
+        </test>
+        <test><!-- Test TIFF input -->
+            <param name="img_in" value="sample_ovule.tiff" />
+            <output name="masks" value="sample_ovule_output.h5" ftype="h5" compare="sim_size" delta="100" delta_frac="0.1" />
+        </test>
+    </tests>
+    <help>
+
+        **Perform segmentation in densely packed 3-D volumetric images.**
+
+        PlantSeg is a tool for cell instance aware segmentation in densely packed 3D volumetric images.
+        The pipeline uses a two stages segmentation strategy (Neural Network + Segmentation).
+        The pipeline is tuned for plant cell tissue acquired with confocal and light sheet microscopy.
+
+    </help>
+    <citations>
+        <citation type="doi">10.7554/eLife.57613</citation>
+    </citations>
+</tool>
Binary file test-data/sample_ovule.h5 has changed
Binary file test-data/sample_ovule.tiff has changed
Binary file test-data/sample_ovule_output.h5 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests.xml	Wed Jun 26 08:03:08 2024 +0000
@@ -0,0 +1,95 @@
+<macros>
+
+    <!-- Macros for verification of image outputs -->
+
+    <xml
+        name="tests/binary_image_diff"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="mae"
+        token_eps="0.01">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0">
+            <assert_contents>
+                <has_image_n_labels n="2"/>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <xml
+        name="tests/label_image_diff"
+        tokens="name,value,ftype,metric,eps,pin_labels"
+        token_metric="iou"
+        token_eps="0.01"
+        token_pin_labels="0">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <xml
+        name="tests/intensity_image_diff"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="rms"
+        token_eps="0.01">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <!-- Variants of the above for verification of collection elements -->
+
+    <xml
+        name="tests/binary_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="mae"
+        token_eps="0.01">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0">
+            <assert_contents>
+                <has_image_n_labels n="2"/>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+    <xml
+        name="tests/label_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="iou"
+        token_eps="0.01"
+        token_pin_labels="0">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+    <xml
+        name="tests/intensity_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="rms"
+        token_eps="0.01">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+</macros>