changeset 3:b2fa406276e7 draft default tip

"planemo upload for repository https://github.com/blankenberglab/galaxy-tools-blankenberg/tree/main/data_managers/data_manager_refgenie_pull commit 793d970b919fcfd5f21a2d6e03e825b05dd56b69"
author blankenberglab
date Fri, 01 Apr 2022 16:14:13 +0000
parents 2cb1863cd236
children
files data_manager/data_manager_refgenie_pull.py data_manager/data_manager_refgenie_pull.xml
diffstat 2 files changed, 43 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/data_manager_refgenie_pull.py	Fri Oct 01 14:40:21 2021 +0000
+++ b/data_manager/data_manager_refgenie_pull.py	Fri Apr 01 16:14:13 2022 +0000
@@ -4,6 +4,7 @@
 import argparse
 import logging
 from base64 import urlsafe_b64encode
+from html import escape
 from urllib.parse import urljoin
 
 import refgenconf
@@ -15,20 +16,21 @@
 
 def galaxy_code_get_refgenie_assets(refgenie_config_file):
     try:
+        rval = []
         rgc = refgenconf.RefGenConf(refgenie_config_file, writable=False, skip_read_lock=True)
-    except refgenconf.exceptions.RefgenconfError as e:
-        return[{'name': str(e), 'value': 'ERROR', 'options': [], 'selected': False}]
-    rval = []
-    for urlname, genomes in rgc.listr().items():
-        urlname_64 = urlsafe_b64encode(bytes(urlname, 'utf8')).decode('utf8')
-        ul = []
-        for genome, assets in genomes.items():
-            al = []
-            for name in assets:
-                al.append({'name': name, 'value': '%s/%s/%s' % (urlname_64, genome, name), 'options': [], 'selected': False})
-            ul.append({'name': genome, 'value': genome, 'options': al, 'selected': False})
-        rval.append({'name': urlname, 'value': urlname_64, 'options': ul, 'selected': False})
-    return rval
+        for urlname, genomes in rgc.listr().items():
+            urlname_64 = urlsafe_b64encode(bytes(urlname, 'utf8')).decode('utf8')
+            ul = []
+            for genome, assets in genomes.items():
+                al = []
+                for name in assets:
+                    al.append({'name': name, 'value': '%s/%s/%s' % (urlname_64, genome, name), 'options': [], 'selected': False})
+                ul.append({'name': genome, 'value': genome, 'options': al, 'selected': False})
+            rval.append({'name': urlname, 'value': urlname_64, 'options': ul, 'selected': False})
+        return rval
+    except Exception as e:
+        log.debug("Failed to access refgenie server: %s", e)
+        return[{'name': escape(str(e)), 'value': 'ERROR', 'options': [], 'selected': False}]
 
 
 if __name__ == '__main__':
@@ -36,10 +38,17 @@
     parser.add_argument('-n', '--names', dest='names', action='store', default=None, help='Table names to reload')
     parser.add_argument('-u', '--url', dest='url', action='store', default=None, help='Base url for reload')
     parser.add_argument('-k', '--key', dest='key', action='store', default=None, help='Galaxy API Key')
+    parser.add_argument('-g', '--graceful', dest='graceful', action='store_true', help='Fail gracefully')
 
     args = parser.parse_args()
-    if not args.names:
-        tables = requests.get(urljoin(args.url, "api/tool_data"), params={'key': args.key}).json()
-        args.names = [d.get('name') for d in tables]
-    for name in args.names:
-        print(requests.get(urljoin(args.url, "api/tool_data/%s/reload" % (name)), params={'key': args.key}).json())
+    try:
+        if not args.names:
+            tables = requests.get(urljoin(args.url, "api/tool_data"), params={'key': args.key}).json()
+            args.names = [d.get('name') for d in tables]
+        for name in args.names:
+            print(requests.get(urljoin(args.url, "api/tool_data/%s/reload" % (name)), params={'key': args.key}).json())
+    except Exception as e:
+        if args.graceful:
+            print("Failed to reload data tables:\n%s" % (e))
+        else:
+            raise e
--- a/data_manager/data_manager_refgenie_pull.xml	Fri Oct 01 14:40:21 2021 +0000
+++ b/data_manager/data_manager_refgenie_pull.xml	Fri Apr 01 16:14:13 2022 +0000
@@ -1,4 +1,4 @@
-<tool id="data_manager_refgenie_pull" name="refgenie asset pulling" version="@VERSION@" tool_type="manage_data" profile="20.05">
+<tool id="data_manager_refgenie_pull" name="refgenie asset pulling" version="@VERSION@+galaxy0" tool_type="manage_data" profile="20.05">
     <description>from remote resource</description>
     <macros>
         <import>macros.xml</import>
@@ -18,8 +18,12 @@
          &&
        #end for
        echo '{}' > '${out_file}'
-       #if $api_refresh:
-         && python '${__tool_directory__}/data_manager_refgenie_pull.py' -k "\$API_KEY" -u '${__galaxy_url__}' >> '${out_log}'
+       #if "refresh" in $str($api_refresh):
+         && python '${__tool_directory__}/data_manager_refgenie_pull.py' -k "\$API_KEY" -u '${__galaxy_url__}'
+         #if "graceful" in $str($api_refresh):
+           --graceful
+         #end if
+         >> '${out_log}'
        #end if
     ]]></command>
     <inputs>
@@ -27,17 +31,21 @@
             <validator type="regex" message="You must select an asset, not the remote URL or genome.">.+/.+/.+</validator>
         </param>
         <param argument="--force" name="force" type="boolean" truevalue="--force" falsevalue="" checked="False" label="Force (re-)download" />
-        <param argument="--api_refresh" name="api_refresh" type="boolean" truevalue="--api_refresh" falsevalue="" checked="True" label="Refresh Galaxy data tables using API" />
+        <param name="api_refresh" type="select" label="Refresh Galaxy data tables using API" help="Refresh gracefully will attempt to refresh, but a failure will not be fatal.">
+            <option value="refresh">Refresh</option>
+            <option value="refresh_graceful" selected="True">Refresh gracefully</option>
+            <option value="no">Do not refresh</option>
+        </param>
     </inputs>
     <outputs>
-        <data name="out_file" format="data_manager_json"/>
-        <data name="out_log" format="txt"/>
+        <data name="out_file" format="data_manager_json" label="${tool.name}: data manager json"/>
+        <data name="out_log" format="txt" label="${tool.name}: log file"/>
     </outputs>
     <tests>
         <test>
             <param name="assets" value="aHR0cDovL3JlZmdlbm9tZXMuZGF0YWJpby5vcmcvdjIvYXNzZXRz/t7/fasta:default"/>
             <param name="force" value="--force"/>
-            <param name="api_refresh" value=""/>
+            <param name="api_refresh" value="no"/>
             <output name="out_file">
                 <assert_contents>
                     <has_text text="{}"/>
@@ -57,7 +65,7 @@
 
 .. class:: infomark
 
-**Notice:** Galaxy data tables will be refreshed using API calls.
+**Notice:** Galaxy data tables will be refreshed using API calls. You must have configured Galaxy to work with refgenie, see https://galaxyproject.org/admin/refgenie/.
 
 .. class:: warning