annotate data_manager/data_manager_eggnog.py @ 2:a74d61dbd155 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
author jjohnson
date Mon, 04 Nov 2019 16:38:44 -0500
parents
children 9d94fe7ce8b9
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
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
9 from sqlite3 import OperationalError
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
10 import sys
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
11
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
12 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
13 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
14 try:
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
15 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
16 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
17 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
18 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
19 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
20 except OperationalError as e:
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
21 print('Assuming eggnog version %s because %s %s' % (version, sqlitedb_path, e), 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
22 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
23
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
24 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
25 parser = argparse.ArgumentParser()
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
26 parser.add_argument( '--config_file' )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
27 parser.add_argument( '--install_path' )
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.add_argument( '--dbs', default='')
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
29 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
30
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
31 eggnog_db_path = os.path.join(args.install_path,'eggnog.db')
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
32 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
33 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
34 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
35 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
36
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
37 params = json.loads( open( args.config_file ).read() )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
38 data_manager_dict = {}
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
39 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
40 data_table = 'eggnog_mapper_db'
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
41 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get( data_table, [] )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
42 data_table_entry = dict(value=db_version, name=db_version, path=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
43 data_manager_dict['data_tables'][data_table].append( data_table_entry )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
44 data_table = 'eggnog_mapper_hmm_dbs'
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
45 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get( data_table, [] )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
46 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
47 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
48 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
49 key = '%s_%s' % (db_version, db)
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
50 data_table_entry = dict(key=key, db_version=db_version, value=db, name=db, path=db)
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
51 data_manager_dict['data_tables'][data_table].append( data_table_entry )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
52
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
53 # save info to json file
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
54 open( args.config_file, 'wb' ).write( json.dumps( data_manager_dict ) )
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
55
a74d61dbd155 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/eggnog_mapper commit f431329cd1c7f8a6014207a4ebfd9ffaa67e5497-dirty
jjohnson
parents:
diff changeset
56 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
57 main()