diff data_manager/data_manager_snpEff_databases.py @ 5:78bcf4ac437c

Use tool_data_table with key and version columns added to allow for multiple versions in a .loc file
author Jim Johnson <jj@umn.edu>
date Tue, 13 Jan 2015 12:54:20 -0600
parents c6769a700e55
children a329eda0cdff
line wrap: on
line diff
--- a/data_manager/data_manager_snpEff_databases.py	Thu Oct 23 05:43:46 2014 -0500
+++ b/data_manager/data_manager_snpEff_databases.py	Tue Jan 13 12:54:20 2015 -0600
@@ -18,6 +18,28 @@
     sys.stderr.write(msg)
     sys.exit(1)
 
+def getSnpeffVersion(jar_path):
+    snpeff_version = 'SnpEff ?.?'
+    (snpEff_dir,snpEff_jar) = os.path.split(jar_path)
+    stderr_path = 'snpeff.err'
+    stderr_fh = open(stderr_path,'w')
+    args = [ 'java','-jar', ]
+    args.append( snpEff_jar )
+    args.append( '-h' )
+    proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stderr=stderr_fh.fileno() )
+    return_code = proc.wait()
+    if return_code != 255:
+        sys.exit( return_code )
+    stderr_fh.close()
+    fh = open(stderr_path,'r')
+    for line in fh:
+        m = re.match('^[Ss]npEff version (SnpEff)\s*(\d+\.\d+).*$',line)
+        if m:
+            snpeff_version = m.groups()[0] + m.groups()[1]
+            break
+    fh.close()
+    return snpeff_version
+
 def fetch_databases(data_manager_dict, target_directory, jar_path):
     (snpEff_dir,snpEff_jar) = os.path.split(jar_path)
     if not os.path.exists(target_directory):
@@ -35,9 +57,10 @@
     if return_code:
         sys.exit( return_code )
     databases_output.close()
+    snpeff_version = getSnpeffVersion(jar_path)
     try:
         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_manager_dict['data_tables']['snpeffv_databases'] = data_manager_dict['data_tables'].get( 'snpeffv_databases', [] )
         data_table_entries = []
         fh = open(databases_path,'r')
         for i,line in enumerate(fh):
@@ -50,8 +73,9 @@
                 if genome_version == '30c2c903' or fields[1].strip() == 'TestCase' or fields[1].strip().startswith('Test_'):
                     continue
                 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
+                key = snpeff_version + '_' + genome_version
+                data_table_entries.append(dict(key=key, version=snpeff_version, value=genome_version, name=description))
+        data_manager_dict['data_tables']['snpeffv_databases'] = data_table_entries
     except Exception, e:
         stop_err( 'Error parsing %s %s\n' % (config,str( e )) )
     else: