changeset 1:52f0767fe68d draft

planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
author sanbi-uwc
date Thu, 13 Sep 2018 06:25:32 -0400
parents f86c65c60056
children 495439e68fca
files data_manager/shapeit_ref.py data_manager/shapeit_ref.xml data_manager_conf.xml test-data/sample.out tool-data/shapeit_ref.loc.sample tool_data_tables_conf.xml.sample
diffstat 6 files changed, 35 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/shapeit_ref.py	Tue Sep 11 10:39:38 2018 -0400
+++ b/data_manager/shapeit_ref.py	Thu Sep 13 06:25:32 2018 -0400
@@ -14,34 +14,46 @@
     return data_manager_dict
 
 
+_add_data_table_entry.__annotations__ = {'data_manager': dict, 'data_table_name': str, 'data_table_entry': dict, 'return': dict}
+
+
+def assert_prefix_exists(prefix, path, prefix_type):
+    prefix_exists = False
+    for filename in os.listdir(path):
+        if filename.startswith(prefix):
+            prefix_exists = True
+            break
+    else:
+        if not prefix_exists:
+            exit("Unable to find a file with {} prefix {} in {}".format(prefix_type, prefix, path))
+
+
+assert_prefix_exists.__annotations__ = {'prefix': str, 'path': str, 'prefix_type': str, 'return': None}
+
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Generate a data manager output for SHAPEIT reference data')
     parser.add_argument('key', help='Short key to identify this reference set (no spaces)')
     parser.add_argument('description', help='Description of reference set')
     parser.add_argument('path', help='Filesystem path to directory containing this reference set')
-    parser.add_argument('prefix', help='Filename prefix for files in this reference set')
+    parser.add_argument('reference_prefix', help='Filename prefix for the reference (.hap / .legend / .sample) files')
+    parser.add_argument('map_prefix', help='Filename prefix for map files in this reference set')
     parser.add_argument('output_file', type=argparse.FileType('w'), help='JSON file used to write data manager values to')
     args = parser.parse_args()
 
     if not os.path.exists(args.path):
         exit("Unable to find specified path {}".format(args.path))
 
-    prefix_exists = False
-    for filename in os.listdir(args.path):
-        if filename.startswith(args.prefix):
-            prefix_exists = True
-            break
-    else:
-        if not prefix_exists:
-            exit("Unable to find a file with prefix {} in {}".format(args.prefix, args.path))
+    assert_prefix_exists(args.reference_prefix, args.path, 'reference')
+    assert_prefix_exists(args.map_prefix, args.path, 'map')
 
-    for column in ('key', 'description', 'path', 'prefix'):
+    for column in ('key', 'description', 'path', 'reference_prefix', 'map_prefix'):
         value = getattr(args, column)
         if '\t' in value:
             exit("TAB character found in {} argument".format(column))
 
     data_manager_dict = {}
-    data_table_entry = dict(key=args.key, description=args.description, path=args.path, prefix=args.prefix)
+    data_table_entry = dict(key=args.key, description=args.description, path=args.path,
+                            reference_prefix=args.reference_prefix, map_prefix=args.map_prefix)
     _add_data_table_entry(data_manager_dict, 'shapeit_ref', data_table_entry)
 
-    args.output_file.write(json.dumps(data_manager_dict) + '\n')
+    args.output_file.write(json.dumps(data_manager_dict, sort_keys=True) + '\n')
--- a/data_manager/shapeit_ref.xml	Tue Sep 11 10:39:38 2018 -0400
+++ b/data_manager/shapeit_ref.xml	Thu Sep 13 06:25:32 2018 -0400
@@ -1,17 +1,19 @@
-<tool id="shapeit_reference_manager" name="SHAPEIT reference data path manager" tool_type="manage_data" version="0.0.1">
+<tool id="shapeit_reference_manager" name="SHAPEIT reference data path manager" tool_type="manage_data" version="0.0.2">
     <command detect_errors="aggressive"><![CDATA[
     python $__tool_directory__/shapeit_ref.py
         '${key}'
         '${description}'
         '${path}'
-        '${prefix}'
+        '${reference_prefix}'
+        '${map_prefix}'
         '${output_file}'
     ]]></command>>
     <inputs>
         <param name="key" type="text" label="Short key to identify this reference set (no spaces)" />
         <param name="description" type="text" label="Description of the reference data" />
         <param name="path" type="text" label="Filesystem path to directory containing this reference set" />
-        <param name="prefix" type="text" label="Filename prefix for files in this reference set" />
+        <param name="reference_prefix" type="text" label="Filename prefix for the reference (.hap / .legend / .sample) files" />
+        <param name="map_prefix" type="text" label="Filename prefix for map files in this reference set" />
     </inputs>
     <outputs>
         <data name="output_file" format="data_manager_json" />
--- a/data_manager_conf.xml	Tue Sep 11 10:39:38 2018 -0400
+++ b/data_manager_conf.xml	Thu Sep 13 06:25:32 2018 -0400
@@ -6,7 +6,8 @@
                 <column name="key" />
                 <column name="description" />
                 <column name="path" />
-                <column name="prefix" />
+                <column name="reference_prefix">
+                <column name="map_prefix" />
             </output>
         </data_table>
     </data_manager>    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sample.out	Thu Sep 13 06:25:32 2018 -0400
@@ -0,0 +1,1 @@
+{"data_tables": {"shapeit_ref": [{"description": "1000 Genomes Project (phase 3) haplotypes (http://mathgen.stats.ox.ac.uk/impute/1000GPX20Phase3.html)", "key": "1000GP_Phase3", "map_prefix": "genetic_map_", "path": "/tools/databases/1000G/1000GP_Phase3", "reference_prefix": "1000GP_Phase3_"}]}}
--- a/tool-data/shapeit_ref.loc.sample	Tue Sep 11 10:39:38 2018 -0400
+++ b/tool-data/shapeit_ref.loc.sample	Thu Sep 13 06:25:32 2018 -0400
@@ -1,7 +1,7 @@
 #This file lists the locations of SHAPEIT reference data connections
 #
-#<unique_key>	<description>		<path>	<file_prefix>
+#<unique_key>	<description>		<path>	<reference_file_prefix> <map_file_prefix>
 #
 #For example
 #
-#1000G_Phase3	1000 Genomes project haplotypes		/path/to/shapeit_ref/1000G  1000GP_Phase3_
+#1000G_Phase3	1000 Genomes project haplotypes		/path/to/shapeit_ref/1000G  1000GP_Phase3_  genetic_map_
--- a/tool_data_tables_conf.xml.sample	Tue Sep 11 10:39:38 2018 -0400
+++ b/tool_data_tables_conf.xml.sample	Thu Sep 13 06:25:32 2018 -0400
@@ -1,7 +1,7 @@
 <tables>
     <!-- Locations of all fasta files under genome directory -->
     <table name="shapeit_ref" comment_char="#">
-        <columns>key, description, path, prefix</columns>
+        <columns>key, description, path, reference_prefix, map_prefix</columns>
         <file path="tool-data/shapeit_ref.loc" />
     </table>
 </tables>
\ No newline at end of file