Mercurial > repos > jjohnson > data_manager_snpeff
comparison data_manager/data_manager_snpEff_databases.py @ 6:a329eda0cdff draft default tip
Uploaded
author | jjohnson |
---|---|
date | Wed, 09 Dec 2015 13:49:55 -0500 |
parents | 78bcf4ac437c |
children |
comparison
equal
deleted
inserted
replaced
5:78bcf4ac437c | 6:a329eda0cdff |
---|---|
16 | 16 |
17 def stop_err(msg): | 17 def stop_err(msg): |
18 sys.stderr.write(msg) | 18 sys.stderr.write(msg) |
19 sys.exit(1) | 19 sys.exit(1) |
20 | 20 |
21 def getSnpeffVersion(jar_path): | |
22 snpeff_version = 'SnpEff ?.?' | |
23 (snpEff_dir,snpEff_jar) = os.path.split(jar_path) | |
24 stderr_path = 'snpeff.err' | |
25 stderr_fh = open(stderr_path,'w') | |
26 args = [ 'java','-jar', ] | |
27 args.append( snpEff_jar ) | |
28 args.append( '-h' ) | |
29 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stderr=stderr_fh.fileno() ) | |
30 return_code = proc.wait() | |
31 if return_code != 255: | |
32 sys.exit( return_code ) | |
33 stderr_fh.close() | |
34 fh = open(stderr_path,'r') | |
35 for line in fh: | |
36 m = re.match('^[Ss]npEff version (SnpEff)\s*(\d+\.\d+).*$',line) | |
37 if m: | |
38 snpeff_version = m.groups()[0] + m.groups()[1] | |
39 break | |
40 fh.close() | |
41 return snpeff_version | |
42 | |
43 def fetch_databases(data_manager_dict, target_directory, jar_path): | 21 def fetch_databases(data_manager_dict, target_directory, jar_path): |
44 (snpEff_dir,snpEff_jar) = os.path.split(jar_path) | 22 (snpEff_dir,snpEff_jar) = os.path.split(jar_path) |
45 if not os.path.exists(target_directory): | 23 if not os.path.exists(target_directory): |
46 os.makedirs(target_directory) | 24 os.makedirs(target_directory) |
47 databases_path = os.path.join( target_directory, 'databases.out' ) | 25 databases_path = os.path.join( target_directory, 'databases.out' ) |
55 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) | 33 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) |
56 return_code = proc.wait() | 34 return_code = proc.wait() |
57 if return_code: | 35 if return_code: |
58 sys.exit( return_code ) | 36 sys.exit( return_code ) |
59 databases_output.close() | 37 databases_output.close() |
60 snpeff_version = getSnpeffVersion(jar_path) | |
61 try: | 38 try: |
62 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) | 39 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) |
63 data_manager_dict['data_tables']['snpeffv_databases'] = data_manager_dict['data_tables'].get( 'snpeffv_databases', [] ) | 40 data_manager_dict['data_tables']['snpeff4_databases'] = data_manager_dict['data_tables'].get( 'snpeff4_databases', [] ) |
64 data_table_entries = [] | 41 data_table_entries = [] |
65 fh = open(databases_path,'r') | 42 fh = open(databases_path,'r') |
66 for i,line in enumerate(fh): | 43 for i,line in enumerate(fh): |
67 fields = line.split('\t') | 44 fields = line.split('\t') |
68 if len(fields) >= 2: | 45 if len(fields) >= 2: |
71 continue | 48 continue |
72 #snpeff test genome | 49 #snpeff test genome |
73 if genome_version == '30c2c903' or fields[1].strip() == 'TestCase' or fields[1].strip().startswith('Test_'): | 50 if genome_version == '30c2c903' or fields[1].strip() == 'TestCase' or fields[1].strip().startswith('Test_'): |
74 continue | 51 continue |
75 description = fields[1].strip() + ' : ' + genome_version | 52 description = fields[1].strip() + ' : ' + genome_version |
76 key = snpeff_version + '_' + genome_version | 53 data_table_entries.append(dict(value=genome_version, name=description)) |
77 data_table_entries.append(dict(key=key, version=snpeff_version, value=genome_version, name=description)) | 54 data_manager_dict['data_tables']['snpeff4_databases'] = data_table_entries |
78 data_manager_dict['data_tables']['snpeffv_databases'] = data_table_entries | |
79 except Exception, e: | 55 except Exception, e: |
80 stop_err( 'Error parsing %s %s\n' % (config,str( e )) ) | 56 stop_err( 'Error parsing %s %s\n' % (config,str( e )) ) |
81 else: | 57 else: |
82 fh.close() | 58 fh.close() |
83 return data_manager_dict | 59 return data_manager_dict |