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