changeset 6:fca923910aaa draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
author iuc
date Sun, 22 Nov 2020 12:46:50 +0000
parents 5ab25caa7b7d
children
files data_manager/bwameth_index_builder.py
diffstat 1 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/bwameth_index_builder.py	Mon Feb 03 17:19:38 2020 -0500
+++ b/data_manager/bwameth_index_builder.py	Sun Nov 22 12:46:50 2020 +0000
@@ -2,19 +2,19 @@
 # Based heavily on the HISAT2 data manager wrapper
 
 import argparse
+import json
 import os
 import subprocess
 import sys
-from json import dumps, loads
 
 DEFAULT_DATA_TABLE_NAME = "bwameth_indexes"
 
 
 def build_bwameth_index(data_manager_dict, params, args):
     data_table_name = args.data_table_name
-    target_directory = params[ 'output_data' ][0]['extra_files_path']
-    if not os.path.exists( target_directory ):
-        os.mkdir( target_directory )
+    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.basename(args.fasta_filename)
     sym_linked_fasta_filename = os.path.join(target_directory, fasta_base_name)
     os.symlink(os.path.abspath(args.fasta_filename), sym_linked_fasta_filename)
@@ -23,41 +23,43 @@
     return_code = proc.wait()
     if return_code:
         print("Error building index.", file=sys.stderr)
-        sys.exit( return_code )
+        sys.exit(return_code)
     data_table_entry = dict(value=args.dbkey, dbkey=args.dbkey, name=args.name, path=sym_linked_fasta_filename)
     _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 )
+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', default=None )
-    parser.add_argument( '--fasta_filename', default=None )
-    parser.add_argument( '--dbkey', default=None )
-    parser.add_argument( '--name', default=None )
-    parser.add_argument( '--description', default=None )
-    parser.add_argument( '--data_table_name', default=DEFAULT_DATA_TABLE_NAME )
+    parser.add_argument('--output', default=None)
+    parser.add_argument('--fasta_filename', default=None)
+    parser.add_argument('--dbkey', default=None)
+    parser.add_argument('--name', default=None)
+    parser.add_argument('--description', default=None)
+    parser.add_argument('--data_table_name', default=DEFAULT_DATA_TABLE_NAME)
     args = parser.parse_args()
 
     filename = args.output
-    params = loads(open(filename).read())
+    with open(filename) as fh:
+        params = json.load(fh)
     data_manager_dict = {}
 
-    if args.dbkey in [ None, '', '?' ]:
+    if args.dbkey in [None, '', '?']:
         raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (args.dbkey))
 
     # build the index
     build_bwameth_index(data_manager_dict, params, args)
 
     # save info to json file
-    open(filename, 'w').write(dumps(data_manager_dict, sort_keys=True))
+    with open(filename, 'w') as fh:
+        json.dump(data_manager_dict, fh, sort_keys=True)
 
 
 if __name__ == "__main__":