changeset 0:6843a0db2da0 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_kallisto_index_builder commit 3b54163c4f7daff76fcc589c4a9057bb03904380
author iuc
date Sat, 05 Aug 2017 04:02:01 -0400
parents
children 18e2dd472525
files data_manager/kallisto_index_builder.py data_manager/kallisto_index_builder.xml data_manager_conf.xml tool-data/all_fasta.loc.sample tool-data/kallisto_indexes.loc.sample tool_data_table_conf.xml.sample
diffstat 6 files changed, 217 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/kallisto_index_builder.py	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Based heavily on the Bowtie 2 data manager wrapper script by Dan Blankenberg
+from __future__ import print_function
+
+import argparse
+import os
+import subprocess
+import sys
+from json import dumps, loads
+
+DEFAULT_DATA_TABLE_NAME = "kallisto_indexes"
+
+
+def get_id_name( params, dbkey, fasta_description=None):
+    # TODO: ensure sequence_id is unique and does not already appear in location file
+    sequence_id = params['param_dict']['sequence_id']
+    if not sequence_id:
+        sequence_id = dbkey
+
+    sequence_name = params['param_dict']['sequence_name']
+    if not sequence_name:
+        sequence_name = fasta_description
+        if not sequence_name:
+            sequence_name = dbkey
+    return sequence_id, sequence_name
+
+
+def build_kallisto_index( data_manager_dict, options, params, sequence_id, sequence_name ):
+    data_table_name = options.data_table_name or DEFAULT_DATA_TABLE_NAME
+    target_directory = params[ 'output_data' ][0]['extra_files_path']
+    if not os.path.exists( target_directory ):
+        os.mkdir( target_directory )
+    fasta_base_name = os.path.split( options.fasta_filename )[-1]
+    sym_linked_fasta_filename = os.path.join( target_directory, fasta_base_name )
+    os.symlink( options.fasta_filename, sym_linked_fasta_filename )
+    args = [ 'kallisto', 'index' ]
+    args.extend( [ sym_linked_fasta_filename, '-i', sequence_id ] )
+    proc = subprocess.Popen( args=args, shell=False, cwd=target_directory )
+    return_code = proc.wait()
+    if return_code:
+        print("Error building index.", file=sys.stderr)
+        sys.exit( return_code )
+    data_table_entry = dict( value=sequence_id, dbkey=options.fasta_dbkey, name=sequence_name, path=sequence_id )
+    _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry )
+
+
+def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ):
+    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():
+    # Parse Command Line
+    parser = argparse.ArgumentParser()
+    parser.add_argument( '--output', dest='output', action='store', type=str, default=None )
+    parser.add_argument( '--fasta_filename', dest='fasta_filename', action='store', type=str, default=None )
+    parser.add_argument( '--fasta_dbkey', dest='fasta_dbkey', action='store', type=str, default=None )
+    parser.add_argument( '--fasta_description', dest='fasta_description', action='store', type=str, default=None )
+    parser.add_argument( '--data_table_name', dest='data_table_name', action='store', type=str, default='kallisto_indexes' )
+    options = parser.parse_args()
+
+    filename = options.output
+
+    params = loads( open( filename ).read() )
+    data_manager_dict = {}
+
+    if options.fasta_dbkey in [ None, '', '?' ]:
+        raise Exception( '"%s" is not a valid dbkey. You must specify a valid dbkey.' % ( options.fasta_dbkey ) )
+
+    sequence_id, sequence_name = get_id_name( params, dbkey=options.fasta_dbkey, fasta_description=options.fasta_description )
+
+    # build the index
+    build_kallisto_index( data_manager_dict, options, params, sequence_id, sequence_name )
+
+    # save info to json file
+    open( filename, 'w' ).write( dumps( data_manager_dict ) )
+
+
+if __name__ == "__main__":
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/kallisto_index_builder.xml	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,51 @@
+<tool id="kallisto_index_builder_data_manager" name="Kallisto" tool_type="manage_data" version="0.43.1">
+    <description>index builder</description>
+    <requirements>
+        <requirement type="package" version="0.43.1">kallisto</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        python '$__tool_directory__/kallisto_index_builder.py' --output '${out_file}'
+            --fasta_filename '${all_fasta_source.fields.path}'
+            --fasta_dbkey '${all_fasta_source.fields.dbkey}'
+            --fasta_description '${all_fasta_source.fields.name}'
+            --data_table_name kallisto_indexes
+        ]]>
+    </command>
+    <inputs>
+        <param label="Source FASTA Sequence" name="all_fasta_source" type="select">
+            <options from_data_table="all_fasta" />
+        </param>
+        <param name="sequence_name" type="text" value="" label="Name of sequence" />
+        <param name="sequence_id" type="text" value="" label="ID for sequence" />
+    </inputs>
+    <outputs>
+        <data name="out_file" format="data_manager_json" />
+    </outputs>
+    <help>
+<![CDATA[
+.. class:: infomark
+
+**Notice:** If you leave name, description, or id blank, it will be generated automatically.
+
+What is Kallisto?
+---------------
+
+`kallisto <https://pachterlab.github.io/kallisto/about>`__ is a program for
+quantifying abundances of transcripts from RNA-Seq data, or more generally of
+target sequences using high-throughput sequencing reads. It is based on the
+novel idea of pseudoalignment for rapidly determining the compatibility of
+reads with targets, without the need for alignment. On benchmarks with standard
+RNA-Seq data, kallisto can quantify 30 million human reads in less than 3
+minutes on a Mac desktop computer using only the read sequences and a
+transcriptome index that itself takes less than 10 minutes to build.
+Pseudoalignment of reads preserves the key information needed for
+quantification, and kallisto is therefore not only fast, but also as accurate
+as existing quantification tools. In fact, because the pseudoalignment
+procedure is robust to errors in the reads, in many benchmarks kallisto
+significantly outperforms existing tools.
+]]>
+    </help>
+    <citations>
+        <citation type="doi">10.1038/nmeth.3317</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<data_managers>
+    <data_manager tool_file="data_manager/kallisto_index_builder.xml" id="kallisto_index_builder" version="0.43.1">
+        <data_table name="kallisto_indexes">
+            <output>
+                <column name="value" />
+                <column name="dbkey" />
+                <column name="name" />
+                <column name="path" output_ref="out_file" >
+                    <move type="directory" relativize_symlinks="True">
+                        <!-- <source>${path}</source>--> <!-- out_file.extra_files_path is used as base by default --> <!-- if no source, eg for type=directory, then refers to base -->
+                        <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">${dbkey}/kallisto_index/${value}</target>
+                    </move>
+                    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/${dbkey}/kallisto_index/${value}/${path}</value_translation>
+                    <value_translation type="function">abspath</value_translation>
+                </column>
+            </output>
+        </data_table>
+    </data_manager>
+</data_managers>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/all_fasta.loc.sample	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,18 @@
+#This file lists the locations and dbkeys of all the fasta files
+#under the "genome" directory (a directory that contains a directory
+#for each build). The script extract_fasta.py will generate the file
+#all_fasta.loc. This file has the format (white space characters are
+#TAB characters):
+#
+#<unique_build_id>	<dbkey>	<display_name>	<file_path>
+#
+#So, all_fasta.loc could look something like this:
+#
+#apiMel3	apiMel3	Honeybee (Apis mellifera): apiMel3	/path/to/genome/apiMel3/apiMel3.fa
+#hg19canon	hg19	Human (Homo sapiens): hg19 Canonical	/path/to/genome/hg19/hg19canon.fa
+#hg19full	hg19	Human (Homo sapiens): hg19 Full	/path/to/genome/hg19/hg19full.fa
+#
+#Your all_fasta.loc file should contain an entry for each individual
+#fasta file. So there will be multiple fasta files for each build,
+#such as with hg19 above.
+#
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/kallisto_indexes.loc.sample	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,33 @@
+# kallisto_indexes.loc.sample
+# This is a *.loc.sample file distributed with Galaxy that enables tools
+# to use a directory of indexed data files. This one is for kallisto.
+# See the wiki: http://wiki.galaxyproject.org/Admin/NGS%20Local%20Setup
+# First create these data files and save them in your own data directory structure.
+# Then, create a kallisto_indexes.loc file to use those indexes with tools.
+# Copy this file, save it with the same name (minus the .sample), 
+# follow the format examples, and store the result in this directory.
+# The file should include an one line entry for each index set.
+# The path points to the "basename" for the set, not a specific file.
+# It has four text columns seperated by TABS.
+#
+# <unique_build_id>	<dbkey>	<display_name>	<file_base_path>
+#
+# So, for example, if you had sacCer3 indexes stored in:
+#
+#    /depot/data2/galaxy/sacCer3/kallisto_indexes/
+#
+# containing sacCer3 genome and sacCer3.*.ht2 files, such as:
+#
+#   -rw-rw-r-- 1 dave dave  12M Sep 23 13:57 sacCer3.fa
+#   -rw-rw-r-- 1 dave dave 2.9M Sep 23 13:57 sacCer3.kallisto
+#
+# then the kallisto_indexes.loc entry could look like this:
+#
+#sacCer3	sacCer3	S. cerevisiae Apr. 2011 (SacCer_Apr2011/sacCer3) (sacCer3)	/depot/data2/galaxy/sacCer3/kallisto_indexes/sacCer3.kallisto
+#
+#More examples:
+#
+#mm10	mm10	Mouse (mm10)	/depot/data2/galaxy/kallisto_indexes/mm10
+#dm3	dm3		D. melanogaster (dm3)	/depot/data2/galaxy/kallisto_indexes/dm3
+#
+#
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample	Sat Aug 05 04:02:01 2017 -0400
@@ -0,0 +1,13 @@
+<!-- Use the file tool_data_table_conf.xml.oldlocstyle if you don't want to update your loc files as changed in revision 4550:535d276c92bc-->
+<tables>
+    <!-- Locations of all fasta files under genome directory -->
+    <table name="all_fasta" comment_char="#" allow_duplicate_entries="False">
+        <columns>value, dbkey, name, path</columns>
+        <file path="tool-data/all_fasta.loc" />
+    </table>
+    <!-- Locations of indexes in the kallisto mapper format -->
+    <table name="kallisto_indexes" comment_char="#" allow_duplicate_entries="False">
+        <columns>value, dbkey, name, path</columns>
+        <file path="tool-data/kallisto_indexes.loc" />
+    </table>
+</tables>