Mercurial > repos > iuc > data_manager_snpeff
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 |
rev | line source |
---|---|
0 | 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 | 4 import os |
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 | 7 |
8 | |
9 def stop_err(msg): | |
10 sys.stderr.write(msg) | |
11 sys.exit(1) | |
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 | 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 | 16 if not os.path.exists(target_directory): |
17 os.makedirs(target_directory) | |
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 | 21 args.append( snpEff_jar ) |
22 args.append( 'databases' ) | |
23 # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" ) | |
24 # databases_output = open(databases_path) | |
25 # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() ) | |
26 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) | |
27 return_code = proc.wait() | |
28 if return_code: | |
29 sys.exit( return_code ) | |
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 | 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 | 37 fields = line.split('\t') |
38 if len(fields) >= 2: | |
39 genome_version = fields[0].strip() | |
40 if genome_version.startswith("Genome") or genome_version.startswith("-"): | |
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 | 43 if genome_version == '30c2c903' or fields[1].strip() == 'TestCase' or fields[1].strip().startswith('Test_'): |
44 continue | |
45 description = fields[1].strip() + ' : ' + genome_version | |
46 data_table_entries.append(dict(value=genome_version, name=description)) | |
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 | 50 else: |
51 fh.close() | |
52 return data_manager_dict | |
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 | 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 | 57 parser = optparse.OptionParser() |
58 parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' ) | |
59 (options, args) = parser.parse_args() | |
60 | |
61 filename = args[0] | |
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 | 64 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
65 os.mkdir( target_directory ) | |
66 data_manager_dict = {} | |
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 | 69 data_manager_dict = fetch_databases( data_manager_dict, target_directory, options.jar_path) |
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 | 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() |