Mercurial > repos > galaxyp > data_manager_eggnog_mapper
annotate data_manager/data_manager_eggnog.py @ 1:077cf0a99144 draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit 2200885b5049b2d952959001c8a9b5ae5c62bee5"
author | galaxyp |
---|---|
date | Fri, 04 Sep 2020 21:38:59 +0000 |
parents | 6d8144eef202 |
children | 3d82020b1e3b |
rev | line source |
---|---|
0
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
1 #!/usr/bin/env python |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
2 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
3 from __future__ import print_function |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
4 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
5 import argparse |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
6 import json |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
7 import os.path |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
8 import sqlite3 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
9 import sys |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
10 from sqlite3 import OperationalError |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
11 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
12 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
13 def _get_db_version(sqlitedb_path): |
1
077cf0a99144
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit 2200885b5049b2d952959001c8a9b5ae5c62bee5"
galaxyp
parents:
0
diff
changeset
|
14 version = '5.0' |
0
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
15 try: |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
16 query = 'select version from version' |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
17 conn = sqlite3.connect(sqlitedb_path) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
18 cur = conn.cursor() |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
19 cur.execute(query) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
20 version = cur.fetchone()[0] |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
21 except OperationalError as e: |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
22 print('Assuming eggnog version %s because %s %s' % |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
23 (version, sqlitedb_path, e), file=sys.stderr) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
24 return version |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
25 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
26 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
27 def main(): |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
28 parser = argparse.ArgumentParser() |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
29 parser.add_argument('--config_file') |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
30 parser.add_argument('--install_path') |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
31 args = parser.parse_args() |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
32 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
33 eggnog_db_path = os.path.join(args.install_path, 'eggnog.db') |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
34 if not os.path.exists(eggnog_db_path): |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
35 print('Can not open: %s' % eggnog_db_path, file=sys.stderr) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
36 exit(1) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
37 db_version = _get_db_version(eggnog_db_path) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
38 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
39 # params = json.loads(open(args.config_file).read()) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
40 dm_dict = {} |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
41 dm_dict['data_tables'] = dm_dict.get('data_tables', {}) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
42 data_table = 'eggnog_mapper_db' |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
43 dm_dict['data_tables'][data_table]\ |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
44 = dm_dict['data_tables'].get(data_table, []) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
45 data_table_entry = dict(value=db_version, name=db_version, |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
46 path=args.install_path) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
47 dm_dict['data_tables'][data_table].append(data_table_entry) |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
48 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
49 # save info to json file |
1
077cf0a99144
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit 2200885b5049b2d952959001c8a9b5ae5c62bee5"
galaxyp
parents:
0
diff
changeset
|
50 open(args.config_file, 'w').write(json.dumps(dm_dict)) |
0
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
51 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
52 |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
53 if __name__ == "__main__": |
6d8144eef202
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper/eggnog_mapper_data_manager commit ba81f4bfe31157aa6b986e81d5e4405ae1372b3b"
galaxyp
parents:
diff
changeset
|
54 main() |