-
Notifications
You must be signed in to change notification settings - Fork 7
/
ot-taxon-subtree.py
executable file
·33 lines (27 loc) · 1.09 KB
/
ot-taxon-subtree.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
#!/usr/bin/env python
"""Simple command-line tool for reporting information a subtree of the OTT reference taxonomy using
which is described at https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs#subtree
"""
import sys
def fetch_and_write_taxon_subtree(ott_id, output):
from peyotl.sugar import taxonomy
subtree = taxonomy.subtree(ott_id)['subtree']
output.write(subtree)
output.write('\n')
def main(argv):
"""This function sets up a command-line option parser and then calls match_and_print
to do all of the real work.
"""
import argparse
description = 'Uses Open Tree of Life web services to find information for each OTT ID.'
parser = argparse.ArgumentParser(prog='ot-taxon-info', description=description)
parser.add_argument('ids', nargs='+', type=int, help='OTT IDs')
args = parser.parse_args(argv)
id_list = args.ids
for ott_id in id_list:
fetch_and_write_taxon_subtree(ott_id, sys.stdout)
if __name__ == '__main__':
try:
main(sys.argv[1:])
except Exception as x:
sys.exit('{}\n'.format(str(x)))