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