changeset 0:72deb053b5a5 draft

"planemo upload for repository https://github.com/ximg-chess/galaxytools/tools/hexrd commit 3e41869cdb6ad4c9a60a4b60dcf9bb4a40955cfa-dirty"
author ximgchess
date Sat, 21 Nov 2020 03:34:48 +0000
parents
children a0be4e3aa66d
files datatypes_conf.xml hexrd_find_orientations.xml hexrd_fit_grains.xml macros.xml
diffstat 4 files changed, 493 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datatypes_conf.xml	Sat Nov 21 03:34:48 2020 +0000
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<datatypes>
+  <registration>
+    <datatype extension="material.hexrd" type="galaxy.datatypes.binary:Binary" subclass="true" display_in_upload="true"/>
+    <datatype extension="hexrd.npz" type="galaxy.datatypes.binary:CompressedZipArchive" subclass="true" display_in_upload="true"/>
+    <datatype extension="hexrd.yml" type="galaxy.datatypes.data:Text" subclass="true" display_in_upload="true"/>
+  </registration>
+</datatypes>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hexrd_find_orientations.xml	Sat Nov 21 03:34:48 2020 +0000
@@ -0,0 +1,84 @@
+<tool id="hexrd_find_orientations" name="HEXRD find-orientations" version="@TOOL_VERSION@+galaxy0" python_template_version="3.5">
+    <description>Process rotation image series to find grain orientations</description>
+    <macros>
+        <import>macros.xml</import>
+    </macros>
+    <expand macro="requirements" />
+    <command detect_errors="exit_code"><![CDATA[
+        cp '$config_yml' $config &&
+        cp '$config_yml' config.yml &&
+        ## symlink input files
+        @CMD_LINKS@
+        hexrd find-orientations config.yml &&
+        @CONVERT2TAB@ &&
+        cp find-orientations_analysis_*.log '$log' &&
+        cp  accepted_orientations_analysis_*.dat '$accepted_orientations' &&
+        cp  scored_orientations_analysis_*.npz '$score_orientations' &&
+        cp analysis_*_eta-ome_maps.npz '$ome_maps' 
+    ]]></command>
+    <configfiles>
+        <configfile name="config_yml"><![CDATA[@FIND_ORIENTATIONS_YML@
+]]></configfile>
+    </configfiles>
+
+    <inputs>
+        <expand macro="find_orientations_config"/> 
+    </inputs>
+    <outputs>
+        <data name="config" format="hexrd.yml" label="${tool.name} on ${on_string}: ${active_material}_config.yml"/>
+        <data name="log" format="txt" label="${tool.name} on ${on_string}: find-orientations_analysis_${active_material}.log"/>
+        <data name="ome_maps" format="hexrd.npz" label="${tool.name} on ${on_string}: analysis_${active_material}_eta-ome_maps.npz"/>
+        <data name="score_orientations" format="hexrd.npz" label="${tool.name} on ${on_string}: scored_orientations_analysis_${active_material}.npz"/>
+        <data name="accepted_orientations" format="tabular" label="${tool.name} on ${on_string}: accepted_orientations_analysis_${active_material}.dat"/>
+        <data name="grains" format="tabular" label="${tool.name} on ${on_string}: grains.out" from_work_dir="analysis/grains.out" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="inputs" ftype="hexrd.npz" value="RUBY_0000-fc_GE.npz,RUBY_0001-fc_GE.npz,RUBY_0002-fc_GE.npz,RUBY_0003-fc_GE.npz,RUBY_0004-fc_GE.npz,RUBY_0005-fc_GE.npz"/>
+            <conditional name="detector">
+                <param name="panel_assignment" value="infer_from_name"/>
+            </conditional>
+            <param name="instrument" ftype="hexrd.yml" value="ge_detector.yml"/>
+            <param name="material" ftype="material.hexrd" value="materials_py38.hexrd"/>
+            <param name="active_material" value="ruby"/>
+            <section name="orientation_maps">
+                <param name="threshold" value="25"/>
+                <param name="bin_frames" value="1"/>
+                <param name="active_hkls" value="0,1,2,3,4,5"/>
+            </section>
+            <section name="search_options">
+                <conditional name="search">
+                    <param name="search_type" value="seed_search"/>
+                    <param name="hkl_seeds" value="0,1,2"/>
+                    <param name="fiber_step" value="0.5"/>
+                    <conditional name="params">
+                        <param name="method" value="label"/>
+                        <param name="filter_radius" value="1"/>
+                        <param name="threshold" value="1"/>
+                    </conditional>
+                </conditional>
+            </section>
+            <section name="omega">
+                <param name="omega_tolerance" value="1.0"/>
+            </section>
+            <section name="eta">
+                <param name="eta_tolerance" value="1.0"/>
+                <param name="eta_mask" value="5.0"/>
+            </section>
+            <section name="clustering">
+                <param name="clustering_algorithm" value="dbscan"/>
+                <param name="clustering_radius" value="1.0"/>
+                <param name="clustering_completeness" value="0.85"/>
+            </section>
+            <output name="grains">
+                <assert_contents>
+                    <has_text text="6.6655" />
+                </assert_contents>
+            </output>
+        </test>
+    </tests>
+    <help><![CDATA[
+        TODO: Fill in help.
+    ]]></help>
+    <expand macro="citations" />
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hexrd_fit_grains.xml	Sat Nov 21 03:34:48 2020 +0000
@@ -0,0 +1,73 @@
+<tool id="hexrd_fit_grains" name="HEXRD fit-grains" version="@TOOL_VERSION@.0" python_template_version="3.5">
+    <description>Extracts G vectors, grain position and strain</description>
+    <macros>
+        <import>macros.xml</import>
+    </macros>
+    <expand macro="requirements" />
+    <command detect_errors="exit_code"><![CDATA[
+        cp '$config_yml' $config &&
+        cp '$config_yml' config.yml &&
+        ## symlink input files
+        @FIT_GRAIN_LINKS@
+        hexrd fit-grains config.yml -f &&
+        cp analysis/*.log '$log' && 
+        @CONVERT2TAB@ 
+        && for i in analysis/*/spots*.out; do dest=`echo \${i\#*/} | tr '/' '_'`; mv \${i} analysis/\$dest; done
+    ]]></command>
+    <configfiles>
+        <configfile name="config_yml"><![CDATA[@FIT_GRAINS_YML@
+]]></configfile>
+    </configfiles>
+    <inputs>
+        <expand macro="fit_grains_config"/>
+    </inputs>
+    <outputs>
+        <data name="config" format="hexrd.yml" label="${tool.name} on ${on_string}: ${active_material}_config.yml"/>
+        <data name="log" format="txt" label="${tool.name} on ${on_string}:fit_grains_analysis_${active_material}.log"/>
+        <data name="grains" format="tabular" label="${tool.name} on ${on_string}: grains.out" from_work_dir="analysis/grains.out" />
+        <collection name="spots" type="list" label="${tool.name} on ${on_string}:spots">
+            <discover_datasets pattern="(?P&lt;designation&gt;.+_spots.+\.out)" ext="tabular" directory="analysis"/>
+        </collection>
+    </outputs>
+    <tests>
+        <test>
+            <param name="inputs" ftype="hexrd.npz" value="RUBY_0000-fc_GE.npz,RUBY_0001-fc_GE.npz,RUBY_0002-fc_GE.npz,RUBY_0003-fc_GE.npz,RUBY_0004-fc_GE.npz,RUBY_0005-fc_GE.npz"/>
+            <conditional name="detector">
+                <param name="panel_assignment" value="infer_from_name"/>
+            </conditional>
+            <param name="instrument" ftype="hexrd.yml" value="ge_detector.yml"/>
+            <param name="material" ftype="material.hexrd" value="materials_py38.hexrd"/>
+            <param name="active_material" value="ruby"/>
+            <param name="ome_map" ftype="hexrd.npz" value="analysis_ruby_eta-ome_maps.npz"/>
+            <param name="accepted_orientations" ftype="tabular" value="accepted_orientations_analysis_ruby.dat"/>
+            <param name="grains_estimate" ftype="tabular" value="grains.out"/>
+            <param name="do_fit" value="true"/>
+            <param name="npdiv" value="2"/>
+            <param name="threshold" value="25"/>
+            <section name="tolerance">
+                <repeat name="tolerance_lists">
+                    <param name="tth" value="0.25"/>
+                    <param name="eta" value="3.0"/>
+                    <param name="omega" value="2.0"/>
+                    <param name="refit" value="1"/>
+                </repeat>
+                <repeat name="tolerance_lists">
+                    <param name="tth" value="0.20"/>
+                    <param name="eta" value="2.0"/>
+                    <param name="omega" value="1.0"/>
+                    <param name="refit" value="1"/>
+                </repeat>
+                <param name="tth_max" value="14.25"/>
+            </section>
+            <output name="grains">
+                <assert_contents>
+                    <has_text text="6.6655" />
+                </assert_contents>
+            </output>
+        </test>
+    </tests>
+    <help><![CDATA[
+        TODO: Fill in help.
+    ]]></help>
+    <expand macro="citations" />
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/macros.xml	Sat Nov 21 03:34:48 2020 +0000
@@ -0,0 +1,328 @@
+<macros>
+    <token name="@TOOL_VERSION@">0.8.0</token>
+    <xml name="requirements">
+        <requirements>
+        <requirement type="package" version="@TOOL_VERSION@">hexrd</requirement>
+            <yield/>
+        </requirements>
+    </xml>
+    <xml name="citations">
+        <citations>
+            <citation type="doi">10.1016/j.matchar.2020.110366</citation>
+            <yield />
+        </citations>
+    </xml>
+
+    <token name="@CMD_IMPORTS@">
+#import re
+#import yaml
+
+#set global $img_panel_dict = dict()
+#if $detector.panel_assignment == 'panel_table'
+#set $fh = open(str($detector.image_panel_table),'r')
+#for $line in $fh:
+    #set $fields = $line.strip().split('\t')
+    #silent $img_panel_dict[$fields[0]] = $fields[1]
+#end for
+#end if
+#set global $panels = $yaml.safe_load(open(str($instrument),'r'))['detectors'].keys()
+#def identifier_or_name($input1)
+    #if hasattr($input1, 'element_identifier')
+        #return $input1.element_identifier
+    #elif hasattr($input1, 'name')
+        #return $input1.name
+    #else
+        #return str($input1)
+    #end if
+#end def
+#def clean($name1)
+    #set $name_clean = $re.sub('[^\w\-_]', '_', $re.sub('(?i)[.](npz|hexrd|yml|dat|out)$','', $name1.split()[-1]))
+    #return $name_clean
+#end def
+#def ln_name($ds,$ext)
+    #set $lname = "%s.%s" % ($clean($identifier_or_name($ds)),$ext)
+    #return $lname
+#end def
+#def get_panel($img_input):
+    #set $img_name = $identifier_or_name($img_input)
+    #if $img_panel_dict and $img_name in $img_panel_dict:
+        #return $img_panel_dict[$img_name]
+    #end if
+    #for $p in $panels:
+        #if $p in $img_name:
+            #return $p
+        #end if
+    #end for
+    #return $img_name
+#end def
+    </token>
+
+    <xml name="common_config" token_multiple_inputs="true" >
+        <param name="inputs" type="data" format="hexrd.npz" multiple="true" label="Image series frame-cache"/>
+        <conditional name="detector">
+            <param name="panel_assignment" type="select" label="Assign detector panel to images">
+                <option value="infer_from_name" selected="true">Infer the panel from the image name</option>
+                <option value="panel_table">Input a table with image panels assignments</option>
+            </param>
+            <when value="infer_from_name"/>
+            <when value="panel_table">
+                <param name="image_panel_table" type="data" format="tabular" label="Image panel assignment table">
+                    <help>A 2-column table:image dataset name   detector panel name</help>
+                </param>
+            </when>
+        </conditional>
+        <param name="instrument" type="data" format="hexrd.yml" label="instrument"/>
+        <param name="material" type="data" format="material.hexrd" label="material"/>
+        <param name="active_material" type="text" value="" label="active material name">
+            <validator type="empty_field" />
+        </param>
+    </xml>
+
+    <token name="@CMD_LINKS@"><![CDATA[@CMD_IMPORTS@
+mkdir -p imageseries &&
+ln -s '$material' $ln_name($material,'hexrd') &&
+ln -s '$instrument' $ln_name($instrument,'yml') &&
+#for $input in $inputs
+ln -s '$input' imageseries/$ln_name($input,'npz') &&
+#end for
+]]>
+    </token>
+    <token name="@FIT_GRAIN_LINKS@"><![CDATA[@CMD_LINKS@
+ln -s '$ome_map' $ln_name($ome_map,'npz') &&
+ln -s '$accepted_orientations' $ln_name($accepted_orientations,'dat') &&
+##mkdir -p analysis &&
+##cp '$grains_estimate' analysis/$ln_name($grains_estimate,'out') &&
+]]>
+    </token>
+
+    <token name="@CONVERT2TAB@"><![CDATA[for i in `find analysis -name '[gs]*.out'`; do sed -i.bak "s/[ ][ ][ ]*/\$(printf '\t')/g" \${i}; done]]></token>
+
+    <token name="@COMMON_YML@"><![CDATA[@CMD_IMPORTS@
+analysis_name: analysis
+
+multiprocessing: -1
+
+material:
+  definitions: $ln_name($material,'hexrd')
+  active: $active_material
+
+instrument: $ln_name($instrument,'yml')
+
+image_series:
+  format: frame-cache
+  data:
+#for $input in $inputs
+    - file: imageseries/$ln_name($input,'npz')
+      args: {}
+      panel: $get_panel($input)  # must match detector key
+#end for
+
+]]></token>
+
+    <xml name="find_orientations_config">
+        <expand macro="common_config" token_multiple_inputs="true" />
+        <section name="orientation_maps" title="Orientation Maps" expanded="true">
+            <param name="threshold" type="integer" value="25" min="1" label="threshold"/>
+            <param name="bin_frames" type="integer" value="1" label="bin frames"/>
+            <param name="active_hkls" type="text" value="" optional="true" label="active hkls">
+                <validator type="regex" message="">^\d(,\d)*$</validator>
+	    </param> 
+        </section>
+        <param name="on_map_threshold" type="integer" value="1" min="1" label="on-map threshold used in the scoring"/>
+        <section name="search_options" title="Search Options" expanded="true">
+            <conditional name="search">
+                <param name="search_type" type="select" label="Specify Search">
+                    <option value="seed_search" selected="true">use seed search</option>
+                    <option value="use_quaternion_grid">use quaternion grid</option>
+                </param>
+                <when value="seed_search">
+                    <param name="hkl_seeds" type="text" value="" optional="true" label="hkl seeds">
+                        <validator type="regex" message="">^\d(,\d)*$</validator>
+    	        </param> 
+                    <param name="fiber_step" type="float" value="0.5" min="0" max="10" label="fiber step"/>
+                    <conditional name="params">
+                        <param name="method" type="select" label="Method">
+                            <option value="label" selected="true">label</option>
+                            <option value="blob_dog">blob_dog</option>
+                            <option value="blob_log">blob_log</option>
+                        </param>
+                        <when value="label">
+                            <param name="filter_radius" type="integer" value="1" min="1" label="label filter radius"/>
+                            <param name="threshold" type="integer" value="1" min="1" label="label threshold"/>
+                        </when>
+                        <when value="blob_dog">
+                            <param name="min_sigma" type="float" value="0.5" min="0" max="10" label="blob_dog min_sigma"/>
+                            <param name="max_sigma" type="float" value="5.0" min="0" max="10" label="blob_dog max_sigma"/>
+                            <param name="sigma_ratio" type="float" value="1.6" min="0" max="10" label="blob_dog sigma_ratio"/>
+                            <param name="threshold" type="float" value="0.01" min="0" max="1.0" label="blob_dog threshold"/>
+                            <param name="overlap" type="float" value="0.1" min="0" max="1.0" label="blob_dog overlap"/>
+                        </when>
+                        <when value="blob_log">
+                            <param name="min_sigma" type="float" value="0.5" min="0" max="10" label="blob_log min_sigma"/>
+                            <param name="max_sigma" type="float" value="5.0" min="0" max="10" label="blob_log max_sigma"/>
+                            <param name="num_sigma" type="integer" value="10" min="0" max="20" label="blob_log num_sigma"/>
+                            <param name="threshold" type="float" value="0.01" min="0" max="1.0" label="blob_log threshold"/>
+                            <param name="overlap" type="float" value="0.1" min="0" max="1.0" label="blob_log overlap"/>
+                        </when>
+                    </conditional>
+                </when>
+                <when value="use_quaternion_grid">
+                    <param name="quaternion_grid" type="data" format="hexrd.npz" label="quaterion grid file"/>
+                </when>
+            </conditional>
+        </section>
+        <section name="omega" title="Omega" expanded="true">
+            <param name="omega_tolerance" type="float" value="1.0" min="0" max="10.0" label="omega tolerance"/>
+        </section>
+        <section name="eta" title="eta" expanded="true">
+            <param name="eta_tolerance" type="float" value="1.0" min="0" max="10.0" label="eta tolerance"/>
+            <param name="eta_mask" type="float" value="5.0" min="0" max="10.0" label="eta mask"/>
+        </section>
+        <section name="clustering" title="Clustering" expanded="true">
+            <param name="clustering_algorithm" type="select" label="Clustering algorithm">
+                <option value="dbscan" selected="true">dbscan</option>
+                <option value="sph-dbscan">sph-dbscan</option>
+                <option value="ort-dbscan">ort-dbscan</option>
+                <option value="fclusterdata">fclusterdata (won't work for large problems)</option>
+            </param>
+            <param name="clustering_radius" type="float" value="1.0" min="0" max="10" label="clustering radius"/>
+            <param name="clustering_completeness" type="float" value="0.85" min="0" max="1" label="clustering completeness threshold"/>
+        </section>
+        <!-- 
+        -->
+    </xml>
+
+    <token name="@FIND_ORIENTATIONS_YML@"><![CDATA[@COMMON_YML@
+
+#set active_hkls = 'all'
+#if $orientation_maps.active_hkls:
+#set active_hkls = '[' + str($orientation_maps.active_hkls) + ']'
+#end if
+find_orientations:
+  orientation_maps:
+    # A file name must be specified. If it doesn't exist, one will be created
+    file: null
+
+    threshold: $orientation_maps.threshold
+    bin_frames: $orientation_maps.bin_frames # defaults to 1
+
+    # "all", or a list of hkl orders used to find orientations
+    # defaults to all orders listed in the material definition
+    active_hkls: $active_hkls
+
+  # either search full quaternion grid, or seed search based on sparse
+  # orientation maps.  For input search space:
+  #
+  # use_quaternion_grid: some/file/name
+  #
+  # otherwise defaults to seeded search
+#if $search_options.search.search_type == 'use_quaternion_grid'
+  use_quaternion_grid: 
+#elif $search_options.search.search_type == 'seed_search'
+#set hkl_seeds = '[' + str($search_options.search.hkl_seeds) + ']'
+  seed_search: # this section is ignored if use_quaternion_grid is defined
+    hkl_seeds: $hkl_seeds # hkls ids to use, must be defined for seeded search
+    fiber_step: $search_options.search.fiber_step # degrees, defaults to ome tolerance
+    # Method selection:
+    #   Now 3 choices: label (the original), 'blob_dog', and 'blob_log'
+    #   Each has its own parameter names, examples below.
+    #
+    method:
+    #if $search_options.search.params.method == 'label'
+      label:
+        filter_radius: $search_options.search.params.filter_radius
+        threshold: $search_options.search.params.threshold
+    #elif $search_options.search.params.method == 'blob_dog'
+      blob_dog:
+        min_sigma: $search_options.search.params.min_sigma
+        max_sigma: $search_options.search.params.max_sigma
+        sigma_ratio: $search_options.search.params.sigma_ratio
+        threshold: $search_options.search.params.threshold
+        overlap: $search_options.search.params.overlap
+    #elif $search_options.search.params.method == 'blob_log'
+      blob_log:
+        min_sigma: $search_options.search.params.min_sigma
+        max_sigma: $search_options.search.params.max_sigma
+        num_sigma: $search_options.search.params.num_sigma
+        threshold: $search_options.search.params.threshold
+        overlap: $search_options.search.params.overlap
+    #end if
+  # this is the on-map threshold using in the scoring
+  # defaults to 1
+#end if
+  threshold: $on_map_threshold
+
+  omega:
+    tolerance: $omega.omega_tolerance  # in degrees, defaults to 2x ome step
+
+  eta:
+    tolerance: $eta.eta_tolerance  # in degrees, defaults to 2x ome step
+    mask: $eta.eta_mask  # degrees, mask angles close to ome rotation axis, defaults to 5
+
+  clustering:
+    # algorithm choices are
+    #   sph-dbscan
+    #   ort-dbscn
+    #   dbscan <default>
+    #   fclusterdata; this is a fallback and won't work for large problems
+    algorithm: $clustering.clustering_algorithm
+    radius: $clustering.clustering_radius
+    completeness: $clustering.clustering_completeness
+
+]]></token>
+
+    <xml name="fit_grains_config">
+        <expand macro="common_config" token_multiple_inputs="true"/>
+        <param name="ome_map" type="data" format="hexrd.npz" label="analysis eta-ome_maps.npz from find_orientations"/>
+        <param name="accepted_orientations" type="data" format="tabular" label="accepted_orientations from find_orientations"/>
+        <param name="grains_estimate" type="data" format="tabular" label="grains.out from find_orientations"/>
+        <param name="do_fit" type="boolean" truevalue="true" falsevalue="false" checked="true" label="fit grains" help="if false, extracts grains but doesn't fit"/>
+        <param name="npdiv" type="integer" value="2" min="1" label="number of polar pixel grid subdivisions"/>
+        <param name="threshold" type="integer" value="25" min="1" label="threshold"/>
+        <section name="tolerance" title="Fit Grain Tolerance" expanded="true">
+            <repeat name="tolerance_lists" title="Tolerance values" min="1">
+                <param name="tth" type="float" value="" min="0" label="tth"/>
+                <param name="eta" type="float" value="" min="0" label="eta"/>
+                <param name="omega" type="float" value="" min="0" label="omega"/>
+            </repeat>
+            <param name="refit" type="text" value="1" label="refit">
+                <validator type="regex" message="">^\d(,\d)*$</validator>
+            </param>
+            <param name="tth_max" type="float" value="14.25" label="tth_max"/>
+        </section>
+    </xml>
+
+    <token name="@FIT_GRAINS_YML@"><![CDATA[@COMMON_YML@
+find_orientations:
+  orientation_maps:
+    # A file name must be specified. If it doesn't exist, one will be created
+    file: $ln_name($ome_map,'npz')
+
+fit_grains:
+  do_fit: $do_fit # if false, extracts grains but doesn't fit. defaults to true
+
+  # estimate: null
+
+  npdiv: $npdiv # number of polar pixel grid subdivisions, defaults to 2
+
+  threshold: $threshold
+
+#set $tth = []
+#set $eta = []
+#set $omega = []
+#set refit = '[' + str($tolerance.refit) + ']'
+#for $tol in $tolerance.tolerance_lists
+$tth.append(float($tol.tth))
+$eta.append(float($tol.eta))
+$omega.append(float($tol.omega))
+#end for
+  tolerance:
+    tth: $tth # tolerance lists must be identical length
+    eta: $eta
+    omega: $omega
+
+  refit: $refit
+  tth_max: $tolerance.tth_max # true, false, or a non-negative value, defaults to true
+]]></token>
+
+</macros>