changeset 0:af7b7c99ae9f draft default tip

Uploaded
author brenninc
date Sun, 08 May 2016 04:08:18 -0400
parents
children
files data_manager/gene_transfer_by_path_data_manager.xml data_manager/path_name_value_key_manager.py data_manager_conf.xml tool-data/gene_transfer.loc.sample tool_data_table_conf.xml.sample
diffstat 5 files changed, 142 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/gene_transfer_by_path_data_manager.xml	Sun May 08 04:08:18 2016 -0400
@@ -0,0 +1,37 @@
+<tool id="gene_transfer_by_path_manager" name="gene_transfer by path data manager" tool_type="manage_data" version="0.0.1">
+    <description>path inputer</description>
+    <command interpreter="python">
+        path_name_value_key_manager.py 
+        --value "${value}" 
+        --dbkey "${dbkey}" 
+        --name "${name}" 
+        --path "${path}" 
+        --data_table_name "gene_transfer" 
+        --json_output_file "${json_output_file}"
+    </command>
+    <inputs>
+        <param name="value" type="text" value="" label="value field for the entry.  Defaults to name if left blank." />
+        <param name="dbkey" type="text" value="" label="dbkey field for the entry.  Defaults to value if left blank." />
+        <param name="name" type="text" value="" label="name field for the entry. Defaults to the file name from path if left blank." />
+        <param name="path" type="text" value="" label="path field for the entry" />
+    </inputs>
+    <outputs>
+        <data name="json_output_file" format="data_manager_json"/>
+    </outputs>
+
+    <help>
+Adds a server path to the gene_transfer data table.
+
+The tool will check the path exists but NOT check that it holds the expected data type.
+
+If name is not provided the filename from path less the exstension is used.
+
+If value is not provided, the name will be used (or its default)
+
+If dbkey is not provided, the value will be used (or its default)
+
+    </help>
+    <citations>
+    </citations>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/path_name_value_key_manager.py	Sun May 08 04:08:18 2016 -0400
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import json
+import optparse
+import os.path
+
+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 check_param(name, value, default=None,  check_tab=True):
+    if value in [ None, '', '?' ]:
+        if default:
+            print "Using {0} for {1} as no value provided".format( default, name )
+            value = default
+        else:
+            raise Exception( '{0} is not a valid {1}. You must specify a valid {1}.'.format( value, name ) )
+    if check_tab and "\t" in value:
+        raise Exception( '{0} is not a valid {1}. It may not contain a tab because these are used as seperators by galaxy .'.format( value, name ) )
+    return value
+
+
+def main():
+
+    #value = "test_value"
+    #name = "test_name"
+    #print '{0} other {1} more{0}'.format(value, name )
+    #print '{0} is not a valid {1}. It may not contain a tab.'.format( value, name )
+
+    #Parse Command Line
+    parser = optparse.OptionParser()
+    parser.add_option( '--value', action='store', type="string", default=None, help='value' )
+    parser.add_option( '--dbkey', action='store', type="string", default=None, help='dbkey' )
+    parser.add_option( '--name',  action='store', type="string", default=None, help='name' )
+    parser.add_option( '--path', action='store', type="string", default=None, help='path' )
+    parser.add_option( '--data_table_name', action='store', type="string", default=None, help='path' )
+    parser.add_option( '--json_output_file', action='store', type="string", default=None, help='path' )
+    (options, args) = parser.parse_args()
+ 
+    path = check_param("path", options.path)
+    if not os.path.exists(path):
+        raise Exception( 'Unable to find path {0}.'.format( path ) )
+    basename = os.path.basename(path)
+    filename = os.path.splitext(basename)[0]
+    name = check_param("name", options.name, default=filename)
+    value = check_param("value", options.value, default=name)
+    dbkey = check_param("dbkey", options.dbkey, default=value)
+    data_table_name = check_param("data_table_name", options.data_table_name)
+    json_output_file = check_param("json_output_file", options.json_output_file, check_tab=False)
+
+    if os.path.exists(json_output_file):
+        params = json.loads( open( json_output_file ).read() )
+        print "params", params
+    else:
+        params = {}
+
+    data_manager_dict = {}
+    data_table_entry = dict( value=value, dbkey=dbkey, name=name, path=path )
+    _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry )
+
+    #save info to json file
+    with open( json_output_file, 'wb' ) as output_file:
+        output_file.write( json.dumps( data_manager_dict ) )
+        output_file.write( "\n" )
+
+if __name__ == "__main__": 
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml	Sun May 08 04:08:18 2016 -0400
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<data_managers>
+    <data_manager tool_file="data_manager/gene_transfer_by_path_data_manager.xml" id="gene_transfer_by_path_manager" version="0.0.1">
+        <data_table name="gene_transfer">
+            <output>
+                <column name="value" />
+                <column name="dbkey" />
+                <column name="name" />
+                <column name="path" />
+            </output>
+        </data_table>
+    </data_manager>
+
+</data_managers>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/gene_transfer.loc.sample	Sun May 08 04:08:18 2016 -0400
@@ -0,0 +1,14 @@
+#This file lists the locations and dbkeys of all the gene transfer files
+
+#This file has the format (white space characters are TAB characters):
+#
+#<unique_build_id>	<dbkey>		<display_name>	<file_path>
+#
+#So, gene_transfer.loc could look something like this:
+#
+#vm5	vm5	vM5 annotation	/path/to/vM5.annotation.gtf
+#
+#Your gene_transfer.loc file should contain an entry for each individual
+#gtf file. 
+#
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample	Sun May 08 04:08:18 2016 -0400
@@ -0,0 +1,7 @@
+<!-- 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>
+    <table name="gene_transfer" comment_char="#">
+        <columns>value, dbkey, name, path</columns>
+        <file path="tool-data/gene_transfer.loc" />
+    </table>
+ </tables>