annotate data_manager/data_manager_snpEff_databases.py @ 1:85a23e2dd92b draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
author iuc
date Tue, 07 Jun 2016 10:11:50 -0400
parents 9ac823a8b328
children 847b0f43c0e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
2 import json
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
3 import optparse
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
4 import os
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
5 import subprocess
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
6 import sys
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
7
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
8
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
9 def stop_err(msg):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
10 sys.stderr.write(msg)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
11 sys.exit(1)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
12
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
13
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
14 def fetch_databases(data_manager_dict, target_directory, jar_path):
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
15 (snpEff_dir, snpEff_jar) = os.path.split(jar_path)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
16 if not os.path.exists(target_directory):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
17 os.makedirs(target_directory)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
18 databases_path = os.path.join( target_directory, 'databases.out' )
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
19 databases_output = open(databases_path, 'w')
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
20 args = [ 'java', '-jar' ]
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
21 args.append( snpEff_jar )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
22 args.append( 'databases' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
23 # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
24 # databases_output = open(databases_path)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
25 # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
26 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
27 return_code = proc.wait()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
28 if return_code:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
29 sys.exit( return_code )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
30 databases_output.close()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
31 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} )
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
32 data_manager_dict['data_tables']['snpeff4_databases'] = data_manager_dict['data_tables'].get( 'snpeff4_databases', [] )
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
33 data_table_entries = []
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
34 try:
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
35 fh = open(databases_path, 'r')
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
36 for i, line in enumerate(fh):
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
37 fields = line.split('\t')
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
38 if len(fields) >= 2:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
39 genome_version = fields[0].strip()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
40 if genome_version.startswith("Genome") or genome_version.startswith("-"):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
41 continue
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
42 # snpeff test genome
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
43 if genome_version == '30c2c903' or fields[1].strip() == 'TestCase' or fields[1].strip().startswith('Test_'):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
44 continue
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
45 description = fields[1].strip() + ' : ' + genome_version
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
46 data_table_entries.append(dict(value=genome_version, name=description))
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
47 data_manager_dict['data_tables']['snpeff4_databases'] = data_table_entries
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
48 except Exception as e:
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
49 stop_err( 'Error parsing %s %s\n' % (databases_path, str( e )) )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
50 else:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
51 fh.close()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
52 return data_manager_dict
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
53
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
54
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
55 def main():
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
56 # Parse Command Line
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
57 parser = optparse.OptionParser()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
58 parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
59 (options, args) = parser.parse_args()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
60
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
61 filename = args[0]
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
62
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
63 params = json.loads( open( filename ).read() )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
64 target_directory = params[ 'output_data' ][0]['extra_files_path']
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
65 os.mkdir( target_directory )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
66 data_manager_dict = {}
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
67
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
68 # Create Defuse Reference Data
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
69 data_manager_dict = fetch_databases( data_manager_dict, target_directory, options.jar_path)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
70
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
71 # save info to json file
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
72 open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
73
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
74 if __name__ == "__main__":
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
75 main()