changeset 56:ca61007a60fa draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit fc9b26da497e467c28b0adf3f94422b4cb61f59c"
author rv43
date Tue, 02 Aug 2022 19:52:47 +0000
parents bead50a4eadc
children 28ea840a96f0
files general.py tomo_setup.xml
diffstat 2 files changed, 173 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/general.py	Thu Jul 28 17:44:49 2022 +0000
+++ b/general.py	Tue Aug 02 19:52:47 2022 +0000
@@ -334,6 +334,7 @@
         i = input()
         if isinstance(i, str) and not len(i):
             v = default
+            print(f'{v}')
         else:
             v = literal_eval(i)
         if inset and v not in inset:
@@ -389,6 +390,7 @@
         i = input()
         if isinstance(i, str) and not len(i):
             v = default
+            print(f'{v}')
         else:
             v = literal_eval(i)
     except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
@@ -460,6 +462,7 @@
     i = input()
     if isinstance(i, str) and not len(i):
         i = default
+        print(f'{i}')
     if i is not None and i.lower() in 'yes':
         v = True
     elif i is not None and i.lower() in 'no':
@@ -487,16 +490,25 @@
         print(f'{header} (1, {len(items)}){default_string}:')
     for i, choice in enumerate(items):
         print(f'  {i+1}: {choice}')
-    choice  = input()
-    if isinstance(choice, str) and not len(choice):
-        choice = items.index(default)
-    else:
-        choice = literal_eval(choice)
-        if isinstance(choice, int) and 1 <= choice <= len(items):
-            choice -= 1
+    try:
+        choice  = input()
+        if isinstance(choice, str) and not len(choice):
+            choice = items.index(default)
+            print(f'{choice+1}')
         else:
-            print(f'Illegal choice, enter a number between 1 and {len(items)}')
-            choice = input_menu(items, default)
+            choice = literal_eval(choice)
+            if isinstance(choice, int) and 1 <= choice <= len(items):
+                choice -= 1
+            else:
+                raise ValueError
+    except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
+        choice = None
+    except:
+        print('Unexpected error')
+        raise
+    if choice is None:
+        print(f'Illegal choice, enter a number between 1 and {len(items)}')
+        choice = input_menu(items, default)
     return choice
 
 def create_mask(x, bounds=None, reverse_mask=False, current_mask=None):
@@ -525,7 +537,7 @@
     return mask
 
 def draw_mask_1d(ydata, xdata=None, current_index_ranges=None, current_mask=None,
-        select_mask=True, num_index_ranges_max=None, title=None, legend=None):
+        select_mask=True, num_index_ranges_max=None, title=None, legend=None, test_mode=False):
     def draw_selections(ax):
         ax.clear()
         ax.set_title(title)
@@ -679,30 +691,32 @@
         if current_include[-1][1] < num_data-1:
             current_exclude.append((current_include[-1][1]+1, num_data-1))
 
-    # Set up matplotlib figure
-    plt.close('all')
-    fig, ax = plt.subplots()
-    plt.subplots_adjust(bottom=0.2)
-    draw_selections(ax)
+    if not test_mode:
 
-    # Set up event handling for click-and-drag range selection
-    cid_click = fig.canvas.mpl_connect('button_press_event', onclick)
-    cid_release = fig.canvas.mpl_connect('button_release_event', onrelease)
+        # Set up matplotlib figure
+        plt.close('all')
+        fig, ax = plt.subplots()
+        plt.subplots_adjust(bottom=0.2)
+        draw_selections(ax)
+
+        # Set up event handling for click-and-drag range selection
+        cid_click = fig.canvas.mpl_connect('button_press_event', onclick)
+        cid_release = fig.canvas.mpl_connect('button_release_event', onrelease)
 
-    # Set up confirm / clear range selection buttons
-    confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm')
-    clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear')
-    cid_confirm = confirm_b.on_clicked(confirm_selection)
-    cid_clear = clear_b.on_clicked(clear_last_selection)
+        # Set up confirm / clear range selection buttons
+        confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm')
+        clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear')
+        cid_confirm = confirm_b.on_clicked(confirm_selection)
+        cid_clear = clear_b.on_clicked(clear_last_selection)
 
-    # Show figure
-    plt.show(block=True)
+        # Show figure
+        plt.show(block=True)
 
-    # Disconnect callbacks when figure is closed
-    fig.canvas.mpl_disconnect(cid_click)
-    fig.canvas.mpl_disconnect(cid_release)
-    confirm_b.disconnect(cid_confirm)
-    clear_b.disconnect(cid_clear)
+        # Disconnect callbacks when figure is closed
+        fig.canvas.mpl_disconnect(cid_click)
+        fig.canvas.mpl_disconnect(cid_release)
+        confirm_b.disconnect(cid_confirm)
+        clear_b.disconnect(cid_clear)
 
     # Swap selection depending on select_mask
     if not select_mask:
--- a/tomo_setup.xml	Thu Jul 28 17:44:49 2022 +0000
+++ b/tomo_setup.xml	Tue Aug 02 19:52:47 2022 +0000
@@ -1,4 +1,4 @@
-<tool id="tomo_setup" name="Tomo Setup" version="0.2.0" python_template_version="3.9">
+<tool id="tomo_setup" name="Tomo Setup" version="0.2.1" python_template_version="3.9">
     <description>Preprocess tomography images</description>
     <macros>
         <import>tomo_macros.xml</import>
@@ -24,55 +24,136 @@
             --output_config 'output_config.yaml'
             -l '$log'
             #for $s in $input.tomo_sets# ${s.offset} ${s.num} #end for
+
         ]]>
     </command>
     <configfiles>
-         <configfile name="inputfiles"><![CDATA[#slurp
-#if str( $input.type_selector ) == "collection"
-#for $s in $input.tomo_sets
-#for $input in $s.inputs
-#echo str($input) + '\t' + $input.element_identifier #
-#end for
-#end for
-#end if
-]]></configfile>
+         <configfile name="inputfiles">
+             <![CDATA[#slurp
+                #if str( $input.type_selector ) == "collection"
+                    #for $s in $input.tomo_sets
+                        #for $input in $s.inputs
+                            #echo str($input) + '\t' + $input.element_identifier #
+                        #end for
+                    #end for
+                #end if
+            ]]>
+        </configfile>
     </configfiles>
     <inputs>
-        <expand macro="common_inputs"/>
-        <section name="thetas" title="Tomography angles">
-            <param name="theta_start" type="float" min="0.0" max="360.0" value="0.0" label="Lower bound"/>
-            <param name="theta_end" type="float" min="0.0" max="360.0" value="0.0" label="Upper bound"/>
-            <param name="num_thetas" type="integer" min="1" value="1" label="Number of angles"/>
-        </section>
-
-        <conditional name="input">
-            <param name="type_selector" type="select" label="Choose the dataset format">
-                <option value="collection">datasets as collections</option>
-                <option value="file">datasets as files</option>
+        <conditional name="config_type">
+            <param name="config_selector" type="select" label="Read config from file or enter manually">
+                <option value="file" selected="true">Read config from file</option>
+                <option value="manual">Manually enter config parameters</option>
             </param>
-            <when value="collection">
-                <repeat name='tomo_sets' title="Tomography image collections">
-                    <param name="inputs" type="data_collection" label="Image file collection"/>
-                    <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
-                    <param name="num" type="integer" min="1" value="1" label="Number of images"/>
-                </repeat>
+            <when value="file">
+                <expand macro="common_inputs"/>
+                <param name="num_stack" type="select" label="number of stacks">
+                    <options>
+                        <filter type="data_meta" ref="config" key="num_stack"/>
+                    </options>
+                </param>
+                <section name="thetas" title="Tomography angles">
+                    <param name="theta_start" type="select" label="Lower theta range value (from config)">
+                        <options>
+                            <filter type="data_meta" ref="config" key="theta_start"/>
+                        </options>
+                    </param>
+                    <param name="theta_end" type="select" label="Upper theta range value (from config)">
+                        <options>
+                            <filter type="data_meta" ref="config" key="theta_end"/>
+                        </options>
+                    </param>
+                    <param name="num_thetas" type="integer" min="1" value="1" optional="false" label="Number of angles"/>
+                </section>
+                <conditional name="input">
+                    <param name="type_selector" type="select" label="Choose the dataset format">
+                        <option value="collection">datasets as collections</option>
+                        <option value="file">datasets as files</option>
+                    </param>
+                    <when value="collection">
+                        <repeat name='tomo_sets' title="Tomography image collections">
+                            <param name="inputs" type="data_collection" label="Image file collection"/>
+                            <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
+                            <param name="ref_height" type="select" label="Reference height (from config)">
+                                <options>
+                                    <filter type="data_meta" ref="config" key="ref_height"/>
+                                </options>
+                            </param>
+                            <!--
+                            <param name="num" type="integer" min="1" value="1" label="Number of images"/>
+                            -->
+                        </repeat>
+                    </when>
+                    <when value="file">
+                        <repeat name='tomo_sets' title="Tomography image datasets">
+                            <conditional name="set_type">
+                                <param name="type_selector" type="select" label="Choose the dataset type">
+                                    <option value="tdf">dark field</option>
+                                    <option value="tbf">bright field</option>
+                                    <option value="data">tomography field</option>
+                                </param>
+                                <when value="tdf"/>
+                                <when value="tbf"/>
+                                <when value="data"/>
+                            </conditional>
+                            <param name="inputs" type="data" format='h5' optional='false' label="Image file"/>
+                            <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
+                            <param name="ref_height" type="select" label="Reference height (from config)">
+                                <options>
+                                    <filter type="data_meta" ref="config" key="ref_height"/>
+                                </options>
+                            </param>
+                            <!--
+                            <param name="num" type="integer" min="1" value="1" label="Number of images"/>
+                            -->
+                        </repeat>
+                    </when>
+                </conditional>
             </when>
-            <when value="file">
-                <repeat name='tomo_sets' title="Tomography image datasets">
-                    <conditional name="set_type">
-                        <param name="type_selector" type="select" label="Choose the dataset type">
-                            <option value="tdf">dark field</option>
-                            <option value="tbf">bright field</option>
-                            <option value="data">tomography field</option>
-                        </param>
-                        <when value="tdf"/>
-                        <when value="tbf"/>
-                        <when value="data"/>
-                    </conditional>
-                    <param name="inputs" type="data" format='h5' optional='false' label="Image file"/>
-                    <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
-                    <param name="num" type="integer" min="1" value="1" label="Number of images"/>
-                </repeat>
+            <when value="manual">
+                <param name="num_stack" type="integer" min="1" value="1" label="Number of stacks"/>
+                <section name="thetas" title="Tomography angles">
+                    <param name="theta_start" type="float" min="0.0" max="360.0" value="0.0" label="Lower bound"/>
+                    <param name="theta_end" type="float" min="0.0" max="360.0" value="0.0" label="Upper bound"/>
+                    <param name="num_thetas" type="integer" min="1" value="1" label="Number of angles"/>
+                </section>
+                <conditional name="input">
+                    <param name="type_selector" type="select" label="Choose the dataset format">
+                        <option value="collection">datasets as collections</option>
+                        <option value="file">datasets as files</option>
+                    </param>
+                    <when value="collection">
+                        <repeat name='tomo_sets' title="Tomography image collections">
+                            <param name="inputs" type="data_collection" label="Image file collection"/>
+                            <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
+                            <param name="ref_height" type="float" value="0.0" label="Reference height"/>
+                            <!--
+                            <param name="num" type="integer" min="1" value="1" label="Number of images"/>
+                            -->
+                        </repeat>
+                    </when>
+                    <when value="file">
+                        <repeat name='tomo_sets' title="Tomography image datasets">
+                            <conditional name="set_type">
+                                <param name="type_selector" type="select" label="Choose the dataset type">
+                                    <option value="tdf">dark field</option>
+                                    <option value="tbf">bright field</option>
+                                    <option value="data">tomography field</option>
+                                </param>
+                                <when value="tdf"/>
+                                <when value="tbf"/>
+                                <when value="data"/>
+                            </conditional>
+                            <param name="inputs" type="data" format='h5' optional='false' label="Image file"/>
+                            <param name="offset" type="integer" min="0" value="0" label="Image index offset"/>
+                            <param name="ref_height" type="float" value="0.0" label="Reference height"/>
+                            <!--
+                            <param name="num" type="integer" min="1" value="1" label="Number of images"/>
+                            -->
+                        </repeat>
+                    </when>
+                </conditional>
             </when>
         </conditional>
     </inputs>
@@ -87,8 +168,10 @@
         <data name="output_config" format="yaml" label="Output config setup" from_work_dir="output_config.yaml"/>
         <data name="output_data" format="npz" label="Preprocessed tomography data" from_work_dir="output_data.npz"/>
     </outputs>
-    <help><![CDATA[
-        Preprocess tomography images.
-    ]]></help>
+    <help>
+        <![CDATA[
+            Preprocess tomography images.
+        ]]>
+    </help>
     <expand macro="citations"/>
 </tool>