changeset 0:27e7e4d38e44 draft

planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/erecord-deploy/-/tree/main/galaxy-tools/erecord_file commit 88beb443a737b4c4d42bb0011a26a0acf535c366
author siwaa
date Tue, 12 Dec 2023 17:33:05 +0000
parents
children 9f7e56f56079
files erecord_file.xml main_file.py
diffstat 2 files changed, 349 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/erecord_file.xml	Tue Dec 12 17:33:05 2023 +0000
@@ -0,0 +1,201 @@
+<tool id="erecord_file" name="erecord_file" version="1.0.0">
+
+  <description>erecord returning .json + maybe .zip or .xls</description>
+
+  <requirements>
+
+    <!-- singularity -->
+    <container type="singularity">oras://registry.forgemia.inra.fr/nathalie.rousse/erecord-deploy/erecord_rep0_vle2:82d8fea607be20851e194828125785fb0f7e96d0</container>
+
+  </requirements>
+
+  <command detect_errors="aggressive">
+    <![CDATA[
+
+    echo "action_name VAUT $request_condition.action_name";
+    #if $request_condition.action_name == 'post_vpz_experiment':
+        /bin/bash -c "python3 $__tool_directory__/main_file.py -action ${request_condition.action_name} -data ${input_json} -datafolder ${datafolder} -experimentfile ${experimentfile}";
+    #elif $request_condition.action_name == 'post_vpz_report':
+        /bin/bash -c "python3 $__tool_directory__/main_file.py -action ${request_condition.action_name} -data ${input_json} -datafolder ${datafolder}";
+    #elif $request_condition.action_name == 'post_vpz_output':
+        /bin/bash -c "python3 $__tool_directory__/main_file.py -action ${request_condition.action_name} -data ${input_json} -datafolder ${datafolder}";
+    #elif $request_condition.action_name == 'post_vpz_inout':
+        /bin/bash -c "python3 $__tool_directory__/main_file.py -action ${request_condition.action_name} -data ${input_json} -datafolder ${datafolder}";
+    #else:
+        /bin/bash -c "python3 $__tool_directory__/main_file.py -action ${request_condition.action_name} -data ${input_json}";
+    #end if
+
+    cp WS/OUT/output.json ${output_json};
+
+    #if $request_condition.action_name == 'get_vpz_experiment':
+        cp WS/OUT/experiment.xls ${experiment};
+    #elif $request_condition.action_name == 'post_vpz_experiment':
+        cp WS/OUT/experiment.xls ${experiment};
+    #elif $request_condition.action_name == 'get_vpz_report_conditions':
+        cp WS/OUT/conditions.xls ${conditions};
+    #elif $request_condition.action_name == 'post_vpz_report_conditions':
+        cp WS/OUT/conditions.xls ${conditions};
+    #elif $request_condition.action_name == 'get_vpz_report':
+        cp WS/OUT/report.zip ${report};
+    #elif $request_condition.action_name == 'post_vpz_report':
+        cp WS/OUT/report.zip ${report};
+    #end if
+
+    ]]>
+  </command>
+
+  <inputs>
+
+    <param name="input_json" optional="true" type="data" format="json"
+           label="Input json file"/>
+
+    <conditional name="request_condition">
+
+      <param name="action_name" type="select" label="Select action">
+          <option value="help" selected="true">help</option>
+          <option value="get_pkg_list">get_pkg_list</option>
+          <option value="get_pkg_vpz_list">get_pkg_vpz_list</option>
+          <option value="get_pkg_data_list">get_pkg_data_list</option>
+          <option value="get_vpz_input">get_vpz_input</option>
+          <option value="post_vpz_input">post_vpz_input</option>
+          <option value="get_vpz_output">get_vpz_output</option>
+          <option value="post_vpz_output">post_vpz_output</option>
+          <option value="get_vpz_inout">get_vpz_inout</option>
+          <option value="post_vpz_inout">post_vpz_inout</option>
+          <option value="get_vpz_experiment">get_vpz_experiment</option>
+          <option value="post_vpz_experiment">post_vpz_experiment</option>
+          <option value="get_vpz_report">get_vpz_report</option>
+          <option value="post_vpz_report">post_vpz_report</option>
+          <option value="get_vpz_report_conditions">get_vpz_report_conditions</option>
+          <option value="post_vpz_report_conditions">post_vpz_report_conditions</option>
+      </param>
+
+      <when value="post_vpz_experiment">
+            
+          <param name="experimentfile" type="data" format="csv,xls"
+                 label="Add a experiment xls (csv) file"
+                 help="experimentfile from gest_vpz_experiment + modifications"/>
+          <param name="datafolder" optional="true" type="data" format="zip"
+                 label="Add a datafolder zip file"
+                 help="Precisions sur forme du dossier..."/>
+      </when>
+
+      <when value="post_vpz_report">
+          <param name="datafolder" optional="true" type="data" format="zip"
+                 label="Add a datafolder zip file"
+                 help="Precisions sur forme du dossier..."/>
+      </when>
+      <when value="post_vpz_output">
+          <param name="datafolder" optional="true" type="data" format="zip"
+                 label="Add a datafolder zip file"
+                 help="Precisions sur forme du dossier..."/>
+      </when>
+      <when value="post_vpz_inout">
+          <param name="datafolder" optional="true" type="data" format="zip"
+                 label="Add a datafolder zip file"
+                 help="Precisions sur forme du dossier..."/>
+      </when>
+
+      <when value="get_vpz_experiment" />
+      <when value="get_vpz_report_conditions" />
+      <when value="post_vpz_report_conditions"/>
+      <when value="get_vpz_report" />
+      <when value="get_vpz_input" />
+      <when value="post_vpz_input" />
+      <when value="get_vpz_output" />
+      <when value="get_vpz_inout" />
+      <when value="get_pkg_list" />
+      <when value="get_pkg_vpz_list" />
+      <when value="get_pkg_data_list" />
+      <when value="help" />
+
+    </conditional>
+
+  </inputs>
+
+  <outputs>
+
+    <data name="output_json" format="json" label="output_json"/>
+
+    <data name="experiment" format="xls" label="experiment">
+        <filter>request_condition['action_name'] == 'get_vpz_experiment' or request_condition['action_name'] == 'post_vpz_experiment'</filter>
+    </data>
+
+    <data name="conditions" format="xls" label="conditions.xls file">
+        <filter>request_condition['action_name'] == 'get_vpz_report_conditions' or request_condition['action_name'] == 'post_vpz_report_conditions'</filter>
+    </data>
+
+    <data name="report" format="zip" label="report">
+        <filter>request_condition['action_name'] == 'get_vpz_report' or request_condition['action_name'] == 'post_vpz_report'</filter>
+    </data>
+
+  </outputs>
+
+  <tests>
+  </tests>
+
+  <help><![CDATA[
+
+erecord_file.xml
+
+================
+
+Actions:
+
+-------
+
+- 'help'
+- 'get_pkg_list' 'get_pkg_vpz_list' 'get_pkg_data_list'
+- 'get_vpz_input' 'post_vpz_input'
+- 'get_vpz_output' 'post_vpz_output'
+- 'get_vpz_inout' 'post_vpz_inout'
+- 'get_vpz_experiment' 'post_vpz_experiment'
+- 'get_vpz_report_conditions' 'post_vpz_report_conditions'
+- 'get_vpz_report' 'post_vpz_report'
+
+Code:
+
+----
+
+- main_file.py
+
+Inputs:
+
+-------
+
+- action value (mandatory)
+
+- data json file (optional) (json file, param type="data")
+  An action value that would be into data would be ignored
+
+- experiment.xls (only in 'post_vpz_experiment' case)
+
+- datafolder (optional) (only in cases : 
+  'post_vpz_experiment', 'post_vpz_report', 'post_vpz_output', 'post_vpz_inout')
+
+Outputs:
+
+--------
+
+- data json file 
+
+- 1 other file (xls or zip) :
+  - if 'action' == get_vpz_experiment, post_vpz_experiment :
+    experiment.xls file
+  - if 'action' == get_vpz_report_conditions, post_vpz_report_conditions :
+    conditions.xls file
+  - if 'action' == get_vpz_report, post_vpz_report :
+    report.zip file
+
+Credits:
+
+--------
+
+-  Author: Nathalie Rousse nathalie.rousse@inrae.fr
+-  Copyright: INRAE
+
+  ]]>
+  </help>
+
+</tool>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_file.py	Tue Dec 12 17:33:05 2023 +0000
@@ -0,0 +1,148 @@
+# -*- coding: UTF-8 -*-
+""" 
+    main_file
+
+    Requests having as OUTput : 1 json data + maybe 1 more file (xls or zip)
+
+    Accepts actions (all) :
+    'help'
+    'get_pkg_list' 'get_pkg_vpz_list' 'get_pkg_data_list'
+    'get_vpz_input' 'post_vpz_input'
+    'get_vpz_output' 'post_vpz_output'
+    'get_vpz_inout' 'post_vpz_inout'
+    'get_vpz_experiment' 'post_vpz_experiment'
+    'get_vpz_report_conditions' 'post_vpz_report_conditions'
+    'get_vpz_report' 'post_vpz_report'
+
+    Parameters (Inputs) :
+    - '-action' parameter : action value (mandatory)
+    - '-data'   parameter : data (JSON format) (optional)
+    - '-datafolder' parameter : datafolder file path (optional,
+      available only in some cases)
+    - '-experimentfile' parameter : experimentfile path (optional,
+      available only in some cases) :
+
+    If there is an action value into data, then this one is ignored.
+
+    Outputs :
+    - output.json data file
+    - 1 other file in following cases : 
+      - experiment.xls file
+        if 'action' == get_vpz_experiment, post_vpz_experiment
+      - conditions.xls file
+        if 'action' == get_vpz_report_conditions,
+                       post_vpz_report_conditions
+      - report.zip file
+        if 'action' == get_vpz_report, post_vpz_report
+"""
+
+MAIN_DEBUG=False # True for more information returned
+
+import argparse
+import json
+import erecord.api.erecord as erecord_api
+from erecord.api.cmn.views_mixins import ActionViewMixin
+import os
+import shutil
+from erecord.api.cmn.utils.dir_and_file import create_dir_if_absent
+from erecord.api.cmn.configs.config import PROJECT_HOME
+from erecord.api.cmn.configs.config import out_path
+
+PM = "[main_file.py]"
+
+jsonoutput_filepath = os.path.join(out_path, "output.json") # tool.xml uses it
+
+r = dict()
+
+import sys
+if MAIN_DEBUG: r["sys.path"] = sys.path # debug
+if MAIN_DEBUG: r["sys.argv"] = sys.argv # debug
+if MAIN_DEBUG: r["out_path"] = out_path # debug
+
+data = dict()
+json_response = dict()
+
+create_dir_if_absent(PROJECT_HOME) # required
+
+try :
+    parser = argparse.ArgumentParser()
+
+    # -action
+    available_action_list = ActionViewMixin.get_action_list()
+    htext = "action value among : " + str(available_action_list)
+    parser.add_argument("-action", default='help', help=htext,
+                        choices=available_action_list)
+
+    # -data
+    parser.add_argument("-data", type=str, help="data json file path")
+
+    # -datafolder
+    htext = "datafolder file path, available for action : "
+    htext +="post_vpz_output, post_vpz_inout,"
+    htext +="post_vpz_experiment, post_vpz_report"
+    parser.add_argument("-datafolder", type=str, help=htext)
+
+    # -experimentfile
+    htext = "experimentfile path, available for action : post_vpz_experiment"
+    parser.add_argument("-experimentfile", type=str, help=htext)
+
+    args = parser.parse_args()
+
+    if (args.action is None) or (args.action == 'None') :
+        warn = "NO action given => enforced to 'help'"
+        r["warning"] = warn
+        action = 'help' # enforced (default)
+    else : 
+        action = args.action
+
+        if (args.data is None) or (args.data == 'None') :
+            data = dict() # NO data (JSON format) given as argument
+        else : 
+            jsoninput_filename = args.data
+            inputfile = open(jsoninput_filename, 'r')
+            data = json.load(inputfile) # get data
+
+        if (args.datafolder is None) or (args.datafolder == 'None') :
+            pass # NO datafolder given
+        else :
+            data['datafolder'] = args.datafolder
+
+        if (args.experimentfile is None) or (args.experimentfile == 'None') :
+            pass # NO experimentfile given
+        else :
+            data['experimentfile'] = args.experimentfile
+
+    data['action'] = action
+
+    r["data"] = data
+    r_init = erecord_api.init()
+    if MAIN_DEBUG: r["init"] = r_init # debug
+    response = erecord_api.action(data)
+    json_response = json.loads(response)
+    
+    # Restitution : file (experiment.xls, conditions.xls, report.zip)
+    if action in ['get_vpz_experiment', 'post_vpz_experiment',
+            'get_vpz_report_conditions', 'post_vpz_report_conditions',
+            'get_vpz_report', 'post_vpz_report']:
+
+        filename = json_response["outputfile_name"]
+        outputfile_path = json_response["outputfile_path"]
+        shutil.copyfile(src=outputfile_path,
+                      dst=os.path.join(out_path,filename)) # tool.xml uses them
+
+        if not MAIN_DEBUG: # some response information not kept
+            for k in ('outputfile_name', 'outputfile_path', 'zip_file_path'):
+                if k in json_response.keys():
+                    del(json_response[k])
+
+except Exception as e :
+
+    response = erecord_api.error_case(data=data, msg=PM, e=e)
+    json_response = json.loads(response)
+
+r["response"] = json_response
+
+# Restitution : json file
+with open(jsonoutput_filepath, "w") as outfile:
+    json.dump(r, outfile)
+