Mercurial > repos > devteam > data_manager_bwa_index_builder
comparison data_manager/bwa_index_builder.py @ 1:cc5ae94acf01 draft default tip
planemo upload commit 2b9ef766ea9ee24964464363a9d41faeefa3d360-dirty
author | devteam |
---|---|
date | Wed, 26 Aug 2015 11:50:48 -0400 |
parents | 367878cb3698 |
children |
comparison
equal
deleted
inserted
replaced
0:367878cb3698 | 1:cc5ae94acf01 |
---|---|
5 import os | 5 import os |
6 import tempfile | 6 import tempfile |
7 import optparse | 7 import optparse |
8 import subprocess | 8 import subprocess |
9 | 9 |
10 from galaxy.util.json import from_json_string, to_json_string | 10 from json import loads, dumps |
11 | 11 |
12 | 12 |
13 CHUNK_SIZE = 2**20 | 13 CHUNK_SIZE = 2**20 |
14 ONE_GB = 2**30 | 14 ONE_GB = 2**30 |
15 | 15 |
44 | 44 |
45 args = [ 'bwa', 'index', '-a', index_algorithm ] | 45 args = [ 'bwa', 'index', '-a', index_algorithm ] |
46 if color_space: | 46 if color_space: |
47 args.append( '-c' ) | 47 args.append( '-c' ) |
48 args.append( sym_linked_fasta_filename ) | 48 args.append( sym_linked_fasta_filename ) |
49 tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-bwa-index-builder-stderr" ) | 49 proc = subprocess.Popen( args=args, shell=False, cwd=target_directory ) |
50 proc = subprocess.Popen( args=args, shell=False, cwd=target_directory, stderr=tmp_stderr.fileno() ) | |
51 return_code = proc.wait() | 50 return_code = proc.wait() |
52 if return_code: | 51 if return_code: |
53 tmp_stderr.flush() | 52 print >> sys.stderr, "Error building index." |
54 tmp_stderr.seek(0) | |
55 print >> sys.stderr, "Error building index:" | |
56 while True: | |
57 chunk = tmp_stderr.read( CHUNK_SIZE ) | |
58 if not chunk: | |
59 break | |
60 sys.stderr.write( chunk ) | |
61 sys.exit( return_code ) | 53 sys.exit( return_code ) |
62 tmp_stderr.close() | |
63 data_table_entry = dict( value=sequence_id, dbkey=dbkey, name=sequence_name, path=fasta_base_name ) | 54 data_table_entry = dict( value=sequence_id, dbkey=dbkey, name=sequence_name, path=fasta_base_name ) |
64 _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ) | 55 _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ) |
65 | 56 |
66 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ): | 57 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ): |
67 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) | 58 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) |
79 parser.add_option( '-c', '--color_space', dest='color_space', action='store_true', default=False, help='color_space' ) | 70 parser.add_option( '-c', '--color_space', dest='color_space', action='store_true', default=False, help='color_space' ) |
80 (options, args) = parser.parse_args() | 71 (options, args) = parser.parse_args() |
81 | 72 |
82 filename = args[0] | 73 filename = args[0] |
83 | 74 |
84 params = from_json_string( open( filename ).read() ) | 75 params = loads( open( filename ).read() ) |
85 target_directory = params[ 'output_data' ][0]['extra_files_path'] | 76 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
86 os.mkdir( target_directory ) | 77 os.mkdir( target_directory ) |
87 data_manager_dict = {} | 78 data_manager_dict = {} |
88 | 79 |
89 dbkey = options.fasta_dbkey | 80 dbkey = options.fasta_dbkey |
95 | 86 |
96 #build the index | 87 #build the index |
97 build_bwa_index( data_manager_dict, options.fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name, data_table_name=options.data_table_name or DEFAULT_DATA_TABLE_NAME, color_space=options.color_space ) | 88 build_bwa_index( data_manager_dict, options.fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name, data_table_name=options.data_table_name or DEFAULT_DATA_TABLE_NAME, color_space=options.color_space ) |
98 | 89 |
99 #save info to json file | 90 #save info to json file |
100 open( filename, 'wb' ).write( to_json_string( data_manager_dict ) ) | 91 open( filename, 'wb' ).write( dumps( data_manager_dict ) ) |
101 | 92 |
102 if __name__ == "__main__": main() | 93 if __name__ == "__main__": main() |