changeset 7:ae6180bdb1e9 draft

planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit 70494d589aa1990618ebc7a895e91477d41c3203-dirty
author dfornika
date Mon, 04 Mar 2019 19:20:33 -0500
parents ce101123d015
children f53064ca5398
files data_manager/kraken2_build_special.py data_manager/kraken2_build_special.xml data_manager/kraken2_build_standard.py data_manager_conf.xml
diffstat 4 files changed, 161 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/kraken2_build_special.py	Mon Mar 04 19:20:33 2019 -0500
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import argparse
+import datetime
+import errno
+import json
+import os
+import string
+import subprocess
+import sys
+
+
+DATA_TABLE_NAME = "kraken2_databases"
+
+def run(args, cwd):
+    proc = subprocess.Popen(args=args, shell=False, cwd=cwd)
+    return_code = proc.wait()
+    if return_code:
+        print("Error building database.", file=sys.stderr)
+        sys.exit( return_code )
+
+def kraken2_build_standard(data_manager_dict, kraken2_args, target_directory, data_table_name=DATA_TABLE_NAME):
+    today = datetime.date.today().isoformat()
+    database_name = "_".join([
+        today,
+        kraken2_args["special"],
+        "kmer-len=" + str(kraken2_args["kmer_len"]),
+        "minimizer-len=" + str(kraken2_args["minimizer_len"]),
+        "minimizer-spaces=" + str(kraken2_args["minimizer_spaces"]),
+    ])
+    
+    args = [
+        '--threads', str(kraken2_args["threads"]),
+        '--special', kraken2_args["special"]
+        '--kmer-len', str(kraken2_args["kmer_len"]),
+        '--minimizer-len', str(kraken2_args["minimizer_len"]),
+        '--minimizer-spaces', str(kraken2_args["minimizer_spaces"]),
+        '--db', database_name
+    ]
+
+    run(['kraken2-build'] + args, target_directory)
+
+    args = [
+        '--threads', str(kraken2_args["threads"]),
+        '--clean',
+        '--db', database_name
+    ]
+
+    run(['kraken2-build'] + args, target_directory)
+
+    data_table_entry = {
+        "value": database_name,
+        "name": database_name,
+        "path": database_name
+    }
+    
+    _add_data_table_entry(data_manager_dict, data_table_entry)
+
+
+def _add_data_table_entry(data_manager_dict, data_table_entry, data_table_name=DATA_TABLE_NAME):
+    data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} )
+    data_manager_dict['data_tables'][data_table_name] = data_manager_dict['data_tables'].get( data_table_name, [] )
+    data_manager_dict['data_tables'][data_table_name].append( data_table_entry )
+    return data_manager_dict
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('data_manager_json')
+    parser.add_argument( '-b', '--db-type', dest='db_type', help='database type (one of: silva, rdp, greengenes)' )
+    parser.add_argument( '-k', '--kmer-len', dest='kmer_len', type=int, default=35, help='kmer length' )
+    parser.add_argument( '-m', '--minimizer-len', dest='minimizer_len', type=int, default=31, help='minimizer length' )
+    parser.add_argument( '-s', '--minimizer-spaces', dest='minimizer_spaces', default=6, help='minimizer spaces' )
+    parser.add_argument( '-t', '--threads', dest='threads', default=1, help='threads' )
+    args = parser.parse_args()
+
+    kraken2_args = {
+        "special": args.db_type,
+        "kmer_len": args.kmer_len,
+        "minimizer_len": args.minimizer_len,
+        "minimizer_spaces": args.minimizer_spaces,
+        "threads": args.threads,
+    }
+    
+    data_manager_input = json.loads(open(args.data_manager_json).read())
+
+    target_directory = data_manager_input['output_data'][0]['extra_files_path']
+
+    try:
+        os.mkdir( target_directory )
+    except OSError as exc:
+        if exc.errno == errno.EEXIST and os.path.isdir( target_directory ):
+            pass
+        else:
+            raise
+
+    kraken2_build_standard(
+        data_manager_input,
+        kraken2_args,
+        target_directory,
+    )
+
+    open(args.data_manager_json, 'wb').write(json.dumps(data_manager_input))
+
+
+if __name__ == "__main__":
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/kraken2_build_special.xml	Mon Mar 04 19:20:33 2019 -0500
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<tool id="kraken2_build_special" name="Kraken2 Special Database Builder" tool_type="manage_data" version="2.0.7_beta">
+    <description>database builder</description>
+    <requirements>
+        <requirement type="package" version="2.0.7_beta">kraken2</requirement>
+    </requirements>
+    <version_command>kraken2 -version | head -n 1 | awk '{print $NF}'</version_command>
+    <command detect_errors="exit_code">
+    <![CDATA[
+        python '$__tool_directory__/kraken2_build_special.py'
+          '${out_file}'
+	  --db-type ${db_type}
+          --threads \${GALAXY_SLOTS:-1}
+          --kmer-len ${kmer_len}
+          --minimizer-len ${minimizer_len}
+          --minimizer-spaces ${minimizer_spaces}
+    ]]>
+    </command>
+    <inputs>
+        <param name="db_type" type="select" multiple="false" label="Select database to build">
+            <option value="greengenes">Greengenes</option>
+	    <option value="silva">Silva</option>
+	    <option value="rdp">RDP</option>
+        </param>
+        <param name="kmer_len" type="integer" value="35" label="K-mer length in BP" />
+        <param name="minimizer_len" type="integer" value="31" label="Minimizer length" />
+	<param name="minimizer_spaces" type="integer" value="6" label="Minimizer spaces" />
+    </inputs>
+    <outputs>
+        <data name="out_file" format="data_manager_json" />
+    </outputs>
+    <help>
+    </help>
+    <citations>
+        <citation type="doi">10.1186/gb-2014-15-3-r46</citation>
+    </citations>
+</tool>
--- a/data_manager/kraken2_build_standard.py	Mon Mar 04 19:01:17 2019 -0500
+++ b/data_manager/kraken2_build_standard.py	Mon Mar 04 19:20:33 2019 -0500
@@ -42,7 +42,6 @@
     run(['kraken2-build'] + args, target_directory)
 
     args = [
-        'kraken2-build',
         '--threads', str(kraken2_args["threads"]),
         '--clean',
         '--db', database_name
--- a/data_manager_conf.xml	Mon Mar 04 19:01:17 2019 -0500
+++ b/data_manager_conf.xml	Mon Mar 04 19:20:33 2019 -0500
@@ -29,4 +29,19 @@
 	    </output>
 	</data_table>
     </data_manager>
+    <data_manager tool_file="data_manager/kraken2_build_special.xml" id="kraken2_build_special" version="1.0">
+	<data_table name="kraken2_databases">
+	    <output>
+		<column name="value"/>
+		<column name="name"/>
+		<column name="path" output_ref="out_file">
+		    <move type="directory" relativize_symlinks="True">
+			<target base="${GALAXY_DATA_MANAGER_DATA_PATH}">kraken2_databases</target>
+		    </move>
+		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_databases</value_translation>
+		    <value_translation type="function">abspath</value_translation>
+		</column>
+	    </output>
+	</data_table>
+    </data_manager>
 </data_managers>