-
Notifications
You must be signed in to change notification settings - Fork 4
/
tree_precision.py
executable file
·42 lines (32 loc) · 1.22 KB
/
tree_precision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import sys
try:
import argparse as ap
except ImportError:
sys.stderr.write( "argparse not found" )
sys.exit(-1)
try:
import pyphlan as ppa
except ImportError:
sys.stderr.write( "pyphlan.py not found" )
sys.exit(-1)
def read_params( args ):
p = ap.ArgumentParser(description='Compute taxonomic precision')
p.add_argument( 'intree', nargs='?', default=None, type=str,
help= "the input tree [stdin if not present]")
p.add_argument('out_file', nargs='?', default=None, type=str,
help= "the out file [stdout if not present]")
p.add_argument('-f', default=None, type=str,
help= "file containing the list of taxonomic clades to test "
"end the corresponding leaf taxa" )
st = ['lca','ltcs']
p.add_argument('-s', choices=st, default='lca', type=str,
help= "select the lcs strategy")
return vars( p.parse_args() )
if __name__ == "__main__":
args = read_params( sys.argv )
tree = ppa.PpaTree( args['intree'] )
res = tree.tax_precision( args['f'], strategy = args['s'] )
with open( args['out_file'], "w") as outf:
for r in res:
outf.write( "\t".join( r ) + "\n" )