diff 2d_feature_extraction.xml @ 5:5530132d500e draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_feature_extraction/ commit bb2d58ed37d8eb09583b86e3cdd9f5d1b56c42a0
author imgteam
date Sun, 04 Jan 2026 20:56:17 +0000
parents a4bc9dfde846
children 8e3a52b74876
line wrap: on
line diff
--- a/2d_feature_extraction.xml	Wed Dec 17 11:20:49 2025 +0000
+++ b/2d_feature_extraction.xml	Sun Jan 04 20:56:17 2026 +0000
@@ -2,84 +2,122 @@
     <description>with scikit-image</description>
     <macros>
         <import>creators.xml</import>
-        <token name="@TOOL_VERSION@">0.18.1</token>
+        <import>validators.xml</import>
+        <token name="@TOOL_VERSION@">0.25.2</token>
         <token name="@VERSION_SUFFIX@">0</token>
+        <xml name="features">
+            <param name="features" type="select" label="Available features" multiple="true" display="checkboxes"
+                   help="*) Features marked with an asterisk are only available for 2-D images (not for 3-D images).">
+                <option value="label" selected="true">Label from the label map</option>
+                <yield/>
+                <option value="area">Area</option>
+                <option value="area_convex">Convex area</option>
+                <option value="area_filled">Filled area</option>
+                <option value="axis_major_length">Major axis length</option>
+                <option value="axis_minor_length">Minor axis length</option>
+                <option value="bbox">Bounding box</option>
+                <option value="centroid">Centroid</option>
+                <option value="eccentricity">Eccentricity*</option>
+                <option value="equivalent_diameter_area">Equivalent diameter</option>
+                <option value="euler_number">Euler number</option>
+                <option value="extent">Extent</option>
+                <option value="inertia_tensor_eigvals">Inertia tensor eigenvalues</option>
+                <option value="moments">Moments</option>
+                <option value="moments_hu">Moments Hu*</option>
+                <option value="orientation">Orientation*</option>
+                <option value="perimeter">Perimeter</option>
+                <option value="solidity">Solidity</option>
+            </param>
+        </xml>
+        <xml name="zarr-isolated-feature-test" tokens="feature">
+            <test>
+                <param name="labels" value="input/input13.zarr"/>
+                <conditional name="setup">
+                    <param name="mode" value="with-intensities"/>
+                    <param name="intensities" value="input/input1_uint8.tiff"/>
+                    <param name="features" value="@FEATURE@"/>
+                </conditional>
+                <output name="output" ftype="tabular" value="output/input13-@FEATURE@.tsv"/>
+            </test>
+        </xml>
     </macros>
     <creator>
         <expand macro="creators/bmcv"/>
+        <expand macro="creators/kostrykin"/>
     </creator>
     <edam_operations>
         <edam_operation>operation_3443</edam_operation>
     </edam_operations>
     <xrefs>
         <xref type="bio.tools">scikit-image</xref>
+        <xref type="bio.tools">giatools</xref>
+        <xref type="bio.tools">galaxy_image_analysis</xref>
         <xref type="biii">scikit-image</xref>
     </xrefs>
     <requirements>
         <requirement type="package" version="@TOOL_VERSION@">scikit-image</requirement>
         <requirement type="package" version="2.2.2">pandas</requirement>
-        <requirement type="package" version="1.23.3">numpy</requirement>
-        <requirement type="package" version="2020.10.1">tifffile</requirement>
-        <requirement type="package" version="0.1">giatools</requirement>
+        <requirement type="package" version="0.7.3">giatools</requirement>
+        <requirement type="package" version="0.12.2">ome-zarr</requirement>
     </requirements>
-    <command detect_errors="aggressive">
-    <![CDATA[
-    python '$__tool_directory__/2d_feature_extraction.py'
-    #if $feature_options['features'] == 'all'
-      --all
-    #else if $feature_options['features'] == 'select'
-      ${' '.join(str( $feature_options['selected_features'] ).split(','))}
-    #end if
-    #if $use_raw_option['use_raw'] == 'raw_image'
-      --raw '$input_raw'
-    #end if
-    '$input_label' '$output'
-    ]]>
-    </command>
+    <required_files>
+        <include type="literal" path="2d_feature_extraction.py"/>
+    </required_files>
+    <command detect_errors="aggressive"><![CDATA[
+
+        python '$__tool_directory__/2d_feature_extraction.py'
+
+        #if $labels.extension == "zarr"
+            --labels '$labels.extra_files_path/$labels.metadata.store_root'
+        #else
+            --labels '$labels'
+        #end if
+
+        #if $setup.mode == "with-intensities"
+            #if $setup.intensities.extension == "zarr"
+                --intensities '$setup.intensities.extra_files_path/$setup.intensities.metadata.store_root'
+            #else
+                --intensities '$setup.intensities'
+            #end if
+        #end if
+
+        --output '$output'
+        --params '$params'
+        --verbose
+
+    ]]></command>
+    <configfiles>
+        <configfile name="params"><![CDATA[
+            {
+                "features": [
+                    ${ ', '.join('"%s"' % t.strip() for t in str( $setup['features'] ).split(',')) }
+                ]
+            }
+        ]]></configfile>
+    </configfiles>
     <inputs>
-        <param name="input_label" type="data" format="tiff,png" label="Label map"/>
-        <conditional name="use_raw_option">
-            <param label="Use the intensity image to compute additional features" name="use_raw" type="select">
-                <option selected="True" value="no_original">No intensity image</option>
-                <option value="raw_image">Use intensity image</option>
+        <param name="labels" type="data" format="tiff,zarr,png" label="Label map">
+            <expand macro="validators/is_single_channel"/>
+            <expand macro="validators/is_single_frame"/>
+        </param>
+        <conditional name="setup">
+            <param label="Features to compute" name="mode" type="select">
+                <option value="without-intensities" selected="true">Only use the label map for feature extraction (no intensity-based features)</option>
+                <option value="with-intensities">Use the intensity image to compute additional features</option>
             </param>
-            <when value="no_original"/>
-            <when value="raw_image">
-                <param name="input_raw" type="data" format="tiff,png" label="Intensity image"/>
+            <when value="without-intensities">
+                <expand macro="features"/>
             </when>
-        </conditional>
-        <conditional name="feature_options">
-            <param label="Select features to compute" name="features" type="select">
-                <option selected="True" value="all">All features</option>
-                <option value="select">Select features</option>
-            </param>
-            <when value="all"> </when>
-            <when value="select">
-                <param name="selected_features" type="select" label="Available features" multiple="true" display="checkboxes">
-                    <option value="--label">Label from the label map</option>
-                    <option value="--patches">Patches (requires original image)</option>
-                    <option value="--max_intensity">Max Intensity (requires original image)</option>
-                    <option value="--mean_intensity">Mean Intensity (requires original image)</option>
-                    <option value="--min_intensity">Minimum Intensity (requires original image)</option>
-                    <option value="--moments_hu">Moments Hu</option>
-                    <option value="--centroid">Centroid</option>
-                    <option value="--bbox">Bounding box</option>
-                    <option value="--area">Area</option>
-                    <option value="--filled_area">Filled area</option>
-                    <option value="--convex_area">Convex area</option>
-                    <option value="--perimeter">Perimeter</option>
-                    <option value="--extent">Extent</option>
-                    <option value="--eccentricity">Eccentricity</option>
-                    <option value="--equivalent_diameter">Equivalent diameter</option>
-                    <option value="--euler_number">Euler number</option>
-                    <option value="--inertia_tensor_eigvals">Inertia tensor eigenvalues</option>
-                    <option value="--major_axis_length">Major axis length</option>
-                    <option value="--minor_axis_length">Minor axis length</option>
-                    <option value="--orientation">Orientation</option>
-                    <option value="--solidity">Solidity</option>
-                    <option value="--moments">Moments</option>
-                    <option value="--convexity">Convexity</option>
+            <when value="with-intensities">
+                <param name="intensities" type="data" format="tiff,zarr,png,jpg" label="Intensity image">
+                    <expand macro="validators/is_single_channel"/>
+                    <expand macro="validators/is_single_frame"/>
                 </param>
+                <expand macro="features">
+                    <option value="max_intensity">Maximum intensity</option>
+                    <option value="mean_intensity">Mean intensity</option>
+                    <option value="min_intensity">Minimum intensity</option>
+                </expand>
             </when>
         </conditional>
     </inputs>
@@ -87,23 +125,133 @@
         <data format="tabular" name="output"/>
     </outputs>
     <tests>
+        <!-- Single-channel 2-D -->
         <test>
-            <param name="input_label" value="input.tiff" ftype="tiff"/>
-            <conditional name="feature_options">
-                <param name="features" value="select"/>
-                <param name="selected_features" value="--label,--area"/>
+            <param name="labels" value="input/input12.png"/>
+            <conditional name="setup">
+                <param name="mode" value="without-intensities"/>
+                <param name="features" value="label,area,area_convex,solidity"/>
+            </conditional>
+            <output name="output" ftype="tabular" value="output/input12.tsv"/>
+        </test>
+        <test>
+            <param name="labels" value="input/input11.tiff"/>
+            <conditional name="setup">
+                <param name="mode" value="with-intensities"/>
+                <param name="intensities" value="input/input1_uint8.tiff"/>
+                <param name="features" value="area,mean_intensity,perimeter"/>
             </conditional>
-            <output name="output" ftype="tabular" value="out.tsv"/>
+            <output name="output" ftype="tabular" value="output/input11.tsv"/>
+        </test>
+        <!-- Single-channel 2-D Zarr (isolated features, verify that Dask arrays are converted to NumPy arrays whenever necessary) -->
+        <expand macro="zarr-isolated-feature-test" feature="area"/>
+        <expand macro="zarr-isolated-feature-test" feature="area_convex"/>
+        <expand macro="zarr-isolated-feature-test" feature="area_filled"/>
+        <expand macro="zarr-isolated-feature-test" feature="axis_major_length"/>
+        <expand macro="zarr-isolated-feature-test" feature="axis_minor_length"/>
+        <expand macro="zarr-isolated-feature-test" feature="bbox"/>
+        <expand macro="zarr-isolated-feature-test" feature="centroid"/>
+        <expand macro="zarr-isolated-feature-test" feature="eccentricity"/>
+        <expand macro="zarr-isolated-feature-test" feature="equivalent_diameter_area"/>
+        <expand macro="zarr-isolated-feature-test" feature="euler_number"/>
+        <expand macro="zarr-isolated-feature-test" feature="extent"/>
+        <expand macro="zarr-isolated-feature-test" feature="inertia_tensor_eigvals"/>
+        <expand macro="zarr-isolated-feature-test" feature="moments"/>
+        <expand macro="zarr-isolated-feature-test" feature="moments_hu"/>
+        <expand macro="zarr-isolated-feature-test" feature="orientation"/>
+        <expand macro="zarr-isolated-feature-test" feature="perimeter"/>
+        <expand macro="zarr-isolated-feature-test" feature="solidity"/>
+        <expand macro="zarr-isolated-feature-test" feature="max_intensity"/>
+        <expand macro="zarr-isolated-feature-test" feature="mean_intensity"/>
+        <expand macro="zarr-isolated-feature-test" feature="min_intensity"/>
+        <!-- Single-channel 3-D, test all features are supported in 3-D -->
+        <test>
+            <param name="labels" value="input/input9.zarr"/>
+            <conditional name="setup">
+                <param name="mode" value="with-intensities"/>
+                <param name="intensities" value="input/input8_zyx.zarr"/>
+                <param name="features" value="area,area_convex,area_filled,axis_major_length,axis_minor_length,bbox,centroid,eccentricity,equivalent_diameter_area,euler_number,extent,inertia_tensor_eigvals,moments,moments_hu,orientation,perimeter,solidity,max_intensity,mean_intensity,min_intensity"/>
+            </conditional>
+            <output name="output" ftype="tabular" value="output/input9.tsv"/>
+            <assert_stdout>
+                <has_line line='Skip feature that is not available for 3-D images: "eccentricity"'/>
+                <has_line line='Skip feature that is not available for 3-D images: "moments_hu"'/>
+                <has_line line='Skip feature that is not available for 3-D images: "orientation"'/>
+            </assert_stdout>
+        </test>
+        <!-- Multi-channel (forbidden) -->
+        <test expect_failure="true">
+            <param name="labels" value="input/input12.png"/>
+            <conditional name="setup">
+                <param name="mode" value="with-intensities"/>
+                <param name="intensities" value="input/input3_uint16.tiff"/>
+                <param name="features" value="label"/>
+            </conditional>
+            <assert_stderr>
+                <!-- Rejected by validator -->
+                <has_n_lines n="0"/>
+            </assert_stderr>
+            <assert_stdout>
+                <!-- Rejected by validator -->
+                <has_n_lines n="0"/>
+            </assert_stdout>
+        </test>
+        <test expect_failure="true">
+            <param name="labels" value="input/input10.zarr"/>
+            <conditional name="setup">
+                <param name="mode" value="without-intensities"/>
+                <param name="features" value="label"/>
+            </conditional>
+            <assert_stderr>
+                <!-- Rejected by py-script -->
+                <has_text text="This tool is not applicable to images with CYX axes."/>
+            </assert_stderr>
         </test>
     </tests>
     <help>
 
-        **Computes features of a label map.**
+**Computes features of a label map.**
+
+The computed features are computed based solely on the properties of the objects in the label map, or, optionally, by also taking the intensities from a corresponding intensity image into account. Labels with value 0 are ignored.
+
+Both images must be 2-D or 3-D single-channel images.
+
+Supported Features
+==================
+
+**Area:** Area of the region i.e. number of pixels of the region scaled by pixel-area.
+
+**Convex area:** Area of the convex hull image, which is the smallest convex polygon that encloses the region.
+
+**Filled area:** Area of the region with all the holes filled in.
+
+**Major axis length:** The length of the major axis of the ellipse that has the same normalized second central moments as the region.
+
+**Minor axis length:** The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
+
+**Bounding box:** Bounding box `(min_row, min_col, max_row, max_col)`. Pixels belonging to the bounding box are in the half-open interval `[min_row; max_row)` and `[min_col; max_col)`.
 
-        The computed features are computed based solely on the properties of the labels in the label map,
-        or, optionally, by also taking the intensities from a corresponding intensity image into account.
+**Centroid:** Centroid coordinate tuple `(row, col)`.
+
+**Eccentricity:** Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
+
+**Equivalent diameter:** The diameter of a circle with the same area as the region.
+
+**Euler number:** Euler characteristic of the set of non-zero pixels. Computed as number of connected components subtracted by number of holes (input.ndim connectivity). In 3-D, number of connected components plus number of holes subtracted by number of tunnels.
+
+**Extent:** Ratio of pixels in the region to pixels in the total bounding box. Computed as `area / (rows * cols)`.
 
-        The label map must be a 2-D or 3-D single-channel image.
+**Inertia tensor eigenvalues:** The eigenvalues of the inertia tensor in decreasing order.
+
+**Moments:** Spatial moments up to 3rd order: `m_ij = sum{ array(row, col) * row^i * col^j }` where the sum is over the row, col coordinates of the region.
+
+**Moments Hu:** Hu moments (translation, scale and rotation invariant).
+
+**Orientation:** Angle between the vertical axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from `-pi/2` to `pi/2` counter-clockwise.
+
+**Perimeter:** Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity. Generalizes to the surface of an object in 3-D, which uses a different approximation.
+
+**Solidity:** Ratio of pixels in the region to pixels of the convex hull image.
     
     </help>
     <citations>