Skip to content

Commit 51ef924

Browse files
authored
Create orthoxml2rootHOGidLevel.py
1 parent d891d69 commit 51ef924

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

utils/orthoxml2rootHOGidLevel.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
import sys
3+
import logging
4+
import pyham
5+
6+
7+
"""
8+
To run
9+
python orthoxml2rootHOGidLevel.py fastoma_out
10+
fastoma_out: where species_tree_checked.nwk and FastOMA_HOGs.orthoxml are located.
11+
12+
output:
13+
a two-column tsv file, HOGid taxid
14+
15+
"""
16+
17+
18+
fastoma_out=sys.argv[1]
19+
20+
treeFile=fastoma_out+'/species_tree_checked.nwk'
21+
orthoxmlFile=fastoma_out+'/FastOMA_HOGs.orthoxml'
22+
23+
24+
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
25+
logger = logging.getLogger("hog")
26+
logger.setLevel(logging.INFO)
27+
28+
ham_analysis = pyham.Ham(treeFile, orthoxmlFile, use_internal_name=True)
29+
rootHOG_dic=ham_analysis.get_dict_top_level_hogs()
30+
HOGid_level_list=[]
31+
for HOGid, HOG in rootHOG_dic.items():
32+
level=HOG.__dict__['_properties']['TaxRange']
33+
HOGid_level_list.append((HOGid,level))
34+
print('We found ' +str(len(HOGid_level_list))+ ' rootHOGs.')
35+
36+
output_f = open('FastOMA_HOGs.level.tsv','w')
37+
output_f.write('##rootHOGid'+'\t'+'TaxRange'+'\n')
38+
for HOGid,level in HOGid_level_list :
39+
output_f.write(HOGid+'\t'+level+'\n')
40+
output_f.close()
41+
42+
print('RootHOGs level info is written in FastOMA_HOGs.level.tsv')

0 commit comments

Comments
 (0)