changeset 0:0dbe46f58158 draft

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/export_to_cluster/ commit e80af91bced56efdb4fbf62ac03232655a22f25d-dirty
author earlhaminst
date Thu, 11 Aug 2016 15:27:30 -0400
parents
children a9d1991c90e3
files export_to_cluster.py export_to_cluster.xml tool_dependencies.xml
diffstat 3 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/export_to_cluster.py	Thu Aug 11 15:27:30 2016 -0400
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+from __future__ import print_function
+
+import optparse
+import os
+import os.path
+import re
+import shutil
+import sys
+
+parser = optparse.OptionParser()
+parser.add_option('-d', '--export_dir', help='Directory where to export the datasets')
+parser.add_option('-p', '--dir_prefix', help='How the export dir should start')
+(options, args) = parser.parse_args()
+if not options.export_dir:
+    parser.error('Export directory cannot be empty')
+if not options.dir_prefix:
+    parser.error('Directory prefix cannot be empty')
+if len(args) < 2:
+    parser.error('Require at least two arguments')
+if len(args) % 2 != 0:
+    parser.error('Require an even number of arguments')
+
+real_export_dir = os.path.realpath(options.export_dir)
+dir_prefix = options.dir_prefix.rstrip(os.sep)
+if not real_export_dir.startswith(dir_prefix):
+    sys.exit("%s must be a subdirectory of %s" % (options.export_dir, dir_prefix))
+if not os.path.exists(real_export_dir):
+    sys.exit("%s does not exist or it is not accessible by the Galaxy user" % options.export_dir)
+if not os.path.isdir(real_export_dir):
+    sys.exit("%s is not a directory" % options.export_dir)
+
+dataset_paths = args[::3]
+dataset_names = args[1::3]
+dataset_exts = args[2::3]
+for dp, dn, de in zip(dataset_paths, dataset_names, dataset_exts):
+    """
+    Copied from get_valid_filename from django
+    https://github.com/django/django/blob/master/django/utils/text.py
+    """
+    dn_de = "%s.%s" % (dn, de)
+    dn_de_safe = re.sub(r'(?u)[^-\w.]', '', dn_de.strip().replace(' ', '_'))
+    dest = os.path.join(real_export_dir, dn_de_safe)
+    try:
+        shutil.copy2(dp, dest)
+        print("Dataset '%s' copied to '%s'" % (dn, dest))
+    except Exception as e:
+        msg = "Error copying dataset '%s' to '%s', %s" % (dn, dest, e)
+        print(msg)
+        sys.stderr.write(msg)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/export_to_cluster.xml	Thu Aug 11 15:27:30 2016 -0400
@@ -0,0 +1,30 @@
+<tool id="export_to_cluster" name="Export datasets to cluster" version="0.0.1">
+    <requirements>
+        <requirement type="set_environment">EXPORT_DIR_PREFIX</requirement>
+    </requirements>
+    <command>
+<![CDATA[
+python $__tool_directory__/export_to_cluster.py -d '$export_dir' -p "\$EXPORT_DIR_PREFIX"
+#for $d in $datasets
+    '${d}' '${d.hid}: ${d.name}' '${d.ext}'
+#end for
+> $log
+]]>
+    </command>
+    <inputs>
+        <param name="datasets" type="data" format="data" multiple="true" label="Datasets to export" />
+        <param name="export_dir" type="text" value="" label="Directory where to export the datasets" help="Must be writable by the Galaxy user">
+            <validator type="empty_field" />
+            <sanitizer sanitize="false" />
+        </param>
+    </inputs>
+    <outputs>
+        <data name="log" format="txt" />
+    </outputs>
+    <tests>
+    </tests>
+    <help>
+Simple tool to copy datasets to a directory on the cluster.
+    </help>
+    <citations/>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml	Thu Aug 11 15:27:30 2016 -0400
@@ -0,0 +1,5 @@
+<tool_dependency>
+    <set_environment version="1.0">
+        <environment_variable name="EXPORT_DIR_PREFIX" action="set_to"></environment_variable>
+    </set_environment>
+</tool_dependency>