annotate data_manager/data_manager_eggnog.py @ 1:df699325bb3b draft default tip

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