comparison data_manager/bwameth_index_builder.py @ 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
comparison
equal deleted inserted replaced
5:5ab25caa7b7d 6:fca923910aaa
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Based heavily on the HISAT2 data manager wrapper 2 # Based heavily on the HISAT2 data manager wrapper
3 3
4 import argparse 4 import argparse
5 import json
5 import os 6 import os
6 import subprocess 7 import subprocess
7 import sys 8 import sys
8 from json import dumps, loads
9 9
10 DEFAULT_DATA_TABLE_NAME = "bwameth_indexes" 10 DEFAULT_DATA_TABLE_NAME = "bwameth_indexes"
11 11
12 12
13 def build_bwameth_index(data_manager_dict, params, args): 13 def build_bwameth_index(data_manager_dict, params, args):
14 data_table_name = args.data_table_name 14 data_table_name = args.data_table_name
15 target_directory = params[ 'output_data' ][0]['extra_files_path'] 15 target_directory = params['output_data'][0]['extra_files_path']
16 if not os.path.exists( target_directory ): 16 if not os.path.exists(target_directory):
17 os.mkdir( target_directory ) 17 os.mkdir(target_directory)
18 fasta_base_name = os.path.basename(args.fasta_filename) 18 fasta_base_name = os.path.basename(args.fasta_filename)
19 sym_linked_fasta_filename = os.path.join(target_directory, fasta_base_name) 19 sym_linked_fasta_filename = os.path.join(target_directory, fasta_base_name)
20 os.symlink(os.path.abspath(args.fasta_filename), sym_linked_fasta_filename) 20 os.symlink(os.path.abspath(args.fasta_filename), sym_linked_fasta_filename)
21 cmd = ['bwameth.py', 'index', sym_linked_fasta_filename] 21 cmd = ['bwameth.py', 'index', sym_linked_fasta_filename]
22 proc = subprocess.Popen(args=cmd, shell=False, cwd=target_directory) 22 proc = subprocess.Popen(args=cmd, shell=False, cwd=target_directory)
23 return_code = proc.wait() 23 return_code = proc.wait()
24 if return_code: 24 if return_code:
25 print("Error building index.", file=sys.stderr) 25 print("Error building index.", file=sys.stderr)
26 sys.exit( return_code ) 26 sys.exit(return_code)
27 data_table_entry = dict(value=args.dbkey, dbkey=args.dbkey, name=args.name, path=sym_linked_fasta_filename) 27 data_table_entry = dict(value=args.dbkey, dbkey=args.dbkey, name=args.name, path=sym_linked_fasta_filename)
28 _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry) 28 _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry)
29 29
30 30
31 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ): 31 def _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry):
32 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) 32 data_manager_dict['data_tables'] = data_manager_dict.get('data_tables', {})
33 data_manager_dict['data_tables'][ data_table_name ] = data_manager_dict['data_tables'].get( data_table_name, [] ) 33 data_manager_dict['data_tables'][data_table_name] = data_manager_dict['data_tables'].get(data_table_name, [])
34 data_manager_dict['data_tables'][ data_table_name ].append( data_table_entry ) 34 data_manager_dict['data_tables'][data_table_name].append(data_table_entry)
35 return data_manager_dict 35 return data_manager_dict
36 36
37 37
38 def main(): 38 def main():
39 # Parse Command Line 39 # Parse Command Line
40 parser = argparse.ArgumentParser() 40 parser = argparse.ArgumentParser()
41 parser.add_argument( '--output', default=None ) 41 parser.add_argument('--output', default=None)
42 parser.add_argument( '--fasta_filename', default=None ) 42 parser.add_argument('--fasta_filename', default=None)
43 parser.add_argument( '--dbkey', default=None ) 43 parser.add_argument('--dbkey', default=None)
44 parser.add_argument( '--name', default=None ) 44 parser.add_argument('--name', default=None)
45 parser.add_argument( '--description', default=None ) 45 parser.add_argument('--description', default=None)
46 parser.add_argument( '--data_table_name', default=DEFAULT_DATA_TABLE_NAME ) 46 parser.add_argument('--data_table_name', default=DEFAULT_DATA_TABLE_NAME)
47 args = parser.parse_args() 47 args = parser.parse_args()
48 48
49 filename = args.output 49 filename = args.output
50 params = loads(open(filename).read()) 50 with open(filename) as fh:
51 params = json.load(fh)
51 data_manager_dict = {} 52 data_manager_dict = {}
52 53
53 if args.dbkey in [ None, '', '?' ]: 54 if args.dbkey in [None, '', '?']:
54 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (args.dbkey)) 55 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (args.dbkey))
55 56
56 # build the index 57 # build the index
57 build_bwameth_index(data_manager_dict, params, args) 58 build_bwameth_index(data_manager_dict, params, args)
58 59
59 # save info to json file 60 # save info to json file
60 open(filename, 'w').write(dumps(data_manager_dict, sort_keys=True)) 61 with open(filename, 'w') as fh:
62 json.dump(data_manager_dict, fh, sort_keys=True)
61 63
62 64
63 if __name__ == "__main__": 65 if __name__ == "__main__":
64 main() 66 main()