changeset 29:551d1ea2416d draft

planemo upload for repository https://github.com/rolfverberg/galaxytools commit f8c4bdb31c20c468045ad5e6eb255a293244bc6c-dirty
author rv43
date Tue, 21 Mar 2023 18:46:02 +0000
parents 562fc79de827
children 3342c0518d4c
files tomo_find_center.xml tomo_reconstruct.xml workflow/run_tomo.py
diffstat 3 files changed, 80 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/tomo_find_center.xml	Tue Mar 21 17:59:41 2023 +0000
+++ b/tomo_find_center.xml	Tue Mar 21 18:46:02 2023 +0000
@@ -11,16 +11,25 @@
             --input_file "$input_file"
             --output_file "output.yaml"
             --galaxy_flag
-            --center_rows $center_rows.low $center_rows.upp
+            #if str($center_rows.type_selector) == "enter_range"
+                --center_rows $center_rows.low $center_rows.upp
+            #end if
             -l "$log"
         ]]>
     </command>
     <inputs>
         <param name="input_file" type="data" format="nex" optional="false" label="Reduced tomography data"/>
-        <section name="center_rows" title="Find center axis planes">
-            <param name="low" type="integer" value="-1" label="Lower bound"/>
-            <param name="upp" type="integer" value="-1" label="Upper bound"/>
-        </section>
+        <conditional name="center_rows">
+            <param name="type_selector" type="select" label="Choose find center axis planes">
+                <option value="full_range" selected="true">Use the top and bottom image planes</option>
+                <option value="enter_range">Manually select the image planes</option>
+            </param>
+            <when value="full_range"/>
+            <when value="enter_range">
+                <param name="low" type="integer" value="-1" optional="false" label="Lower plane index in vertical direction"/>
+                <param name="upp" type="integer" value="-1" optional="false" label="Upper plane index in vertical direction"/>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <expand macro="common_outputs"/>
--- a/tomo_reconstruct.xml	Tue Mar 21 17:59:41 2023 +0000
+++ b/tomo_reconstruct.xml	Tue Mar 21 18:46:02 2023 +0000
@@ -12,22 +12,40 @@
             --center_file "$center_file"
             --output_file "output.nex"
             --galaxy_flag
-            --x_bounds $x_bounds.low $x_bounds.upp
-            --y_bounds $y_bounds.low $y_bounds.upp
+            #if str($x_bounds.type_selector) == "enter_range"
+                --x_bounds $x_bounds.low $x_bounds.upp
+            #end if
+            #if str($y_bounds.type_selector) == "enter_range"
+                --y_bounds $y_bounds.low $y_bounds.upp
+            #end if
             -l "$log"
         ]]>
     </command>
     <inputs>
         <param name="input_file" type="data" format="nex" optional="false" label="Reduced tomography data"/>
         <param name="center_file" type="data" format="yaml" optional="false" label="Center axis input file"/>
-        <section name="x_bounds" title="Boundaries of reconstructed images in x-direction">
-            <param name="low" type="integer" value="-1" label="Lower bound"/>
-            <param name="upp" type="integer" value="-1" label="Upper bound"/>
-        </section>
-        <section name="y_bounds" title="Boundaries of reconstructed images in y-direction">
-            <param name="low" type="integer" value="-1" label="Lower bound"/>
-            <param name="upp" type="integer" value="-1" label="Upper bound"/>
-        </section>
+        <conditional name="x_bounds">
+            <param name="type_selector" type="select" label="Choose reconstructed image range in x-direction">
+                <option value="full_range" selected="true">Use the full image range</option>
+                <option value="enter_range">Manually enter the image range</option>
+            </param>
+            <when value="full_range"/>
+            <when value="enter_range">
+                <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in x-direction"/>
+                <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in x-direction"/>
+            </when>
+        </conditional>
+        <conditional name="y_bounds">
+            <param name="type_selector" type="select" label="Choose reconstructed image range in y-direction">
+                <option value="full_range" selected="true">Use the full image range</option>
+                <option value="enter_range">Manually enter the image range</option>
+            </param>
+            <when value="full_range"/>
+            <when value="enter_range">
+                <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in y-direction"/>
+                <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in y-direction"/>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <expand macro="common_outputs"/>
--- a/workflow/run_tomo.py	Tue Mar 21 17:59:41 2023 +0000
+++ b/workflow/run_tomo.py	Tue Mar 21 18:46:02 2023 +0000
@@ -301,14 +301,18 @@
         nxentry = nxroot[nxroot.attrs['default']]
         if not isinstance(nxentry, NXentry):
             raise ValueError(f'Invalid nxentry ({nxentry})')
-        if self.galaxy_flag:
-            if center_rows is not None:
-                center_rows = tuple(center_rows)
-                if not is_int_pair(center_rows):
+        if center_rows is not None:
+            if self.galaxy_flag
+                is not is_int_pair(center_rows, ge=-1):
                     raise ValueError(f'Invalid parameter center_rows ({center_rows})')
-        elif center_rows is not None:
-            logger.warning(f'Ignoring parameter center_rows ({center_rows})')
-            center_rows = None
+                if (center_rows[0] != -1 and center_rows[1] != -1 and
+                        center_rows[0] > center_rows[1]):
+                    center_rows = (center_rows[1], center_rows[0])
+                else:
+                    center_rows = tuple(center_rows)
+            else:
+                logger.warning(f'Ignoring parameter center_rows ({center_rows})')
+                center_rows = None
         if self.galaxy_flag:
             if center_stack_index is not None and not is_int(center_stack_index, ge=0):
                 raise ValueError(f'Invalid parameter center_stack_index ({center_stack_index})')
@@ -377,7 +381,7 @@
             if center_rows is None or center_rows[0] == -1:
                 lower_row = 0
             else:
-                lower_row = min(center_rows)
+                lower_row = center_rows[0]
                 if not 0 <= lower_row < tomo_fields_shape[2]-1:
                     raise ValueError(f'Invalid parameter center_rows ({center_rows})')
         else:
@@ -388,7 +392,6 @@
         logger.debug('Finding center...')
         t0 = time()
         lower_center_offset = self._find_center_one_plane(
-                #np.asarray(nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:]),
                 nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:],
                 lower_row, thetas, eff_pixel_size, cross_sectional_dim, path=path,
                 num_core=self.num_core)
@@ -403,7 +406,7 @@
             if center_rows is None or center_rows[1] == -1:
                 upper_row = tomo_fields_shape[2]-1
             else:
-                upper_row = max(center_rows)
+                upper_row = center_rows[1]
                 if not lower_row < upper_row < tomo_fields_shape[2]:
                     raise ValueError(f'Invalid parameter center_rows ({center_rows})')
         else:
@@ -513,15 +516,31 @@
         # Resize the reconstructed tomography data
         #   reconstructed data order in each stack: row/z,x,y
         if self.test_mode:
-            x_bounds = self.test_config.get('x_bounds')
-            y_bounds = self.test_config.get('y_bounds')
+            x_bounds = tuple(self.test_config.get('x_bounds'))
+            y_bounds = tuple(self.test_config.get('y_bounds'))
             z_bounds = None
         elif self.galaxy_flag:
-            if x_bounds is not None and not is_int_pair(x_bounds, ge=-1,
-                    lt=tomo_recon_stacks[0].shape[1]):
+            x_max = tomo_recon_stacks[0].shape[1]
+            if x_bounds is None:
+                x_bounds = (0, x_max)
+            elif is_int_pair(x_bounds, ge=-1, le=x_max):
+                x_bounds = tuple(x_bounds)
+                if x_bounds[0] == -1:
+                    x_bounds = (0, x_bounds[1])
+                if x_bounds[1] == -1:
+                    x_bounds = (x_bounds[0], x_max)
+            if not is_index_range(x_bounds, ge=0, le=x_max):
                 raise ValueError(f'Invalid parameter x_bounds ({x_bounds})')
-            if y_bounds is not None and not is_int_pair(y_bounds, ge=-1,
-                    lt=tomo_recon_stacks[0].shape[1]):
+            y_max = tomo_recon_stacks[0].shape[1]
+            if y_bounds is None:
+                y_bounds = (0, y_max)
+            elif is_int_pair(y_bounds, ge=-1, le=y_max):
+                y_bounds = tuple(y_bounds)
+                if y_bounds[0] == -1:
+                    y_bounds = (0, y_bounds[1])
+                if y_bounds[1] == -1:
+                    y_bounds = (y_bounds[0], y_max)
+            if not is_index_range(y_bounds, ge=0, le=y_max):
                 raise ValueError(f'Invalid parameter y_bounds ({y_bounds})')
             z_bounds = None
         else:
@@ -989,10 +1008,11 @@
                 if img_x_bounds is None:
                     img_x_bounds = (0, first_image.shape[0])
                 elif is_int_pair(img_x_bounds, ge=-1, le=first_image.shape[0]):
+                    img_x_bounds = tuple(img_x_bounds)
                     if img_x_bounds[0] == -1:
-                        img_x_bounds[0] = 0
+                        img_x_bounds = (0, img_x_bounds[1])
                     if img_x_bounds[1] == -1:
-                        img_x_bounds[1] = first_image.shape[0]
+                        img_x_bounds = (img_x_bounds[0], first_image.shape[0])
                 if not is_index_range(img_x_bounds, ge=0, le=first_image.shape[0]):
                     raise ValueError(f'Invalid parameter img_x_bounds ({img_x_bounds})')
             else: