changeset 1:700ae37e5c69 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
author imgteam
date Thu, 06 Jul 2023 00:01:18 +0000
parents 1b0fc671187f
children 244f67290d28
files run-superdsm.py superdsm.xml
diffstat 2 files changed, 92 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/run-superdsm.py	Sun Jun 25 21:48:40 2023 +0000
+++ b/run-superdsm.py	Thu Jul 06 00:01:18 2023 +0000
@@ -19,6 +19,37 @@
 import superdsm.render
 
 
+hyperparameters = [
+    ('AF_scale', float),
+    ('c2f_region_analysis/min_atom_radius', float),
+    ('c2f_region_analysis_min_norm_energy_improvement', float),
+    ('c2f_region_analysis_max_atom_norm_energy', float),
+    ('c2f_region_analysis_max_cluster_marker_irregularity', float),
+    ('dsm_alpha', float),
+    ('dsm_AF_alpha', float),
+    ('global_energy_minimization_betai', float),
+    ('global_energy_minimization_AF_beta', float),
+    ('postprocess_mask_max_distance', int),
+    ('postprocess_mask_stdamp', float),
+    ('postprocess_max_norm_energy', float),
+    ('postprocess_min_contrast', float),
+    ('postprocess_min_object_radius', float),
+]
+
+
+def get_param_name(key):
+    return key.replace('/', '_')
+
+
+def create_config(args):
+    cfg = superdsm.config.Config()
+    for key, _ in hyperparameters:
+        value = getattr(args, get_param_name(key))
+        if value is not None:
+            cfg[key] = value
+    return cfg
+
+
 if __name__ == "__main__":
     parser = argparse.ArgumentParser(description='Segmentation of cell nuclei in 2-D fluorescence microscopy images')
     parser.add_argument('image', help='Path to the input image')
@@ -27,6 +58,8 @@
     parser.add_argument('overlay', help='Path to the file containing the overlay of the segmentation results')
     parser.add_argument('seg_border', type=int)
     parser.add_argument('slots', type=int)
+    for key, ptype in hyperparameters:
+        parser.add_argument('--' + get_param_name(key), type=ptype, default=None)
     args = parser.parse_args()
 
     if args.slots >= 2:
@@ -49,7 +82,7 @@
         shutil.copy(str(args.image), img_filepath)
 
         pipeline = superdsm.pipeline.create_default_pipeline()
-        cfg = superdsm.config.Config()
+        cfg = create_config(args)
         img = superdsm.io.imread(img_filepath)
         data, cfg, _ = superdsm.automation.process_image(pipeline, cfg, img)
 
--- a/superdsm.xml	Sun Jun 25 21:48:40 2023 +0000
+++ b/superdsm.xml	Thu Jul 06 00:01:18 2023 +0000
@@ -1,7 +1,7 @@
-<tool id="ip_superdsm" name="SuperDSM" version="0.1.2-1" profile="20.05">
+<tool id="ip_superdsm" name="SuperDSM" version="0.1.3" profile="20.05">
    <description>globally optimal segmentation method based on superadditivity and deformable shape models for cell nuclei in fluorescence microscopy images</description>
    <requirements> 
-        <requirement type="package" version="0.1.2">superdsm</requirement>
+        <requirement type="package" version="0.1.3">superdsm</requirement>
         <requirement type="package" version="1.6.0">ray-core</requirement>
         <requirement type="package" version="0.18.1">scikit-image</requirement>
    </requirements>
@@ -14,19 +14,71 @@
    'overlay.png'
    $seg_border
    \${GALAXY_SLOTS:-4}
-   > stdout.txt
+   #if str($config.AF_scale) != '':
+       --AF_scale '${config.AF_scale}'
+   #end if
+   #if str($config.c2f_region_analysis_min_atom_radius) != '':
+       --c2f_region_analysis_min_atom_radius '${config.c2f_region_analysis_min_atom_radius}'
+   #end if
+   #if str($config.c2f_region_analysis_min_norm_energy_improvement) != '':
+       --c2f_region_analysis_min_norm_energy_improvement '${config.c2f_region_analysis_min_norm_energy_improvement}'
+   #end if
+   #if str($config.c2f_region_analysis_max_atom_norm_energy) != '':
+       --c2f_region_analysis_max_atom_norm_energy '${config.c2f_region_analysis_max_atom_norm_energy}'
+   #end if
+   #if str($config.c2f_region_analysis_max_cluster_marker_irregularity) != '':
+       --c2f_region_analysis_max_cluster_marker_irregularity '${config.c2f_region_analysis_max_cluster_marker_irregularity}'
+   #end if
+   #if str($config.dsm_alpha) != '':
+       --dsm_alpha '${config.dsm_alpha}'
+   #end if
+   #if str($config.dsm_AF_alpha) != '':
+       --dsm_AF_alpha '${config.dsm_AF_alpha}'
+   #end if
+   #if str($config.global_energy_minimization_beta) != '':
+       --global_energy_minimization_beta '${config.global_energy_minimization_beta}'
+   #end if
+   #if str($config.global_energy_minimization_AF_beta) != '':
+       --global_energy_minimization_AF_beta '${config.global_energy_minimization_AF_beta}'
+   #end if
+   #if str($config.postprocess_mask_max_distance) != '':
+       --postprocess_mask_max_distance '${config.postprocess_mask_max_distance}'
+   #end if
+   #if str($config.postprocess_mask_stdamp) != '':
+       --postprocess_mask_stdamp '${config.postprocess_mask_stdamp}'
+   #end if
+   #if str($config.postprocess_max_norm_energy) != '':
+       --postprocess_max_norm_energy '${config.postprocess_max_norm_energy}'
+   #end if
+   #if str($config.postprocess_min_contrast) != '':
+       --postprocess_min_contrast '${config.postprocess_min_contrast}'
+   #end if
+   #if str($config.postprocess_min_object_radius) != '':
+       --postprocess_min_object_radius '${config.postprocess_min_object_radius}'
+   #end if
    ]]>
    </command>
    <inputs>
         <param name="dataset" type="data" format="tiff,png" label="Dataset" />
         <param name="seg_border" type="integer" min="1" value="8" label="Width of the outlines (in pixels) of the segmentation results (overlays)" />
-        <!--
         <section name="config" title="Hyperparameters" expanded="false">
+            <param argument="--AF_scale" optional="true" type="float" value="" min="0" label="scale Οƒ" help="The scale of the objects to be segmented. Leave empty to use the automatically determined value." />
+            <param argument="--c2f_region_analysis_min_atom_radius" optional="true" type="float" value="" min="0" label="min_atom_radius" help="No region determined by the Coarse-to-fine region analysis scheme is smaller than a circle of this radius (in terms of the surface area). Leave empty to use the automatically determined value." />
+            <param argument="--c2f_region_analysis_min_norm_energy_improvement" type="float" value="0.1" min="0" label="min_norm_energy_improvement" help="Each split performed during the computation of the atomic image regions must improve the normalized energy π‘Ÿ(πœ”) of an image region πœ” by at least this factor. Given that an image region is split into the sub-regions πœ”β‚, πœ”β‚‚, the improvement of the split is defined by the fraction max{π‘Ÿ(πœ”)₁, π‘Ÿ(πœ”β‚‚)} / π‘Ÿ(πœ”β‚ βˆͺ πœ”β‚‚). Lower values of the fraction correspond to better improvements." />
+            <param argument="--c2f_region_analysis_max_atom_norm_energy" type="float" value="0.05" min="0" label="max_norm_energy1" help="No atomic image region πœ” determined by the Coarse-to-fine region analysis has a normalized energy π‘Ÿ(πœ”) smaller than this value." />
+            <param argument="--c2f_region_analysis_max_cluster_marker_irregularity" type="float" value="0.2" min="0" label="max_pa_ratio" help="Threshold for the β€œirregularity” of image regions. Image regions with an β€œirregularity” higher than this value are masked as β€œempty” image regions and discarded from further considerations." />
+            <param argument="--dsm_alpha" type="float" value="" optional="true" min="0" label="regularization of the deformations 𝛼" help="Governs the regularization of the deformations. Increasing this value leads to a smoother segmentation result. Leave empty to use the automatically determined value." />
+            <param argument="--dsm_AF_alpha" type="float" value="0.0005" min="0" label="factor used for automatic computation of 𝛼" />
+            <param argument="--global_energy_minimization_beta" type="float" value="" optional="true" min="0" label="sparsity 𝛽" help="Increasing this value leads to a sparser segmentation result. Leave empty to use the automatically determined value." />
+            <param argument="--global_energy_minimization_AF_beta" type="float" value="0.66" min="0" label="factor used for automatic computation of 𝛽" />
+            <param argument="--postprocess_mask_max_distance" type="integer" value="1" min="0" label="mask_max_distance" help="Image points within this maximum distance of the boundary of the original segmentation mask are subject to refinement in post-processing. Image points further away from the boundary are neither added to nor removed from the segmentation mask." />
+            <param argument="--postprocess_mask_stdamp" type="float" value="2" min="0" label="mask_stdamp" help="An image point adjacent to the boundary of the original segmentation mask is added to the segmentation mask in post-processing, if its Gaussian-smoothed intensity is sufficiently similar to the mean intensity of the mask. The image point is removed otherwise. The lower the value set, the stricter the similarity must be." />
+            <param argument="--postprocess_max_norm_energy" type="float" value="0.2" label="max_norm_energy2" help="Objects with a normalized energy larger than this value are discarded in post-processing." />
+            <param argument="--postprocess_min_contrast" type="float" value="1.35" label="min_contrast" help="A segmented object is discarded in post-processing, if the contrast as defined above is below this threshold." />
+            <param argument="--postprocess_min_object_radius" type="float" value="0" label="min_object_radius" help="Objects smaller than a circle of this radius are discarded in post-processing (in terms of the surface area)." />
         </section>
-        -->
     </inputs>
     <outputs>
-        <data format="txt" name="stdout" from_work_dir="stdout.txt" label="${tool.name} on ${on_string}: stdout" />
         <data format="json" name="cfg" from_work_dir="cfg.json" label="${tool.name} on ${on_string}: cfg" />
         <data format="png" name="masks" from_work_dir="masks.png" label="${tool.name} on ${on_string}: masks" />
         <data format="png" name="overlay" from_work_dir="overlay.png" label="${tool.name} on ${on_string}: overlay" />