changeset 0:f58178a5eebc draft

Uploaded
author greg
date Fri, 14 Feb 2020 13:41:36 -0500
parents
children 5c4173a0b2c6
files .shed.yml data_manager/vsnp_dnaprints_fetcher.py data_manager/vsnp_dnaprints_fetcher.xml data_manager_conf.xml tool-data/vsnp_dnaprints.loc.sample tool_data_table_conf.xml.sample
diffstat 6 files changed, 208 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.shed.yml	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,10 @@
+name: data_manager_vsnp_dnaprints
+owner: greg
+description: Data manager to download vSNP analysis DNAprints file
+homepage_url: https://github.com/USDA-VS/vSNP
+long_description: |
+  vSNP generates annotated SNP tables, this data manager installs the vSNP DNAprints file.
+remote_repository_url: "https://github.com/gregvonkuster/galaxy_tools/tree/master/tools/data_managers/vsnp_dnaprints"
+type: unrestricted
+categories:
+- Data Managers
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/vsnp_dnaprints_fetcher.py	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,66 @@
+import argparse
+import json
+import os
+import sys
+try:
+    # For Python 3.0 and later
+    from urllib.request import Request, urlopen
+except ImportError:
+    # Fall back to Python 2 imports
+    from urllib2 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(dbkey, name, url, out_file):
+
+    with open(out_file) as fh:
+        params = json.loads(fh.read())
+
+    workdir = params['output_data'][0]['extra_files_path']
+    os.makedirs(workdir)
+    file_path = url_download(url, workdir)
+    entry_name = os.path.basename(file_path)
+
+    data_manager_json = {"data_tables": {}}
+    data_manager_entry = {}
+    data_manager_entry['value'] = dbkey
+    data_manager_entry['name'] = entry_name
+    data_manager_entry['path'] = file_path
+    data_manager_entry['description'] = "DNAprints file for %s" % name
+    data_manager_json["data_tables"]["vsnp_dnaprints"] = data_manager_entry
+
+    with open(out_file, 'w') as fh:
+        fh.write(json.dumps(data_manager_json, sort_keys=True))
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--dbkey', dest='dbkey', help='Genome reference dbkey')
+parser.add_argument('--name', dest='name', help='Reference display name')
+parser.add_argument('--url', dest='url', help='URL to download DNAprints file')
+parser.add_argument('--out_file', dest='out_file', help='JSON output file')
+
+args = parser.parse_args()
+
+download(args.dbkey, args.name, args.url, args.out_file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/vsnp_dnaprints_fetcher.xml	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,100 @@
+<?xml version="1.0"?>
+<tool id="vsnp_dnaprints_fetcher" name="vSNP DNAprints data manager" tool_type="manage_data" profile="18.09" version="0.0.8">
+    <description>Download vSNP DNAprints files</description>
+    <requirements>
+        <requirement type="package" version="3.7">python</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+    python '$__tool_directory__/vsnp_dnaprints_fetcher.py'
+    --dbkey '${all_fasta_source.fields.dbkey}'
+    --name '${all_fasta_source.fields.name}'
+    --out_file '$out_file'
+    --url '$url'
+    ]]>
+    </command>
+    <inputs>
+        <param name="all_fasta_source" type="select" label="FASTA reference">
+            <options from_data_table="all_fasta"/>
+        </param>
+        <param name="url" type="text" value="" label="URL to download the DNAprints file associated with the selected FASTA reference" optional="False" />
+    </inputs>
+    <outputs>
+        <data name="out_file" format="data_manager_json" />
+    </outputs>
+    <tests>
+        <test>
+        </test>
+    </tests>
+    <help><![CDATA[
+This tool fetches a vSNP DNAprints file associated with each supported genome reference to populate the vsnp_dnaprints data table.  The dbkey and name fields
+in the vsnp data table are inherited from the *all_fasta* data table, so no user entry is necessary.  These public vSNP DNAprints files are available in GitHub
+at https://github.com/USDA-VS/vSNP_reference_options.
+
+ * **Mycobacterium bovis AF2122/97**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Mycobacterium_AF2122/NC_002945v4.yml
+
+ * **Brucella abortus bv. 1 str. 9-941**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_abortus1/NC_006932-NC_006933.yml
+
+ * **Brucella abortus strain BER**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_abortus3/NZ_CP007682-NZ_CP007683.yml
+
+ * **Brucella canis ATCC 23365**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_canis/NC_010103-NC_010104.yml
+
+ * **Brucella ceti TE10759-12**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_ceti2/NC_022905-NC_022906.yml
+
+ * **Brucella melitensis bv. 1 str. 16M**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_melitensis-bv1/NC_003317-NC_003318.yml
+
+ * **Brucella melitensis bv. 3 str. Ether**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_melitensis-bv3/NZ_CP007760-NZ_CP007761.yml
+
+ * **Brucella melitensis BwIM_SOM_36b**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_melitensis-bv1b/NZ_CP018508-NZ_CP018509.yml
+
+ * **Brucella melitensis ATCC 23457**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_melitensis-bv2/NC_012441-NC_012442.yml
+
+ * **Brucella ovis ATCC 25840**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_ovis/NC_009505-NC_009504.yml
+
+ * **Brucella suis 1330**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_suis1/NC_017251-NC_017250.yml
+
+ * **Mycobacterium tuberculosis H37Rv**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Mycobacterium_H37/NC_000962.yml
+
+ * **Mycobacterium avium subsp. paratuberculosis strain Telford**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/para-CP033688/CP033688.yml
+
+ * **Mycobacterium avium subsp. paratuberculosis K-10**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/para-NC002944/NC_002944.yml
+
+ * **Brucella suis ATCC 23445**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_suis2/NC_010169-NC_010167.yml
+
+ * **Brucella suis bv. 3 str. 686**
+
+   * **DNAprints file**  https://raw.githubusercontent.com/USDA-VS/vSNP_reference_options/master/Brucella_suis3/NZ_CP007719-NZ_CP007718.yml
+
+    ]]></help>
+    <citations>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<data_managers>
+    <data_manager tool_file="data_manager/vsnp_dnaprints_fetcher.xml" id="vsnp_dnaprints_fetcher">
+        <data_table name="vsnp_dnaprints">
+            <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}">vsnp/${value}/dnaprints/${name}</target>
+                    </move>
+                    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/vsnp/${value}/dnaprints/${name}</value_translation>
+                    <value_translation type="function">abspath</value_translation>
+                </column>
+                <column name="description" />
+            </output>
+        </data_table>
+    </data_manager>
+</data_managers>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/vsnp_dnaprints.loc.sample	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,4 @@
+## vSNP DNAprints files
+#Value	Name	Path	Description
+#AF2122	Mycobacterium_AF2122/NC_002945v4.yml	vsnp/AF2122/Mycobacterium_AF2122/NC_002945v4.yml	DNAprints file for Mycobacterium bovis AF2122/97
+#NC_006932	Brucella_abortus1/NC_006932-NC_006933.yml	/vsnp/NC_006932/Brucella_abortus1/NC_006932-NC_006933.yml	DNAprints file for Brucella abortus bv. 1 str. 9-941
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample	Fri Feb 14 13:41:36 2020 -0500
@@ -0,0 +1,7 @@
+<tables>
+    <table name="vsnp_dnaprints" comment_char="#">
+        <columns>value, name, path, description</columns>
+        <file path="tool-data/vsnp_dnaprints.loc" />
+    </table>
+</tables>
+