changeset 0:47839d77a281 draft default tip

"planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/value_from_yaml_or_json commit 28fa7f14add96533ed9538b675a5fb58438566d5-dirty"
author jjohnson
date Thu, 14 Jul 2022 17:02:53 +0000
parents
children
files test-data/input.json test-data/input.yaml value_from_yaml_or_json.xml
diffstat 3 files changed, 379 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input.json	Thu Jul 14 17:02:53 2022 +0000
@@ -0,0 +1,136 @@
+{
+    "beam": {
+        "energy": 41.9906,
+        "vector": {
+            "azimuth": 90.0,
+            "polar_angle": 90.0
+        }
+    },
+    "calibration_crystal": {
+        "0": {
+            "inv_stretch": [
+                1.0,
+                1.0,
+                1.0,
+                0.0,
+                0.0,
+                0.0
+            ],
+            "orientation": [
+                1.2148784044413221,
+                0.6945507909200794,
+                0.765702046701113
+            ],
+            "position": [
+                0.06060121926310595,
+                0.1312120981443553,
+                -0.06694059935413639
+            ]
+        },
+        "1": {
+            "inv_stretch": [
+                1.0,
+                1.0,
+                1.0,
+                0.0,
+                0.0,
+                0.0
+            ],
+            "orientation": [
+                1.4105172207115466,
+                -0.14336674130145605,
+                -0.37238882282338215
+            ],
+            "position": [
+                0.016940740257706914,
+                -0.1183857552099456,
+                0.34767784259162654
+            ]
+        },
+        "2": {
+            "inv_stretch": [
+                1.0,
+                1.0,
+                1.0,
+                0.0,
+                0.0,
+                0.0
+            ],
+            "orientation": [
+                0.34356534660437343,
+                0.8170405732053853,
+                -0.01649123635877074
+            ],
+            "position": [
+                0.01052568572502354,
+                -0.11080094260256373,
+                -0.33689416855383947
+            ]
+        }
+    },
+    "detectors": {
+        "ff1": {
+            "buffer": [
+                2.0,
+                2.0
+            ],
+            "pixels": {
+                "columns": 3072,
+                "rows": 3888,
+                "size": [
+                    0.0748,
+                    0.0748
+                ]
+            },
+            "saturation_level": 15800.0,
+            "transform": {
+                "tilt": [
+                    0.010486950176001908,
+                    -0.006152055149709758,
+                    0.0014922461489979366
+                ],
+                "translation": [
+                    123.3706062259476,
+                    3.325955053634411,
+                    -670.7508650125019
+                ]
+            }
+        },
+        "ff2": {
+            "buffer": [
+                2.0,
+                2.0
+            ],
+            "pixels": {
+                "columns": 3072,
+                "rows": 3888,
+                "size": [
+                    0.0748,
+                    0.0748
+                ]
+            },
+            "saturation_level": 15800.0,
+            "transform": {
+                "tilt": [
+                    0.00991389059922992,
+                    -0.01010540645355334,
+                    0.00026733734489633163
+                ],
+                "translation": [
+                    -123.5603890819458,
+                    3.186895450085356,
+                    -671.04758940985
+                ]
+            }
+        }
+    },
+    "id": "dexelas_id3a_20200130",
+    "oscillation_stage": {
+        "chi": 0.0007535217427322955,
+        "translation": [
+            0.0,
+            0.0,
+            0.0
+        ]
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input.yaml	Thu Jul 14 17:02:53 2022 +0000
@@ -0,0 +1,102 @@
+beam:
+  energy: 41.9906
+  vector:
+    azimuth: 90.0
+    polar_angle: 90.0
+calibration_crystal:
+  0:
+    inv_stretch:
+    - 1.0
+    - 1.0
+    - 1.0
+    - 0.0
+    - 0.0
+    - 0.0
+    orientation:
+    - 1.2148784044413221
+    - 0.6945507909200794
+    - 0.765702046701113
+    position:
+    - 0.06060121926310595
+    - 0.1312120981443553
+    - -0.06694059935413639
+  1:
+    inv_stretch:
+    - 1.0
+    - 1.0
+    - 1.0
+    - 0.0
+    - 0.0
+    - 0.0
+    orientation:
+    - 1.4105172207115466
+    - -0.14336674130145605
+    - -0.37238882282338215
+    position:
+    - 0.016940740257706914
+    - -0.1183857552099456
+    - 0.34767784259162654
+  2:
+    inv_stretch:
+    - 1.0
+    - 1.0
+    - 1.0
+    - 0.0
+    - 0.0
+    - 0.0
+    orientation:
+    - 0.34356534660437343
+    - 0.8170405732053853
+    - -0.01649123635877074
+    position:
+    - 0.01052568572502354
+    - -0.11080094260256373
+    - -0.33689416855383947
+detectors:
+  ff1:
+    buffer:
+    - 2.0
+    - 2.0
+    pixels:
+      columns: 3072
+      rows: 3888
+      size:
+      - 0.0748
+      - 0.0748
+    saturation_level: 15800.0
+    transform:
+      tilt:
+      - 0.010486950176001908
+      - -0.006152055149709758
+      - 0.0014922461489979366
+      translation:
+      - 123.3706062259476
+      - 3.325955053634411
+      - -670.7508650125019
+  ff2:
+    buffer:
+    - 2.0
+    - 2.0
+    pixels:
+      columns: 3072
+      rows: 3888
+      size:
+      - 0.0748
+      - 0.0748
+    saturation_level: 15800.0
+    transform:
+      tilt:
+      - 0.00991389059922992
+      - -0.01010540645355334
+      - 0.00026733734489633163
+      translation:
+      - -123.5603890819458
+      - 3.186895450085356
+      - -671.04758940985
+id: dexelas_id3a_20200130
+oscillation_stage:
+  chi: 0.0007535217427322955
+  translation:
+  - 0.0
+  - 0.0
+  - 0.0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/value_from_yaml_or_json.xml	Thu Jul 14 17:02:53 2022 +0000
@@ -0,0 +1,141 @@
+<tool id="value_from_yaml_or_json" name="Value from YAML or JSON" version="0.1.0" python_template_version="3.5">
+    <requirements>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+#def getValue(contents, path)
+  #set $rslt = $contents
+  #set $keys = path.split(':')
+  #for k in $keys:
+      #if isinstance($rslt,dict)
+          #if k in $rslt.keys()
+              #set $rslt = $rslt[k]
+          #else
+              #for dk in $rslt.keys():
+                  #if str(dk) == k
+                      #set $rslt = $rslt[dk]
+                  #end if
+              #end for
+          #end if
+      #elif isinstance($rslt,list)
+          #set $rslt = $rslt[int(k)]
+      #end if
+  #end for
+  #return $rslt
+#end def
+#set $fh = open(str($input),'r')
+#if $input.is_of_type('yaml')
+#import yaml
+#set $data = $yaml.safe_load(fh.read())
+#else
+#import json
+#set $data =  $json.load($fh)
+#end if
+#silent $fh.close()
+#set $value = $getValue($data,  $path)
+echo "$value" > '$output'
+    ]]></command>
+    <inputs>
+        <param name="input" type="data" format="yaml,json" label="YAML or JSON from which to extract value"/>
+        <param name="path" type="text" value="" label="path to value via dict keys or list indices" 
+               help="separate keys/indexes with the colon char : ">
+            <sanitizer>
+                <valid initial="string.printable">
+                </valid>
+            </sanitizer>
+        </param>
+    </inputs>
+    <outputs>
+        <data name="output" format="txt" />
+    </outputs>
+    <tests>
+        <!-- Test-1 json dict -->
+        <test>
+            <param name="input" ftype="json" value="input.json"/> 
+            <param name="path" value="beam:energy"/> 
+            <output name="output">
+                <assert_contents>
+                    <has_line line="41.9906" />
+                </assert_contents>
+            </output>
+        </test>
+        <!-- Test-2 json list -->
+        <test>
+            <param name="input" ftype="json" value="input.json"/> 
+            <param name="path" value="calibration_crystal:0:orientation:1"/> 
+            <output name="output">
+                <assert_contents>
+                    <has_line line="0.6945507909200794" />
+                </assert_contents>
+            </output>
+        </test>
+        <!-- Test-3 yaml dict -->
+        <test>
+            <param name="input" ftype="yaml" value="input.yaml"/> 
+            <param name="path" value="beam:energy"/> 
+            <output name="output">
+                <assert_contents>
+                    <has_line line="41.9906" />
+                </assert_contents>
+            </output>
+        </test>
+        <!-- Test-4 yaml list -->
+        <test>
+            <param name="input" ftype="yaml" value="input.yaml"/> 
+            <param name="path" value="calibration_crystal:0:orientation:1"/> 
+            <output name="output">
+                <assert_contents>
+                    <has_line line="0.6945507909200794" />
+                </assert_contents>
+            </output>
+        </test>
+    </tests>
+    <help><![CDATA[
+Extract a value from a YAML or JSON dataset and save to the output dataset.  
+It is expected that this will be most useful in workflows for extracting values that can be linked to parameters.
+
+*If more elaborate filtering of JSON datasets is required, the* `JQ tool`_ *is available.*
+
+.. _JQ tool: https://toolshed.g2.bx.psu.edu/view/iuc/jq/5ff75eb1a893 
+
+-----
+
+With a JSON or YAML input dataset, specify the path for the value you wish to output by listing the key/index of the elements separated by the colon character.
+
+**Example Input YAML File** ::
+
+    beam:
+      energy: 41.9906
+      vector:
+        azimuth: 90.0
+        polar_angle: 90.0
+    calibration_crystal:
+      0:
+        orientation:
+        - 1.2148784044413221
+        - 0.6945507909200794
+        - 0.765702046701113
+        position:
+        - 0.06060121926310595
+        - 0.1312120981443553
+        - -0.06694059935413639
+      1:
+        orientation:
+        - 1.4105172207115466
+        - -0.14336674130145605
+        - -0.37238882282338215
+        position:
+        - 0.016940740257706914
+        - -0.1183857552099456
+        - 0.34767784259162654
+
+*Specifying path:*  **beam:energy** 
+    *outputs:* **41.9906**
+
+*Specifying path:*  **calibration_crystal:1:position:2**
+    *outputs:* **0.34767784259162654**
+
+*Specifying path:*  **calibration_crystal:1:position**
+    *outputs:* **[0.016940740257706914, -0.1183857552099456, 0.34767784259162654]**
+
+    ]]></help>
+</tool>