changeset 5:1f6fe9dc5490 draft

planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit 47bcc8467200adee842a5574b67bc6ef46c0be71-dirty
author dfornika
date Mon, 04 Mar 2019 18:59:44 -0500
parents 988c436ad798
children ce101123d015
files data_manager/kraken2_build_custom.py data_manager/kraken2_build_custom.xml data_manager/kraken2_build_standard.py data_manager/kraken2_custom_database_builder.xml data_manager/kraken2_standard_database_builder.xml data_manager/make_json.py data_manager_conf.xml tool_data_table_conf.xml.sample
diffstat 8 files changed, 56 insertions(+), 188 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/kraken2_build_custom.py	Fri Mar 01 14:01:57 2019 -0500
+++ b/data_manager/kraken2_build_custom.py	Mon Mar 04 18:59:44 2019 -0500
@@ -23,36 +23,43 @@
         sys.exit( return_code )
 
 
-def kraken2_build(data_manager_dict, kraken2_args, params, target_directory, data_table_name=DATA_TABLE_NAME):
+def kraken2_build(data_manager_dict, kraken2_args, database_name, params, target_directory, data_table_name=DATA_TABLE_NAME):
     today = datetime.date.today().isoformat()
-    database_name = "_".join([today, "custom"])
     
     args = [
-        'kraken2-build',
         '--threads', str(kraken2_args["threads"]),
         '--download-taxonomy',
         '--db', database_name
     ]
     
-    # run(args, target_directory)
+    run(['kraken2-build'] + args, target_directory)
     
     args = [
-        'kraken2-build',
         '--threads', str(kraken2_args["threads"]),
         '--add-to-library', kraken2_args["fasta"],
         '--db', database_name
     ]
     
-    run(args, target_directory)
-        
+    run(['kraken2-build'] + args, target_directory)
+
     args = [
-        'kraken2-build',
+        '--threads', str(kraken2_args["threads"]),
+        '--build',
+        '--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(args, target_directory)
+    run(['kraken2-build'] + args, target_directory)
     
     data_table_entry = {
         "value": database_name,
@@ -73,6 +80,7 @@
 def main():
     parser = argparse.ArgumentParser()
     parser.add_argument('params')
+    parser.add_argument( '-d', '--db', dest='database_name', help='database name' )
     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' )
--- a/data_manager/kraken2_build_custom.xml	Fri Mar 01 14:01:57 2019 -0500
+++ b/data_manager/kraken2_build_custom.xml	Mon Mar 04 18:59:44 2019 -0500
@@ -10,6 +10,7 @@
         python '$__tool_directory__/kraken2_build_custom.py'
           '${out_file}'
           --threads \${GALAXY_SLOTS:-1}
+          --db ${database_name}
           --kmer-len ${kmer_len}
           --minimizer-len ${minimizer_len}
           --minimizer-spaces ${minimizer_spaces}
@@ -18,6 +19,7 @@
     </command>
     <inputs>
         <param name="input_fasta" type="data" format="fasta" multiple="False" optional="true" label="Select history item" />
+	<param name="database_name" type="text" label="Name for this database" />
         <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" />
--- a/data_manager/kraken2_build_standard.py	Fri Mar 01 14:01:57 2019 -0500
+++ b/data_manager/kraken2_build_standard.py	Mon Mar 04 18:59:44 2019 -0500
@@ -11,15 +11,26 @@
 import subprocess
 import sys
 
-from pprint import pprint
 
 DATA_TABLE_NAME = "kraken2_databases"
 
-def kraken2_build_standard(data_manager_dict, kraken2_args, params, target_directory, data_table_name=DATA_TABLE_NAME):
+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, "standard"])
+    database_name = "_".join([
+        today,
+        "standard",
+        "kmer-len=" + str(kraken2_args["kmer_len"]),
+        "minimizer-len=" + str(kraken2_args["minimizer_len"]),
+        "minimizer-spaces=" + str(kraken2_args["minimizer_spaces"]),
+    ])
     args = [
-        'kraken2-build',
         '--threads', str(kraken2_args["threads"]),
         '--standard',
         '--kmer-len', str(kraken2_args["kmer_len"]),
@@ -27,41 +38,37 @@
         '--minimizer-spaces', str(kraken2_args["minimizer_spaces"]),
         '--db', database_name
     ]
-    proc = subprocess.Popen(args=args, shell=False, cwd=target_directory)
-    return_code = proc.wait()
-    if return_code:
-        print("Error building database.", file=sys.stderr)
-        sys.exit( return_code )
+
+    run(['kraken2-build'] + args, target_directory)
+
     args = [
         'kraken2-build',
         '--threads', str(kraken2_args["threads"]),
         '--clean',
         '--db', database_name
     ]
-    proc = subprocess.Popen(args=args, shell=False, cwd=target_directory)
-    return_code = proc.wait()
-    if return_code:
-        print("Error building database.", file=sys.stderr)
-        sys.exit( return_code )
+
+    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_name, data_table_entry)
+    _add_data_table_entry(data_manager_dict, data_table_entry)
 
 
-def _add_data_table_entry(data_manager_dict, data_table_name, 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 )
+    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('params')
+    parser.add_argument('data_manager_json')
     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' )
@@ -75,9 +82,9 @@
         "threads": args.threads,
     }
     
-    params = json.loads(open(args.params).read())
-    pprint(params)
-    target_directory = params['output_data'][0]['extra_files_path']
+    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 )
@@ -87,18 +94,13 @@
         else:
             raise
 
-    data_manager_dict = {}
-
-    # build the index
     kraken2_build_standard(
-        data_manager_dict,
+        data_manager_input,
         kraken2_args,
-        params,
-        target_directory
+        target_directory,
     )
 
-    # save info to json file
-    open(args.params, 'wb').write(json.dumps(data_manager_dict))
+    open(args.data_manager_json, 'wb').write(json.dumps(data_manager_input))
 
 
 if __name__ == "__main__":
--- a/data_manager/kraken2_custom_database_builder.xml	Fri Mar 01 14:01:57 2019 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-<?xml version="1.0"?>
-<tool id="kraken2_custom_database_builder" name="Kraken2 Custom 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[
-        #set $library_list = str($libraries).split(',')
-        mkdir kraken2-database && cd kraken2-database &&
-        kraken2-build --threads \${GALAXY_SLOTS:-1} --download-taxonomy --db '${database_name}' &&
-        #for $library in $library_list:
-            #if str($library) != 'None':
-                kraken2-build --threads \${GALAXY_SLOTS:-1} --download-library $library --db '${database_name}' &&
-            #end if
-        #end for
-        #for $fasta in $input_fasta:
-            #if str($fasta) != 'None':
-                kraken2-build --threads \${GALAXY_SLOTS:-1} --db '${database_name}' --add-to-library '$fasta' &&
-            #end if
-        #end for
-        kraken2-build --threads \${GALAXY_SLOTS:-1} --db '${database_name}' --build --kmer-len ${kmer_len} --minimizer-len ${minimizer_len} &&
-        cd .. &&
-        python '$__tool_directory__/make_json.py' --db '${database_name}' --out '${out_file}'
-    ]]>
-    </command>
-    <inputs>
-        <param name="database_name" type="text" label="Name for this database" />
-        <param name="libraries" type="select" multiple="true" label="Select partial library to download">
-            <option value="archaea">Archaea</option>
-	    <option value="bacteria">Bacteria</option>
-            <option value="plasmid">Plasmid</option>
-            <option value="viral">Viral</option>
-            <option value="human">Human</option>
-        </param>
-        <param name="input_fasta" type="data" format="fasta" multiple="True" optional="true" label="Select history item" />
-        <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_standard_database_builder.xml	Fri Mar 01 14:01:57 2019 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-<?xml version="1.0"?>
-<tool id="kraken2_standard_database_builder" name="Kraken2 Standard 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[
-        #import datetime
-	#set kraken2_db_name = datetime.date.today().strftime('%Y-%m-%d') + "_standard"
-        mkdir kraken2-database && cd kraken2-database &&
-        kraken2-build 
-          --standard
-	  --threads \${GALAXY_SLOTS:-1}
-          --db '${kraken2_db_name}'
-          --kmer-len ${kmer_len}
-          --minimizer-len ${minimizer_len}
-          --minimizer-spaces ${minimizer_spaces} &&
-        cd .. &&
-        python '$__tool_directory__/make_json.py' --db '${kraken2_db_name}' --out '${out_file}'
-    ]]>
-    </command>
-    <inputs>
-        <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/make_json.py	Fri Mar 01 14:01:57 2019 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-import argparse
-import json
-import os
-import shutil
-
-
-def main(args):
-    data_manager_entry = {}
-    data_manager_entry['value'] = args.database.lower()
-    data_manager_entry['name'] = args.database
-    data_manager_entry['path'] = '.'
-    data_manager_json = dict(data_tables=dict(kraken2_databases=data_manager_entry))
-    params = json.loads(open(args.output).read())
-    target_directory = params['output_data'][0]['extra_files_path']
-    os.mkdir(target_directory)
-    output_path = os.path.join(os.getcwd(), 'kraken2-database')
-    for filename in os.listdir(output_path):
-        shutil.move(os.path.join(output_path, filename), target_directory)
-    file(args.output, 'w').write(json.dumps(data_manager_json))
-
-
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description='Create data manager json.')
-    parser.add_argument('--db', dest='database', action='store', help='Database name')
-    parser.add_argument('--out', dest='output', action='store', help='JSON filename')
-    args = parser.parse_args()
-    main(args)
--- a/data_manager_conf.xml	Fri Mar 01 14:01:57 2019 -0500
+++ b/data_manager_conf.xml	Mon Mar 04 18:59:44 2019 -0500
@@ -1,34 +1,4 @@
 <data_managers>
-    <data_manager tool_file="data_manager/kraken2_custom_database_builder.xml" id="kraken2_custom_database_builder" 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_database/${value}</target>
-		    </move>
-		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_database/${value}</value_translation>
-		    <value_translation type="function">abspath</value_translation>
-		</column>
-	    </output>
-	</data_table>
-    </data_manager>
-    <data_manager tool_file="data_manager/kraken2_standard_database_builder.xml" id="kraken2_standard_database_builder" 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_database/${value}</target>
-		    </move>
-		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_database/${value}</value_translation>
-		    <value_translation type="function">abspath</value_translation>
-		</column>
-	    </output>
-	</data_table>
-    </data_manager>
     <data_manager tool_file="data_manager/kraken2_build_standard.xml" id="kraken2_build_standard" version="1.0">
 	<data_table name="kraken2_databases">
 	    <output>
@@ -36,9 +6,9 @@
 		<column name="name"/>
 		<column name="path" output_ref="out_file">
 		    <move type="directory" relativize_symlinks="True">
-			<target base="${GALAXY_DATA_MANAGER_DATA_PATH}">kraken2_database/${value}</target>
+			<target base="${GALAXY_DATA_MANAGER_DATA_PATH}">kraken2_databases</target>
 		    </move>
-		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_database/${value}</value_translation>
+		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_databases</value_translation>
 		    <value_translation type="function">abspath</value_translation>
 		</column>
 	    </output>
@@ -51,9 +21,9 @@
 		<column name="name"/>
 		<column name="path" output_ref="out_file">
 		    <move type="directory" relativize_symlinks="True">
-			<target base="${GALAXY_DATA_MANAGER_DATA_PATH}">kraken2_database/${value}</target>
+			<target base="${GALAXY_DATA_MANAGER_DATA_PATH}">kraken2_databases</target>
 		    </move>
-		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_database/${value}</value_translation>
+		    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/kraken2_databases</value_translation>
 		    <value_translation type="function">abspath</value_translation>
 		</column>
 	    </output>
--- a/tool_data_table_conf.xml.sample	Fri Mar 01 14:01:57 2019 -0500
+++ b/tool_data_table_conf.xml.sample	Mon Mar 04 18:59:44 2019 -0500
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <tables>
-    <!-- Locations of Kraken database in the required format -->
+    <!-- Locations of Kraken2 database in the required format -->
     <table name="kraken2_databases" comment_char="#">
         <columns>value, name, path</columns>
         <file path="tool-data/kraken2_databases.loc" />