changeset 0:9972e1e07347 draft default tip

Uploaded
author greg
date Mon, 12 Dec 2022 15:02:14 +0000
parents
children
files .shed.yml data_manager/pima_pv_downloader.py data_manager/pima_pv_downloader.xml data_manager_conf.xml test-data/pima_pv.json test-data/pima_pv.loc tool-data/pima_pv.loc.sample tool_data_table_conf.xml.sample tool_data_table_conf.xml.test
diffstat 9 files changed, 153 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.shed.yml	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,13 @@
+name: data_manager_pima_pv_downloader
+owner: greg
+description: Data manager to download the PIMA plasmids_and_vectors.fasta files for use by the PIMA pipeline tools.
+homepage_url: https://github.com/appliedbinf/pima_md
+long_description: |
+  PIMA (Plasmid, Integrations, Mutations, and Antibiotic) resistance annotation pipeline is a high-throughput
+  sequence analysis pipeline. PIMA is an end-to-end solution encompassing all the steps required to transform
+  raw ONT output into high-quality annotated assemblies. PIMA supports providing optional Illumina paired end
+  reads for polishing and error correcting assemblies.
+remote_repository_url: https://github.com/gregvonkuster/galaxy_tools/tree/master/tools/data_managers/data_manager_pima_pv_downloader
+type: unrestricted
+categories:
+- Data Managers
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/pima_pv_downloader.py	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,60 @@
+import argparse
+import datetime
+import json
+import os
+import sys
+from urllib.request import Request, urlopen
+
+
+def url_download(url, workdir):
+    file_path = os.path.abspath(os.path.join(workdir, os.path.basename(url)))
+    src = None
+    dst = None
+    try:
+        req = Request(url)
+        src = urlopen(req)
+        with open(file_path, 'wb') as dst:
+            while True:
+                chunk = src.read(2**10)
+                if chunk:
+                    dst.write(chunk)
+                else:
+                    break
+    except Exception as e:
+        sys.exit(str(e))
+    finally:
+        if src:
+            src.close()
+    return file_path
+
+
+def download(url, out_file):
+    today = datetime.datetime.utcnow().strftime("%Y-%m-%d")
+
+    with open(out_file) as fh:
+        params = json.load(fh)
+
+    workdir = params['output_data'][0]['extra_files_path']
+    os.makedirs(workdir)
+    file_path = url_download(url, workdir)
+    name = '%s_%s' % (today, os.path.basename(file_path))
+
+    data_manager_json = {"data_tables": {}}
+    data_manager_entry = {}
+    data_manager_entry['value'] = today
+    data_manager_entry['name'] = name
+    data_manager_entry['path'] = file_path
+    data_manager_json["data_tables"]["pima_pv"] = data_manager_entry
+
+    with open(out_file, 'w') as fh:
+        json.dump(data_manager_json, fh, sort_keys=True)
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--url', dest='url', help='URL to download plasmids_and_vectors.fasta file')
+parser.add_argument('--out_file', dest='out_file', help='JSON output file')
+
+args = parser.parse_args()
+
+download(args.url, args.out_file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/pima_pv_downloader.xml	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,30 @@
+<tool id="pima_pv_downloader" name="PIMA pv data manager" tool_type="manage_data" profile="21.09" version="1.0.0">
+    <description>Download plasmids_and_vectors.fasta files</description>
+    <requirements>
+        <requirement type="package" version="3.10.6">python</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+python '$__tool_directory__/pima_pv_downloader.py'
+--out_file '$out_file'
+--url '$url'
+    ]]>
+    </command>
+    <inputs>
+        <param name="url" type="text" value="http://pima.appliedbinf.com/data/plasmids_and_vectors.fasta" label="URL to download the plasmids_and_vectors.fasta file"/>
+    </inputs>
+    <outputs>
+        <data name="out_file" format="data_manager_json"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="url" value="http://pima.appliedbinf.com/data/plasmids_and_vectors.fasta"/>
+            <output name="out_file" value="pima_pv.json" compare="contains"/>
+        </test>
+    </tests>
+    <help><![CDATA[
+This tool downloads the current PIMA plasmids_and_vectors.fasta file for use by various PIMA tools.
+    ]]></help>
+    <citations>
+        <citation type="doi">10.1038/s41598-019-49700-1</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,19 @@
+<data_managers>
+    <data_manager tool_file="data_manager/pima_pv_downloader.xml" id="pima_pv_downloader">
+        <data_table name="pima_pv">
+            <output>
+                <column name="value"/>
+                <column name="name"/>
+                <column name="path" output_ref="out_file">
+                    <move type="file" relativize_symlinks="True">
+                        <source>${path}</source>
+                        <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">pima_pv/${value}/${name}</target>
+                    </move>
+                    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/pima_pv/${value}/${name}</value_translation>
+                    <value_translation type="function">abspath</value_translation>
+                </column>
+            </output>
+        </data_table>
+    </data_manager>
+</data_managers>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/pima_pv.json	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,1 @@
+{"data_tables": {"pima_pv": {"name": 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/pima_pv.loc	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,12 @@
+# This is a sample file distributed with Galaxy that enables tools
+# to use a selected PIMA plasmids_and_vectors.fasta file.  The pima_pv.loc
+# file has this format (longer white space characters are TAB characters):
+#
+# <version> <display_name> <directory_path>
+#
+# So, for example, if you have the plasmids_and_vectors.fasta files stored in 
+# /depot/data2/galaxy/pima_pv/, 
+# then the pima_pv.loc entry would look like this:
+#
+# 2022-10-18	PIMA plasmids_and_vectors.fasta	/depot/data2/galaxy/pima_pv
+2022-10-18   2022-10-18 plasmids_and_vectors.fasta    ${__HERE__}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/pima_pv.loc.sample	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,3 @@
+## PIMA plasmids_and_vectors.fasta files
+#Value	Name	Path
+#2022-10-18	plasmids_and_vectors.fasta (2022-10-18)	/depot/data2/galaxy/tool-data/pima_pv/2022-10-18
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,8 @@
+<tables>
+    <!-- Locations of pima plasmids_and_vectors.fasta files -->
+    <table name="pima_pv" comment_char="#">
+        <columns>value, name, path</columns>
+        <file path="tool-data/pima_pv.loc" />
+    </table>
+</tables>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.test	Mon Dec 12 15:02:14 2022 +0000
@@ -0,0 +1,7 @@
+<tables>
+    <!-- Locations of pima plasmids_and_vectors.fasta files -->
+    <table name="pima_pv" comment_char="#">
+        <columns>value, name, path</columns>
+        <file path="${__HERE__}/test-data/pima_pv.loc" />
+    </table>
+</tables>