Mercurial > repos > iuc > data_manager_snpeff
diff data_manager/data_manager_snpEff_databases.py @ 5:3d9dd4b9fb09 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_snpeff commit 5c6d595ecbf2e4e39c25662a165c9e475e01ecd1-dirty
author | iuc |
---|---|
date | Tue, 18 Apr 2017 09:40:03 -0400 |
parents | 847b0f43c0e5 |
children | 2107b4f40945 |
line wrap: on
line diff
--- a/data_manager/data_manager_snpEff_databases.py Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager/data_manager_snpEff_databases.py Tue Apr 18 09:40:03 2017 -0400 @@ -6,33 +6,20 @@ import sys -def stop_err(msg): - sys.stderr.write(msg) - sys.exit(1) - - -def fetch_databases(data_manager_dict, target_directory, jar_path): - (snpEff_dir, snpEff_jar) = os.path.split(jar_path) +def fetch_databases(data_manager_dict, target_directory): if not os.path.exists(target_directory): os.makedirs(target_directory) databases_path = os.path.join( target_directory, 'databases.out' ) databases_output = open(databases_path, 'w') - args = [ 'java', '-jar' ] - args.append( snpEff_jar ) - args.append( 'databases' ) - # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" ) - # databases_output = open(databases_path) - # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() ) - proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) - return_code = proc.wait() + args = ['snpEff', 'databases'] + return_code = subprocess.call(args=args, shell=False, stdout=databases_output.fileno()) if return_code: sys.exit( return_code ) databases_output.close() data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) data_manager_dict['data_tables']['snpeff4_databases'] = data_manager_dict['data_tables'].get( 'snpeff4_databases', [] ) data_table_entries = [] - try: - fh = open(databases_path, 'r') + with open(databases_path, 'r') as fh: for i, line in enumerate(fh): fields = line.split('\t') if len(fields) >= 2: @@ -45,17 +32,11 @@ description = fields[1].strip() + ' : ' + genome_version data_table_entries.append(dict(value=genome_version, name=description)) data_manager_dict['data_tables']['snpeff4_databases'] = data_table_entries - except Exception as e: - stop_err( 'Error parsing %s %s\n' % (databases_path, str( e )) ) - else: - fh.close() return data_manager_dict def main(): - # Parse Command Line parser = optparse.OptionParser() - parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' ) (options, args) = parser.parse_args() filename = args[0] @@ -66,7 +47,7 @@ data_manager_dict = {} # Create Defuse Reference Data - data_manager_dict = fetch_databases( data_manager_dict, target_directory, options.jar_path) + data_manager_dict = fetch_databases( data_manager_dict, target_directory) # save info to json file open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )