comparison data_manager/data_manager_eggnog.py @ 3:9d94fe7ce8b9 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit e711920c41c8862d7d8133f7b455cf475924e103
author jjohnson
date Tue, 05 Nov 2019 15:53:42 -0500
parents a74d61dbd155
children ea9772670fb5
comparison
equal deleted inserted replaced
2:a74d61dbd155 3:9d94fe7ce8b9
4 4
5 import argparse 5 import argparse
6 import json 6 import json
7 import os.path 7 import os.path
8 import sqlite3 8 import sqlite3
9 import sys
9 from sqlite3 import OperationalError 10 from sqlite3 import OperationalError
10 import sys 11
11 12
12 def _get_db_version(sqlitedb_path): 13 def _get_db_version(sqlitedb_path):
13 version = '4.5' 14 version = '4.5'
14 try: 15 try:
15 query = 'select version from version' 16 query = 'select version from version'
16 conn = sqlite3.connect(sqlitedb_path) 17 conn = sqlite3.connect(sqlitedb_path)
17 cur = conn.cursor() 18 cur = conn.cursor()
18 cur.execute(query) 19 cur.execute(query)
19 version = cur.fetchone()[0] 20 version = cur.fetchone()[0]
20 except OperationalError as e: 21 except OperationalError as e:
21 print('Assuming eggnog version %s because %s %s' % (version, sqlitedb_path, e), file=sys.stderr) 22 print('Assuming eggnog version %s because %s %s' %
23 (version, sqlitedb_path, e), file=sys.stderr)
22 return version 24 return version
25
23 26
24 def main(): 27 def main():
25 parser = argparse.ArgumentParser() 28 parser = argparse.ArgumentParser()
26 parser.add_argument( '--config_file' ) 29 parser.add_argument('--config_file')
27 parser.add_argument( '--install_path' ) 30 parser.add_argument('--install_path')
28 parser.add_argument( '--dbs', default='') 31 parser.add_argument('--dbs', default='')
29 args = parser.parse_args() 32 args = parser.parse_args()
30 33
31 eggnog_db_path = os.path.join(args.install_path,'eggnog.db') 34 eggnog_db_path = os.path.join(args.install_path, 'eggnog.db')
32 if not os.path.exists(eggnog_db_path): 35 if not os.path.exists(eggnog_db_path):
33 print('Can not open: %s' % eggnog_db_path, file=sys.stderr) 36 print('Can not open: %s' % eggnog_db_path, file=sys.stderr)
34 exit(1) 37 exit(1)
35 db_version = _get_db_version(eggnog_db_path) 38 db_version = _get_db_version(eggnog_db_path)
36 39
37 params = json.loads( open( args.config_file ).read() ) 40 # params = json.loads(open(args.config_file).read())
38 data_manager_dict = {} 41 dm_dict = {}
39 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) 42 dm_dict['data_tables'] = dm_dict.get('data_tables', {})
40 data_table = 'eggnog_mapper_db' 43 data_table = 'eggnog_mapper_db'
41 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get( data_table, [] ) 44 dm_dict['data_tables'][data_table]\
42 data_table_entry = dict(value=db_version, name=db_version, path=eggnog_db_path) 45 = dm_dict['data_tables'].get(data_table, [])
43 data_manager_dict['data_tables'][data_table].append( data_table_entry ) 46 data_table_entry = dict(value=db_version, name=db_version,
47 path=eggnog_db_path)
48 dm_dict['data_tables'][data_table].append(data_table_entry)
44 data_table = 'eggnog_mapper_hmm_dbs' 49 data_table = 'eggnog_mapper_hmm_dbs'
45 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get( data_table, [] ) 50 dm_dict['data_tables'][data_table]\
51 = dm_dict['data_tables'].get(data_table, [])
46 if args.dbs: 52 if args.dbs:
47 dbs = [x.strip() for x in args.dbs.split(',')] 53 dbs = [x.strip() for x in args.dbs.split(',')]
48 for db in dbs: 54 for db in dbs:
49 key = '%s_%s' % (db_version, db) 55 key = '%s_%s' % (db_version, db)
50 data_table_entry = dict(key=key, db_version=db_version, value=db, name=db, path=db) 56 data_table_entry = dict(key=key, db_version=db_version,
51 data_manager_dict['data_tables'][data_table].append( data_table_entry ) 57 value=db, name=db, path=db)
58 dm_dict['data_tables'][data_table].append(data_table_entry)
52 59
53 # save info to json file 60 # save info to json file
54 open( args.config_file, 'wb' ).write( json.dumps( data_manager_dict ) ) 61 open(args.config_file, 'wb').write(json.dumps(dm_dict))
62
55 63
56 if __name__ == "__main__": 64 if __name__ == "__main__":
57 main() 65 main()